function getAgentInfo()
{
	var currUrl = window.location.href;
	agenttmp = currUrl.split("?adid=");
	if (agenttmp.length>1)
		document.getElementById('adid').value = agenttmp[1];
}

function chkUserName()
{
	var username=document.getElementById('username').value;
	if(!username)
	{
		alert('Email can not be empty');
		return false;
	}
	var paras='&username='+username;
	if (!regSvrChk("http://www.77.net/include/ChkUserInfo.php",paras))
	{
		};  //添加是否已经被注册；
}

function regSvrChk(url,paras) {
	$.ajax(
    {
        type:"POST",
        url:url,
				data:paras,
        success: function(result)
        {  
					if(result=='0')
					{
						return true;
					}else if(result=='1')
					{
						alert('The Email have been registered!please try another!');
						return false;
					}else if(result=='2')
					{
						alert('The Email can not be empty!please enter your Email!');
						return false;
					}
        },
        error:function()
        {
            alert('login has failed!Please check your net status!');
            return false;
        }
    });
}
function chkPwdClt()
{
	var login_pwd=document.getElementById('new_password').value;
	var password_confirm=document.getElementById('password_confirm').value;
	if(!login_pwd)
	{
		alert('password can not be empty');
		return false;
	}
	if(!password_confirm)
	{
		alert('confirm password can not be empty');
		return false;
	}
	if (login_pwd!=password_confirm)
	{
		alert('Please enter the same password!');
		return false;		
	}
	return true;
}

function regDataChk(theform) //注册
{
	var username=document.getElementById('username').value;
	var login_pwd=document.getElementById('new_password').value;
	var password_confirm=document.getElementById('password_confirm').value;
	var chkAgree=document.getElementById('chkAgree').checked;	
	if (!chkAgree)
	{
		alert("Please choose 'I agree to receive and notification from Majesty'");
		return false;		
		}
	if(!username)
	{
		alert('Email can not be empty');
		return false;
	}
	else
	{
	if (!emailCheck('username'))
	   return false;
	}
	chkPwdClt();
	
	<!--需要js补充的数据-->
	document.getElementById('email').value = username;
	document.getElementById('email_confirm').value = username;

	var paras='&username='+username;
	if (!regSvrChk("http://www.77.net/include/ChkUserInfo.php",paras))  //添加是否已经被注册；
	{	
	  document.myform.submit();
	}else {
		document.getElementById('new_password').value="";
		document.getElementById('password_confirm').value="";
	}
}

function emailCheck(emailObj){//邮箱验证；
    var theEmail=document.getElementById(emailObj).value;
    var Email = theEmail.toLowerCase();
    var ok = false;
    var count = 0;
    var fullEmail;
    if (Email.length!=0 && Email.indexOf('@') != -1 && Email.indexOf('.') != -1 && (Email.indexOf('.') - Email.indexOf('@') > 1)){
        if ((Email.length-1) != Email.indexOf('@') && (Email.length-1) !=Email.indexOf('.') && Email.indexOf('@')!=0 && Email.indexOf('.')!=0){
            for (var i=0;i<Email.length;i++){
            fullEmail=Email.charAt(i);
              if ((fullEmail>= 'a' && fullEmail<= 'z') || (fullEmail >= 0 && fullEmail<= 9) || (fullEmail == '-')|| (fullEmail == '_') || (fullEmail == '@') || (fullEmail == '.')){
                  if (fullEmail == '@'){
                     count++;
                  }
              }else{
               alert("the Email has illegal character");
               return false;
              }
          }
          if((Email.indexOf('@')+1)<3 || (Email.indexOf('@')+1)>45){
           alert("the number of that the left of character '@' have to from 3 to 45");
           return false;
                }

                if (count != 1){
                alert("the Email can not have two '@' character!");
                return false;
               }
        }else{
         alert("the first of the Email can not be @or . and the end can not be @or '.'");
		 return false;
        }
    }else{
      alert("Please enter your Email");
	  return false;
    }
    return true;
   }

function getCurDate(aObjName)//以太平洋时间显示；
{
	$.get("http://www.77.net/Common/GetServerDt.php",{localdt:new Date().getTime()},function(data){ //new Date().getTime() 为了解决get相同url时读取IE的问题；
    if (data){
			eval("var serverDtTmp = "+unescape(data));
			document.getElementById(aObjName).innerHTML= serverDtTmp;
	  }
	});	
	window.setTimeout("getCurDate('"+aObjName+"')", 1000);			
}

function AfterLoad()
{
	getCurDate("localdate");
	}

//获取cookie值；
function getCookie(sName)
{
  var aCookie = document.cookie.split("; ");

	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		
		if (encodeURIComponent(sName) == aCrumb[0])
		{
			return decodeURIComponent(aCrumb[1]);
		}
	}
  return null;
}


function checkLogin(theform) //登录验证；
{
    var username=document.getElementById('username').value;
    var login_pwd=document.getElementById('password').value;

	if(!username)
	{
		alert('Email can not be empty');
		return false;
	}
	else
	{
	    if (!emailCheck('username'))
		   return false;
	}
    if(!login_pwd)
	{
		alert('password can not be empty');
		return false;
	}
	var login_id_tem=getCookie('loginreg');
    if(login_id_tem){
			alert('Hello '+username+'! Please choose the server!');
			location.href='http://www.77.net/list/';
	}
	var paras='&isMReg=1&act=2&username='+username+'&password='+login_pwd;
	loginChk(document.getElementById("myform").action,paras);	
	return false;	
}

function loginChk(url,paras) {
	$.ajax(
    {
        type:"POST",
        url:url,
				data:paras,
        success: function(result)
        {  
					if(result=='LOGIN_SUCCESS')
					{
						location.href='http://www.77.net/list/';
					}else if(result=='LOGIN_BREAK')
					{
						alert('error:login break!');
						return false;
					}else if(result=='LOGIN_ERROR_ATTEMPTS')
					{
						alert('You exceeded the maximum allowed number of login attempts. In addition to your username and password you now also have to enter the confirm code from the image you see below.');
						return false;
					}else if(result=='LOGIN_ERROR_PASSWORD_CONVERT')
					{
						alert('It was not possible to convert your password when updating this bulletin board’s software.Please try another');
						return false;
					}	else {
					  alert('Error! Please check you Email and password and try angain!');
						return false;
						}
        },
        error:function()
        {
            alert('login has failed!Please check you Email or password!');
            return false;
        }
    });
}

function IsEmpty(v){
	switch (typeof v){
		case 'undefined' : return true;break;
		case 'string' : if(v.length == 0) return true; break;
		case 'boolean' : if(!v) return true; break;
		case 'number' : if(0 === v) return true; break;
		case 'object' :
			if(null === v) return true;
			if(undefined !== v.length && v.length==0) return true;
			for(var k in v)
				{return false;} 
			return true;
			break;
	}
	return false;
}

function MakeServerUrl(asid){
	var uname = unescape(getCookie('login_name'));
	if (!IsEmpty(uname)){
		window.location.href = "http://www.77.net/user/LoginApi.php?act=login&u="+uname+"&sid="+asid;
	}else{
		alert('Please login!');		
	}
}

function MakeChargeUrl(){
	var uname = unescape(getCookie('login_name'));
	if (!IsEmpty(uname)){
		window.location.href = "http://www.77.net/pay/";
	}else{
		alert('Please login!');		
	}
}