//定义XMLHttpRequest对象实例
var http_request = false;

//定义可复用的http请求发送函数
function send_request(method, url, content, async, responseType, callback, objID, addScript) 
{
	http_request = false;
	//开始初始化XMLHttpRequest对象
	if(window.XMLHttpRequest) 
	{ 
		//Mozilla浏览器
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			//设置MiME类别
			http_request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject) 
	{ 
		// IE浏览器
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
			}
		}
	}
	if (!http_request) 
	{ 
		// 异常，创建对象实例失败
		alert("创建XMLHttpRequest对象实例失败！");
		return;
	}
	// 确定发送请求的方式和URL以及是否异步执行下段代码
	http_request.open(method, url, async);
	if(method.toLowerCase()=="get") 
	{
	}
	else if(method.toLowerCase()=="post") 
	{
		//http_request.setrequestheader("contentType","text/html;charset=uft-8"); 
		http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	else 
	{
		window.alert("http请求类别参数错误。");
		return false;
	}
	http_request.send(content);
	if (async)
	{
		http_request.onreadystatechange = function() 
		{
			if (http_request.readyState == 4)
			{
				callback(objID, addScript);
			}
		};
	}
	else
	{
		callback(objID, addScript);
	}
}

function processHtmlResponse(objID, addScript) 
{
	// 判断对象状态
	if (http_request.status == 200) 
	{ 
		// 信息已经成功返回，开始处理信息
		str = http_request.responseText;
		if (str.lastIndexOf("\r\n") == (str.length - 2))
		{
			str = str.substring(0, str.length - 2);
		}
		else if (str.lastIndexOf("\n") == (str.length - 1))
		{
			str = str.substring(0, str.length - 1);
		}
		document.getElementById(objID).innerHTML = str;
		if (addScript)
		{
			addScriptElement();
		}
	} 
	else 
	{ 
		//页面不正常
		//alert("获取数据错误，错误代码：" + http_request.status);
	}
}

function addScriptElement()
{
	scriptObj = document.getElementById("appScript");
	if (scriptObj != null)
	{
		var script = document.createElement("script");
		script.src = scriptObj.src;
		document.body.appendChild(script);
	}
}

function getUrlParam( paramName )
{
	var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
	var oMatch = oRegex.exec( self.location.search ) ;

	if ( oMatch && oMatch.length > 1 )
		return oMatch[1] ;
	else
		return '' ;
}