﻿// JScript 文件
    (function($){
	// 改变默认配置
	var d = $.dialog.defaults;
	// 预缓存皮肤，数组第一个为默认皮肤
	d.skin = ['default', 'chrome', 'facebook', 'aero'];
	d.plus = true;
	// 是否开启特效
	//d.effect = true;
	// 指定超过此面积的对话框拖动的时候用替身
	//d.showTemp = 0;
	
})(art);
$(function(){
    $('#btnSearch_SecurityCode').click(function(){
        querySecurityCode();
    });
    $('#btnLogin').click(function(){
        userLogin();
    });
    $('#btnRegister').click(function(){
        window.open("../UserShow/UserRegister.aspx");
    });
    $('#a_register').click(function(){
        window.open("../UserShow/UserRegister.aspx");
    });
})
function userLogin()
{
    if(!!checkUserLogin())
    {
        
        window.open("../UserShow/Index.aspx");
    }
    else
    {
        art.dialog.tips("<p style='font-size:12px;color:red;'>用户名或密码输入有误，请核查！</p>",3);
    }
}
///用户登录验证
function checkUserLogin()
{
    var username=$('#tbUserName').val();
    var password=$('#tbPassword').val();
    var tempFlag=0;
    if(username===''||password==='')
    {
        art.dialog.tips("<p style='font-size:12px;color:red;'>用户名或密码不允许为空，请核查！</p>",3);
    }
    else
    {
         $.ajax(
            {   
                type: "get",  
                contentType: "application/json;utf-8",
                cache: false,
                async:false,
                url: "../UserShow/AjaxHandler/CheckUserLogin.ashx",                                     
                data: "username="+encodeURI(username)+"&password="+encodeURI(password),     
                success: function(msg)
                {
                   if(msg==="1")
                   {
                        tempFlag=1;
                       
                   }
                },   
                error:function(msg)
                {   //alert(msg);
                }   
      
             });  
    }         
    return tempFlag; 
}
///查询防伪码
function querySecurityCode()
{
    var code=$('#txt_SecurityCode').val();
    if(code===null||code==='')
    {
        art.dialog.tips("<p style='font-size:12px;color:red;'>防伪码不能为空，请重新输入！</p>",3);
        $('#txt_SecurityCode').focus();
    }
    else
    {   
        var pattern=/[0-9]{16}/;
        if(!pattern.exec(code))
        {
            art.dialog.tips("<p style='font-size:12px;color:red;'>对不起，你输入的防伪码格式有误（应该为16位数字），请核查！</p>",3);
            return false;
        }
        else
        {
            if(!!checkSecurityCodeRight(code))
            {
                art.dialog.tips("<div style='font-size:12px;color:green;'><p>恭喜，该防伪码有效！</p><p>您登录后，您可以凭借此号获取相应的权限！</p></div>",3);
            }
            else
            {
                 art.dialog.tips("<div style='font-size:12px;color:red;'><p>对不起，你输入的防伪码未能通过验证,可能的原因：</p><p>1.你的防伪码已经过期<br/>2.你输入了错误的防伪码<p></div>",3);
            }
        }
    }
}
///判断防伪码是否正确
function checkSecurityCodeRight(code)
{
    var tempFlag=0;
     $.ajax(
            {   
                type: "get",  
                contentType: "application/json;utf-8",
                cache: false,
                async:false,
                url: "../UserShow/AjaxHandler/CheckSecurityCodeRight.ashx",                                     
                data: "code="+code,     
                success: function(msg)
                {
                   if(msg==="1")
                   {
                        tempFlag=1;
                       
                   }
                },   
                error:function(msg)
                {   //alert(msg);
                }   
      
             });  
           return tempFlag;   
}

