﻿// JavaScript Document

jQuery(document).ready(function(){
   jQuery("#nav li").mouseover(function(){
		jQuery(this).hover(function() {
		}, function(){	
		});
		}).hover(function() { 
			jQuery(this).addClass("on"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			jQuery(this).removeClass("on"); //On hover out, remove class "subhover"
	});
   var rhtml = (jQuery("#toprights").html());
   if(rhtml)
   {
	   
        openMsg(rhtml, '确定' , 400, 200, '系统提示' , 'new dialog().close()');
   }
   var ehtml = (jQuery("#toperrors").html());
   if(ehtml)
   {
        openAlert(ehtml,'确定' , 400, 200, '系统提示' , 'new dialog().close()')
    }

}); 
function openLogin()
{
    var html = '<ul class="inputform">\
			     <li>\
				  <em>用户ID或E-mail:</em><input type="text" name="win_username" id="win_username" size="30" maxlength="50"/><span>*</span>\
				 </li>\
				 <li>\
				  <em>登录密码:</em><input type="password" name="win_password" id="win_password" size="30" maxlength="20"/><span>*</span>\
				 </li>\
				 <li class="verycode">\
				  <em>验证码:</em><input type="text" name="win_verycode" id="win_verycode" size="10" /><span>*</span><img id="code" src="'+RootDir+'/code'+ExName+'?rnd='+Math.random()+'"  onclick="sxCode();"/>\
				 </li>\
				 <li>\
				  <em>&nbsp;</em><input type="checkbox" name="win_autologin" id="win_autologin" value="yes"/><label style="display:inline; " for="win_autologin">记住我</label>\
				 </li>\
			    <li>\
				   <em>&nbsp;</em><button title="登录" onclick="javascript:checkLogin();" type="button" >登录</button>\
			    </li>\
		       </ul>';
	var oEdit = new dialog(400, 260, '用户登录','yes');
	oEdit.init();
	oEdit.show();
	myInnerHTML('dialogBody', html);
	//sxCode();
}
function checkLogin()
{
	if (jQuery("#win_username").val().match(/^\d{6,20}|([a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)$/)==null)
	{
		alert('用户ID或E-mail格式有误');
		jQuery("#win_username").focus();
		return;
	}
	if (jQuery("#win_password").val().match(/^[0-9a-zA-Z_-]{6,20}$/)==null)
	{
		alert('登录密码输入有误');
		jQuery("#win_password").focus();
		return;
	}
	if(jQuery("#win_verycode").val().match(/^\d{4}$/)==null)
	{
		alert('验证码输入有误');
		jQuery("#win_verycode").focus();
		return;
	}
	var username=jQuery("#win_username").val();
    var password=jQuery("#win_password").val();
	var vcode=jQuery("#win_verycode").val();
	var autologin=jQuery("#win_autologin").val();
	jQuery.post(RootDir+'/login'+ExName, { action:"LoginAjax", username:username,password:password,vcode:vcode,autologin:autologin,param:Math.random() }, 
          function(msg)
          {

             if(msg.indexOf("succs")>-1)
             {
				location.href=location.href;
             }
             else
             {
                 alert(msg);
                 return;
             }
          }
        ); 
}
