//Variable used to initilize the XMLHttp request object
var reqObject; 

function getXMLHttpReq(){
    try {reqObject = new ActiveXObject("Msxml2.XMLHTTP"); } 
    catch (e){try {reqObject = new ActiveXObject("Microsoft.XMLHTTP");}catch (oc){reqObject = null;}} 
    if (!reqObject && typeof XMLHttpRequest!= "undefined"){reqObject = new XMLHttpRequest();}
} 
//function to change the content of the div
function setContent(c_Container,c_Content){
	var c_con = document.getElementById(c_Container);
	c_con.innerHTML=c_Content;
	hLoading();
}
   

function AjSend(p_Param,c_Container,e_errPage){
	sLoading();
	getXMLHttpReq();
	reqObject.open('GET',p_Param,true);
	reqObject.onreadystatechange= function() {
		try {
				if (reqObject.readyState == 4)    // Check the request status
				{
					if (reqObject.status == 200)    //Done
					{
						if (reqObject.responseText.indexOf("<ERROR>") == 0){    
							alert(reqObject.responseText.replace("<ERROR>",""));
							hLoading();
						} 
						else{
							//	Change Content
							try {setContent(c_Container,reqObject.responseText);eS(reqObject.responseText);} 
							//if error
							catch (e){ alert('error'); window.location.replace(e_errPage.php);
							}
						}
					} 
					else{ alert("There was a problem retrieving data:"+reqObject.statusText);hLoading();
							window.location.replace(e_errPage);
					}
				}
				//else alert(reqObject.readyState);
			} 
			catch (e){ alert ('Unknow Error :'); window.location.replace(e_errPage);
		 }
	}	
	reqObject.send(null);
	// hide loading

}
function eS(mystr)
{
    if (mystr.indexOf('<SCRIPT>') != - 1)
    {
        var scr;
        scr = mystr.substr(mystr.indexOf('<SCRIPT>'),mystr.indexOf('</SCRIPT>'));
        scr = scr.replace("<SCRIPT>","");
        if (scr.indexOf('</SCRIPT>') != - 1) scr=scr.substr(0,scr.indexOf('</SCRIPT>'));
        eval(scr);
    }
}
function sLoading(){
	if(document.getElementById("dvLoad"))  
	{
		document.getElementById("dvLoad").style.display='block';
		document.getElementById("dvLoad").style.top=getScrollXY()+"px";
		document.getElementById("dvLoad").style.height=getWindowHeight();
	}
	//b();
}
 function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;	
}
function getScrollXY() {
	var  scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; 
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; 
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; 
	}
	return scrOfY;
}
function hLoading()
{
  	if(document.getElementById("dvLoad")) document.getElementById("dvLoad").style.display='none';
    document.body.style.cursor='default';   
}