adTime=3;  // seconds ad reminder is shown
chanceAd=1; // ad will be shown 1 in X times (put 1 for everytime)

var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
var expanded = 0;

adCount=0;
function initAd(){
//chanceAd=1;
adCount=0;
	if(!ns && !ie && !w3) return;
	if(ie)		adDiv=eval('document.all.sponsorAdDiv.style');
	else if(ns)	adDiv=eval('document.layers["sponsorAdDiv"]');
	else if(w3)	adDiv=eval('document.getElementById("sponsorAdDiv").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-200+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 quickedit(pid, type) {
	var pid1 = pid;
	var xmlHttp = false;

	if((type == null) || (type == "")){
		type = "quickedit_get";
	}

  	// Only go on if there are values for both fields
  	if ((pid1 == null) || (pid1 == "")){
	  	return;
  	}

	/* Create a new XMLHttpRequest object to talk to the Web server */

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
  		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
  		try {
    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} catch (e2) {
    			xmlHttp = false;
  		}
	}
	@end @*/
	if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
  		xmlHttp = new XMLHttpRequest();
		if(type == "quickedit_update")
		{
			xmlHttp.overrideMimeType('application/x-www-form-urlencoded');
			//xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		}
		else
		{
			xmlHttp.overrideMimeType('text/plain');
		}
	}


  	// Build the URL to connect to
  	// Open a connection to the server
	if((type == "quickedit_get") || (type == "quickedit_cancel"))
	{
		var url = "./quickedit_process.php?pid=" + escape(pid1) + "&action="+type;
  		xmlHttp.open("GET", url, true);
	}
	else
	{
		var url = "./quickedit_process.php?action=quickedit_update&pid=" + pid;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}

  	// Setup a function for the server to run when its done
  	xmlHttp.onreadystatechange = function() {
  				if (xmlHttp.readyState == 4) {
					if(type == "quickedit_get")
					{
						var text = '<textarea id="quickedit_pid'+pid1+'" rows="7" cols="100">'+xmlHttp.responseText+'</textarea><br /><input type="Submit" onClick="javascript:quickedit(\''+pid1+'\', \'quickedit_update\');" value="Update"><input type="button" onClick="javascript:quickedit(\''+pid1+'\', \'quickedit_cancel\');" value="Cancel"><input type="button" onClick="javascript:document.location.href=\'./editpost.php?pid='+pid1+'\';" value="Full Edit">';
					}
					/*else if(type == "quickedit_cancel")
					{
						var text = xmlHttp.responseText;
					}
					else if(type == "quickedit_update")
					{
						var text = xmlHttp.responseText;
					}
					*/
					else
					{
						var text = xmlHttp.responseText;
					}
					document.getElementById("qpid"+pid1).innerHTML = text;
					closeAd();
					expanded = 0;
					//pointto.innerHTML = text;
  				}
				else
				{
					initAd();
					showAd();
					//document.getElementById('pid'+pid1).innerHTML="<textarea rows='5' cols='100'>Loading....</textarea>";
				}
			}

  	// Send the request
	if(type == "quickedit_update")
	{
		message = document.getElementById("quickedit_pid"+pid1).value;
  		xmlHttp.send("message="+escape(message));
	}
	else
	{
  		xmlHttp.send(null);
	}
}
