//------------------------------------------------------------------------------
// Class:  SignIn
//------------------------------------------------------------------------------
// Author:  JY
// Date:  2007/02/26
// Description:  This class defines the functions used by the sign-in area.
//------------------------------------------------------------------------------
function SignIn()
{
	// Properties:
	this.isSignedIn = false;
	this.isCookieWrapperTopExist = false;
	this.cookieWrapperTopValue = 0;
	this.UI_CONTENT_WIDTH = 800;

	//--------------------------------------------------------------------------

	// Methods:
	this.goSignOut = goSignOut;
	this.positionSignInArea = positionSignInArea;
	this.showLoginArea = showLoginArea;
	this.hideLoginArea = hideLoginArea;
	this.goSignIn = goSignIn;
	this.goForgotPassword = goForgotPassword;
	this.moveContentDown = moveContentDown;
	this.moveContentUp = moveContentUp;
	this.moveLoginAreaDown = moveLoginAreaDown;
	this.moveLoginAreaUp = moveLoginAreaUp;

	//--------------------------------------------------------------------------

	function goSignOut()
	{
		var oCookieManager = new CookieManager();
		oCookieManager.setCookie("IS_SHOW_LOGIN_AREA", 0, null, "/");
		oCookieManager.setCookie("WRAPPER_TOP", 0, null, "/");
		document.frmSignOut.action = location.href.replace(/^https:/, "http:");
		document.frmSignOut.submit();			
	}

	//--------------------------------------------------------------------------

	function positionSignInArea()
	{
		var obj = document.getElementById("wrapper");
		var noLoginArea = document.getElementById("noLoginArea");
		var loginArea = document.getElementById("loginArea");
		var x = 0;

		if (obj)
		{
			if (this.isSignedIn)
			{
				if (obj.offsetParent)
				{
					x = obj.offsetLeft;
					while (obj = obj.offsetParent)
					{
						x += obj.offsetLeft;
					}
				}
				loginArea.style.left = (x + (this.UI_CONTENT_WIDTH-230)) + "px";
				loginArea.style.top = "0px";
			}
			else
			{
				if (this.isCookieWrapperTopExist)
				{
					obj.style.top = this.cookieWrapperTopValue + "px";
				}

				if (obj.offsetParent)
				{
					x = obj.offsetLeft;
					while (obj = obj.offsetParent)
					{
						x += obj.offsetLeft;
					}
				}
				noLoginArea.style.left = (x + (this.UI_CONTENT_WIDTH-210)) + "px";
				noLoginArea.style.top = "0px";
				loginArea.style.left = (x + (this.UI_CONTENT_WIDTH-312)) + "px";
				loginArea.style.top = "0px";
			}
		}
	}

	//--------------------------------------------------------------------------

	function showLoginArea()
	{
		var loginArea = document.getElementById("loginArea");
		var oCookieManager = new CookieManager();

		document.getElementById("noLoginArea").style.display = "none";

		loginArea.style.top = "-100px";
		loginArea.style.display = "block";

		moveLoginAreaDown();

		if (document.frmSignIn.loginEmailAddress)
		{
			document.frmSignIn.loginEmailAddress.focus();
		}

		oCookieManager.setCookie("IS_SHOW_LOGIN_AREA", 1, null, "/");
	}

	//--------------------------------------------------------------------------

	function hideLoginArea()
	{
		var oCookieManager = new CookieManager();
		moveLoginAreaUp();
		oCookieManager.setCookie("IS_SHOW_LOGIN_AREA", 0, null, "/");
	}

	//--------------------------------------------------------------------------

	function goSignIn(form)
	{
		var str = location.href;
		//form.action = str.replace(/^http:/, "https:");
		form.action = str;
		form.submit();
	}

	//--------------------------------------------------------------------------

	function goForgotPassword()
	{
		document.frmForgotPassword.emailAddress.value = document.frmSignIn.loginEmailAddress.value;
		document.frmForgotPassword.submit();
	}

	//--------------------------------------------------------------------------

	function moveContentDown()
	{
		var wrapper = document.getElementById("wrapper");
		var y = parseInt(wrapper.style.top);
		var oCookieManager = new CookieManager();

		y += 10;
		wrapper.style.top = y + "px";
		oCookieManager.setCookie("WRAPPER_TOP", y, null, "/");
		this.cookieWrapperTopValue = y;
	}

	//--------------------------------------------------------------------------

	function moveContentUp()
	{
		var wrapper = document.getElementById("wrapper");
		var y = parseInt(wrapper.style.top);
		var oCookieManager = new CookieManager();

		y -= 10;
		wrapper.style.top = y + "px";
		oCookieManager.setCookie("WRAPPER_TOP", y, null, "/");
		this.cookieWrapperTopValue = y;
	}

	//--------------------------------------------------------------------------

	function moveLoginAreaDown()
	{
		var loginArea = document.getElementById("loginArea");
		var y = parseInt(loginArea.style.top);

		if (y < 0)
		{
			y += 10;
			loginArea.style.top = y + "px";
			if (y > -50)
			{
				moveContentDown();
			}
			setTimeout(moveLoginAreaDown, 1);
		}
	}

	//--------------------------------------------------------------------------

	function moveLoginAreaUp()
	{
		var wrapper = document.getElementById("wrapper");
		var y = parseInt(wrapper.style.top);
		var loginArea = document.getElementById("loginArea");
		var y2 = parseInt(loginArea.style.top);
		var mesg = document.getElementById("loginMesg");

		if (y > 0)
		{
			y2 -= 10;
			loginArea.style.top = y2 + "px";
			moveContentUp();
			setTimeout(moveLoginAreaUp, 1);
		}
		else
		{
			loginArea.style.display = "none";
			document.getElementById("noLoginArea").style.display = "block";
			if (mesg.innerHTML != "")
			{
				mesg.innerHTML = "";
			}
		}
	}
}

// Create sign-in object.
oSignIn = new SignIn();

