var xmlHttp
var loadstatustext="<p style='color:#15428B'>updating...</p>"
var loadstatusimage = "<img src='/images/ajax-loader.gif' height='13' align='top' />";

function ajaxSelect(page_id,filename,displayid)
{ 

	var xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 

	var url=filename;
	url=url+"?page_id="+page_id;
	url=url+"&sid="+Math.random();
	document.getElementById(displayid).innerHTML=loadstatustext
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	

	function stateChanged() {
		if (xmlHttp.readyState==4) { 
		document.getElementById(displayid).innerHTML=xmlHttp.responseText;
		}
	}
}

function setAndExecute(divId, innerHTML)  
{  
	var div = document.getElementById(divId);  
	div.innerHTML = innerHTML; 
	var x = div.getElementsByTagName("script"); 
	 
	for(var i=0;i<x.length;i++)
	{  
	    eval(x[i].text); 
	}  
 }

function AdaoxAjaxSelect(page_id,filename,displayid,param1,param2,param3,param4,param5,param6,param7,param8)
{
	
	var xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 

	var url=filename;
	url=url+"?page_id="+page_id;
	url=url+"&sid="+Math.random();	
	if (param1) url=url+"&param1="+param1;	
	if (param2) url=url+"&param2="+param2;
	if (param3) url=url+"&param3="+param3;
	if (param4) url=url+"&param4="+param4;
	if (param5) url=url+"&param5="+param5;
	if (param6) url=url+"&param6="+param6;
	if (param7) url=url+"&param7="+param7;
	if (param8) url=url+"&param8="+param8;
	
	try {
		document.getElementById(displayid).innerHTML=loadstatusimage
	}catch(e){
		
	}
	
	//document.getElementById(displayid).innerHTML=loadstatustext
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	function stateChanged() {
		if (xmlHttp.readyState==4) {
			setAndExecute(displayid, xmlHttp.responseText);
			//document.getElementById(displayid).innerHTML=xmlHttp.responseText;
		}
	}
}

function easyAjaxNoLoader(url,displayid,requestMethod,form,fieldList,statusText,action){
	
	var xmlHttp=GetXmlHttpObject();
	
	if(!statusText) statusText=loadstatustext;
	if(!action) action = void(0);
	
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
		
	
	if (url.indexOf("?")=='-1')
		url=url+"?sid="+Math.random();
	else
		url=url+"&sid="+Math.random();
	
	//document.getElementById(displayid).innerHTML=statusText;
	xmlHttp.onreadystatechange=stateChanged;
	
	if (!requestMethod) requestMethod='GET' 
	
	if (requestMethod=='POST')
	{
		xmlHttp.open("POST", url, true);		
		var params ="";
		var frm= document.forms[form];
		
		if (fieldList)
		{			
			valueArray = fieldList.split(",");		
			
			for(var i=0; i<valueArray.length; i++){
				var fldtemp=valueArray[i];
				currentfield=frm[fldtemp];				
				if (currentfield) 
				{					
					if (params=='')					
				 		params=valueArray[i]+"="+currentfield.value;
					else
						params=params+"&"+valueArray[i]+"="+currentfield.value;
				}							
			}	
		}	
			
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");		
	}
	else
	{
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	
	function stateChanged() {
		if (xmlHttp.readyState==4) { 
			setAndExecute(displayid, xmlHttp.responseText);
			eval(action);
		}
	}

	params=encodeURI(params);
	
	if (requestMethod=='POST')
	{
		xmlHttp.send(params);
		//document.getElementById(displayid).innerHTML=statusText
	}
}

function easyAjax(url,displayid,requestMethod,form,fieldList,statusText,action) {
	
	var xmlHttp=GetXmlHttpObject();
	
	if(!statusText) statusText=loadstatustext;
	if(!action) action = void(0);
	
	if (xmlHttp==null) {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
		
	
	if (url.indexOf("?")=='-1')
		url=url+"?sid="+Math.random();
	else
		url=url+"&sid="+Math.random();
	
	//document.getElementById(displayid).innerHTML=statusText (This is a mistake being here. It produces a javascript error in the case you replace the dive that contains the form)
	xmlHttp.onreadystatechange=stateChanged;
	
	if (!requestMethod) requestMethod='GET' 
	
	if (requestMethod=='POST')
	{
		xmlHttp.open("POST", url, true);		
		var params ="";
		var frm= document.forms[form];
		
		if (fieldList)
		{			
			valueArray = fieldList.split(",");		
			
			for(var i=0; i<valueArray.length; i++){
				var fldtemp=valueArray[i];
				currentfield=frm[fldtemp];				
				if (currentfield) 
				{					
					if (params=='')					
				 		params=valueArray[i]+"="+currentfield.value;
					else
						params=params+"&"+valueArray[i]+"="+currentfield.value;
				}							
			}	
		}	
			
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");		
	}
	else
	{
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	
	function stateChanged() {
		if (xmlHttp.readyState==4) { 
			setAndExecute(displayid, xmlHttp.responseText);
			eval(action);
		}
	}

	params=encodeURI(params);
	
	if (requestMethod=='POST')
	{
		xmlHttp.send(params);
		document.getElementById(displayid).innerHTML=statusText
	}
}


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;
}
