﻿
function CheckLogin(userName,passWrod,Valitar)
{
    if(userName=="")  {  
       alert("温馨提示：登陆名不能为空！");
       return false;
    }else {
      // document.getElementById("spanName").innerHTML=""; 
    }
    if(passWrod=="")  {
       alert("温馨提示：密码不能为空！");
       return false;
    }else  {
      // document.getElementById("spanPass").innerHTML="";
    }
  SendAjax("ConMain",userName,passWrod,Valitar);
}


function CheckLogin()
{
   var userName = jQuery("#txtLoginName").val();
   var passWrod= jQuery("#txtPassword").val();
   var Valitar= jQuery("#txtCode").val();
   var s=userName+passWrod;
    if(userName=="")  {  
       alert("温馨提示：登陆名不能为空！");
    }else {
      // document.getElementById("spanName").innerHTML=""; 
    }
    if(passWrod=="")  {
       alert("温馨提示：密码不能为空！");
    }else  {
      // document.getElementById("spanPass").innerHTML="";
    }
    if(userName!=""&&passWrod!=""){
       SendAjax("ConMain",userName,passWrod,Valitar);
    }
 
}

function SendAjax(op,Name,passWrod,Valitar) {
    var host ="http://"+ document.location.host+"/";
    //var port=document.location
   jQuery.ajax({
    type:"POST",
    url:host+"filehandle/loginform.ashx",
    data:"Option="+ op +"&txtLoginName="+ Name +"&txtPassword="+ passWrod+"&txtCode="+Valitar,
    success:function(retval){
      	  if(retval=="true") {
		    //var url=document.referrer; //update by yepeng 20110625
		    var returl=document.location+"";
		    var returnurl="";
		    if(returl.indexOf("returnurl=")>0){
		       returnurl=returl.split("returnurl=")[1];
		    }
		 
		    if(returnurl!=""){
		       window.location.href=returnurl; 
		    }
		    else{
		       window.location.href=host+"account/info"; 
		    }
            
		  }else {
		     alert(retval);
		  }
    }
   });//end ajax
}
$(document).ready(function() 
    {
       var xzsyw=$.cookie("xzsyw");
       if(xzsyw!=null){
       
           var username="username";
           var usernameval="";
           var arrval=xzsyw.split('&');
           for(var i = 0; i < arrval.length;i++){
             if(arrval[i].substring(0,username.length+1)==(username + '=')){
                usernameval=decodeURIComponent(arrval[i].substring(username.length + 1));
                break;
             }
           }
            if(usernameval!=""){
             $("#panel-login").hide();
             $("#panel-logined").show();            
             $("#top-username").html(usernameval);
           }
           
       }
 
    }
);

jQuery.cookie = function(name, value, options) { 
    if (typeof value != 'undefined') { // name and value given, set cookie 
        options = options || {}; 
        if (value === null) { 
            value = ''; 
            options.expires = -1; 
        } 
        var expires = ''; 
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 
            var date; 
            if (typeof options.expires == 'number') { 
                date = new Date(); 
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 
            } else { 
                date = options.expires; 
            } 
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 
        } 
        var path = options.path ? '; path=' + options.path : ''; 
        var domain = options.domain ? '; domain=' + options.domain : ''; 
        var secure = options.secure ? '; secure' : ''; 
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 
    } else { // only name given, get cookie 
        var cookieValue = null; 
        if (document.cookie && document.cookie != '') { 
            var cookies = document.cookie.split(';'); 
            for (var i = 0; i < cookies.length; i++) { 
                var cookie = jQuery.trim(cookies[i]); 
                // Does this cookie string begin with the name we want? 
                if (cookie.substring(0, name.length + 1) == (name + '=')) { 
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break; 
                } 
            } 
        } 
        return cookieValue; 
    } 
};
  
