﻿var IsUpdate=false;
var $ =function(ID){return document.getElementById(ID);};
//enter event
function checkenter(evt,para,option)
{
	evt = evt ? evt : (window.event ? window.event : null);	
	if(evt.keyCode == 13)
	{
		switch(para)
		{
			case 0:
				var option=document.getElementById(option);
				option.focus();
				break;
			case 1:
				setTimeout(option,100)
				break;
		}
		return false;
	}
}
//
function Login()
{
	var txtEmail=$("txtEmail");
	var txtPassword=$("txtPassword");
	if(txtEmail.value=="")
	{
		alert("Email can't be empty.");
		return;
	}
	if(txtPassword.value=="")
	{
		alert("Password can't be empty.");
		return;
	}	
	var result=aoc.ajax.common.Login(txtEmail.value,txtPassword.value).value;
	if(result!="")
	{
		$("tbIsLogin").style.display="";
		$("tbNotLogin").style.display="none";
		$("tdLoginInfo").innerHTML=result;
		if(IsUpdate)
			LoginReload();
	}
	else
	{
		$("tbIsLogin").style.display="none";
		$("tbNotLogin").style.display="";
		alert("Email or Password Error.");
	}
	txtEmail.value="";
	txtPassword.value="";
}
//
function Logout()
{
	var result=aoc.ajax.common.Logout().value;
	$("tbIsLogin").style.display="none";
	$("tbNotLogin").style.display="";
	if(IsUpdate)
		LogoutReload();	
}
//
function CheckLogin()
{
	var result=aoc.ajax.common.CheckLogin().value;
	if(result!="")
	{
		$("tbIsLogin").style.display="";
		$("tbNotLogin").style.display="none";
		$("tdLoginInfo").innerHTML=result;
	}
	else
	{
		$("tbIsLogin").style.display="none";
		$("tbNotLogin").style.display="";
	}
}
//
function getQueryString(key)
{
	var locString = location.search;
	var reg = new RegExp("(\\?|\\&)" + key + "=([^\\&]*)(\\&?)","i").exec(locString);
	return RegExp.$2;
}
//
function CheckAff()
{
	var aff=getQueryString("aff")
	if(aff!="")
		var result=aoc.ajax.common.SaveAff(aff).value;
}
function WebAction()
{
	var blnCheckUnload = true;
	window.onbeforeunload=function(){aoc.ajax.index.windowclose();if( (event.clientX > document.body.clientWidth && event.clientY < 0)|| event.altKey ){aoc.ajax.index.Updateend();}};
	var lfile=window.location.pathname;
	var visitUrl=window.location.href;
	var fromurl=document.referrer;
	var fromurl=document.referrer;
	if(fromurl=="")
		fromurl="about:blank";
	var ii=aoc.ajax.index.indexstart(window.location.href,fromurl).value;
	var ru = aoc.ajax.index.UpdateisScript("1").value;
	var wh=window.screen.width+"x"+window.screen.height;
	aoc.ajax.index.UpdateRatio(wh);
	if(visitUrl.toLowerCase().indexOf("buy%2daoc%2dgold")<0)
		aoc.ajax.index.wPage(lfile,visitUrl);
}
WebAction();
CheckLogin();
CheckAff();

