
var isIe=(document.all)?true:false;
//设置select的可见状态
function setSelectState(state)
{
var objl=document.getElementsByTagName('select');
for(var i=0;i<objl.length;i++)
{
objl[i].style.visibility=state;
}
}
function mousePosition(ev)
{
if(ev.pageX || ev.pageY)
{
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}


//弹出方法
function showMessageBox(wTitle,content,wWidth)
{
closeWindow();
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight);
if(isIe){
setSelectState('hidden');}

var back=document.createElement("div");
back.id="back";
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=40);":"opacity:0.40;";
back.style.cssText=styleStr;
document.body.appendChild(back);
var mesW=document.createElement("div");
mesW.id="mesWindow";
mesW.className="mesWindow";
var strHtml =" <div style='width:376px;height:247px;background-image:url" + '("images/login_bg.png")' + ";background-repeat:inherit;'>  <div class='mesWindowTop'>";
	strHtml += "<table width='100%' height='40px;' cellpadding='0' cellspacing='0'>";
	strHtml += "<tr><td style='width:100%;height:50px;text-align:right'>";
	strHtml += "<img style='width:31px;height:29px;margin-right:5px;margin-bottom:10px;' src='images/close.png' alt='' onclick='closeWindow();'/></td></tr>"
	strHtml += "<tr><td style='height:20px;font-size:12px;padding-left:36px;'><span id='ts' style='color:red' align='left'></span> </td></tr>";
	strHtml += "</table></div>"
	strHtml += "<div class='mesWindowContent' id='mesWindowContent'>"+content+"</div>"
	strHtml += "</div>";

mesW.innerHTML= strHtml 

styleStr="left:" + (document.body.clientWidth/2 - 175) +"px;top:"+(document.body.clientHeight/2 - 200)+"px;position:absolute;width:"+wWidth+"px;";

mesW.style.cssText=styleStr;
document.body.appendChild(mesW);
}
function showBackground(obj,endInt)
{
obj.filters.alpha.opacity+=1;
if(obj.filters.alpha.opacity<endInt)
{
setTimeout(function(){showBackground(obj,endInt)},8);
}
}


//关闭窗口
function closeWindow()
{
if(document.getElementById('back')!=null)
{
document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
}
if(document.getElementById('mesWindow')!=null)
{
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
}
if(isIe){
setSelectState('');}
}

var test;
//测试弹出
function testMessageBox(event)
{
	if(event != null){
	
	event  =  event  ||  window.event;
	 var  target    =  event.target  ||  event.srcElement;
	test =  target.getAttribute("href");
	}else{
	test=null;
	}


var messContent = ""
 //  messContent += "<form action='${request.contextPath}/userLogin.do'  method='post'>";
   messContent += "<div style='padding:0px 0 20px 0;text-align:left'>";
   messContent += "<table style='margin-left:30px;'><tr style='height:30px;'><td>用户名：</td>	<td colspan='2'><input id='inputUserName' name='inputUserName' style='width:160px;' /></td><td></td></tr>";
   messContent += "<tr style='height:30px;'><td>密　码：</td><td colspan='2'><input type='password' id='inputPassName' name='inputPassName' style='width:160px;' /></td>	<td align='left'><a href='turnToForgotPassword.do' alt=''>忘记密码？</a></td></tr>";
   messContent += "<tr style='height:30px;'><td>验证码：</td>	<td><input style='width:68px;' id='checkCodeString' name='checkCodeString' /></td><td><img id='codeView' src='makeCheckCodeImage.do' onClick='changeValidateCode(this)'  alt='' ></img></td><td>看不清，点图片</td></tr>";
   messContent += "<tr style='height:30px;'><td></td><td colspan='2'><input type='button' onclick='login()' style='border:0;margin-right:5px;width:74px;height:22px;";
   messContent += 'background-image:url("images/login_1.png")';
   messContent += "'/><a href='register.do' style='text-decoration:underline;margin-top:8px;' alt=''>注册新用户</a></td>	<td></td></tr></table>";
 
   messContent += "</div>";



showMessageBox('用户登录',messContent,350);
}


//登陆，输入用户名密码点击登陆
function login(){
	document.getElementById("ts").innerHTML="";
	var username = document.getElementById('inputUserName');
	var pwd = document.getElementById('inputPassName');
	var checkCodeString = document.getElementById('checkCodeString');


	if(username.value==null || username.value==""){
		document.getElementById("ts").innerHTML="请输入用户名！";
		username.focus();
		username.select();
		return;
	}
	if(pwd.value==null || pwd.value==""){
		document.getElementById("ts").innerHTML="请输入密码！";
		pwd.focus();
		pwd.select();
		return;
	}
	if(checkCodeString.value==null || checkCodeString.value==""){
		document.getElementById("ts").innerHTML="请输入验证码！";
		checkCodeString.focus();
		checkCodeString.select();
		return;
	}
	gradedtlogin(username.value,pwd.value,checkCodeString.value);


}

var xmlHttp; 
var stateString; 
function createXMLHttpRequestlogin(){ 
     if (window.ActiveXObject){ 
          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     }else if(window.XMLHttpRequest){ 
          xmlHttp = new XMLHttpRequest(); 
     } 
} 

function gradedtlogin(username,pwd,checkCodeString){ 

    createXMLHttpRequestlogin(); 

    var sUrl = "jsonUserLogin.do";
    var paramSTR = "username="+username+"&password="+pwd+"&checkCodeString="+checkCodeString;
    xmlHttp.open("post",sUrl,true); 
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlHttp.send(paramSTR); 
    xmlHttp.onreadystatechange = callbacklogin; 
   
}


function callbacklogin(){ 
    if (xmlHttp.readyState == 4) { 

      if (xmlHttp.status == 200) { 
 
		var resultStr = xmlHttp.responseText;
		
		var fenshu = eval("[" + resultStr + "]");

		if(fenshu=="yes"){
			if(test != null){
				doSub(test);
			}
			else
			{
				doSub("${request.contextPath}/index.htm");
			}
			closeWindow();
			return;	
		}else if(fenshu=="no"){
        	document.getElementById("ts").innerHTML="用户名或者密码输入错误，请重新输入！";

        	changeValidateCode(document.getElementById('codeView'));
      
			return;
        }else if(fenshu=="noVer"){
        	document.getElementById("ts").innerHTML="您的账号没有激活，请激活后登陆！";
        	doSub("${request.contextPath}/toError.do");
        	
			return;
        }else if(fenshu=="code"){
        	document.getElementById("ts").innerHTML="验证码输入错误，请重新输入！";
        	changeValidateCode(document.getElementById('codeView'));
        	return;
        }else{
        	doSub("${request.contextPath}/index.htm")
        }
     }          
  } 
}
	function doSub(toUrl){ 
		 var myForm1 = document.createElement("FORM");
		 document.body.appendChild(myForm1);
		 myForm1.method = "POST";
		myForm1.action=toUrl;
	 	myForm1.submit();    
	}
