// JavaScript Document
/* 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;
	}
	
	/* Tab 1 */
	var jsTab1;
	if ((jsTab1 = document.getElementById("jsTab1"))) {
		jsTab1.onclick = tabSwitch1;
	}
	
	/* Tab 2  */
	var jsTab2;
	if ((jsTab2 = document.getElementById("jsTab2"))) {
		jsTab2.onclick = tabSwitch2;
	}
	
	/* Tab 3 */
	var jsTab3;
	if ((jsTab3 = document.getElementById("jsTab3"))) {
		jsTab3.onclick = tabSwitch3;
	}
	
}


/* 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 Tab 1 */
function tabSwitch1(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("js1");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTab1");
	toHighlight.parentNode.className = "extFirstTabSelected";
	var toHighlight = document.getElementById("jsTab2");
	toHighlight.parentNode.className = "extSelectedTabRight";
	var toHighlight = document.getElementById("jsTabEmpty");
	toHighlight.parentNode.className = "extRightEndBlock";
	return false;
}

/* Click event handler for Tab 2 */
function tabSwitch2(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("js2");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTab2");
	toHighlight.parentNode.className = "tabSelected";
	var toHighlight = document.getElementById("jsTab1");
	toHighlight.parentNode.className = "extFirstTab extSelectedTabLeft";
	var toHighlight = document.getElementById("jsTab3");
	toHighlight.parentNode.className = "extSelectedTabRight";
	var toHighlight = document.getElementById("jsTabEmpty");
	toHighlight.parentNode.className = "extSelectedTabRightEndBlock";
	return false;
}

/* Click event handler for Tab 3  */
function tabSwitch3(e) {
	tabGroupMainHideAll();
	var toShow = document.getElementById("js3");
	toShow.style.display = "block";
	tabGroupMainDeselectAll();
	var toHighlight = document.getElementById("jsTab3");
	toHighlight.parentNode.className = "tabSelected";
	var toHighlight = document.getElementById("jsTab1");
	toHighlight.parentNode.className = "extFirstTab";
	var toHighlight = document.getElementById("jsTab2");
	toHighlight.parentNode.className = "extSelectedTabLeft";
	var toHighlight = document.getElementById("jsTabEmpty");
	toHighlight.parentNode.className = "extSelectedTabRightEndBlock";
	return false;
}


/* Hides all contents for the main tab group on the homepage */
function tabGroupMainHideAll() {
	var toHide;
	
	if ((toHide = document.getElementById("js1"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("js2"))) {
		toHide.style.display = "none";
	}
	if ((toHide = document.getElementById("js3"))) {
		toHide.style.display = "none";
	}
}

/* Deselects all tabs for the main tab group on the homepage */
function tabGroupMainDeselectAll() {
	var toDeselect;
	
	if ((toDeselect = document.getElementById("jsTab1"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTab2"))) {
		toDeselect.parentNode.className = "";
	}
	if ((toDeselect = document.getElementById("jsTab3"))) {
		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;
	var toHighlight;
	if ((toShow = document.getElementById("js1"))) {
		toShow.style.display = "block";
	}
	if ((toHighlight = document.getElementById("jsTab1"))) {
		toHighlight.parentNode.className = "extFirstTabSelected";
	}
	if ((toHighlight = document.getElementById("jsTab2"))) {
		toHighlight.parentNode.className = "extSelectedTabRight";
	}
	if ((toHighlight = document.getElementById("jsTabEmpty"))) {
		toHighlight.parentNode.className = "extRightEndBlock";
	}
	
}

/* 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);
