//-------------------MtsProject.jsp网站首页面-------------------校验会员名、密码----Begin-----------------------//
$(document).ready(function() 
		{
		    $("#LoginButton").click(function()
		    {
		       var loginFrom=$("#LoginFrom");
		       var username=$("#userNameHeaderLogin");
		       var userValue=username.val();
		       
		       if(userValue.length==0)
			    {
			      tipsWindown("错误提示","text:请输入会员登录名称!","250","60","false","2000","true","text");
			      username.focus();
			      return false;
			    }
			   
 				//给会员 登录密码进行 加密处理 hidSessuibMath
                //alert("----------------------------"+$("#hidSessuibMath").val());
 				encryPwd($("#hidSessuibMath").val());
			   
			   var password=$("#loginPassWord");
		       var passValue=password.val();
			    if(passValue.length==0){
			      tipsWindown("错误提示","text:请输入会员登录密码!","250","60","false","2000","true","text");
			      password.focus();
			      return false;
			    }
			    
			    $.ajax({
			          type: "post",
			          url: "./register.do?method=checkIsUserAndPswd&loginUserName="+userValue+"&loginPswd="+passValue+"&paswdLength="+$("#paswdLength").val(),
			          async: true,
			          success: function(msg)
			          {
			             var msgArr = msg.split("#");
		
			             if(msgArr[0] == "userName"){
			                tipsWindown("错误提示","text:您输入的会员登录名称不存在!","250","60","false","2000","true","text");
			                document.getElementById("loginPassWord").value="";
			                document.getElementById("userNameHeaderLogin").focus();
			             }else if(msgArr[0] == "pswd"){
			                tipsWindown("错误提示","text:您输入的会员登录密码不正确!","250","60","false","2000","true","msg");
			                document.getElementById("loginPassWord").value="";
			                document.getElementById("loginPassWord").focus();
			             }else if(msgArr[0] == "0"){
			                tipsWindown("错误提示","text:您的信息正处于待审核状态，请稍后登陆!!!","350","60","true","","true","msg");
			             }else if(msgArr[0] == "2"){
			                tipsWindown("错误提示","text:<font size='2' color='red'>对不起! 您的注册信息由于下面的原因没有审核通过，<br>请仔细核实，并可以重新修改注册信息提交</font><br><br>"+msgArr[1]+"!!!<br><br><br><p><a href='register/userUpdateRegister/201004011-1.html&userId="+msgArr[2]+"'>立即修改</a></p>","350","150","true","","true","msg");
			             }else if(msgArr[0] == "3"){
			                tipsWindown("错误提示","text:<font size='2' color='red'>对不起！您的账号已经处于无效状态<br>原因可能是：</font><br>1,.....<br>2,.....","350","150","true","","true","msg");
			             }else{
		       loginFrom.submit();
			             }
			          }
			          
			    });
		    });
	   });
//----------------------------------End---------------------------------------------------------------------//



//------------------Login.jsp会员单独登录页面-----------------校验会员名、密码、验证码----Begin---------------------//

//加载验证码图片
//document.getElementById('container').onload=function()
    //	{
	// 	reloadImage('register/ImageJsp.jsp');
	//}
	function reloadImage(url)
	{
	   var img = document.getElementById("pic");
	    img.src = url+"?" + Math.random();
	}
	
	 function expand(obj)
	 {
	    if(obj.checked){
			document.getElementById("exp").style.display = "block";
		}else{
			document.getElementById("exp").style.display = "none";
		}
	}


 $(document).ready(function() 
		{
		    $("#userLoginButton2").click(function()
		    {
		        var userLoginFrom2=$("#userLoginFrom2");
		        var username=$("#loginUserName");
		        var userValue=username.val();
		       if(userValue.length==0)
			    {
			      tipsWindown("错误提示","text:请输入会员登录名称!","250","60","false","1000","true","text");
			      username.focus();
			      return false;
			    }
                
                //给会员 登录密码进行 加密处理 hidSessuibMath
                //alert("----------------------------"+$("#hidSessuibMath").val());
				 encryPwd($("#hidSessuibMath").val());
			   	var password=$("#loginPassWord");
		       	var passValue=password.val();
			    if(passValue.length==0){
			      tipsWindown("错误提示","text:请输入会员登录密码!","250","60","false","1000","true","text");
			      password.focus();
			      return false;
			    }
			    
			    var textCode = $("#TxtCode");
			    var textCodeValue = textCode.val();
			    if(textCodeValue.length==0){
			      tipsWindown("错误提示","text:请输入验证码!","250","60","false","1000","true","text");
			      textCode.focus();
			      return false;
			    }
			
				 
			    
			       $.ajax({
			          type: "post",
			          url: "./register.do?method=checkIsUserAndPswdTwo&loginUserName="+userValue+"&loginPswd="+passValue+"&TxtCode="+textCodeValue+"&paswdLength="+$("#paswdLength").val(),
			          async: true,
			          success: function(msg)
			          {
						 //添加校验不通过时，将验证码刷新一遍
			             if("code" == msg){
			                tipsWindown("错误提示","text:您输入的验证码不正确!","250","60","false","2000","true","text");
			                document.getElementById("loginPassWord").value="";
							reloadImage('register/ImageJsp.jsp');
			                document.getElementById("loginPassWord").focus();
			             }
			             else if("userName" == msg){
			                tipsWindown("错误提示","text:您输入的会员登录名称不存在!","250","60","false","2000","true","text");
			                reloadImage('register/ImageJsp.jsp');
							document.getElementById("loginPassWord").value="";
			                document.getElementById("loginPassWord").focus();
			             }else if("pswd" == msg){
			                tipsWindown("错误提示","text:您输入的会员登录密码不正确!","250","60","false","2000","true","msg");
			                document.getElementById("loginPassWord").value="";
							reloadImage('register/ImageJsp.jsp');
			                 document.getElementById("loginPassWord").focus();
			             }else{
							 
						    userLoginFrom2.submit();
			             }
			          }
			          
			    });
			    
		    });
	   });
	   
	   
//处理 用户 登录 密码
 function encryPwd(tmpMaths)
{
  
      //用户所输入的密码
      var pwd = document.getElementById("loginPassWord").value;
      var oldpwd = pwd;
      //插入字随机数后的密码
      var hidPwd = getNewString(pwd,tmpMaths,1);
      document.getElementById("loginPassWord").value=hidPwd;
      //用户所输入的真实密码的长度，用于Action中与所插入随机码长度比较判断
      document.getElementById("paswdLength").value=oldpwd.length;
      //alert(document.getElementById("paswdLength").value);
}
    
    //往当密码中插入随机数的函数
    var getNewString = function ()
    { 
        var getIc = function (ic,mathindex)
        { 
            var arric = ic.split(","); 
            //alert(Math.ceil(Math.random()*20));
            randomIc = arric[mathindex]; 
            return randomIc 
        }; 

        return function (oc,ic,re)
        { 
            var reStr = "(.{"+re+"}|.*)"; 
            var reg = new RegExp(reStr,"g"); 
            var ocArray = oc.match(reg) 
            var arrLength = oc.length*2-1; 
            var mathindex=0;
            for(var element=0;element<arrLength;element+=2)
            { 
                 ocArray.splice(element+1,0,getIc(ic,mathindex)) 
                 mathindex+=1;
            } 
             return ocArray.join(''); 
        } 
   }();	   
	   

//------------------------------------------------End----------------------------------------------------------//


///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2009-11-22]
//--------------------------------------------------------------------------
/*参数：[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
    title:	窗口标题
  content:  内容(可选内容为){ text | id | img | url | iframe }
    width:	内容宽度
   height:	内容高度
	 drag:  是否可以拖动(ture为是,false为否)
     time:	自动关闭等待的时间，为空是则不自动关闭
   showbg:	[可选参数]设置是否显示遮罩层(0为不显示,1为显示)
  cssName:  [可选参数]附加class名称
 ------------------------------------------------------------------------*/
 //示例:
 //------------------------------------------------------------------------
 //simpleWindown("例子","text:例子","500","400","true","3000","0","exa")
 //------------------------------------------------------------------------
var showWindown = true;
var templateSrc = "../index-images/"; //设置loading.gif路径
function tipsWindown(title,content,width,height,drag,time,showbg,cssName) {
	$("#windown-box").remove(); //请除内容
	var width = width>= 950?this.width=950:this.width=width;	    //设置最大窗口宽度
	var height = height>= 527?this.height=527:this.height=height;  //设置最大窗口高度
	if(showWindown == true) {
		var simpleWindown_html = new String;
			simpleWindown_html = "<div id=\"windownbg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index: 999901\"></div>";
			simpleWindown_html += "<div id=\"windown-box\">";
			simpleWindown_html += "<div id=\"windown-title\"><h2></h2><span id=\"windown-close\">关闭</span></div>";
			simpleWindown_html += "<div id=\"windown-content-border\"><div id=\"windown-content\"></div></div>"; 
			simpleWindown_html += "</div>";
			$("body").append(simpleWindown_html);
			show = false;
	}
	contentType = content.substring(0,content.indexOf(":"));
	content = content.substring(content.indexOf(":")+1,content.length);
	switch(contentType) {
		case "text":
		$("#windown-content").html(content);
		break;
		case "id":
		$("#windown-content").html($("#"+content+"").html());
		break;
		case "img":
		$("#windown-content").ajaxStart(function() {
			$(this).html("<img src='"+templateSrc+"loading.gif' class='loading' />");
		});
		$.ajax({
			error:function(){
				$("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
			},
			success:function(html){
				$("#windown-content").html("<img src="+content+" alt='' />");
			}
		});
		break;
		case "url":
		var content_array=content.split("?");
		$("#windown-content").ajaxStart(function(){
			$(this).html("<img src='"+templateSrc+"loading.gif' class='loading' />");
		});
		$.ajax({
			type:content_array[0],
			url:content_array[1],
			data:content_array[2],
			error:function(){
				$("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
			},
			success:function(html){
				$("#windown-content").html(html);
			}
		});
		break;
		case "iframe":
		$("#windown-content").ajaxStart(function(){
			$(this).html("<img src='"+templateSrc+"loading.gif' class='loading' />");
		});
		$.ajax({
			error:function(){
				$("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
			},
			success:function(html){
				$("#windown-content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+parseInt(height)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
			}
		});
	}
	$("#windown-title h2").html(title);
	if(showbg == "true") {$("#windownbg").show();}else {$("#windownbg").remove();};
	$("#windownbg").animate({opacity:"0.5"},"normal");//设置透明度
	$("#windown-box").show();
	if( height >= 527 ) {
		$("#windown-title").css({width:(parseInt(width)+22)+"px"});
		$("#windown-content").css({width:(parseInt(width)+17)+"px",height:height+"px",'line-height':height+'px'});
	}else {
		$("#windown-title").css({width:(parseInt(width)+10)+"px"});
		$("#windown-content").css({width:width+"px",height:height+"px",'line-height':height+'px'});
	}
	var	cw = document.documentElement.clientWidth,ch = document.documentElement.clientHeight,est = document.documentElement.scrollTop; 
	var _version = $.browser.version;
	if ( _version == 6.0 ) {
		$("#windown-box").css({left:"50%",top:(parseInt((ch)/2)+est)+"px",marginTop: -((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	}else {
		$("#windown-box").css({left:"50%",top:"50%",marginTop:-((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	};
	var Drag_ID = document.getElementById("windown-box"),DragHead = document.getElementById("windown-title");
		
	var moveX = 0,moveY = 0,moveTop,moveLeft = 0,moveable = false;
		if ( _version == 6.0 ) {
			moveTop = est;
		}else {
			moveTop = 0;
		}
	var	sw = Drag_ID.scrollWidth,sh = Drag_ID.scrollHeight;
		DragHead.onmouseover = function(e) {
			if(drag == "true"){DragHead.style.cursor = "move";}else{DragHead.style.cursor = "default";}
		};
		DragHead.onmousedown = function(e) {
		if(drag == "true"){moveable = true;}else{moveable = false;}
		e = window.event?window.event:e;
		var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop-moveTop;
		moveX = e.clientX-ol;
		moveY = e.clientY-ot;
		document.onmousemove = function(e) {
				if (moveable) {
				e = window.event?window.event:e;
				var x = e.clientX - moveX;
				var y = e.clientY - moveY;
					if ( x > 0 &&( x + sw < cw) && y > 0 && (y + sh < ch) ) {
						Drag_ID.style.left = x + "px";
						Drag_ID.style.top = parseInt(y+moveTop) + "px";
						Drag_ID.style.margin = "auto";
						}
					}
				}
		document.onmouseup = function () {moveable = false;};
		Drag_ID.onselectstart = function(e){return false;}
	}
	$("#windown-content").attr("class","windown-"+cssName);
	var closeWindown = function() {
		$("#windownbg").remove();
		$("#windown-box").fadeOut("slow",function(){$(this).remove();});
	}
	if( time == "" || typeof(time) == "undefined") {
		$("#windown-close").click(function() {
			$("#windownbg").remove();
			$("#windown-box").fadeOut("slow",function(){$(this).remove();});
		});
	}else { 
		setTimeout(closeWindown,time);
	}
	

}  

