function GetXMLHttpRequest()
{

	var xmlHttp=null;
	if (window.XMLHttpRequest)
	{
		try{  xmlHttp = new XMLHttpRequest(); }catch (e){ xmlHttp = null;}		
	}
	else if (window.createRequest)
	{
		try{ xmlHttp = new window.createRequest(); }catch (e){  xmlHttp = null;}
	}
	
	if (xmlHttp==null && window.ActiveXObject)
	{
		try 
		{     
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");        
		}
		catch (e)
		{            
			try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ xmlHttp = null;}  
		}		
	}
	if (xmlHttp == null)
	{
		alert("You browser doesn't suppor Ajax.");
	}
	return xmlHttp;

}
function httpRetObj()
{
	this.value='';
}
function HttpGetValue(url, obj)
{
	var today = new Date();
	url +="&tm=" + today.getTime();	
	var xmlhttp = GetXMLHttpRequest();
	xmlhttp.onreadystatechange=function() 
	{
	   if (xmlhttp.readyState==4) 
	   {	
		   obj.value=xmlhttp.responseText;
		}
		
	}
	xmlhttp.open("GET",url,false);//block
	xmlhttp.setRequestHeader('Accept','message/x-formresult')
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(null);
}
function AjaxHttpGet(url)
{
	var httpret = new httpRetObj();
	HttpGetValue(url, httpret);
	return httpret.value;
}

//--FORM CLASS for POST --------------------------------------
//define class constructor.
function lnkAjaxForm(frmObj)
{   
	this._frm = frmObj;
	this._para = "";
	this.BlockPost=false;
	this.NonBlockPost=true;
	this.httRet= new httpRetObj();
	this.hasServerRet=false;
}
lnkAjaxForm.prototype.IE_AjaxHttpGet= function (url)
{
	var xmlhttp = GetXMLHttpRequest();
	if (xmlhttp==null) 
		return ;
	xmlhttp.open('GET',url, false);//no-block, false=block, true= no-block
	xmlhttp.onreadystatechange=function() 
	{
	   if (xmlhttp.readyState==4) 
	   {	
		this.httpRet.value = xmlhttp.responseText;
		this.hasServerRet=true;
		return this.httpRet.value
	   }
	}
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(null);	
}

lnkAjaxForm.prototype.SendReq = function(url, method, para, IsNonBlock, szCallbackFunName)
{
	var xmlhttp = GetXMLHttpRequest();
	if (xmlhttp==null) 
		return ;
	xmlhttp.onreadystatechange=function() 
	{
	   if (xmlhttp.readyState==4) 
	   {	
		    this.httRet = xmlhttp.responseText;	
			this.hasServerRet=true;
			if (szCallbackFunName.length>0)
			{
				var cb_func= window[szCallbackFunName];
				if (IsValidObj(cb_func) && typeof(cb_func)=='function')
					cb_func(this.httRet)
			}
	   }
	}
	xmlhttp.open(method,url,IsNonBlock);//no-block, false=block, true= no-block
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(para);	
}
lnkAjaxForm.prototype.CreatePostParement = function()
{
	for (i=0; i < this._frm.length ; i ++ )
	{
		this._para  +=this._frm.elements[i].name + "=" + UrlEncode( this._frm.elements[i].value) + "&";
 	}
}
lnkAjaxForm.prototype.PostForm= function(url, divButton, szCallbackFunName, IsNonBlock)
{
	if (IsValidObj(divButton))
		ExpendRegion(divButton, 'none');
	if (this._para=="")
		this.CreatePostParement();
	var xmlhttp = GetXMLHttpRequest();
	xmlhttp.onreadystatechange=function() 
	{
	   if (xmlhttp.readyState==4) 
	   {	
		    this.httRet = xmlhttp.responseText;		    
			window[szCallbackFunName](this.httRet);
		   if (IsValidObj(divButton))
			ExpendRegion(divButton, 'inline');
	   } 		
	}
	xmlhttp.open("POST",url,IsNonBlock);//no-block, false=block, true= no-block
	xmlhttp.setRequestHeader('Accept','message/x-formresult')
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", this._para.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(this._para);
}

