/*
	jumpMenu used for dropdown form objects
*/
function jumpMenu(selObj)
{
	var warningURL="/code/tools/site/extURL.jhtml";
	var temp = selObj[0].value;
	var page = selObj[selObj.selectedIndex].value;

	if (temp == page) {
		alert("Please select option");
 	} else {
		document.location.href = page;
	}
}

// Browser detect, looking only NS6
var isNS6 = false;
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf("netscape6") != -1) isNS6 = true;

var fontSize = 100;
var fMax = 120;
var fMin = 100;
/*
	setFontSize
*/
function setFontSize()
{
	var tempSize = getCookie("fontSize");
	if(tempSize!=null && tempSize>=100 && tempSize<=120)
	{
		fontSize = tempSize;
	}
	document.body.style.fontSize = fontSize + "%";
}


/*
	changeFontSize is an internal/private function
	controls how much the font is increased by and
	limits fontsize changes
*/
function changeFontSize(increment)
{

	if(increment)
		fontSize+=10;
	else
		fontSize-=10;

	if(fontSize>fMax)
		fontSize = fMax;
	if(fontSize<fMin)
		fontSize = fMin;

	switch(fontSize){
		case 100:
			document.body.style.fontSize = "1em";
			break;
		case 110:
			document.body.style.fontSize = "1.10em";
			break;
		case 120:
			document.body.style.fontSize = "1.20em";
			break;
		default:
	}
	setCookie("fontSize",fontSize,"","/");
	if (isNS6) window.location.reload();
}


function incrementFontSize()
{
	changeFontSize(true);
}


function decrementFontSize()
{
	changeFontSize(false);
}


/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}




/* Replace the country selection select list with a link */
function replaceSelectList() {
  /* Country selection select list */
	var countrySelectForm;
	
	if ((countrySelectForm = document.getElementById("countrySelectForm"))) {
	
		countrySelectForm.style.display = "none";
		/* View all link */
		var viewAllList = document.getElementById("viewAllList");
		viewAllList.style.display = "block";
		
	}
		
}

/* Setup event handlers */
function assignEventHandlers() {
	
	/* View all link */
	var viewAllLink;
	if (viewAllLink = document.getElementById("viewAllLink"))
	{
	viewAllLink.onclick = viewAllListClick;
	}
	
	/* Close link */
	var closeCountryListPopup
	if (closeCountryListPopup = document.getElementById("closeCountryListPopup"))
	{
		closeCountryListPopup.onclick = closeCountryListPopupClick;
	}

	/* Share Price tab */
	var jsTabSharePrice;
	if (jsTabSharePrice = document.getElementById("jsTabSharePrice")) {
		jsTabSharePrice.onclick = tabSwitchSharePrice;
	}
	
	/* Group News tab */
	var jsTabGroupNews;
	if ((jsTabGroupNews = document.getElementById("jsTabGroupNews"))) {
		jsTabGroupNews.onclick = tabSwitchGroupNews;
	}
	
	/* Personal Banking */
	var jsTabPersonal;
	if ((jsTabPersonal = document.getElementById("jsTabPersonal"))) {
		jsTabPersonal.onclick = tabSwitchPersonal;
	}
	
	/* Private Banking */
	var jsTabPrivate;
	if ((jsTabPrivate = document.getElementById("jsTabPrivate"))) {
		jsTabPrivate.onclick = tabSwitchPrivate;
	}
	
	/* Business & Commercial */
	var jsTabBusiness;
	if ((jsTabBusiness = document.getElementById("jsTabBusiness"))) {
		jsTabBusiness.onclick = tabSwitchBusiness;
	}
	
	/* Corporate & Institutional */
	var jsTabCorporate;
	if ((jsTabCorporate = document.getElementById("jsTabCorporate"))) {
		jsTabCorporate.onclick = tabSwitchCorporate;
	}
	
	/* Specialist areas */
	var jsTabSpecialist;
	if ((jsTabSpecialist = document.getElementById("jsTabSpecialist"))) {
		jsTabSpecialist.onclick = tabSwitchSpecialist;
	}
	
}


/* Click event handler for view all link */
function viewAllListClick(e) {
	var countryListPopup = document.getElementById("countryListPopup");
	countryListPopup.style.display = "block";
	return false;
}

/* Click event handler for close link */
function closeCountryListPopupClick(e) {
	var countryListPopup = document.getElementById("countryListPopup");
	countryListPopup.style.display = "none";
	return false;
}

/* Click event handler for Share Price */
function tabSwitchSharePrice(e) {
	tabGroupRightHideAll();
	var toShow = document.getElementById("jsSharePrice");
	toShow.style.display = "block";
	tabGroupRightDeselectAll();
	var toHighlight = document.getElementById("jsTabSharePrice");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Click event handler for Group News */
function tabSwitchGroupNews(e) {
	tabGroupRightHideAll();
	var toShow= document.getElementById("jsGroupNews");
	toShow.style.display = "block";
	tabGroupRightDeselectAll();
	var toHighlight = document.getElementById("jsTabGroupNews");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Click event handler for Personal Banking */
function tabSwitchPersonal(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("jsPersonal");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTabPersonal");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Click event handler for Private Banking */
function tabSwitchPrivate(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("jsPrivate");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTabPrivate");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Click event handler for Business & Commercial */
function tabSwitchBusiness(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("jsBusiness");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTabBusiness");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Click event handler for Corporate & Institutional */
function tabSwitchCorporate(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("jsCorporate");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTabCorporate");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Click event handler for Specialist areas */
function tabSwitchSpecialist(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("jsSpecialist");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTabSpecialist");
	toHighlight.parentNode.className = "selectedItem";
	return false;
}

/* Hides all contents for the main tab group on the homepage */
function tabGroupMainHideAll() {
	var toHide;
	
	if ((toHide = document.getElementById("jsPersonal"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("jsPrivate"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("jsBusiness"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("jsCorporate"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("jsSpecialist"))) {
		toHide.style.display = "none";
	}
}

/* Deselects all tabs for the main tab group on the homepage */
function tabGroupMainDeselectAll() {
	var toDeselect;
	
	if ((toDeselect = document.getElementById("jsTabPersonal"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTabPrivate"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTabBusiness"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTabCorporate"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTabSpecialist"))) {
		toDeselect.parentNode.className = "";
	}
}

/* Hides all contents for the right hand tab group on the homepage */
function tabGroupRightHideAll() {
	var toHide;
	if ((toHide = document.getElementById("jsSharePrice"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("jsGroupNews"))) {
		toHide.style.display = "none";
	}
}

/* Hides all contents for the right hand tab group on the homepage */
function tabGroupRightDeselectAll() {
	var toDeselect;
	if ((toDeselect = document.getElementById("jsTabSharePrice"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTabGroupNews"))) {
		toDeselect.parentNode.className = "";
	}
}

/* Hides all contents for the main tab group on the homepage */
function tabsShowDefaults() {
	tabGroupMainHideAll();
	tabGroupRightHideAll();
	var toShow;
	var toHide;
	if ((toShow = document.getElementById("jsPersonal"))) {
		toShow.style.display = "block";
	}
	if ((toShow = document.getElementById("jsGroupNews"))) {
		toShow.style.display = "block";
	}
	if ((toShow = document.getElementById("jstTopTabs"))) {
		toShow.style.display = "block";
	}
	
	if ((toHide = document.getElementById("jstGroupNewsHeader"))) {
		toHide.style.display = "none";
	}
	
	if ((toHide = document.getElementById("jstSharePriceHeader"))) {
		toHide.style.display = "none";
	}

}

/* Adds event handlers to the window.onload event */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    };
  }
}

/* Add event handlers to the window.onload event */
addLoadEvent(replaceSelectList);
addLoadEvent(assignEventHandlers);
addLoadEvent(tabsShowDefaults);



