//credit to: http://jibbering.com/2002/4/httprequest.html
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function getrandomboxes() {
	var d = new Date()
	url="/xmlhttp.php?doit=getrandomboxes&x="+d.getTime()+"";
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("randomboxes").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-formresult');
	xmlhttp.send(null);
}

function getusercommlist(aid,numComms,page,per) {
	var d = new Date()
	url="/xmlhttp.php?doit=getusercommlist&authorid="+aid+"&numComms="+numComms+"&page="+page+"&per="+per+"&x="+d.getTime()+"";
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("usercommlist").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-formresult');
	xmlhttp.send(null);
}

function getuserfavboxeslist(aid,num,page,per) {
	var d = new Date()
	url="/xmlhttp.php?doit=getuserfavboxeslist&authorid="+aid+"&num="+num+"&page="+page+"&per="+per+"&x="+d.getTime()+"";
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("userfavboxeslist").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-formresult');
	xmlhttp.send(null);
}


function thumbsup(cid,uid,count,auth) {
	if (!uid || uid == 0) {
		alert("You must be logged in to vote for a comment!");
	} else {
		var d = new Date()
		url="/xmlhttp.php?doit=thumbsup&cid="+cid+"&count="+count+"&auth="+auth+"&x="+d.getTime()+"";
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById("x"+cid+"").innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.setRequestHeader('Accept','message/x-formresult');
		xmlhttp.send(null);
	}
	return false;
}

function thumbsdown(cid,uid,count,auth) {
	var d = new Date()
	url="/xmlhttp.php?doit=thumbsdown&cid="+cid+"&count="+count+"&auth="+auth+"&x="+d.getTime()+"";
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("x"+cid+"").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-formresult');
	xmlhttp.send(null);
	return false;
}

function showcommenteditor(cid,uid) {
	if (!uid || uid == 0) {
		alert("You must be logged in to edit a comment!");
	} else {
		var d = new Date()
		url="/xmlhttp.php?doit=showcommenteditor&cid="+cid+"&x="+d.getTime()+"";
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById("x"+cid+"").innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.setRequestHeader('Accept','message/x-formresult');
		xmlhttp.send(null);
	}
	return false;
}

function cancelcommedit(cid) {
	var d = new Date()
	url="/xmlhttp.php?doit=cancelcommedit&cid="+cid+"&x="+d.getTime()+"";
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("x"+cid+"").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-formresult');
	xmlhttp.send(null);
	return false;
}

function editcomment(cid,uid) {
	if (!uid || uid == 0) {
		alert("You must be logged in to edit a comment!");
	} else {
		var d = new Date()
		url="/xmlhttp.php?doit=editcomment&cid="+cid+"&x="+d.getTime()+"";
		xmlhttp.open("POST",url,true);
		comms = document.getElementById("ncomments").value;
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById("x"+cid+"").innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.setRequestHeader('Accept','message/x-formresult');
		xmlhttp.send(comms);
	}
	return false;
}

function emptychk(what, alertbox) {
	with (what) {
   		if (value==null || value=="") {
			if (alertbox!="") {
				alert(alertbox);
			} 
			return false;
		} else {
			return true;
		}
	}
}

function limText(field, countText, maxText) {
 if (field.value.length > maxText) {
  field.value = field.value.substring(0, maxText);
 } else {
  countText.value = maxText - field.value.length;
 }
}

function RevPop(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+''
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function emailchk(what, alertbox) {
	with (what) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			if (alertbox) {alert(alertbox);} return false;
		} else {
			return true;
		}
	}
}
  
//ANTI-SPAM EMAIL LINKS
function explodeArray(el,dl){
	a=new Array(1); var i=0; var s=new String(el); s=s.substring(7,s.length);
	while (s.indexOf(dl)>0){a[i]=s.substr(0,s.indexOf(dl)); s=s.substr(s.indexOf(dl)+1,s.length-s.indexOf(dl)+1); i=i+1}
	a[i]=s; return a;
}
var f=new RegExp(/^mailto:([a-zA-Z0-9_.-])+_at_NOSP_(([a-zA-Z0-9-])+_dot_)+([a-zA-Z0-9]{2,4})+$/);
window.onload=function() {
    if(document.getElementsByTagName) {
		x=document.getElementsByTagName('a');
		for (var i = 0; i < x.length; i++) {if (f.test(x[i])) {var y=explodeArray(x[i],'_'); y=('mai' + 'lto:' + y[0] + '@' + y[3] + '.' + y[5]); x[i].setAttribute('href',y);}}
	}
}