﻿//$Revision: 1.13 $
function createAjaxObj(){
	var httprequest=false;
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest = new XMLHttpRequest()
		if (httprequest.overrideMimeType){
			httprequest.overrideMimeType('text/xml')
		}
	}
	else if (window.ActiveXObject){ // if IE
		var versions = ['MSXML2.XMLHttp.5.0',
			            'MSXML2.XMLHttp.4.0',
			            'MSXML2.XMLHttp.3.0',
			            'MSXML2.XMLHttp',
			            'Microsoft.XMLHTTP'];
		for(i = 0; i<versions.length; i++){
			try{
				httprequest = new ActiveXObject(versions[i]);
				break;
			}
			catch (e){}
		}
	}
	return httprequest
}
/**
* method:  use method,have two method:POST and GET;
* url:     it is a http url;
* param:   your param list:
* callback:function, if request is successful,this function will be call
*/
function AjaxRequest(method, url, param, callback){
	this.ajaxobj=createAjaxObj();
	this.method = method;
	this.url = url;
	this.param = param;
	this.callback = callback;
	this.initialize();
}
AjaxRequest.prototype.initialize=function(){
	if (this.ajaxobj){
		var instance=this
		this.ajaxobj.onreadystatechange=function(){instance.getAjaxcontent()}
		if('POST' == this.method){
			this.ajaxobj.open('POST',this.url,true);
			if(null != this.param){
			    this.ajaxobj.setRequestHeader("content-length",this.param.length);
			    this.ajaxobj.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
			}
			this.ajaxobj.send(this.param);
		}
		else if('GET' == this.method){
			this.ajaxobj.open('GET',this.url+'?'+this.param,true);
			this.ajaxobj.send(null);
		}
	}
}
AjaxRequest.prototype.getAjaxcontent=function(){ 
	if (4 == this.ajaxobj.readyState){   //if request of file completed
		if (200 == this.ajaxobj.status){ //if request was successful
			var sResponse = this.ajaxobj.responseText;
			var sResponse = deleteHead(sResponse);
			this.callback(sResponse);
		}
		else {
			var instanceOfTicker=this;
			this.callback(null);
		}
	}
}
function deleteHead(sResponse){
	sResponse = sResponse.replace(/lv=/,'');
	return sResponse;
}
