/*
// Copyright reserved to ConspiracyHub Owner!
*/


function addslashes(str){
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str){
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}

//// Space for AJAX mods \\\\
function advanced(){
	var obj;
	var obj2;
	obj = document.getElementById("users_simple");
	obj.className = 'hide';
	obj2 = document.getElementById("users_advanced");
	obj2.className = 'show';
}

function simple(){
	var obj;
	var obj2;
	obj2 = document.getElementById("users_advanced");
	obj2.className = 'hide';
	obj = document.getElementById("users_simple");
	obj.className = 'show';
}
function descriptor(val){
	var obj;
	obj = document.getElementById("descriptor");
	if (!obj) return;
	obj.firstChild.nodeValue = val;
}

function ajax_createRequestObject(){
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

var ajax_http = ajax_createRequestObject();
var ajax_destObj;
function SetSize(obj, x_size){
	if (obj.offsetWidth > x_size){
		obj.style.width = x_size;
	}
}

var c=0;
function shoutthis_ajax(){
	c=0; //reset counter 
	this.ts = window.setInterval("shoutload()",30000);
	//this.ta = window.setInterval("getactive()",32000);
	this.tw = window.setInterval("whosonlineload()",60000);
	this.tpm = window.setInterval("sendPmId()",120000);
	this.idletime = window.setInterval("stopall()",900000);
}

showsmiles = "show";
inprivate = "no";
 
function sndReq(argumentString, destStr){
	showprivateonly = "";
	if(inprivate == "no"){
		showprivateonly = argumentString;
	}else{
		showprivateonly = argumentString+"&shoutuser="+inprivate;
	}
	//alert(showprivateonly);

	if(argumentString == "op=activeusers"){
		//alert("user");
		refreshoff = true;
	}
	
	if(argumentString == "op=view_shout"){
		refreshoff = false;
	}
	if(argumentString.substring(0,14) == "op=more_smiles"){
		if(showsmiles == "show"){
			showsmiles = "hide";
			ajax_destObj = document.getElementById(destStr);
			ajax_http.open('get', './ajax.php?'+showprivateonly);
			ajax_http.onreadystatechange = ajax_handleResponse;
			ajax_http.send(null);
		}
		else if(showsmiles == "hide"){
			showsmiles = "show";
			ajax_destObj = document.getElementById(destStr);
			ajax_http.open('get', './ajax.php?op=take_edit_shout_cancel');
			ajax_http.onreadystatechange = ajax_handleResponse;
			ajax_http.send(null);
		}
	}else{
		ajax_destObj = document.getElementById(destStr);
		ajax_http.open('get', './ajax.php?'+showprivateonly);
		ajax_http.onreadystatechange = ajax_handleResponse;
		ajax_http.send(null);
	}
}

function toggleprivate(nome, pmshout){
	//alert(inprivate);
	//alert(document.getElementById(nome).attributes["onclick"].value)
	if(document.getElementById(nome).value=="Shout!"){
		//document.getElementById(nome).style.display = '';
		 inprivate = pmshout;
		document.getElementById(nome).value= _btshoutnowprivate;
		document.getElementById(nome).attributes["onclick"].value="sndprivateshoutReq(text.value, 'shout_out', '"+pmshout+"')";
		document.getElementById("shoutthisch").attributes["onclick"].value="toggleprivate('shout_send'); sndReq('op=view_shout', 'shout_out');";
		document.getElementById("shout_textarea").attributes["onkeypress"].value="if (event.keyCode == 13) {sndprivateshoutReq(this.value, 'shout_out', '"+pmshout+"');}";
	}else{
		//document.getElementById(nome).style.display = 'auto';
		 inprivate = 'no';
		document.getElementById(nome).value="Shout!";
		document.getElementById(nome).attributes["onclick"].value="sendshoutout(text.value, 'shout_out')";
		document.getElementById("shoutthisch").attributes["onclick"].value="sndReq('op=view_shout', 'shout_out');";
		document.getElementById("shout_textarea").attributes["onkeypress"].value="if (event.keyCode == 13) {sendshoutout(this.value, 'shout_out');}";
	}
}

function getactive(){
	//alert(inprivate);
	ajax_destObj = document.getElementById('shoutbox_activity');
	ajax_http.open('get', './ajax.php?op=getactive');
	ajax_http.onreadystatechange = ajax_handleResponse;
	ajax_http.send(null);
}

function stopall(){
	var div=document.getElementById('idleTD');
	if(div!=null)div.innerHTML ='<div id="mainbox"><p class="center"><span style="color:#FF0000;">Auto page updates are off.</span><br/><a href="?" onclick="return shoutthis_ajax();">Click here to reactivate.</a></p></div>';
	window.clearTimeout(this.ts);
	window.clearTimeout(this.ta);
	window.clearTimeout(this.tw);
	window.clearTimeout(this.tpm);
	window.clearTimeout(this.idletime);
}

function shoutload(){
	showprivateonly = '';
	//alert(inprivate);
	if(inprivate == 'no'){
		showprivateonly = '';
	}else{
		showprivateonly = '&shoutuser='+inprivate;
	}
	ajax_destObj = document.getElementById('shout_out');
	if(ajax_destObj == null){return}
	ajax_http.open('get', './ajax.php?op=view_shout'+showprivateonly);
	ajax_http.onreadystatechange = ajax_handleResponse;
	ajax_http.send(null);
}

function whosonlineload(){
	ajax_destObj=document.getElementById('whosonlineTD');
	if(ajax_destObj==null){return}
	ajax_http.open('get','./ajax.php?op=view_whosonline');
	ajax_http.onreadystatechange=ajax_handleResponse;
	ajax_http.send(null);
}

function sndprivateshoutReq(argumentString, destStr, sendto){
	//alert(argumentString);
	//validate(theform)
	ajax_destObj = document.getElementById(destStr);
	ajax_http.open('get', './ajax.php?op=take_shout&sendto='+sendto+'&text='+argumentString);
	ajax_http.onreadystatechange = ajax_handleResponse;
	ajax_http.send(null);
	//shoutload();
}
function makeurlsafe(text){
	argumentString = text.replace(/&/,"/amp2/");
	return argumentString;
}

function sndshoutReq(argumentString, destStr){
	//alert(makeurlsafe(argumentString));
	//validate(theform)
	ajax_destObj = document.getElementById(destStr);
	ajax_http.open('get', './ajax.php?op=take_shout&text='+makeurlsafe(argumentString));
	ajax_http.onreadystatechange = ajax_handleResponse;
	ajax_http.send(null);
	//shoutload();
}

function sendshoutout(text,destStr){
	c=0;
	//alert(destStr);
	sndshoutReq(text,destStr);
	//shoutload();
}

function ajax_handleResponse(){
	if(ajax_http.readyState == 4){
		var response = ajax_http.responseText;
		if(ajax_destObj != null)ajax_destObj.innerHTML = response;
		//alert(response);
		//ajax_destObj.innerHTML = response;
	}else if(ajax_http.readyState == 1 ){
		// Uncomment the next line if you want
		// to display a Loading text. This will
		// cause the page to blink if lots of
		// data is being transferred. I vote off.
		// However, if your server is slow and
		// you want to tell your users something
		// is being processed, turn it on.
		//ajax_destObj.innerHTML = '<img src="/images/please_wait.gif" title="Loading" border="0" alt="Loading" />';
	}
}
//// END AJAX MODS \\\\

function SetSize(obj, x_size){
	if (obj.offsetWidth > x_size) {
		obj.style.width = x_size;
	}
}

function sendPmId(){
	if(document.getElementById("nopm_notif")){
		try{
		  // Firefox, Opera 8.0+, Safari
		  pmIdsend=new XMLHttpRequest();
		}
		catch(e){
			// Internet Explorer
			try{
				pmIdsend=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e){
				try{
					pmIdsend=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e){
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		 }		  

	pmIdsend.onreadystatechange = pmResponse;
	pmIdsend.open("GET","./pm_ajax.php");
	pmIdsend.send(null);
	return false;
	}  
}

function pmResponse(){
	if(pmIdsend.readyState == 4){
		if(pmIdsend.status == 200){// ok
			try { // precte odpoved
				var response = pmIdsend.responseText;
				//alert(response);
				if(response.length == 0) throw "Invalid server response.";
				/*if(response.indexOf("login_error") >= 0) {
				zobrazChybuPrihlaseni();
				return;
				}*/
				response = pmIdsend.responseXML.documentElement;
				stav = response.getElementsByTagName("status"); // vsechny elementy kontakt
				// nepodarilo se ulozit
				if(stav[0].firstChild.data != "OK"){
					alert("Message was not saved!\n");
					//document.getElementById('tarea_text').focus();
				}else{ //else  zjistiPocetZpravAjax(); //odeslanoOK = true;
					pm = response.getElementsByTagName("pm");
					if(pm[0].firstChild.data != "false"){
						 // alert(pm[0].firstChild.data+"\n");
						pmNotif = document.getElementById("nopm_notif");
						pmNotif.id = "pm_notif";  

						while(pmNotif.hasChildNodes()) pmNotif.removeChild(pmNotif.firstChild);

						a = document.createElement("a");
						atr = document.createAttribute("href");
						atr.value = "pm.php?op=inbox";
						a.setAttributeNode(atr);
						txt = document.createTextNode(pm[0].firstChild.data);
						a.appendChild(txt);
						blink = document.createElement("blink");
						blink.appendChild(a);
						pmNotif.appendChild(blink);

						conftext = response.getElementsByTagName("confirm");
						conftext = conftext[0].firstChild.data;
						var answer = confirm (conftext);
						if (answer) window.location="pm.php?op=inbox";
					}
				}				
			}
			catch(e) {
				alert("Error when processing:\n " + e.toString());
			}
		}
	}
}

var newwindow;
function popshout(url){
	newwindow=window.open(url,'popshout','height=500,width=900');
}

function openWin(url, width, height, windowid){
	return window.open(
		url,
		(typeof windowid == 'undefined' ? 'vBPopup' : windowid),
		'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes'
		+ (typeof width != 'undefined' ? (',width=' + width) : '') + (typeof height != 'undefined' ? (',height=' + height) : '')
	);
}

function popusers(url){
	newwindow=window.open(url,'popusers','height=70,width=400');
	if (window.focus) {newwindow.focus()}
}

function togglesec(elem,tempValue,tempValue2){
	if(document.getElementById(elem).style.display=='none'){
	document.getElementById(elem).style.display='';
	document.getElementById(elem+"img").src=tempValue2;
	}else{
	document.getElementById(elem).style.display='none';
	document.getElementById(elem+"img").src=tempValue;
	}
}

open_window=function(url, width, height, hash){openWindow(url,width,height,'Attach'+hash);}
