var yj_arr_ajax_fun=new Array();
var yj_arr_ajax_index=0;
function getRequestObject() {
	if (window.ActiveXObject) {
		return (new ActiveXObject("Microsoft.XMLHTTP"));
	} else {
		if (window.XMLHttpRequest) {
			return (new XMLHttpRequest());
		} else {
			return (null);
		}
	}
}
function yj_ajax_get(msgact,msgbackfun) {
	var xmlhttp_request;
	var lng_index;
	yj_arr_ajax_index++;
	lng_index=yj_arr_ajax_index;
	yj_arr_ajax_fun[yj_arr_ajax_index]=msgbackfun;
	xmlhttp_request = getRequestObject(); 
	xmlhttp_request.onreadystatechange = function(){
		yj_ajax_handleResponse(xmlhttp_request,lng_index);
	};
	xmlhttp_request.open('GET',msgact,true);
	xmlhttp_request.setRequestHeader("If-Modified-Since","0")
	xmlhttp_request.send(null);
}
function yj_ajax_post(objfrm,msgbackfun) {
	var xmlhttp_request;
	var lng_index;
	yj_arr_ajax_index++;
	lng_index=yj_arr_ajax_index;
	yj_arr_ajax_fun[lng_index]=msgbackfun;

	msgtype=objfrm.enctype;
	//"application/x-www-form-urlencoded"
	msginfo=yj_formToString(objfrm);
	msgact=objfrm.action;
	xmlhttp_request = getRequestObject(); 
	xmlhttp_request.onreadystatechange = function(){
		yj_ajax_handleResponse(xmlhttp_request,lng_index);
	};
	xmlhttp_request.open('POST',msgact,true);
	xmlhttp_request.setRequestHeader("Content-Length", msginfo.length);
	xmlhttp_request.setRequestHeader('Content-Type',   msgtype); 
	xmlhttp_request.send(msginfo);
}
function yj_ajax_handleResponse(xmlhttp,key) {
	if (xmlhttp.readyState == 4)// 收到完整的服务器响应 
	{
		if (xmlhttp.status == 200)
		{   //HTTP服务器响应的值OK
			returnval=xmlhttp.responseText;
			//将服务器返回的字符串写到页面中ID为message的区域 
			str_fun=yj_arr_ajax_fun[key];
			eval(str_fun(returnval));
		}
	}

}

function yj_formToString(formObj){
	var allStr="";
	if(formObj){
		var elementsObj=formObj.elements;
		var obj;
		if(elementsObj){
			for(var i=0; i<elementsObj.length;i+=1){
				obj=elementsObj[i];
				if(obj.name!=undefined&&obj.name!=""){
					if(obj.type=="radio"){
						if(obj.checked){
							allStr+="&"+obj.name+"="+encodeURIComponent(obj.value);
						}
					}else if(obj.type=="checkbox"){
						if(obj.checked){
							allStr+="&"+obj.name+"="+encodeURIComponent(obj.value);
						}
					}else{
						allStr+="&"+obj.name+"="+encodeURIComponent(obj.value);
					}
				}
			}
		}else{
			return "";
		}
	}else{
		return "";
	}
	return allStr;
}
