
var XMLHttpReq;
 	//创建XMLHttpRequest对象
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) { //Mozilla 浏览器
        XMLHttpReq = new XMLHttpRequest();
    } else {
        if (window.ActiveXObject) { // IE浏览器
            try {
                XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                }
            }
        }
    }
}

	//发送请求函数
	function loginRequest(url) {
		createXMLHttpRequest();
		XMLHttpReq.open("GET",url, true);
     	XMLHttpReq.onreadystatechange = processLoginResponse;//指定响应函数
    	XMLHttpReq.send(null);  // 发送请求
	}
	// 处理身份验证返回信息函数
    function processLoginResponse() {

    	if (XMLHttpReq.readyState == 4) { // 判断对象状态
 document.getElementById("loading").innerHTML="" ;
        	if (XMLHttpReq.status == 200) { // 信息已经成功返回，开始处理信息
            	var res=XMLHttpReq.responseXML.getElementsByTagName("res")[0].firstChild.nodeValue;
            	var url=XMLHttpReq.responseXML.getElementsByTagName("url")[0].firstChild.nodeValue;
			
            	     if (res==1){

                	window.alert("用户名错误！");   
          
                }
                else if (res==2){

                	window.alert("密码错误！"); 
			                  
                } else if (res==22){

                	window.alert("您的账号未激活，需够买E卡币！咨询热线：400-618-0111 ");                
                }else if (res==33){

                	window.alert("您的账号已被系统注销！");    
					                   
                }
          
                else if (res==0){
				if(url.indexOf("login")!=-1){
                  window.location = "index.jsp";  
				}else if(url.indexOf("wall")!=-1){
				
				window.location = "wall.jsp"; 

				}else if(url.indexOf("babyshow")!=-1){
				
				window.location = "babyshow.jsp"; 

				}else if(url.indexOf("summer_sale")!=-1){
				
				window.location = "summer_sale.jsp"; 

				}else{
				window.location = "guess_happy.jsp"; 
				}
           
                }
				else if(res==4){
	
				    window.location = "index_representative.jsp";   
				}
				else if(res==3){
    				window.location = "index_suppliers.jsp"; 
				}
				else if(res==6){
					window.location = "admin/index.jsp";    
				}else if(res==5){
					window.location = "index_ZJyys_ys.jsp";    
				}
				else if(res==7){
					window.location = "index_yys_ys.jsp";    
				}
				else if(res==9){
					window.location = "index_message.jsp";    
				}
				else if(res==10){
					window.location = "admin/index_suppliersEditor.jsp";    
				}else if(res==11){
					window.location = "retailSystem/indexWeb.jsp";    
				}
            } else { //页面不正常
                window.alert("您所请求的页面有异常。");
            }
        }else
		{
		 document.getElementById("loading").innerHTML="<img src='images/loading.gif' border='0'> 请等待..." ;
		}
		
    }
	
    function userCheck() {
        
		uname = document.loginform.username.value;
		psw = document.loginform.passwd.value;
		url = document.loginform.url.value;
		var checkbox=0;
		if(document.loginform.checkbox.checked){
		checkbox=1;
		}
		if(uname=="") {
			window.alert("用户名不能为空。");
			document.loginform.username.focus();
			return false;
		}else if(psw==""){
		window.alert("密码不能为空。");
			document.loginform.passwd.focus();
			return false;
		}
		else {
			loginRequest("/loginUser?uname=" + uname +"&url="+url+ "&psw=" + psw+"&checkbox="+checkbox);
		}
	}
	