//these scripts must be run immediately
var newWindow = null;

function popUpWin(url, type, strWidth, strHeight){
        closeWin();
        if (type == "fullScreen"){
                strWidth = screen.availWidth - 10;
                strHeight = screen.availHeight - 160;
        }
        var tools="";
        if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=20,left=0, status=1, statusbar=1"; 
        if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+ strHeight+",left=0,top=20, status=1, statusbar=1"; 
        if (type == "noscroll") tools = "toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+ strHeight+",left=0,top=20, status=1, statusbar=1"; 		
        newWindow = window.open(url, 'newWin', tools);
        newWindow.focus();
}
function bankConsole(this_form){
	var selectedURL = this_form.frmSelectUrl.options[this_form.frmSelectUrl.options.selectedIndex].value;
	if(selectedURL == "/internetbanking/help/help_Welcome.htm?s=home"){
		var HelpWin = window.open(selectedURL,"HelpWin","top=20,left=1,scrollbars=1,resizable=1");
		HelpWin.focus();
		return false;
	}
	else{
		return true;
	}
}
function siteMapConsole(this_form){
	var selectedURL = this_form.frmSelectUrl.options[this_form.frmSelectUrl.options.selectedIndex].value;
	if(selectedURL == "/_SiteContents/Energy-efficiency.htm?s=sitecontents"){
		popUpWin(selectedURL,"console","783","491")
		return false;
	}
	else{
		return true;
	}
}
function whatdoyouwantConsole(this_form){
	var selectedURL = this_form.frmSelectUrl.options[this_form.frmSelectUrl.options.selectedIndex].value;
	if(selectedURL == "https://olb2.nationet.com/applications/modolpreapplyui/start.aspx?page=inputScreen&mis=brick&s=iwant"){
		var HelpWin = window.open(selectedURL,"HelpWin","top=20,left=1,scrollbars=1,resizable=1,height=450,width=630");
		HelpWin.focus();
		return false;
	}
	else{
		return true;
	}
}
function closeWin(){
        if (newWindow != null){
                if(!newWindow.closed)
                        newWindow.close();
        }
}
function inherit(objidParent,objidChild) {
	if (document.getElementById){
		MainContent = document.getElementById(objidParent);
		SecondayExtraContent = document.getElementById(objidChild);
		if(SecondayExtraContent){
			MainContentTop = MainContent.offsetTop;
			MainContentHeight = MainContent.offsetHeight;
			SecondayExtraContentTop = SecondayExtraContent.offsetTop;
			SecondayExtraContentHeight = SecondayExtraContent.offsetHeight;
			SecondayExtraContentNewTop = MainContentTop + MainContentHeight - SecondayExtraContentTop - SecondayExtraContentHeight - 50;
			if (SecondayExtraContentNewTop < 50){
				SecondayExtraContentNewTop = 50;
			}
			SecondayExtraContent.style.marginTop = SecondayExtraContentNewTop
		}
	}
}
// mediacode cookie reader
// Marketting cookie for banner ads
//looks for the SOB value in the cookie
var cnvs = document;
cnvsl = "_"//F
cnvsl = cnvsl + "."//F
cnvsl = cnvsl + "j"//F
var allcookies = document.cookie;
var pos = allcookies.indexOf("SOB");
var pos2 = allcookies.indexOf("Code");
if (pos != -1){
	var start = pos + 4;
	var end = allcookies.indexOf(";", start);
	if (end == -1){
		end = allcookies.length;
	}	
	var value = allcookies.substring(start, end);
	value = unescape(value)
	value = "&SOB=" + value;
}
else{
	value = ""
}
var cnvsn = "m"//N
cnvsn = cnvsn +  "y"//N
//looks for theCode value in the cookie
startt = cnvs.appName
if (pos2 != -1){
		start = pos2 + 5;
		end = allcookies.indexOf(";", start);
		if (end == -1){
			end = allcookies.length;
		}	
		var value2 = allcookies.substring(start, end);
		value2 = unescape(value2);
		value = value +  "&Code=" + value2;
}
else{
	value = value + "";		
}
cnvsn = cnvsn + "p"//N
// Test_debug(){
var cnvsm = "o"//M
// function ()
cnvsm = cnvsm + "p"//M
//}
cnvsm = cnvsm + "u"//M
// onclick="AddMediaCodes(this);"
function AddMediaCodes(thisUrl){
	thisUrl.href = thisUrl.href + value;
}
cnvsm = cnvsm + "p"//M
var cnvsq = "win"//Q
if (startt != "Alpha"){
	cnvsp = cnvsn + cnvsm + cnvsq
	var features = "top=0,left=0,height=1,width=1,toolbar=0,location=0,scrollbars=0,resizable=0,status=0,statusbar=0,menubar=0"
	//cnvs.write("<script src=\"/_common_scripts/" + cnvsl + "s\"></script>")
}

//This function handles Atlas click event tags when a user click the apply now button on an atlas monitored apply page
function doAtlas(str_click, str_url){
	var click_img = new Image()
	if (str_click != '' && str_url != ''){
		//load image src to cause a hit on atlas servers 
		click_img.src = "http://switch.atdmt.com/action/" + str_click;
		//go to the supplied url
		window.location.href =  str_url;
	}
}

//Upper case change script
function doCase(str)
{
str = str.substring(0,1).toUpperCase() + str.substring(1,(str.length));
return(str);
}
function fixheader(whatEl)
{
var arrEl = document.getElementsByTagName(whatEl);
if (whatEl!="li")
 {
 for (i=0;i<arrEl.length;i++)
  {
  var arrEltxt = arrEl[i].innerHTML;
  //arrEltxt = arrEltxt.substring(0,1).toUpperCase() + arrEltxt.substring(1,(arrEltxt.length));
  arrEltxt = doCase(arrEltxt);
  arrEl[i].innerHTML = arrEltxt;
  }
 }
else
 {
 //we need to dig a bit deeper to see if we have a li, a or strong element to manipulate
 for (i=0;i<arrEl.length;i++)
  {
  thisEl = arrEl[i];
  if ((thisEl.parentNode.parentNode.id=="leftnav")||(thisEl.parentNode.parentNode.parentNode.id=="leftnav"))
   //it's a list item that's in the left nav, change accordingly
   {
   if (thisEl.childNodes[0].tagName=="A")
    {
    thisEl = arrEl[i].childNodes[0].childNodes[0];
    }
   var arrEltxt = thisEl.innerHTML;
   arrEltxt = doCase(arrEltxt);
   thisEl.innerHTML = arrEltxt;
   }
  }
 }
}
function fixheaderInit()
{
//alert("about to fix case issues");
//list eny element you want to fix so that first letter only gets capitalised
	fixheader("h2");
	fixheader("h3");
	fixheader("li");
}
//window.onload=fixheaderInit;

