﻿function GetAjax()
											{
												var ajax=false; 
												try 
												{ 
    												ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
												} catch (e) 
												{ 
   	 												try { 
    													ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
    												} catch (E) { 
    													ajax = false; 
    												} 
												}
												if (!ajax && typeof XMLHttpRequest!='undefined') { 
    												ajax = new XMLHttpRequest(); 
												} 
												return ajax;
											}
											
												function userLogin()
												{
													var objLoginType = document.getElementById("LoginType");
													var loginType = objLoginType.value;
													
													var objKeyword = document.getElementById("Account");
													keyword = objKeyword.value;
													if( keyword == "")
													{
														alert("请输入帐号");
														objKeyword.focus();
														return;
													}
													
													var objPassword = document.getElementById("Password");
													password = objPassword.value;
													if( password == "")
													{
														alert("请输入密码");
														objPassword.focus();
														return;
													}
													
													var autoLogin = 1;
																	
													
													var ajax = GetAjax();	
													var url = "/ajax.aspx?Action=UserLogin&LoginType=" + loginType + "&Account=" + keyword + "&Password=" + password + "&AutoLogin=" + autoLogin;
													ajax.open("GET", url, true); 
													ajax.onreadystatechange = function() 
													{ 
														if (ajax.readyState == 4 && ajax.status == 200) 
														{ 																		
															var result = ajax.responseText;
															 
															if( result == "1")
															{
																window.navigate("/user/default.aspx");
															}
															else if(result == "2")
															{
																window.navigate("/Master/default.aspx");
															}
															else if(result == "3")
															{
																window.navigate("/Agent/System/default.aspx");
															}
															else if(result == "0")
															{							
																switch(loginType)
																{
																	case "1":
																		alert("无效的数字ID或密码");										
																		break;
																	case "2":
																		alert("无效的Email或密码");										
																		break;
																	case "3":
																		alert("无效的手机或密码");
																		break;										
																}			
																objPassword.focus();					
															}
															else if(result == "2")
															{
																alert("您的帐号已被锁住，请跟管理员联系");
															}
															else
															{
																alert(result);
															}						
														} 
													}
													ajax.send(null); 																				
												}
												
												
