var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"

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(){
	id = setInterval(online, 30000);
}

function DeleteChecked(){
	if(qconfirm("Czy napewno chcesz usun±ć?")) document.forms[0].submit();
}

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; Użytkownik <a href="/profile/' + login + '/">' + login + '</a> przesyła Ci ' + type + '</b></div>';
	}
	
	if(items.length >= 1){
		document.getElementById("alertDiv").innerHTML = '<div style="width: 500px"><div class="kom"><div style="text-align:left; margin: 5px">Powiadomienie 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 online(){	
	ajax3.setVar("r", "1");
	ajax3.requestFile = "/l/a/3.php";
	ajax3.method = "GET";
	ajax3.onCompletion = ShoAlert;
	ajax3.runAJAX();		
}	

function loadtext(){
	var e = document.getElementById('sendme'); 
	e.innerHTML = "<div class='loading'>Proszę czekać trwa wysyłanie</div>";
}

function Send(login, type){
	ajax2.setVar("SendData", "1");
	ajax2.setVar("type", type);			
	ajax2.setVar("login", login);	
	ajax2.requestFile = "/l/a/4.php";
	ajax2.element = 'sendme';
	ajax2.onLoading = loadtext;
	ajax2.onLoaded = loadtext; 
	ajax2.onInteractive = loadtext;
	ajax2.method = "POST";
	ajax2.runAJAX();
}

function WSendMessage(login){
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";	
	document.location.href='/my-mail-new-to-' + login + '.html';
}

function WSendSmile(login){	
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";	
	if(qconfirm("Czy napewno chcesz wysłać u¶miech do użytkownika " + login)) Send(login, 1);	
}

function WSendKiss(login){	
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";	
	if(qconfirm("Czy napewno chcesz wysłać buziaka do użytkownika " + login)) Send(login, 2);	
}

function WAddToContacts(login){
	var e = document.getElementById('sendme'); 
	e.innerHTML = "";	
	if(qconfirm("Czy napewno chcesz dodać użytkownika " + login + " do swoich kontaktów")) Send(login, 3);	
}

function qconfirm(qtext){ 
	if (typeof(window.opera) != 'undefined') return true; 
	var is_confirmed = confirm(qtext); 
	return is_confirmed; 
}

function JBlog(id){
	
	if(id == 1){
		document.getElementById('jblog1').className = 'ublog sel';
		document.getElementById('jblog0').className = 'uprofile';
		document.getElementById('ublog').style.display='';	
		document.getElementById('udata').style.display='none';	
		document.getElementById('idBlog').value = '';
		document.getElementById('n').value = '';
		SBlog(0);
	
	}else{	
		document.getElementById('jblog1').className = 'ublog';
		document.getElementById('jblog0').className = 'uprofile sel';
		document.getElementById('ublog').style.display='none';	
		document.getElementById('udata').style.display='';	
	
	}
	
}

function SBlog(typ){
	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 = "/l/a/5.php";
	ajax.element = 'ublog';
	ajax.method = "POST";
	ajax.runAJAX();	
		
}
