/**
 *作者：rock
 *Email:lanshikun2008@163.com
 *时间：2008年03月06日
 */

function rockAjax(callback,t)
{
	this.xmldoc = getXMLDOC(); //获得XMLHttpRequest对像
	this.callback = callback;  //回调方法
	this.backType = t;          //返回值的类型1：text；2:变量,0:XML
	this.Post = post;          
	this.Get = get;
}

function get(url,para)
{
	var ajax = this;
	function CheckState()
	{
		if(xmldoc.readyState == 4&&xmldoc.status == 200){
			if(ajax.backType==1)
			{
				ajax.callback(xmldoc.responseText);
			}
			else
			{
				ajax.callback(xmldoc.responseXML);
			}
		}
	}
	xmldoc.onreadystatechange = CheckState;
	xmldoc.open('GET',url+"?"+para,true);
	xmldoc.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
	xmldoc.setRequestHeader("Cache-Control","no-cache");
	xmldoc.send("");	
}

function post(url,para)
{
	var ajax = this;
	function CheckState()
	{
		if(xmldoc.readyState == 4&&xmldoc.status == 200){
				if(ajax.backType==1)
				{
					ajax.callback(xmldoc.responseText);
				}
				else
				{
					ajax.callback(xmldoc.responseXML);
				}
		}	
	}
	xmldoc.onreadystatechange = CheckState;
	xmldoc.open('POST',url,true);
	xmldoc.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
	xmldoc.send(para);
}

function getXMLDOC()
{
//Mozill,Safari等浏览器时需要创建的XMLHttp类
	if(window.XMLHttpRequest){
		xmldoc = new XMLHttpRequest();
		/*if(xmldoc.overrideMimeType){
				xmldoc.overrideMimeType('text/xml');
		}*/
	}
//IE浏览器时创建的XMLHttp类
	else if(window.ActiveXObject){
		try{
			xmldoc = new ActiveXObject("Msxml3.XMLHTTP");
		}
		catch(e){
			try{
				xmldoc = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e){
				try{
					xmldoc = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e){}
			}
		}
	}
//不能创建XMLHTTP类时返回
	if(! xmldoc){
		alert("无法创建XMLHttp对象！");
		document.location.reload();
	}
	return xmldoc;
}

