var isLogin = true;

// Create HttpRequest Object
function MakeHttpRequest()
{
	return (window.ActiveXObject) ? new window.ActiveXObject("microsoft.xmlhttp") : new window.XMLHttpRequest();
}

// Post Request To Server
function PostRequest(url, postXml, bRetDOM, bIsGet)
{
	var xmlhttp = MakeHttpRequest();
	xmlhttp.open((bIsGet ? "GET" : "POST"), url, false);
	xmlhttp.setRequestHeader("AsFunction", "PostRequest");
	AppendRequestHeader(xmlhttp);
	
	if(!postXml) xmlhttp.send("");
	else if(typeof(postXml) == "object") xmlhttp.send(postXml.xml);
	else xmlhttp.send(postXml);
	
	return (CheckRequestReturn(xmlhttp) != false) ? ((bRetDOM) ? xmlhttp.responseXML : xmlhttp.responseText) : null;
}

// Post Request To Server As Async
function AjaxRequest(url, postXml, callBackFunction, infoToCallBack, bRetDOM)
{
 
	var xmlhttp = MakeHttpRequest();
	xmlhttp.open("POST", url, true);
 
	xmlhttp.onreadystatechange = function(){
		try{if(xmlhttp.readyState == 4){
				if(CheckRequestReturn(xmlhttp) != false){
					if(callBackFunction){
						if(bRetDOM) callBackFunction(xmlhttp.responseXML, infoToCallBack, true);
						else callBackFunction(xmlhttp.responseText, infoToCallBack, true); }}
				xmlhttp = null; return;
	}}catch(e){}};
	
	if(!postXml) xmlhttp.send("");
	else if(typeof(postXml) == "object") xmlhttp.send(postXml.xml);
	else xmlhttp.send(postXml);
}

// GET Request To Server As Async
function AjaxRequestGet(url, postXml, callBackFunction, infoToCallBack, bRetDOM)
{
	var xmlhttp = MakeHttpRequest();
	xmlhttp.open("GET", url, true);

	AppendRequestHeader(xmlhttp);
	
	xmlhttp.onreadystatechange = function(){
		try{if(xmlhttp.readyState == 4){
				if(CheckRequestReturn(xmlhttp) != false){
					if(callBackFunction){
						if(bRetDOM) callBackFunction(xmlhttp.responseXML, infoToCallBack, true);
						else callBackFunction(xmlhttp.responseText, infoToCallBack, true); }}
				xmlhttp = null; return;
	}}catch(e){}};
	
	if(!postXml) xmlhttp.send("");
	else if(typeof(postXml) == "object") xmlhttp.send(postXml.xml);
	else xmlhttp.send(postXml);
}

// Object : Post Request To Server As Async
function AjaxRequestObject(url, postXml, callBackFunction, infoToCallBack, bRetDOM)
{
	var xmlhttp = MakeHttpRequest();
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("AsFunction","AjaxRequestObject");
	AppendRequestHeader(xmlhttp);
	
	xmlhttp.onreadystatechange = function(){
		try{if(xmlhttp.readyState == 4){
			if(CheckRequestReturn(xmlhttp) != false){
				if(callBackFunction){
					if(bRetDOM) callBackFunction(xmlhttp.responseXML, infoToCallBack, true);
					else callBackFunction(xmlhttp.responseText, infoToCallBack, true); }}
			xmlhttp = null; return;
	}}catch(e){}};
	
	this.Load = function(){
		if(!postXml) xmlhttp.send("");
		else if(typeof(postXml) == "object") xmlhttp.send(postXml.xml);
		else xmlhttp.send(postXml); };
}

// Append Request Header For Spec Application
function AppendRequestHeader(xmlhttp)
{
	if(!xmlhttp) return;
	xmlhttp.setRequestHeader("AjaxRequest","true");
	try{if(isLogin) xmlhttp.setRequestHeader("AjaxBlogger",Blogger);}catch(e){}
}

// Check Request Return For Spec Application
function CheckRequestReturn(xmlhttp)
{
	if(xmlhttp.responseText == "<root>NOT LOGIN</root>")
		Alert("登录超时！请选择重新登录</a>后重试");
	return true;
}