﻿function CheckNull(pValue,pMsg)
{
   if(pValue=='') 
   {
     alert(pMsg);
     return false;
   }
   return true;
}


function jslogin()
{

 var txtName=$.trim($("input[name*='username']").val());
 if(!CheckNull(txtName,"对不起，通行证不能为空")){$("input[name*='username']").focus(); return false;}
  
 var txtPsd=$.trim($("input[name*='userpassword']").val());
 if(!CheckNull(txtPsd,"对不起，密码不能为空")) {$("input[name*='userpassword']").focus(); return false;}
 

 Login(txtName,txtPsd);

$('#username').val("");
$('#userpassword').val("");
}



function Gamelogin()
{

 var txtName=$.trim($("input[name*='username']").val());
 if(!CheckNull(txtName,"对不起，通行证不能为空")){$("input[name*='username']").focus(); return false;}
  
 var txtPsd=$.trim($("input[name*='userpassword']").val());
 if(!CheckNull(txtPsd,"对不起，密码不能为空")) {$("input[name*='userpassword']").focus(); return false;}
 
 var serid=$.trim($("select[id='ser']").val());
 
 ajaxLogin(txtName,txtPsd,serid);

$('#username').val("");
$('#userpassword').val("");
}



function ajaxLogin(txtName,txtPsd,serid)
{

 $.ajax({
        type: "post",
        url: "scripts/login.ashx",
        dataType: "text",  
        cache: false,
        async: false,
        data: "uname="+txtName+"&psd="+txtPsd+"&action=gamelogin&serid="+serid,
        success: function(msg) {

        var msgArr=msg.split(',');
         
             if(msgArr[0]=="succ")
             {
                window.location.href('http://fr1.fangte.com'+msgArr[1])
             }
             else
             {
             alert(msgArr[1]);
             }
       }  });


}




 function logiTips(id){
    $(".befor").hide();
    $(".after").show();
    $("#spanMsg").text(id);
 }


  function Login(txtName,txtPsd)
  {
        $.ajax({
        type: "post",
        url: "scripts/login.ashx",
        dataType: "text",  
        cache: false,
        async: false,
        data: "uname="+txtName+"&psd="+txtPsd+"&action=login",
        success: function(msg) {

        var msgArr=msg.split(',');
         
             if(msgArr[0]=="succ")
             {
               logiTips(txtName);
             }
             else
             {
             alert(msgArr[1]);
             }
       }  });
   }
   
   
   
     function logout()
    { 
        $.ajax({
        type: "post",
        url: "scripts/login.ashx",
        dataType: "text",  
        cache: false,
        async: false,
        data: "action=logout",
        success: function(msg) {
          $(".befor").show();
          $(".after").hide();
        }
        });
    }
    
    
    
    
    
    
    
function GameloginMHXX()
{

 var txtName=$.trim($("input[name*='username']").val());
 if(!CheckNull(txtName,"对不起，通行证不能为空")){$("input[name*='username']").focus(); return false;}
  
 var txtPsd=$.trim($("input[name*='userpassword']").val());
 if(!CheckNull(txtPsd,"对不起，密码不能为空")) {$("input[name*='userpassword']").focus(); return false;}
 
 //var serid=$.trim($("select[id='ser']").val());
 
 ajaxLoginMHXX(txtName,txtPsd);

$('#username').val("");
$('#userpassword').val("");
}



function ajaxLoginMHXX(txtName,txtPsd)
{

 $.ajax({
        type: "post",
        url: "scripts/login.ashx",
        dataType: "text",  
        cache: false,
        async: false,
        data: "uname="+txtName+"&psd="+txtPsd+"&action=mhxxgamelogin",
        success: function(msg) {

        var msgArr=msg.split(',');
         
             if(msgArr[0]=="succ")
             {
                window.location.href(msgArr[1])
             }
             else
             {
             alert(msgArr[1]);
             }
       }  });


}











    
function GameloginTJ()
{

 var txtName=$.trim($("input[name*='username']").val());
 if(!CheckNull(txtName,"对不起，通行证不能为空")){$("input[name*='username']").focus(); return false;}
  
 var txtPsd=$.trim($("input[name*='userpassword']").val());
 if(!CheckNull(txtPsd,"对不起，密码不能为空")) {$("input[name*='userpassword']").focus(); return false;}
 
 var ser = $("select[name*='ser']").val(); 
 var regionid = $("select[name*='regionid']").val()?$("select[name*='regionid']").val():""; 

 ajaxLoginTj(txtName,txtPsd,ser,regionid);

$('#username').val("");
$('#userpassword').val("");
}



function ajaxLoginTj(txtName,txtPsd,ser,regionid)
{

 $.ajax({
        type: "post",
        url: "scripts/login.ashx",
        dataType: "text",  
        cache: false,
        async: false,
        data: "uname="+txtName+"&psd="+txtPsd+"&action=tjLogin&ser="+ser+'&regionid='+regionid,
        success: function(msg) {

        var msgArr=msg.split(',');
         
             if(msgArr[0]=="succ")
             {
                window.location.href=msgArr[1];
             }
             else
             {
             alert(msgArr[1]);
             }
       }  });


}




LoginClass=function(config){

this.url=config.url;
this.success=config.success;
this._uname=config.uname;
this._upsd=config.upsd;

this.CheckNull=function (pValue,pMsg){
   if(pValue=='') 
   {
     alert(pMsg);
     return false;
   }
   return true;
};

this.uname=$("input[name*='"+config.uname+"']"); 
this.upsd=$("input[name*='"+config.upsd+"']"); 

this.Login=function(){

 var txtName=$.trim(this.uname.val());
 if(!this.CheckNull(txtName,"对不起，通行证不能为空")){ this.uname.focus(); return false;}
  
 var txtPsd=$.trim(this.upsd.val());
 if(!this.CheckNull(txtPsd,"对不起，密码不能为空")) { this.upsd.focus(); return false;}
 
 data={uname:_login.uname.val(),psd:_login.upsd.val()};
 $.extend(data, config.data);

  $.ajax({
        type: "post",
        url: this.url,
        dataType: "text",  
        cache: false,
        async: false,
        data: data,
        success: this.success
  });      
};
}






function TestLogin()
{
_login=new LoginClass({
data:{action:"tjLogin"},
url:"scripts/login.ashx",
success: function(msg) {
   alert(msg);           
},
uname:'username',
upsd:'userpassword'


});

data={uname:_login.uname.val(),psd:_login.upsd.val(),action:"tjLogin"};
_login.Login();


}
