function getXmlhttp(){
var xmlhttp=false;
try{
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  //alert("You are using MSIE");
}catch(e){
  try{
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    //alert("You are using MSIE");
  }catch(E){
      xmlhttp=false;
  }
}
if(!xmlhttp && typeof XMLHttpRequest !='undefined'){
  xmlhttp=new XMLHttpRequest();
  //alert("You are not using MSIE");
}
return xmlhttp;
}

function ShowPopup(hoveritem, popup){
if(undefined==popup){popup='hoverpopup';}
hp = document.getElementById(popup);

// Set position of hover-over popup
  var coors = findPos(hoveritem);

  hp.style.top = coors[1] + 18 + 'px';
  hp.style.left = coors[0] + 20 + 'px';

//hp.style.top = hoveritem.offsetTop + 18;
//hp.style.left = hoveritem.offsetLeft + 20;

// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup(popup){
if(undefined==popup){popup='hoverpopup';}
hp = document.getElementById(popup);
hp.style.visibility = "Hidden";
document.getElementById("txtHint").innerHTML="";
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}

function ShowToolHelp(str)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/toolshelp.php";
  url=url+"?q="+str;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
      document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ShowKeywords(str,type,ID)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/keywords.php";
  url=url+"?q="+str+"&t="+type+"&id="+ID;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
    	//alert(url);
      document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ShowContactsRequest(userID,contactID)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/contactsrequest.php";
  url=url+"?u="+userID+"&c="+contactID;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
      document.getElementById("requestdetails"+contactID).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ShowCoAdminRequest(userID,requestID)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/coadminrequest.php";
  url=url+"?u="+userID+"&c="+requestID;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
      document.getElementById("requestcoadmindetails"+requestID).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function SendChanges(str1,str2,str3)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/makechanges.php";
  var params="p="+str1;
  params=params+"&q="+str2;
  params=params+"&r="+str3;
  xmlHttp.open("POST",url,true);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
       if(xmlHttp.responseText){
           alert(xmlHttp.responseText+" "+params);
           location.reload(true);
       }
       else{
           location.reload(true);
       }
    }
  }
  xmlHttp.send(params);
}

function CheckUniqueSlug(str)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/checkuniqueslug.php";
  url=url+"?q="+str;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
      document.getElementById("slugcheck").innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function CheckUniqueLogin(str,type)
{ 
  xmlHttp=getXmlhttp();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }
  var url="/scripts/checkuniquelogin.php";
  url=url+"?q="+str+"&t="+type;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function(){
    if (xmlHttp.readyState==4){
      document.getElementById(type).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 

function autocomp(thevalue,e,objectID,type)
{
	//alert(thevalue);
	theObject=document.getElementById('autocompletediv');
	theObject.style.width="152px";
	var textfieldObj=document.getElementById(objectID)
	var coors = findPos(textfieldObj);

	if(textfieldObj.offsetHeight) var objHeight=textfieldObj.offsetHeight;
	else if(textfieldObj.style.pixelHeight) var objHeight=textfieldObj.style.pixelHeight;

	var posx=coors[0];
	var posy=coors[1]+objHeight;
	theObject.style.left=posx+"px";
	theObject.style.top=posy+"px";

	var theextrachar;
	if(e){
		if (e.keyCode) theextrachar = e.keyCode;
		else if (e.which) theextrachar = e.which;
	}
	//the location we are loading the page into
	var ObjID="autocompletediv";
	//take into account the backspace
	if(theextrachar==8){
		if(thevalue.length==1){
			var serverPage="/scripts/autocomp.php";
		}else{
			var serverPage="/scripts/autocomp.php?q="+thevalue.substr(0,(thevalue.length-1))+"&t="+type+'&id='+objectID;
		}
	}else{
		var serverPage="/scripts/autocomp.php?q="+thevalue+String.fromCharCode(theextrachar)+"&t="+type+'&id='+objectID;
	}
	var obj=document.getElementById(ObjID);
	xmlHttp=getXmlhttp();
	xmlHttp.open("GET", serverPage);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 && xmlHttp.status==200){
			theObject.innerHTML=xmlHttp.responseText;
			//alert(serverPage);
			//alert("|"+xmlHttp.responseText+"|");
			if(xmlHttp.responseText==""){
				theObject.style.visibility="hidden";
				theObject.style.left="0px";
				theObject.style.top="0px";			
			}
			else{
				theObject.style.visibility="visible";
			}
		}
	}
	xmlHttp.send(null);
}

function setvalue(thevalue,objectID)
{
	acObject=document.getElementById('autocompletediv');
	acObject.style.visibility="hidden";
	acObject.style.left="0px";
	acObject.style.top="0px";
	document.getElementById(objectID).value=thevalue;
}

