window.onload = function(){
	var date = new Date();
	var week = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
	document.getElementById("showdate").firstChild.nodeValue=date.toLocaleDateString()+" "+week[date.getDay()];
};
//使用ajax登陆
var xmlHttp;
function createXMLHttpRequest() {
	if (window.XMLHttpRequest) { //Mozilla 浏览器
		xmlHttp = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) { //IE浏览器
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e) {
				}
			}
		}
	}
	if (xmlHttp == null) {
		alert("\u4e0d\u80fd\u521b\u5efaXMLHttpRequest\u5bf9\u8c61");
		return false;
	}
}
function sendAsynchronRequest(url, parameter, callback) {
	//步骤2.创建一个XMLHttpRequest对象
	createXMLHttpRequest();
	//3.配置XMLHttpRequest对象
	if (parameter == null) {
		//3.1 设置属性onreadystatechange,保存一个回调函数指针
		xmlHttp.onreadystatechange = callback;
		//3.2 设置对服务器端调用的参数
		xmlHttp.open("GET", url, true);
		//步骤 4.调用此方法后由XMLHttpRequest对象在后台向服务器端发出一个异步请求，去访问由url指定的一些资源(html jsp servlet action 等)
		xmlHttp.send(null); //null表示不需要向服务器传递参数
	} else {
		xmlHttp.onreadystatechange = callback;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");//post方法要在请求头中添加此信息
		xmlHttp.send(parameter);
	}
}

function login(){
	var loginId = document.getElementById("loginId").value.trim();
	var passwd = document.getElementById("passwd").value.trim();
	var authCode = document.getElementById("authCode").value.trim();
	if(loginId==""){
		alert("用户名不能为空");
		document.getElementById("loginId").focus();
		return;
	}
	if(passwd==""){
		alert("密码不能为空");
		document.getElementById("passwd").focus();
		return;
	}
	if(authCode==""){
		alert("验证码不能为空");
		document.getElementById("authCode").focus();
		return;
	}
	passwd = passwd.replace(/\%/g, "%25");
	passwd = passwd.replace(/\+/g, "%2B");
  	passwd = passwd.replace(/\&/g, "%26");

	sendAsynchronRequest("/sso/login_login.action", "loginId="+loginId+"&passwd="+passwd+"&authCode="+authCode, loginCallBack);
}

function loginCallBack(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var tip = xmlHttp.responseText;
			if(tip.indexOf("success")!=-1){
				window.top.location.href='/web/loginSuccess.jsp';
			}else{
				alert(tip);
			}
			//刷新验证码，清空密码
			document.getElementById("passwd").value="";
			document.getElementById("authCode").value="";
			document.getElementById("imgCode").src="/sso/authimg";
		} else {
			alert("\u8bf7\u6c42\u7684\u9875\u9762\u6709\u9519");
			return false;
		}
	}	
}
String.prototype.trim= function(){     
		return this.replace(/(^\s*)|(\s*$)/g, "");     
} 