﻿function Ajax()
{
	this.OnError = null;
	this.xmlHttp = null;
	this.OnCallBack = null;
}

Ajax.prototype.ExecuteCall = function( url, data )
{
	try 
	{

		this.xmlHttp = this.GetXmlHttpObject();

		if( this.xmlHttp == null )
		{
			alert( "当前未找到任何可用的xml组件" );
			return;
		}
		this.SendXmlHttpRequest( this.xmlHttp, url, data );
　	}
　	catch(e)
	{
		return e.Message;
	}
}

Ajax.prototype.GetXmlHttpObject = function()
{
	var objXmlHttp = null;
	if( !window.XMLHttpRequest )
	{// Microsoft
	　　objXmlHttp = this.GetMSXmlHttp();
	　　if( objXmlHttp != null )
	　　{
	　　	var Tempthis = this;
	　　	objXmlHttp.onreadystatechange = function()
			{
				return Tempthis.OnCallBack( objXmlHttp );
			}
	　　}
	}
	else
	{
		objXmlHttp = new XMLHttpRequest();
	
		if (objXmlHttp != null)
		{
			if( objXmlHttp.overrideMimeType )
			{
				objXmlHttp.overrideMimeType( "text/xml" );
			}
			var Tempthis = this;
			objXmlHttp.onreadystatechange = function()
			{
				return Tempthis.OnCallBack( objXmlHttp );
			}
		}
	}
	return objXmlHttp;
}

Ajax.prototype.GetMSXmlHttp =	function()
{
	var objXmlHttp = null;
　	var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0", 
					"Microsoft.XMLHTTP.1","Microsoft.XMLHTTP","Msxml2.XMLHTTP"];
　	for( var i=0; i<clsids.length && objXmlHttp == null; i++ )
　	{
　　	objXmlHttp = this.CreateXmlHttp(clsids[i]);
　　}
　	return objXmlHttp;
}

Ajax.prototype.CreateXmlHttp = function( clsid ) 
{
	var objXmlHttp = null;
　	try {
　　	objXmlHttp = new ActiveXObject( clsid );
　　	lastclsid = clsid;
　　	return objXmlHttp;
　	}
　	catch(e)
　	{
　	}
	return null;
}

Ajax.prototype.SendXmlHttpRequest = function( objXmlHttp, url, data ) 
{
	var str = "";
	if( url.indexOf( "?" ) != -1 )
	{
		str = url + "&rnd=" + Math.floor( Math.random() * 100000 );
	}
	else
	{
		str = url + "?rnd=" + Math.floor(Math.random()*100000);
	}
//	var contentType = "application/x-www-form-urlencoded; charset=gb2312";
	if ( data != null )
	{
	    objXmlHttp.open('POST', str , true);
	    objXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
　	}
　	else 
　	{
　	    objXmlHttp.open('GET', str, true);
　	}
　	objXmlHttp.send(null); 
}

function mover(id)
{
	var e = document.getElementById(id);
	e.style.cssText="display:block";
}

function movet(id)
{
	var e = document.getElementById(id);
	e.style.cssText="display:none";
}

function trim(str)   
{   
    var   par   =   /^\s+/;   
    var   strRes   =   str.replace(par,'');     //Trim   the   font   blank
    
    par   =   /\s+$/;   
    strRes   =   strRes.replace(par,'');       //   Trim   the   end   blank
    return   strRes;       
}
