function doajax(theurl, thediv){
	var xmlhttp;
	var myresponse = "";
	var myjs = "";
	var myjs2 = "";
	bustcacheparameter=(theurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		alert("Your browser does not support XMLHTTP!");
	}
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState == 4){
			//document.getElementById(thediv).innerHTML = xmlhttp.responseText;
			myresponse = xmlhttp.responseText;
			//console.log(myresponse);
			if(myresponse.indexOf("menus.js") == -1){
				while(myresponse.indexOf("<script>") > -1){
					myresponse = myresponse.replace("<script>","<exec>");
					
				}
				while(myresponse.indexOf("<script language=javascript>") > -1){
					myresponse = myresponse.replace("<script language=javascript>","<exec>");
					
				}
				while(myresponse.indexOf("</script>") > -1){
					myresponse = myresponse.replace("</script>","</exec>");
				}
				//mycount = 0;
				//console.log(myresponse);
				repcount = 0;
				//prevent loops incase an error is returned
				while(myresponse.indexOf("<exec>") > -1 && repcount < 100){
					//alert("executing")
					myjs2 = myresponse.substring(myresponse.indexOf("<exec>") + 6, myresponse.indexOf("</exec>"))
					myjs += myjs2;
					//myresponse = myresponse.substring(0,myresponse.indexOf("<exec>"));
					//alert(myjs);
					myresponse = myresponse.replace("<exec>" + myjs2 + "</exec>","");
					//alert(myresponse.substring(myresponse.length - 100,myresponse.length));
					//document.getElementById(containerid).innerHTML = myresponse + "<br><br>" + myjs;
					//alert(mycount);
					//mycount += 1;
					repcount = repcount + 1;
				}
				if(repcount == 100){
					myjs = "";
				}
			}
			//alert(page_request + " " + containerid + " " + appendflag);
			//if(appendflag == 1){
				//var el = document.createElement('div');
				//el.innerHTML = myresponse;
				//document.getElementById(containerid).appendChild(el);
				//appendflag = 0;
			//}else{
			if(thediv != ''){
				document.getElementById(thediv).innerHTML = myresponse;
			}
			//}
			if(myjs != "" ){
				//alert(myjs);
				eval(myjs);
				//if(myresponse.indexOf("moveps") > -1){
					//alert("script");
				//}
			}
			myresponse = "";
		}
	}
	xmlhttp.open("GET",theurl+bustcacheparameter,true);
	xmlhttp.send(null);
}

function pause(thetime){
	//for strange ie bug
	for(x=0;x<=thetime;x++){
		//pause loop
	}
}

function getYbad(tehobj){
	var objItem = document.getElementById(tehobj)
	var objParent = null
	var intX = 0
	var intY = 0
	do
	{ // Walk up our document tree until we find the body
	 // and add the distance from the parent to our counter.
		intX += objItem.offsetLeft;
		intY += objItem.offsetTop;
		objParent = objItem.offsetParent.tagName;
		objItem = objItem.offsetParent;}
	 while(objParent != 'BODY')
	return {x:intX, y:intY};
}

function centerondiv2(divtocenter,divtocenteron){
	mydiv = getY(divtocenteron);
	document.getElementById(divtocenter).style.left = (document.getElementById(divtocenteron).offsetLeft + ((document.getElementById(divtocenteron).offsetWidth / 2) - (document.getElementById(divtocenter).offsetWidth / 2))) + "px";
	document.getElementById(divtocenter).style.top = (mydiv.y + ((document.getElementById(divtocenteron).offsetHeight / 2) - (document.getElementById(divtocenter).offsetHeight / 2))) + "px";
}

function centerdiv(whichdiv){
	thediv = document.getElementById(whichdiv);
	if(window.innerHeight != null){
		theheight = window.innerHeight;
	}else{
		theheight = document.documentElement.clientHeight;
	}
	if(window.innerWidth != null){
		thewidth = window.innerWidth;
	}else{
		thewidth = document.documentElement.clientWidth;
	}
	thediv.style.top = ((theheight - thediv.offsetHeight) / 2) + "px";
	thediv.style.left = ((thewidth - thediv.offsetWidth) / 2) + "px";
}

function openemail(thepage){
	mywindow = window.open("http://www.judaism.com/emailpage.asp?" + thepage,"Email","height=425,width=500,resizable=no,menubar=no,scrollbars=no,toolbar=no;status=no");
	mywindow.focus();
}
