function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		subobj.style.left=xpos+20+"px"
		subobj.style.top=ypos+"px"
		return false
	}
	else
	return true
}

function highlight(field) {
  field.focus();
  field.select();
}

function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}


function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}

function checkReg(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url="ajax.php?check=reg&string="+str;
	xmlHttp.onreadystatechange=checkRegUpdate;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function checkRegUpdate() { 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.responseText=="8526eacab88d55fe95bc18fbabcd0ec5") {
			document.location="register.php?msg=register";
		} else {
			try {document.getElementById("errorbox").style.display="table-cell";} catch (e){try {document.getElementById("errorbox").style.display="inline";} catch (e){document.getElementById("errorbox").style.display="inline";}}
			try {document.getElementById("errorbox2").style.display="table-cell";} catch (e){try {document.getElementById("errorbox2").style.display="inline";} catch (e){document.getElementById("errorbox2").style.display="inline";}}		
			document.getElementById("errorbox").innerHTML=xmlHttp.responseText;
		}
	}
}

function checkAff(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url="ajax.php?check=aff&string="+str;
	xmlHttp.onreadystatechange=checkAffUpdate;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function checkAffUpdate() { 
	if (xmlHttp.readyState==4) {
		if (xmlHttp.responseText=="8526eacab88d55fe95bc18fbabcd0ec5") {
			document.location="affiliate.php?msg=affiliate";
		} else {
			try {document.getElementById("errorbox").style.display="table-cell";} catch (e){try {document.getElementById("errorbox").style.display="inline";} catch (e){document.getElementById("errorbox").style.display="inline";}}
			try {document.getElementById("errorbox2").style.display="table-cell";} catch (e){try {document.getElementById("errorbox2").style.display="inline";} catch (e){document.getElementById("errorbox2").style.display="inline";}}		
			document.getElementById("errorbox").innerHTML=xmlHttp.responseText;
		}
	}
}

function checkLogin(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="/ajax.php?check=login&string="+str;
	xmlHttp.onreadystatechange=checkLoginUpdate;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function checkLoginUpdate() { 
	if (xmlHttp.readyState==4) {	
		if (xmlHttp.responseText=="8526eacab88d55fe95bc18fbabcd0ec5") {		
			document.location="login.php?msg=login";		
		} else {
			try {document.getElementById("errorbox").style.display="table-cell";} catch (e){try {document.getElementById("errorbox").style.display="inline";} catch (e){document.getElementById("errorbox").style.display="inline";}}
			try {document.getElementById("errorbox2").style.display="table-cell";} catch (e){try {document.getElementById("errorbox2").style.display="inline";} catch (e){document.getElementById("errorbox2").style.display="inline";}}	
			document.getElementById("errorbox").innerHTML=xmlHttp.responseText;
		}
	}
}

function checkAdminLogin(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="/ajax.php?check=adminlogin&string="+str;
	xmlHttp.onreadystatechange=checkAdminLoginUpdate;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function checkAdminLoginUpdate() { 
	if (xmlHttp.readyState==4) {	
		if (xmlHttp.responseText=="8526eacab88d55fe95bc18fbabcd0ec5") {		
			document.location="/admin";		
		} else {
			try {document.getElementById("errorbox").style.display="table-cell";} catch (e){try {document.getElementById("errorbox").style.display="inline";} catch (e){document.getElementById("errorbox").style.display="inline";}}
			try {document.getElementById("errorbox2").style.display="table-cell";} catch (e){try {document.getElementById("errorbox2").style.display="inline";} catch (e){document.getElementById("errorbox2").style.display="inline";}}	
			document.getElementById("errorbox").innerHTML=xmlHttp.responseText;
		}
	}
}

function checkImage(str) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="ajax.php?check=image&string="+str;
	xmlHttp.onreadystatechange=checkImageUpdate;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

var err=false;
var errc=0;
var errt=false;
var errs="";

function checkImageUpdate() { 
	if (xmlHttp.readyState==4) {
		var result=xmlHttp.responseText;
		var result2=result.split(",");
		if (result2[1] !== "") {
			errc=errc+1;
			document.getElementById("error"+result2[0]).innerHTML=result2[1];
		} else {
			if (errc > 0) {
				if (document.getElementById("error"+result2[0]).innerHTML!=="") {
					errc=errc-1;
				}
			}
			document.getElementById("error"+result2[0]).innerHTML="";
		}
		errt=false;
		if (errc > 0) {
			err=true;
		} else {
			err=false;
		}
	}
}

function checkImgErrs() {
	i=1;
	stuff=false;
	for (i>0;i<=30;i=i+1) {
	    if (document.getElementById("file["+i+"]").value !== "") {
	    	stuff="true";
	    }
	}
	if (stuff !== "true") {
		alert("You must upload at least one file.");	
		return false;
	}
	if (errc !== 0 || err == true && stuff=="true") {
		alert("Errors are present.");	
		return false;
	} else {
		document.getElementById("submit").disabled=true;
		return true;
	}
	
}