// JavaScript Document
var xmlhttp;
var userName;//用户名
/**
 *将网站加入收藏夹
**/
function addBookmark(title, url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else {
		if (document.all) {
			window.external.AddFavorite(url, title);
		} else {
			if (window.opera && window.print) {
				return true;
			}
		}
	}
}


function login() {
		if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType("text/xml");
		}
	} else if (window.ActiveXObject) {
		var activexName = [ "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ];
		for ( var i = 0; i < activexName.length; i++) {
			try {
				xmlhttp = new ActiveXObject(activexName[i]);
				break;
			} catch (e) {
			}
		}
	}
	if (!xmlhttp) {
		 alert("XMLHttpRequest对象创建失败,请换个浏览器再试!!");
		return;
	} 
	userName=document.getElementById("userName").value;//用户名
	var password=document.getElementById("password").value;//密码
	//var validateCode=document.getElementById("password2").value;//验证码
	
	var postStr = "name="+ userName +"&password="+ password;
	//POST方式请求的代码
    xmlhttp.open("POST","webUserLogin",true);
    //xmlhttp.setrequestheader("content-length",postStr.length); 
    //POST方式需要自己设置http的请求头
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    //POST方式发送数据
    xmlhttp.send(postStr);
		xmlhttp.onreadystatechange=loginCallBack;
	
	//xmlhttp.send(null);
}

function loginCallBack(){
	if (xmlhttp.readyState == 4) {
		if(xmlhttp.status!=200){
			alert("出错了！");
		}else{
			if(xmlhttp.responseText==1){
				document.getElementById("userMsg").innerText="欢迎回来:"+userName;
				document.getElementById("userLogin").style.display='none';
				document.getElementById("userMsg").style.display='block';
			}else{
				alert("登录失败!");
			}
		}
    }
}





