$(document).ready(function() {
	$("#username").focus(function() {
		hiddenTip("name");
	});
    $("#password").focus(function() {
    	hiddenTip("pwd");
    });
});

function initImgDiv() {

	var getAbsoluteCoords = function (e) {
		var width = e.offsetWidth;
		var height = e.offsetHeight;
		var left = e.offsetLeft;
		var top = e.offsetTop;
		while (e=e.offsetParent) {
			left += e.offsetLeft;
			top += e.offsetTop;
		};
		var right = left+width;
		var bottom = top+height;
		return {
			'width': width,
			'height': height,
			'left': left,
			'top': top,
			'right': right,
			'bottom': bottom
		};
	};
	var getElementById = function (sId) {
	return document.getElementById(String(sId));
	};

	var wrapId = "ImgDiv";
	var wrapTitle = "ImgDivTitle";
	var wrap = getElementById(wrapId);
	var wrapTitle = getElementById(wrapTitle);
	wrapTitle.onmouseover = function () {
		wrapTitle.style.cursor = "move";
		if (window.ActiveXObject)
		wrapTitle.onselectstart = function () { event.returnValue = false; }
		wrapTitle.onmousedown = function (evt) {
			evt = window.event||evt; var a=getAbsoluteCoords(wrap);
			wrap.cx=evt.clientX-(a.left);
			wrap.cy=evt.clientY-(a.top);
			document.onmousemove = function (evt) {
				evt = window.event||evt;
				try {
					wrap.style.left = (evt.clientX-wrap.cx)+"px";
					wrap.style.top = (evt.clientY-wrap.cy)+"px";
				} catch (ex) {};
			};
			document.onmouseup = function () {
				document.onmousemove = null;
				document.onmouseup = null;
				wrap.style.cursor="default";
			};
		};
	}
}
function showImgDiv(eMsg) {
	showHiddenDiv();
	//在div里写入内容
	$("#ImgLogin").html(getLoadingImg());
	$.post("/imagepwd/img_login", {eMsg:eMsg}, function(xml) {
		$("#ImgLogin").html(xml);
	});

	var Div = document.getElementById("ImgDiv");
	var winWidth = window.screen.width;
	var winHeight = window.screen.height;
	var sTop = document.body.scrollTop||document.documentElement.scrollTop;//网页被卷去的高
	divWidth = parseInt(Div.style.width);
	divHeight = parseInt(Div.style.height);
	Div.style.left = winWidth/2 - divWidth/2 + "px";
	Div.style.top = winHeight/2 + sTop - divHeight/2 - 100 + "px";
	Div.style.display = "";
}
function getLoadingImg() {
	var html = "";
	html += '<div style="width:500px; height: 300px; text-align: center; padding-top: 150px;">';
	html += '<img src="/images/loading.gif">';
	html += '</div>';
	return html;
}
function closeImgDiv() {
	var Div = document.getElementById("ImgDiv");
	Div.style.display = "none";
	showHiddenDiv();
}
function isLetter( s )
{//判断是否是数字或字母
	var regu = "^[a-zA-Z]+$";
	var re = new RegExp(regu);
	if(re.test(s)) {
		return true;
	} else {
		return false;
	}
}

function StringTrim(str)
{
    // 用正则表达式将前后空格用空字符串替代。
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
function upperCase()
{
	var text = document.getElementById("text");
	text.value = StringTrim(text.value).toUpperCase();
}

//初始化（注册）
function showImgpwdReg(eMsg){
	showHiddenDiv();
	$("#ImgTest").html(getLoadingImg());
	$.post("/imgpwd/img_reg_verify.jsp", {eMsg:eMsg}, function(xml) {
		$("#ImgTest").html(xml);
	});
	
	var Div = document.getElementById("ImgDiv");
	var winWidth = window.screen.width;
	var winHeight = window.screen.height;
	var sTop = document.body.scrollTop||document.documentElement.scrollTop;//网页被卷去的高
	divWidth = parseInt(Div.style.width);
	divHeight = parseInt(Div.style.height);
	Div.style.left = winWidth/2 - divWidth/2 + "px";
	Div.style.top = winHeight/2 + sTop - divHeight/2 - 100 + "px";
	Div.style.display = "";
}
//刷新（登陆）
function refreshImgpwd(eMsg)
{
	$("#ImgLogin").html(getLoadingImg());
	$.post("/imagepwd/img_login", {eMsg:eMsg}, function(xml) {
		$("#ImgLogin").html(xml);
	});
}
//刷新（注册）
function refreshImgpwdReg(eMsg)
{
	$("#ImgTest").html(getLoadingImg());
	$.post("/imgpwd/img_reg_verify.jsp", {eMsg:eMsg}, function(xml) {
		$("#ImgTest").html(xml);
	});
}
//关闭
function closeImg()
{	
	var divImg = document.getElementById("imgpwd");
	divImg.style.display = "none";
	showHiddenDiv();
}
//黑色遮盖层
function showHiddenDiv()
{
	var bodyw = document.body.clientWidth;
	var bodyh =document.body.scrollHeight;
	var hiddiv = document.getElementById("hiddiv");
	hiddiv.style.width = bodyw + "px";
	hiddiv.style.height = bodyh + "px";
	if (hiddiv.style.display=="") {
		hiddiv.style.display="none";
	} else {
		hiddiv.style.display="";
	}
}
//用户注册时点击图片
var count = 1;
function clickImg(a, b, c)
{
	if(count == 10) return;
	var imgSrc = "/imgpwd/watermarksmall.jsp?type="+a+"&img="+b;
	var clickId = "click_" + count;
	var clickImg = document.getElementById(clickId);
	var userSelectedHid = document.getElementById("userSelectedHid");
	userSelectedHid.value += a;
	clickImg.src = imgSrc;
	viewUserSelectImgNo(c)
	count += 1;
	document.getElementById("errorMsg").innerHTML = "";
}

function refreshClickImg()
{
	document.getElementById("userSelectedHid").value="";
	for(var i=1;i<10;i++) {
		document.getElementById("click_"+i).src="/images/password_images/white.jpg";
	}
	count=1;
	var div = document.getElementById("userSelectImgNo");
	div.innerHTML = "&nbsp;&nbsp;";
	document.getElementById("sam").innerHTML = "";
}
//显示用户选择的图片下标号
function viewUserSelectImgNo(a)
{
	var div = document.getElementById("userSelectImgNo");
	div.innerHTML += a;
	document.getElementById("sam").innerHTML = "&nbsp;&nbsp;(仅为示例)";
}

