var xmlHttp;
var divId;
function sendRequest(pageName,divid)	{
	divId = divid;
	returnSendData = sendData(pageName);
	return false;
}

function formRequest(pageName,divid,formObj)	{
	divId = divid;
	var GetStr='';
	totalControl = parseInt(formObj.length);
	
	for(i = 0;i < totalControl;i++) 		{
		fField = formObj[i];
		fValue = fField.value;
		fName = fField.name;
		
		if (fField.type == "radio") {
        	if(fField.checked)	{
              	GetStr += String(fName + "=" + fValue + "&");
         	}
		}else if(fField.type == "checkbox")	{
			if(fField.checked)	{
              	GetStr += String(fName + "=" + fValue + "&");
         	}
		}else	{
			GetStr += String(fName + "=" + fValue + "&");
		}
	}
	if(pageName.indexOf("?") >= 0)	{
		var formData = String(pageName + "&" + GetStr);
	} else	{
		var formData = String(pageName + "?" + GetStr);
	}

	returnSendData = sendData(formData);		
	return false;
}

function sendData(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)	  {
	  alert ("Your browser does not support AJAX!");
	  return
	}
	var url=str+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");	// Added 22 Nov 2007
	xmlHttp.setRequestHeader("Connection", "close");	// Added 3 Nov 2007
	xmlHttp.send(null);
	return true;
}

function stateChanged()
{
	if (xmlHttp.readyState == 3){	document.getElementById(divId).innerHTML='<img src="images/loading.gif" alt="wait ..." />';	}
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200 || window.location.href.indexOf("http")==-1))
	{ 	
		if(xmlHttp.status == 401) 	{
			document.getElementById(divId).innerHTML='Error: Bad HTTP request.';
		}else if(xmlHttp.status == 402) 	{
			document.getElementById(divId).innerHTML='Error: Not authorized.';
		}else if(xmlHttp.status == 403) 	{
			document.getElementById(divId).innerHTML='Error: Access forbidden.';
		}else if(xmlHttp.status == 404) 	{
			document.getElementById(divId).innerHTML='Error: Web address does not exist.';
		}else if(xmlHttp.status == 1000) 	{
			document.getElementById(divId).innerHTML='Error: Invalid response.';
		}else if(xmlHttp.status == 1001) 	{
			document.getElementById(divId).innerHTML='Error: A network error occurred. Check that you are connected to the internet';
		}else if(xmlHttp.responseText=='')	{
			document.getElementById(divId).innerHTML='Error: The server returned an empty response.';
		}else 	{
			var resptxt = xmlHttp.responseText.replace(/^\s*|\s*$/g,"");			
			document.getElementById(divId).innerHTML = resptxt;
						
			// Added 12 April 2008
			indx_from = resptxt.indexOf('<script type="text/javascript">')+31;
			indx_to = resptxt.indexOf('</script>');

			if(indx_from > 0 && indx_to > 0)	{
				if (window.execScript)	{	/*  If MSIE  */
					//execScript(resptxt.substr(indx_from, indx_to-indx_from), "javascript");				
				}else if (window.eval)	{	/*  If Mozilla, FireFox, Netscape, etc.  */
					setTimeout(eval(resptxt.substr(indx_from, indx_to-indx_from)), 0);
				}else	{	/*  If Safari or other  */
					setTimeout(resptxt.substr(indx_from, indx_to-indx_from), 0);
				};
			}
		}	
		//changeOpac(100, divId);
	}
}
function GetXmlHttpObject()	{
	var xmlHttp=null;
	if(typeof XMLHttpRequest != 'undefined'){
		xmlHttp = new XMLHttpRequest();
	} else if(typeof window.ActiveXObject != 'undefined'){
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.5.0");
		} catch(e){	// catch 1 Start
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
			} catch(e){	// catch 2 Start
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
				} catch(e){	// catch 3 Start
					try {
						xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
					} catch(e){	// catch 4 Start
						try {
							xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
						} catch(e){	// catch 5 Start
							xmlHttp = null;
						}	// catch 5 End
					}	// catch 4 End
				}	// catch 3 End
			}	// catch 2 End
		}	// catch 1 End
	}
	//xmlHttp.onload = displayState;
	if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/xml'); }	// Added 2nd November 2007 (plain xml)
	return xmlHttp;
}
	
