var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"

function CropUserImage(idp){
	show_hide_centered_href('/en/przytnij-zdjecie.html?idp=' + idp, 600, 450, '', 0, 0, 'kim');
}

function ShowRegBox(){
	show_hide_centered_href('/en/simpleregister.html', 480, 400, '', 0, 0, '');
}

function ChangeMT(){
	document.getElementById('form_lista_wiad').submit();
}

function PDGift(ul){
	document.getElementById('guser').value = ul;
	document.getElementById('gform').submit();
}

function ChOn(){
	var o = document.getElementById('online'); 
	var og = document.getElementById('onlineg'); 
	var c = document.getElementById('chon'); 	
	var gm = document.getElementById('chongm'); 	
	var gf = document.getElementById('chongf'); 
	if(gm.checked == true && gf.checked == true ) og.value = 3;
	else if(gm.checked == true && gf.checked == false ) og.value = 1;	
	else if(gm.checked == false && gf.checked == true ) og.value = 2;	
	else og.value = 0;	
	if(c.checked == true) o.value = 2;
	else o.value = 1;
	search(0); 
}

function initAd(){
	if(!ns && !ie && !w3) return;
	if(ie)		adDiv=eval('document.all.alertDiv.style');
	else if(ns)	adDiv=eval('document.layers["alertDiv"]');
	else if(w3)	adDiv=eval('document.getElementById("alertDiv").style');
	if (ie||w3) adDiv.visibility="visible";
	else adDiv.visibility ="show";
	showAd();
}
function showAd(){
	if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}	
	else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
	documentHeight=window.innerHeight/2+window.pageYOffset-20;} 
	else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
	documentHeight=self.innerHeight/2+window.pageYOffset-20;} 
	adDiv.left=documentWidth-250+calunit;adDiv.top =documentHeight-200+calunit;
}

function closeAd(){
	if (ie||w3) adDiv.display="none";
	else adDiv.visibility ="hide";
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ponow(){
}

function ShoAlert(){
	var atext = "</br>";
	var TestXml = ajax3.responseXML;		
	var items = TestXml.getElementsByTagName("l");					
	for (var i=0; i<items.length; i++){
		var login = TestXml.getElementsByTagName("l")[i].firstChild.nodeValue;
		var type = TestXml.getElementsByTagName("t")[i].firstChild.nodeValue;
		atext += '<div><b>&raquo; You have just received a ' + type + ' from <a href="/users/' + login + '/">' + login + '</a></b></div>';
	}
	
	if(items.length >= 1){
		document.getElementById("alertDiv").innerHTML = '<div style="width: 500px"><div class="kom"><div style="text-align:left; margin: 5px">Message online</div><div style="margin: 5px">' + atext + '</div><div style="text-align: right; margin: 5px;"><input type="button" class="btt-1" id="close" value="zamknij" onclick="closeAd()" /></div></div></div>';
		initAd();
	}
}

function DeleteChecked(){
	if(qconfirm("Are you sure you want to delete this message?")) document.forms[0].submit();
}

function DeleteCheckedO(){
	if(qconfirm("Are you sure you want to delete this message?")) document.getElementById('delf').submit();
}

function online(){		
}	

function loadtext(){
	var e = document.getElementById('sendme'); 
	e.innerHTML = "<div class='loading'>Please wait ...</div>";
}

function SendVote(login, vote){
	document.getElementById('sendme').className = 'kom';
	var ajax2 = new sack();
	ajax2.setVar("SendData", "1");
	ajax2.setVar("type", 4);
	ajax2.setVar("vote", vote);		
	ajax2.setVar("login", login);	
	ajax2.setVar("lang", "english");
	ajax2.requestFile = "/_ajax/send.php";
	ajax2.element = 'sendme';
	ajax2.onLoading = loadtext;
	ajax2.onLoaded = loadtext; 
	ajax2.onInteractive = loadtext;
	ajax2.method = "POST";
	ajax2.runAJAX();
}

function Send(login, type){
	document.getElementById('sendme').className = 'kom';
	ajax2.setVar("SendData", "1");
	ajax2.setVar("type", type);			
	ajax2.setVar("login", login);	
	ajax2.setVar("lang", "english");
	ajax2.requestFile = "/_ajax/send.php";
	ajax2.element = 'sendme';
	ajax2.onLoading = loadtext;
	ajax2.onLoaded = loadtext; 
	ajax2.onInteractive = loadtext;
	ajax2.method = "POST";
	ajax2.runAJAX();
}

function SendMail(login){
	document.location.href='/en/moje-konto-poczta-napisz-wiadomosc-' + login + '.html';
}

function SendSmile(login){	
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";
	e.className = "kom2";
	if(qconfirm("Are you sure you want to send a smile to " + login)) Send(login, 1);	
}

function SendKiss(login){	
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";
	if(qconfirm("Are you sure you want to send a kiss to " + login)) Send(login, 2);	
}

function AddToAdressBook(login){
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";	
	if(qconfirm("Are you sure you want to add " + login + " to your contacts")) Send(login, 3);	
}

function confirm2(page){
	var e = document.getElementById('changed');
	if(e){
		if(e.value == 1){
			if(qconfirm("Are you sure you want to leave this page without saving the changes?")) return true;
			else return false;
		}
	}
}

function qconfirm(qtext){ 
	if (typeof(window.opera) != 'undefined') return true; 
	var is_confirmed = confirm(qtext); 
	return is_confirmed; 
}	

function SBlog(typ){
	ajax.setVar("lang", "english");
	ajax.setVar("UserLogin", document.getElementById('UserLogin').value);
	ajax.setVar("n", document.getElementById('n').value);
	ajax.setVar("idBlog", document.getElementById('idBlog').value);
	
	if(typ=="1"){
	
		ajax.setVar("GetData", "0");
		ajax.setVar("SendData", "1");
		ajax.setVar("newsubject", document.getElementById('newsubject').value);
		ajax.setVar("newcontent", document.getElementById('newcontent').value);	
		
	}else{
	
		ajax.setVar("GetData", "1");
		ajax.setVar("SendData", "0");	
		ajax.setVar("newsubject", "");
		ajax.setVar("newcontent", "");		
	}
	
	ajax.requestFile = "/_ajax/blog.php";
	ajax.element = 'data5';
	ajax.method = "POST";
	ajax.runAJAX();	
		
}

function Abuse(login, ses, l){
	if(l == 1) show_hide_centered_href('/en/abuse.html?user=' + login +'&LID=' + ses, 480, 370, '', 0, 0, 'pmboxabuse');
	else{
		document.getElementById('sendme').className = 'kom';
		document.getElementById('sendme').innerHTML = "<div style=\"color: red\">You need to be logged in to be able to use this function.</div>";	
	}
}

function AddToFriends(login){
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";	
	if(qconfirm("Are you sure you want to invite " + login + " to My Friends' list?")) Send(login, 5);	
}

function ConfirmDelete(id, login, type){
	if(type == 1) var m = "Are you sure you want to remove " + login + " from My Friends' list?";
	else if(type == 2) var m = login +  " has removed your profile from his/her friends. Would you like to remove his/her profile from My Friends' list as well?";
	if (confirm(m)) {
		document.getElementById('delfr').value = id;
		document.getElementById('fr').submit();
	}
}

function SFriends(typ){
	ajax.setVar("lang", "english");
	ajax.setVar("UserLogin", document.getElementById('UserLogin').value);
	ajax.setVar("n", document.getElementById('n').value);
	ajax.requestFile = "/_ajax/friends.php";
	ajax.element = 'data7';
	ajax.method = "POST";
	ajax.runAJAX();	
		
}

function checkPostCode (toCheck) {
  var alpha1 = "[abcdefghijklmnoprstuwyz]"; 
  var alpha2 = "[abcdefghklmnopqrstuvwxy]"; 
  var alpha3 = "[abcdefghjkstuw]"; 
  var alpha4 = "[abehmnprvwxy]";
  var alpha5 = "[abdefghjlnpqrstuwxyz]";
  var pcexp = new Array ();
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  var postCode = toCheck;
  var valid = false;
  for ( var i=0; i<pcexp.length; i++) {
	if (pcexp[i].test(postCode)) {
	  pcexp[i].exec(postCode);
	  postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
	  postCode = postCode.replace (/C\/O\s*/,"c/o ");
	  valid = true;
	  break;
	}
  }
  
  if (valid) {return postCode;} else return false;
}