﻿function refreshCc() {
	var ccImg = document.getElementById("checkcodeimg");
	var ccImgSrc = "";
	if (ccImg) {
		if (document.all) {
			ccImgSrc = "../checkcode";
		} else {
			nowTime = new Date()
			ccImgSrc = "../checkcode?r=" + nowTime.getTime();
		}
		ccImg.src = ccImgSrc;
	}
}
 
var msgMap = new Map();
var vUtil = new ValidatorUtil();

function initInfo() {
var usernameMsg = new Array('请输入您的用户名！',
				'您输入的用户名有误！');	

var passwordMsg = new Array(	'请输入您的密码！',
				'您输入的密码有误！', 

				'您输入的用户名或者密码有误！');

var checkcodeMsg	= new Array(	'请输入左侧字符，<a href="javascript:refreshCc();"><u>看不清楚？换个图片</u></a>。',

				'校验码由4位数字或字母组成。请填写左侧字符，<a href="javascript:refreshCc();"><u>看不清楚？换个图片</u></a>。');								

msgMap.put("username",usernameMsg);
msgMap.put("password",passwordMsg);
msgMap.put("checkcode",checkcodeMsg);

$("#username_info").html(usernameMsg[0]);
$("#password_info").html(passwordMsg[0]);
$("#checkcode_info").html(checkcodeMsg[0]);
}

function initInput() {


		$("input[@type='text'], input[@type='password'], textarea").removeClass();
		$("input[@type='text'], input[@type='password'], textarea").addClass("base_input");
		$("input[@type='text'], input[@type='password']").addClass("mustinput_text");

		$("input[@type='button'], input[@type='submit'], input[@type='reset']").removeClass();
		$("input[@type='button'], input[@type='submit'], input[@type='reset']").addClass("img_button");
		$("input[@type='button'], input[@type='submit'], input[@type='reset']").mousedown(function(){if($(this).attr("class")=="img_button"){$(this).removeClass("img_button"),$(this).addClass("img_button_mousedown")}});
		$("input[@type='button'], input[@type='submit'], input[@type='reset']").mouseup(function(){if($(this).attr("class")=="img_button_mousedown"){$(this).removeClass("img_button_mousedown"),$(this).addClass("img_button")}});
		$("input[@type='button'], input[@type='submit'], input[@type='reset']").mouseout(function(){if($(this).attr("class")=="img_button_mousedown"){$(this).removeClass("img_button_mousedown"),$(this).addClass("img_button")}});
		$("input[@type='text'], input[@type='password']").focus(function(){setInputInfo($(this).attr("id"))});
		$("input[@type='text'], input[@type='password']").blur(function(){checkInputInfo($(this).attr("id"),true)});
		$("input[@type='text'], input[@type='password']").keyup(function(){checkInputInfo($(this).attr("id"),false)});
		$("form[@id='SingonForm']").submit(function(){return checkForm($(this))});
}

function checkForm(theForm)
{
	if(theForm)
	{
		$("input[@type='submit']",theForm).attr("disabled","true");
		var rev=true;
		rev=rev && checkInputInfo("username",true);
		rev=rev && checkInputInfo("password",true);
		rev=rev && checkInputInfo("checkcode",true);
		if(!rev)
		{
			$("input[@type='submit']",theForm).removeAttr("disabled");
		}
		return rev;
	}
	return false;
}

function checkusername(str) {
	if(vUtil.isUsername(str))
		return 0;
	else
		return 1;
	
}

function checkpassword(str) {
	if(!vUtil.isPassword(str))
		return 1;
	if(str==$("#username").val())
		return 1;
	if(vUtil.isSameLetter(str))
		return 1;
	if(vUtil.isSerialNumber(str))
		return 1;
	if(vUtil.isSerialLowCase(str))
		return 1;
	if(vUtil.isSerialUpCase(str))
		return 1;
	if(vUtil.isPasswordWeak(str))
		return 1;
	else 
		return 0;
}


function checkcheckcode(str){
	if(vUtil.isCheckCode(str))
		return 0;
	else
		return 1;
}


$(document).ready(function(){
initInput();
initInfo();
checkErrorInfo();
});