function CreateXMLHttp(){
    var XMLHttp=false; 
    try { 
    	XMLHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch (E){ 
   	 	try { 
    		XMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    	} catch (E){ 
    		XMLHttp = false; 
    	} 
    }
    if (!XMLHttp && typeof XMLHttpRequest!='undefined'){ 
    	XMLHttp = new XMLHttpRequest(); 
    } 
	//XMLHttp.overrideMimeType('text/xml');
	//XMLHttp.overrideMimeType("text/html;charset=gb2312");  
    return XMLHttp;
}

function GetHTMLtoObject(ServerPage,objID,style,CallBackFun){ 
	var XMLHttp = CreateXMLHttp();
    var obj = document.getElementById(objID); 
	show_loading();
    XMLHttp.open(style,ServerPage,true); 
    //XMLHttp.setRequestHeader("Content-Type","text/xml");
	XMLHttp.setRequestHeader("Content-Type","text/html;charset=gb2312");
	//XMLHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XMLHttp.send(null); //发送空
	
    XMLHttp.onreadystatechange = function(){//指定响应函数
        if(XMLHttp.readyState == 4 && XMLHttp.status == 200){
		returntext=XMLHttp.responseText;
		hide_loading();
        if(obj)obj.innerHTML = returntext;
		if(typeof CallBackFun == "function")CallBackFun(returntext);
        } 
    }
//return ;
}

function CallBackFunAjaxHTML(ServerPage,CallBackFun){
	var XMLHttp = CreateXMLHttp();
	show_loading();
    XMLHttp.open("GET", ServerPage, true); 
    XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	XMLHttp.send(null);
	
    XMLHttp.onreadystatechange = function(){
        if (XMLHttp.readyState == 4 && XMLHttp.status == 200){ 
            returntext = XMLHttp.responseText;
			hide_loading();
			if(typeof CallBackFun == "function"){CallBackFun(returntext)}else{window.alert(returntext)}
        } 
    }
	//return ;
}
function add_car(PID){
	CallBackFunAjaxHTML("car_add0_ajax.asp?PID="+PID+"&MR="+Math.random(),walert);
}
function add_fav(PID){
	CallBackFunAjaxHTML("fav_add0_ajax.asp?PID="+PID+"&MR="+Math.random(),walert);
}
function walert(str){
if (str==""||str==null){window.alert("空")}else{window.alert(str)}
//if(document.readyState!="complete"){document.execCommand('refresh',false,0)}
}

//会员登入表单
function UserLogin(FormName){
	//var LoginForm=document.all.LoginForm
	var LoginForm=FormName.elements;
	if (LoginCheck(LoginForm)){PostForm("login0_ajax.asp",FormName,UserLoginalert)}
}
function UserLoginalert(str){
if (str=="SUCCESS"){window.alert("恭喜，登入成功！");window.document.location.reload()}else{window.alert(str)}
}
//提交表单数据
function PostForm(ServerPage,FormName,CallBackFun){
	ServerPage=ServerPage+"?MR="+Math.random();
	var XMLHttp = CreateXMLHttp();
	var PostString=GetFormAsString(FormName);
	//window.alert(PostString);
    XMLHttp.open("POST",ServerPage,false);
    //XMLHttp.setRequestHeader("Content-Type","text/xml");
	XMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
    XMLHttp.onreadystatechange = function(){ 
        if(XMLHttp.readyState == 4 && XMLHttp.status == 200){ 
		returntext = XMLHttp.responseText;
		 if(typeof CallBackFun == "function"){CallBackFun(returntext)}else{window.alert(returntext)}
         }
    }
	XMLHttp.send(PostString);
}
//得到一个表单里的全部信息1
function GetFormAsString(FormName){
	returnString ="";
	if (typeof(FormName)=="object")
	 formElements=FormName.elements;
	else
	 formElements=document.forms[FormName].elements;
	for(var i=formElements.length-1;i>=0; --i ){
		returnString+="&" 
		+escape(formElements[i].name)+"=" 
		+escape(formElements[i].value);
	}
	returnString = returnString.substring(1,returnString.length); //去掉最前面的"&"
	return returnString; 
}
//得到一个表单里的全部信息2
function GetFormQueryString(FormID){
var FormID=document.getElementById(FormID); 
var i,queryString = "", and = "";
var ItemID; // for each form's object
var ItemValue;// store each form object's value
	for(i=0;i<FormID.length;i++){
		ItemID = FormID[i];// get form's each object
		  if (ItemID.name!=''){
				if (ItemID.type == 'select-one')
				 {
					 ItemValue = ItemID.options[ItemID.selectedIndex].value;
				 }
				 else if ( ItemID.type=='checkbox' || ItemID.type=='radio')
				 {
					   if ( ItemID.checked == false )
					   {
						   continue;
					   }
					   ItemValue = ItemID.value;
				 }
				else if ( ItemID.type == 'button' || ItemID.type == 'submit' || ItemID.type == 'reset' || ItemID.type == 'image')
				 {// ignore this type
						continue;
				 }
				 else 
				 {
						ItemValue = ItemID.value;
				 }
				 ItemValue = encodeURIComponent(ItemValue);
				 queryString += and + ItemID.name + '=' + ItemValue;
				 and="&";
		  }
	}
	return queryString;
}


