/*******************************************************************************
 * File Name            : JCPFrameTop.js
 * Author               : Keane India Pvt Ltd.,
 * Date of Creation     : 29 September 2008.
 * Description          : Created for FrameTop Module.
 * Version Number       : 1.0
 * Modification History :
 Date         Version  Who             Description of change
 2008-09-29   1.0      Keane India     Initial - created method for setting the
 									   labels,shoppingCart.
*******************************************************************************/
var drillDownHome = "";

// Holds the selected country in the HomePage.
var country = null;

// LanguageId.
var languageId = null;

// Get the Language code for given languageId.
var languageCode = null;

function initialiseFrameTop() {

   if ((top.frames[1].document.getElementById("Country") == null) || (top.frames[1].document.getElementById("Country").value == null) || (top.frames[1].document.getElementById("Country").value.length == 0)) {
      setTimeout(initialiseFrameTop,500);
      return;
   }

   country = top.frames[1].document.getElementById("Country").value;
   languageId = top.frames[1].document.getElementById("languageId").value;;
   languageCode = getLanguageCode(languageId);
   document.body.style.width = document.body.offsetWidth+"px";

   setShoppingCart();
   setLabel();
   initialiseJCPSearch();
   initialiseMenuFrames();
   
}

// Function to change the link in the frame top.
function setShoppingCart() {
	var tableContent = "";

	if ("UnitedStates" == country) {
		tableContent  += "<a href=\"http://www.jaguarusa.com/us/en/_useful_links/locate_a_dealer.htm\" target=\"_blank\" class=\"text11wBold\">" + HtmlDecode(eval("BUY_LOCAL_DEALER" + languageCode)) + "</a>";	
 		document.getElementById('shopCart_id').innerHTML = tableContent;
 	}
}

// Function to direct to My Account.
function directToMyAccount() {
	var loginStatus = top.frames[1].document.getElementById('loginStatus').value;

	if ("false" == loginStatus) {
		top.mainFrame.document.location.href = "JCPLogon.html";
	} else {
		top.mainFrame.document.location.href = "JCPMyAccount.html";
	}
}

// function to handle the log out functionality.
function handleLogout() {
	top.frames[1].document.getElementById('mailId').value = "";
	top.frames[1].document.getElementById('memberId').value = "";
	top.frames[1].document.getElementById('loginStatus').value = "false";
	createCookie(JCPCartCookie, "");
	top.frames[2].document.location.href = "JCPModelMenu.html";
	document.getElementById('logout_Id').style.visibility = "hidden";
}

// Function to set all labels depending on the language selected.
function setLabel() {

	if ("UnitedStates" != country) {
	    document.getElementById('shopCart_id').innerHTML = "<a href=\"JCPShoppingCart.html\"  target=\"mainFrame\" class=\"text11wBold\">" + HtmlDecode(eval("SHOPPNG_CART_LINK" + languageCode)) + "</a>";
	}
	document.getElementById('myAcc_Id').innerHTML = "<a href=\"javascript:directToMyAccount()\" class=\"text11wBold\">" + HtmlDecode(eval("MYACCOUNT_LINK" + languageCode)) + "</a>";
	document.getElementById('contact_Id').innerHTML = "<a href=\"JCPContactUs.html\"  target=\"mainFrame\" class=\"text11wBold\">" +  HtmlDecode(eval("CONTACT_LINK" + languageCode)) + "</a>";	
	document.getElementById('Thesaurus_Id').innerHTML = "<a href=\"javascript:directToThesaurus()\" class=\"text11wBold\">" + HtmlDecode(eval("THESAURUS_LINK" + languageCode)) + "</a>";	 
	document.getElementById('Help_Id').innerHTML = "<a href=\"JCPHelp.html\"  target=\"mainFrame\" class=\"text11wBold\">" + HtmlDecode(eval("HELP_LINK" + languageCode)) + "</a>";
	document.getElementById('logout_Id').innerHTML = "<a href=\"javascript:handleLogout()\" class=\"text11wBold\">" + HtmlDecode(eval("LOGOUT_LINK" + languageCode)) + "</a>";	 	 

	var loginStatus = top.frames[1].document.getElementById("loginStatus").value;

	if ("false" == loginStatus) {
		document.getElementById('logout_Id').style.visibility = "hidden";
	} else {
		document.getElementById('logout_Id').style.visibility = "visible";
	}
}
