﻿
	    	var $j = jQuery.noConflict();
	    	$j(document).ready(function() {
	    		setLoginStyle();
	    		isLogin();
	    	});

	    	function setLoginStyle() {

	    		$j('#login_txtUserName').focus(function() {
	    		if ($j("#login_txtUserName").val() == "LoginEmail")
	    			$j('#login_txtUserName').val('');
	    	
	    		});

	    		$j('#login_txtUserPwd').focus(function() {
	    		if ($j('#login_txtUserPwd').val() == "******")
	    			$j('#login_txtUserPwd').val('');
	    	
	    		});

	    		$j('#login_txtUserName').blur(function() {
	    			var userName = $j(this).val();
	    			if (userName == '') {
	    			    $j(this).val("LoginEmail");
	    				$j(this).next().html($j(this).attr('msg'));
	    			} else {
	    				$j(this).next().html('');
	    			}
	    		});

	    		$j('#login_txtUserPwd').blur(function() {
	    			var userPwd = $j(this).val();
	    			if (userPwd == '') {
	    			    $j(this).val("******");
	    				$j(this).next().html($j(this).attr('msg'));
	    			} else {
	    				$j(this).next().html('');
	    			}
	    		});
	    	}

	    	function checkLogin() {
	    		var userName = $j('#login_txtUserName').val();
	    		var userPwd = $j('#login_txtUserPwd').val();
	    		if (userName == '' || userName == 'LoginEmail') {
	    			
	    			$j('#login_txtUserName').next().html('*');
	    			return false;
	    		}
	    		if (userPwd == '' || userPwd == "******") {
	    			$j('#login_txtUserPwd').next().html('*');
	    			return false;
	    		}
	    		return true;
	    	}

	    	function userLogin() {
	    		if (!checkLogin()) {
	    			return false;
	    		}

	    		var userName = $j('#login_txtUserName').val();
	    		var userPwd = $j('#login_txtUserPwd').val();
	    		$j('#div_login_wait').show();
	    		$j.ajax({
	    			url: '/Ajax.aspx?rd=' + Math.random(),
	    			type: 'post',
	    			data: 'operate=Login&userName=' + userName + '&userPwd=' + userPwd,
	    			dataType: 'json',
	    			success: function(data) {
	    				initLoginControlByJson(data, true);
	    			    window.location.href="/";
	    			}
	    		});
	    	}

	    	function loginOut() {

	    		$j.ajax({
	    			url: '/Ajax.aspx?rd=' + Math.random(),
	    			type: 'post',
	    			data: 'operate=LoginOut',
	    			dataType: 'html',
	    			success: function() {
	    			
	    				$j('#divLoginOut').show();
	    				$j('#divLoginIn').hide();
	    				$j('#div_unLogin').show();
	    				$j('#div_login').hide();
	    				window.location.href="/";
	    			}
	    		});
	    	}

	    	function isLogin() {
	    
	    		$j.ajax({
	    			url: '/Ajax.aspx?rd=' + Math.random(),
	    			type: 'post',
	    			data: 'operate=IsLogin',
	    			dataType: 'json',
	    			success: function(data) {
	    			
	    				initLoginControlByJson(data, false);
	    			}
	    		});
	    	}

	    	function initLoginControlByJson(loginUser, isUserLogin) {
	    		
	    		if (loginUser == null) {
	    			if (isUserLogin) {
                           alert('Login Failed!');
	    				
	    			}
	    		} else {
//	    		    alert('Login Sucess')
	    			$j('#lg_spUserName').html(loginUser.Username);
        			$j('#div_login').show();
                    $j('#div_unLogin').hide();
                    $j('#divLoginOut').hide();
                    $j('#divLoginIn').show();
                    $j('#login_txtUserName1').val(loginUser.Username);
                    $j('#login_txtUserName1').html(loginUser.Username);
                    VipUserInfo();
	    		}
	    	}
	    	
	    	function VipUserInfo(){

	
var email=$j('#login_txtUserName').val();

    $j.ajax({
        url:'/Ajax.aspx?rd='+Math.random(),
        type:'get',
        data:'operate=SelectVipUserInfo&email='+email,
        dataType:'json',
        success:function(data){
//            $j('#VipUserEmail').html($j('#login_spUserName').html());
//            $j('#VipUserRank').html(data.VipUserRank);
//            $j('#VipUserCredits').html(data.VipUserCredits);
            $j('#VipUserPoint').html(data.VipUserPoint);
//            $j('#LoginUserImg').html(getimg(data.VipUserRank));
//            $j('#NextPointChaLabel').html(data.PointsCha);
//            $j('#NextCouponLabel').html(data.VipUserNextCredits);
//            $j('#NextPointChaLabel1').html(data.PointsCha);
//            $j('#NextCouponLabel1').html(data.VipUserNextCredits);
        }
    });
}


