//All global onload events
$(document).ready(
 function()
 {
  initialiseHoverButtons();
  formatListLinks();
  initCollapseExpandNest();
  initHideAndSeek();
  //Function to add warning to external links
  addExternalLinkWarnings();
  truncateNewsLinkAndRemoveQuicklinks();     
  } 
);

// IE6 hover flicker fix
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function truncateNewsLinkAndRemoveQuicklinks() {
	var body = document.getElementsByTagName('body');
	if (body[0].className=='homepage'){		
		var newsMenu = document.getElementById('NewsUL');
		if (newsMenu) {	
			var moreThanTwoLines = true;
			var twoLinesHeight = 55;
			var newsArray = new Array();
			newsArray = newsMenu.getElementsByTagName('a');
			var newsLinkText = newsArray[0].firstChild.data;
			var pdfText = '';
			if (newsLinkText.lastIndexOf(' (PDF')!=-1) {
				pdfText=newsLinkText.substring(newsLinkText.lastIndexOf(' (PDF'));
			}

			var newsLinkTitle = newsLinkText;
			if (newsLinkTitle.indexOf(' (PDF')!=-1) {
				newsLinkTitle = newsLinkText.substring(0,newsLinkTitle.indexOf(' (PDF'));
			}
			var newsMenuHeight=newsMenu.offsetHeight;
			if (newsMenuHeight > twoLinesHeight) {				
				while (moreThanTwoLines) {
					newsMenuHeight=newsMenu.offsetHeight;
					if (newsMenuHeight > twoLinesHeight) {
						newsLinkTitle = newsLinkTitle.substring(0,newsLinkTitle.length-1);
						newsArray[0].firstChild.data=newsLinkTitle;
					}
					else {
						moreThanTwoLines = false;
						var pdfTextSpace = 3;
						if (pdfText!='') {
							pdfTextSpace = 9;
						}
						newsLinkText = newsLinkTitle.substring(0,newsLinkTitle.length-pdfTextSpace)+'...';
						if (pdfText!=''){
							newsLinkText+=pdfText;
						}
						newsArray[0].firstChild.data=newsLinkText;
						moreThanTwoLines = true;
						while (moreThanTwoLines) {
							if (newsMenu.offsetHeight > twoLinesHeight){
								pdfTextSpace++;
								newsLinkText = newsLinkTitle.substring(0,newsLinkTitle.length-pdfTextSpace)+'...';
								if (pdfText!=''){
									newsLinkText+=pdfText;
								}
								newsArray[0].firstChild.data=newsLinkText;
							}
							else {
								moreThanTwoLines = false;
							}
						}
					}
				}
			}

			var quicklinksList = document.getElementById('QuicklinksUL');
			if (quicklinksList) {	
				var quicklinksArray = new Array();
				quicklinksArray = quicklinksList.getElementsByTagName('li');
				while (quicklinksArray.length>8){
					quicklinksList.removeChild(quicklinksList.lastChild);
				}
			}
		}
	}
}
function openPopupWindow(url, name, width, height, returnWindow)
{
	var horizontalOffset, verticalOffset, offsetAmount, windowToReturn, closethiswindow;
		
	offsetAmount = 0;
	
	if(width == -1)
	{
	
  	if ((screen.Height >= 0) && (screen.Width >= 0)) {
     		 width = screen.Width - 10;
 	 }
  	else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
      		 width = screen.availWidth - 10;
  	}
	}	
	
	if(height == -1)
	{
	if ((screen.Height >= 0) && (screen.Width >= 0)) {
     		 height = screen.Height - 75;
    }
  	else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
      		 height = screen.availHeight - 45;
    }
	}
	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		horizontalOffset = window.screenLeft + offsetAmount;
		verticalOffset = window.screenTop + offsetAmount;
	}
	else
	{
		horizontalOffset = window.screenX + offsetAmount;
		verticalOffset = window.screenY + offsetAmount;
	}
	
	if(horizontalOffset + width > screen.availWidth || verticalOffset + height > screen.availHeight)
	{
		horizontalOffset = 0;
		verticalOffset = 0;
	}
		
	windowToReturn = window.open(url, name, "toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=yes,screenX=" + horizontalOffset + ",screenY=" + verticalOffset + ",left=" + horizontalOffset + ",top=" + verticalOffset + ",width=" + width + ",height=" + height);
	//Please do not publish with the return window statement
	//if(returnWindow)
	//{
	//	return(windowToReturn);
	//}
}


function openPopupLocator(country,url)
 { 
 //Passing the URL as argument is optional. However country is compulsory
	var height,width;
	 if(!(country==null)&&!(country==""))
		country=country.toUpperCase();
		switch(country)
		{ 
			case 'AUS': width="900";height="700"; 
				       if ((url==null)||(url==""))
						url='http://www.anz.com.au/australia/aboutanz/anzservices/anzlocator/';		   				   	
				       break;
		    case 'NZ': width="760";height="645"; 
				       if ((url==null)||(url==""))
						url='http://www.anz.co.nz/tools/nzlocator/';
				       break;
			default:   width="600";height="500"; 
										  
		}
		
		if (!(url==null)&&!(url==""))
			openPopupWindow(url,'locator',width,height,false);
} 

//Function to add external link warnings to links with a class of external links

function addExternalLinkWarnings(){
	var currentTag;
	var strLinkClass = "external-link";
	var allTags = getElementsByClassName(strLinkClass, "a", document);
	for(i=0; i<allTags.length; i++){
		var currentTag = allTags[i];
		currentTag.onclick = function(){
			externalwebsite(this);
			return false;
		}
	}
}

function getElementsByClassName(strClass, tag, elm){
	var testClass = new RegExp("(^|\\s)" + strClass + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}




function externalwebsite(link){
	var strURL = link.getAttribute("href");
	var strName = link.innerHTML;
	//remove spaces from window name
	var strWinName=strName.split(" ");
	strWinName=strWinName.join("");
	//tpconfirm(strURL, strWinName, '',  true);
                     windowOptions = 'width=780,height=450,toolbar=1,location=1,directories=0,status=1,menuBar=1,scrollBars=1,resizable=1,top=100,left=100';
               
                     try {
	             window.open(strURL, strWinName, windowOptions);					   
	}
	catch(err)  {
	             window.open(strURL, 'External', windowOptions);
	}


}

function tpconfirm(windowURL, windowName, options, windowPopup)
{
	var msg = "You are leaving an ANZ web site to go to a Third Party web site. Any information you choose to provide on the Third Party web site is not controlled or protected by ANZ and is subject to the privacy policy of the Third Party web site operator. ANZ is not responsible for any loss, damage or inconvenience suffered by you as a result of providing information on the Third Party web site.  Do you wish to continue?";

	if (confirm(msg))
	{
	   //if(windowPopup == true)
	   //{
	   
	      	if (options == '') 
	      	{				
				windowOptions = 'width=640,height=400,toolbar=1,location=1,directories=0,status=1,menuBar=1,scrollBars=1,resizable=1,top=100,left=100';
	        }
	        else 
	        {			
	             windowOptions = options;
	        }
	   		newWin = window.open(windowURL, windowName, windowOptions);
	   //}
	   //else
	   //{
	   //  document.location.href = windowURL;
	   //}  	  
	}
	else return;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function cmsnav(){

	var strnavclass = "navlevel_", strhidenav = "hide_nav", strdisplaynav = "display_nav", strlinkclass = "anznav_widget", strcloseicon = " anznav_closewidget", stropenicon = " anznav_openwidget";
	var strcurrentpage = "currentPage", strExpandable = "anznav_expandable ", strcurrnav = "anznav_current";

	var leftnav, allitems, curitem, curitemclass, curitemlevel, nextitem, nextitemclass, nextitemlevel, newul, ulclass, allATags, curATag, curATagclass;
	var curparent, curparentclass, curparentlevel, curparentuls, curparentul;

	//Get a hold of the left nav
	leftnav = document.getElementById("leftnav");
	if (leftnav == null){
 		return;
	}

	//Append uls to nav items
	allitems = leftnav.getElementsByTagName("li");
	for (var i=0; i<allitems.length; i++){
 		curitem = allitems.item(i);
 		curitemclass = curitem.className;
		curitemlevel = curitemclass.substring(curitemclass.indexOf(strnavclass) + strnavclass.length, curitemclass.length);

 		nextitem = allitems.item(i + 1);
  
  		//create a ul element if next item is a lower level
  		if (nextitem != null){
   			nextitemclass = nextitem.className;
   			nextitemlevel = nextitemclass.substring(nextitemclass.indexOf(strnavclass) + strnavclass.length, nextitemclass.length);
   			if ((nextitemlevel*1) > (curitemlevel*1)){
    				newul = document.createElement("ul");
				ulclass = strhidenav;

				//Update the class to display drop down image and append onclick event
				curitem.className = strExpandable + curitem.className;

				allATags = curitem.getElementsByTagName("a");
				for (var r=0; r<allATags.length; r++){
					curATag = allATags.item(r);
					curATagclass = curATag.className;
					if (curATagclass == strlinkclass){
						if (curitemclass.indexOf(strcurrnav) == -1){
							curATag.className = curATag.className + strcloseicon;
							curATag.href = "javascript:void(0);";
						} else {
							curATag.className = curATag.className + stropenicon;	
						}

						//append onclick event
						curATag.onclick = function() {
							$(this).toggleClass('anznav_closewidget').toggleClass('anznav_openwidget').siblings('ul').slideToggle('fast');
						}
						curATag.href = "javascript:void(0);";
						curATag.title = "Click to expand or contract";
					}

					//find if current page
					if (curATagclass.indexOf(strcurrentpage) != -1){
						ulclass = strdisplaynav;
					}
				}

				//append ul
				newul.className = ulclass;
    				curitem.appendChild(newul);
			}
		}
		//if li is a lower level then loop back up and append to higher level ul
		if ((curitemlevel*1) != 1){

			for (var n=i; n>=0; n--){
				curparent = allitems.item(n);
				curparentclass = curparent.className;
				curparentlevel = curparentclass.substring(curparentclass.indexOf(strnavclass) + strnavclass.length, curparentclass.length);
				if (((curparentlevel*1) + 1) == (curitemlevel*1)){

					//get lower level ul
					curparentuls = curparent.getElementsByTagName("ul");
					for (var w=0; w<curparentuls.length; w++){
						curparentul = curparentuls.item(w);
						curparentul.appendChild(curitem);

						//exit when appended
						w = curparentuls.length;
					}					

					//exit loop when found
					n = 0;
				}
			}
		}
	}
}


//Creates the correct formatting for left nav
function formatNavigation() {

 	var strNavName = "navigation", strCurrentPageClass = "currentPage", strCurrClassName, strNewClassName;
 	var i, n, eleNavigation, allATags, currATag, currPage;
 	var allCurrentPages = new Array;
 	var intArrayLength = 0;

	if (document.getElementById){

 		//get the navigation element
 		eleNavigation = document.getElementById(strNavName);
 		if (!eleNavigation){
  			return;
 		}

 		//get all navigation items
 		allATags = eleNavigation.getElementsByTagName("a");
 		for (i=0; i<allATags.length; i++){

   			//get all links
   			currATag = allATags.item(i);
   			strCurrClassName = currATag.className;

  			//build a list of all items with currentpage class
  			if (strCurrClassName.indexOf(strCurrentPageClass) != -1) {

				allCurrentPages[intArrayLength] = currATag;
				intArrayLength = intArrayLength + 1;

  			}

  		}

  		//Remove the currentpage class from top level pages
		for (n=0;n<intArrayLength - 1; n++){
			currPage = allCurrentPages[n];

  			//remove the current page class
			strCurrClassName = currPage.className;
			strNewClassName = strCurrClassName.split(strCurrentPageClass);
			strNewClassName = strNewClassName.join("");

			//Change the class name
  			currPage.className = strNewClassName;

		}

	}
}

function openDir(form) {
window.location =form.dir.options[form.dir.selectedIndex].value;
return false;
}

function openDirCountrySelector(form) {
	//this function opens the country selected in the country selector
	var selectedValue = form.dir.options[form.dir.selectedIndex].value;
	{
		window.location = selectedValue;
	}
	
	return false;
}

function newWindow(popup,parent)
{
        openPopupWindow(popup,'locator',600,500,false)
        location.replace(parent)
}

function OpenNewWindow(s, width, height) {
	var horizontalOffset, verticalOffset, offsetAmount, windowToReturn, closethiswindow;
		
	offsetAmount = 0;

	if(width == -1){
		if ((screen.Height >= 0) && (screen.Width >= 0)) {
			width = screen.Width - 10;
		}
		else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
			width = screen.availWidth - 10;
		}
	}	

	if(height == -1){
		if ((screen.Height >= 0) && (screen.Width >= 0)) {
			height = screen.Height - 75;
		}
		else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
			height = screen.availHeight - 45;
		}
	}

	if(navigator.appName == "Microsoft Internet Explorer"){
		horizontalOffset = window.screenLeft + offsetAmount;
		verticalOffset = window.screenTop + offsetAmount;
	}
	else {
		horizontalOffset = window.screenX + offsetAmount;
		verticalOffset = window.screenY + offsetAmount;
	}

	if(horizontalOffset + width > screen.availWidth || verticalOffset + height > screen.availHeight) {
		horizontalOffset = 0;
		verticalOffset = 0;
	}
	newWin = window.open(s, "ANZWIN2", "toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width=" + width + ",height=" + height); 
}

function OpenWindowSecure(s) {
  var width = 750;
   var height = 500;
  
  s = "https://www.anz.com/" + s;
  newWin = window.open(s, "ANZIBLOGON", "toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width=" + width + ",height=" + height);
}

function OpenWindow(s) {
  if ((screen.Height >= 0) && (screen.Width >= 0))
  {
      var height = screen.Height - 75;
      var width = screen.Width - 10;
  }
  else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
     
      var height = screen.availHeight - 45;
      var width = screen.availWidth - 10;
  }
     newWin = window.open(s, "ANZWIN2", "toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,screenX=0,screen=0,left=0,top=0,width=" + width + ",height=" + height);
}

function OpenMoneyManager(s) {
	width = 940;
	height = 600;
    newWin = window.open(s, "ANZMM", "toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width=" + width + ",height=" + height);
}
function OpenMoneyManagerDemo(s) {
	width = 950;
	height = 600;
    newWin = window.open(s, "ANZMM", "toolbar=no,status=1,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,width=" + width + ",height=" + height);
}

function openPopupWindow(url, name, width, height, returnWindow) {
	var horizontalOffset, verticalOffset, offsetAmount, windowToReturn, closethiswindow;

	offsetAmount = 0;

	if(width == -1)	{

		if ((screen.Height >= 0) && (screen.Width >= 0)) {
			width = screen.Width - 10;
		}
		else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
			width = screen.availWidth - 10;
		}
	}

	if(height == -1){
		if ((screen.Height >= 0) && (screen.Width >= 0)) {
			height = screen.Height - 75;
		}
		else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
			height = screen.availHeight - 45;
		}
	}

	if(navigator.appName == "Microsoft Internet Explorer")	{
		horizontalOffset = window.screenLeft + offsetAmount;
		verticalOffset = window.screenTop + offsetAmount;
	}
	else {
		horizontalOffset = window.screenX + offsetAmount;
		verticalOffset = window.screenY + offsetAmount;
	}

	if(horizontalOffset + width > screen.availWidth || verticalOffset + height > screen.availHeight) {
		horizontalOffset = 0;
		verticalOffset = 0;
	}

	windowToReturn = window.open(url, name, "toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=yes,screenX=" + horizontalOffset + ",screenY=" + verticalOffset + ",left=" + horizontalOffset + ",top=" + verticalOffset + ",width=" + width + ",height=" + height);
	//Please do not publish with the return window statement
	//if(returnWindow)
	//{
	// return(windowToReturn);
	//}
}

function OpenFAQWindow(s) {
  newWin = window.open(s,"ANZFAQWin","toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=no,width=380,height=302");
}
function populateSelectListWithBookmarks(containerId,containerType) { 
/*
containerType = 'tableSummary' or 'divId' and refers to the html element you are searching within; 
containerID will either be div id, or table summary text.
*/
	var actionstrip = document.getElementById('actionstrip');
	actionstrip.className='actionstrip';
	var selBookmarks = document.getElementById("selBookmarks");
	if (containerType=='tableSummary') {
		container = document.getElementsByTagName('table');
		for (x = 0; x<container.length; x++) {
			if (container[x].summary == containerId) {
				anchor = container[x].getElementsByTagName('a');
				populateOptions(anchor,selBookmarks);
			}
		}
	}
	else if (containerType=='divId') {
		container = document.getElementById(containerId);
		anchor = container.getElementsByTagName('a');
		populateOptions(anchor,selBookmarks);
	}
}
function populateOptions(anchor,selBookmarks) {
	for (i = 0; i<anchor.length; i++) {		
		if (anchor[i].href=="" && anchor[i].name!="top") {
			anchor[i].className = "bookmark";
			option = document.createElement("OPTION");
			option.value = '#'+anchor[i].id;
			option.text = anchor[i].firstChild.data;
			try{
				selBookmarks.add(option, null);
			}
			catch (ex){
				selBookmarks.add(option);
			}
		}
	}
}

/**IB login Area Start**/
function setLogin(s) {
	for (var i = 0; i < document.login_form.selectlogin.length; i++) {
		if (document.login_form.selectlogin[i].checked) {
			var str = document.login_form.selectlogin[i].value;
			break;
		}
	}

	var arrayOfURL = str.split(",");
	var URL1 = arrayOfURL[0];
	var URL2 = arrayOfURL[1];
	var URL3 = arrayOfURL[2];
	if (s == 1) {
		if (URL1 != "") {
			var myFucn = new Function(URL1);
			myFucn();
		}
	}
	else {
		if (s == 3) {
			if (URL3 != "") {
				var myFucn = new Function(URL3);
				myFucn();
			}
		}
		else {
			if (URL2 != "") {
				var myFucn = new Function(URL2);
				myFucn();
			}
		}
	}
	return false;
}
function setLoginTransitionStage(s) {
	for (var i = 0; i < document.login_form.selectlogin.length; i++) {
		if (document.login_form.selectlogin[i].checked) {
			var str = document.login_form.selectlogin[i].value;
			break;
		}
	}

	var arrayOfURL = str.split("|");
	var URL1 = arrayOfURL[0];
	var URL2 = arrayOfURL[1];
	var URL3 = arrayOfURL[2];
	if (s == 1) {
		if (URL1 != "") {
			var myFucn = new Function(URL1);
			myFucn();
		}
	}
	else {
		if (s == 3) {
			if (URL3 != "") {
				var myFucn = new Function(URL3);
				myFucn();
			}
		}
		else {
			if (URL2 != "") {
				var myFucn = new Function(URL2);
				myFucn();
			}
		}
	}
	return false;
}

function initLoginBox() {
	var loginOptions = document.getElementById('loginbuttons').getElementsByTagName('input');
	var oneIsChecked = false;
	var i = 0;
	for (i==0; i<loginOptions.length; i++) {
		if (loginOptions[i].checked) {			
			oneIsChecked = true;
		}
		if (document.getElementById('demoLink')) {
			loginOptions[i].onclick = showHideDemo;
		}
	}
	if (!oneIsChecked) {
		loginOptions[0].checked = 'checked';
	}
	showHideDemo();
}
function showHideDemo() {
	if (document.getElementById('demoLink')){
		var demoLink = document.getElementById('demoLink');
		demoLink.style.visibility="hidden";
		var loginButtons = document.getElementById('loginbuttons');
		var options = loginButtons.getElementsByTagName('input');
		var loginOptions = document.getElementById('loginbuttons').getElementsByTagName('input');
		var j = 0;
		for (j==0; j<loginOptions.length; j++) {
			if (loginOptions[j].checked){	
				if (loginOptions[j].className == "showDemoLink") {
					demoLink.style.visibility="visible";
				}
			}
		}
	}
}
function loginRedirect(form, ib, ebiz){
	if (document.getElementById('radIB').checked){
		openPopupWindow(ib, 'newwindow', -1, -1, false);
	}
	else if (document.getElementById('radeBiz').checked){
		openPopupWindow(ebiz, 'newwindow', -1, -1, false);	
	}
	return false;
}
function loginRedirect(form, ib, ebiz, anzOnline){
	if (document.getElementById('radIB').checked){
		openPopupWindow(ib, 'newwindow', -1, -1, false);
	}
	else if (document.getElementById('radeBiz').checked){
		openPopupWindow(ebiz, 'newwindow', -1, -1, false);	
	}
    else if (document.getElementById('radAnzOnline').checked){
		openPopupWindow(anzOnline, 'newwindow', -1, -1, false);
	}
	return false;
}

/* Hide and Expand functions */
function initHideAndSeek(){
	
	var cbody, celist, cetable, curcelist, curcetable;	
	var listclass = "showcontent";
	
	if (document.getElementById){
		cbody = document.getElementById("contentWrapper");
		if (cbody == null){
			return;
		}
		//get all 'table' from content
		cetable = cbody.getElementsByTagName("table");
		for (var i=0; i<cetable.length; i++){
			
			curcetable = cetable.item(i);
			if (curcetable.className == listclass){
			   //Add link to the headers
				activateDetails(curcetable,'table');
				curcetable.attributes["class"].value = "hidecontent";
			}
		}
	}
}
function activateDetails(item,hideExpandType){
	var alldt, allth, curli, allChildNodes, curChild, curChildName,curTHBookmark,curTHBookmarkid,strcurBookmarkText,strUCTHText;
	strHTMLOpen='<a href="javascript:void(0);" title="Click to expand or contract"  onMouseOver="javascript:this.style.color=\&#39;#007dba\&#39;;" OnMouseOut="javascript:this.style.color=\&#39;#004165\&#39;;" class="HSArrow" onclick="javascript:hideAndSeek(this);">';
    strHTMLOpen= strHTMLOpen + '<span class="arrow-hide-and-seek-more">Click to expand or contract</span><span class="HSHeaderText">';
	strHTMLClose='</span></a>'
	allth = item.getElementsByTagName("th");
	strTHText=allth[0].innerHTML;
	strUCTHText = strTHText.toUpperCase();
    if (strUCTHText.indexOf("A ID") != -1)
	{
		curTHBookmark = allth[0].getElementsByTagName("a");
		curTHBookmarkid = curTHBookmark[0].attributes["id"].value;
		strHTMLOpen='<a href="javascript:void(0);" id="' + curTHBookmarkid ;
		strHTMLOpen = strHTMLOpen + '" title="Click to expand or contract" onMouseOver="javascript:this.style.color=\&#39;#007dba\&#39;;" OnMouseOut="javascript:this.style.color=\&#39;#004165\&#39;;" class="HSArrow" onclick="javascript:hideAndSeek(this);">';
		strHTMLOpen= strHTMLOpen + '<span class="arrow-hide-and-seek-more">Click to expand or contract</span><span class="HSHeaderText">';
		strTHText = curTHBookmark[0].innerHTML;

	}
	allth[0].innerHTML = strHTMLOpen + strTHText + strHTMLClose;
}
function hideAndSeek(title) {
	var ctl = title.parentNode;
	if(ctl.parentNode.parentNode.parentNode.className == "hidecontent")
	{
		ctl.parentNode.parentNode.parentNode.className = "showcontent"
		title.childNodes[0].attributes["class"].value = "arrow-hide-and-seek-down"
	}
	else
	{
		ctl.parentNode.parentNode.parentNode.className = "hidecontent"
		title.childNodes[0].attributes["class"].value = "arrow-hide-and-seek-more"
	}
}

function RHNLogonImageMM_findObj(n, d) {
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=RHNLogonImageMM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}
	
function RHNLogonImageMM_preloadImages() {
	var d=document; 
	if(d.images){ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=RHNLogonImageMM_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
	}
}

function RHNLogonImageMM_swapImage() {
	RHNLogonImageMM_swapImgRestore();
	var i,j=0,x,a=RHNLogonImageMM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
		if ((x=RHNLogonImageMM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x; 
			if(!x.oSrc) x.oSrc=x.src; 
			x.src=a[i+2];
		}
}

function RHNLogonImageMM_swapImgRestore() {
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/**IB login Area End**/

function langtranslate(strCurSite, strTransSite){
	var strHref = window.location.href;

	//replace current site with translated site
                     if (strHref.indexOf("/" + strCurSite + "/") != -1){
	                     var strNewLoc = strHref.split("/" + strCurSite + "/");
	                     strNewLoc = strNewLoc.join("/" + strTransSite + "/");
	                     window.location = strNewLoc;
                                          return false;
                      }
                     return true;                  
}

/**Hover Button Functions**/
function hoverbutton_over(alink){
	var alinkImgs, curImg;
	alinkImgs = alink.getElementsByTagName("img");
	for (var i=0; i<alinkImgs.length; i++){
		curImg = alinkImgs.item(i);
		curImg.style.top="-29px"
	}
}

function hoverbutton_out(alink){
	var alinkImgs, curImg;
	alinkImgs = alink.getElementsByTagName("img");
	for (var i=0; i<alinkImgs.length; i++){
		curImg = alinkImgs.item(i);
		curImg.style.top="0px"
	}
}

function initialiseHoverButtons() {
	var strLinkClass = "hover-button";
	var allTags, parentTag, pTag; 
	allTags = getElementsByClassName(strLinkClass, "img", document);
	for(var i=0; i<allTags.length; i++){

		var currentTag = allTags[i];

		//Append hover functions to a tag
		parentTag = currentTag.parentNode;
		if (parentTag.nodeName.toUpperCase() == "A"){

			//Append hover functions to a tag
			parentTag.onmouseover = function (){
				hoverbutton_over(this);
				return false;
			}

			parentTag.onmouseout = function (){
				hoverbutton_out(this);
				return false;
			}
		}

		//Add hover class to paragraph tag
		pTag = parentTag.parentNode
		if (pTag.nodeName.toUpperCase() == "P"){
			pTag.className += " hover-button-p";
		} else if (pTag.nodeName.toUpperCase() == "DIV"){
			pTag.className += " hover-button-div";
		}
	}
}

/**Collapse and Expand Functionality**/
//function initialises the collapse - expand functionality
function initCollapseExpandNest (){
	var cbody, celist, curcelist;	
	var listclass = "collapse-expand";
	if (document.getElementById){
		cbody = document.getElementById("contentWrapper");
		if (cbody == null){
			return;
		}

		//find all collapse-exand lists
		celist = cbody.getElementsByTagName("ul");
		for (var i=0; i<celist.length; i++){
			curcelist = celist.item(i);
			if (curcelist.className == listclass){
curcelist.className+=" CollapseExpand";
				formatlistitems(curcelist);
			}
		}
	}
}

function formatlistitems(ul){
	var alllis, curli, allChildNodes, curChild, curChildName;
	alllis = ul.getElementsByTagName("li");
	for (var n=0; n<alllis.length; n++){
		curli = alllis.item(n);
		allChildNodes= curli.childNodes;
					
		//check for lower level list
		for (var r=0; r<allChildNodes.length; r++){
			curChild = allChildNodes.item(r);
			curChildName = curChild.nodeName;
			if (curChild){
				if (curChildName.toUpperCase() == "UL" && curChild.className != "hide"){
					addlink(curli);
				}
			}
		}
	}
}

function addlink(liitem){
	var allChildItems, curul, newul, curulnodename;
	var linktext, newlink, newspan, newtext, newspantext;

	//remove old nodes
	allChildItems = liitem.childNodes;
	for (var w=allChildItems.length; w>0; w--){
		curul = allChildItems.item(w-1);	
		if (curul.nodeName){
			curulnodename = curul.nodeName.toUpperCase();
			if(curulnodename == "UL"){
				newul = curul;
				//hide lower levels
				newul.className = "hide";
			} else if (curulnodename == "#TEXT"){
				if (curulnodename != ""){
					linktext = curul.nodeValue;
				}
			}
		}
		liitem.removeChild(allChildItems.item(w-1));
	}

	//create span for accessibility
	newspan = document.createElement("span");
	newspantext = document.createTextNode("Click to expand or contract");
	newspan.className = "hide";
	newspan.appendChild(newspantext);

	//create new link
	liitem.className+="topLink";
	newlink = document.createElement("a");
	newtext = document.createTextNode(linktext);
	newlink.setAttribute("href", "javascript:toggleclasses(this)");
	newlink.appendChild(newspan);
	newlink.title = "Click to expand or contract";
	newlink.appendChild(newtext);
	newlink.className = "anznav_closewidget";
	newlink.onclick = function() {
		toggleclasses(this);			
	}		

	//replace nodes
	liitem.appendChild(newlink);	
	liitem.appendChild(newul);

}

function toggleclasses(item){
	var topli, allChildItems, curul, strClassName;
var backImage = new Array(); 
backImage[0] = "/base/Resources/resources/3/f/3f0ab3804d2fa1cd9ad9be766a918285/minus.gif";
backImage[1] = "/base/Resources/resources/0/2/028b87804d2fa1ce9addbe766a918285/plus.gif";
	topli = item.parentNode;
	if (!topli){
		return;
	}
	if (topli.nodeName.toUpperCase() == "LI"){
		allChildItems = topli.childNodes;
		for (var w=0; w<allChildItems.length; w++){
			curul = allChildItems.item(w);
			if (curul.nodeName){
				if(curul.nodeName.toUpperCase() == "UL"){
					//hide lower levels
					strClassName = curul.className;
					if (strClassName == "hide"){
						curul.className = "show";
						item.className="anznav_openwidget";
//item.style.background="url(" + backImage[0] + ") no-repeat";
//item.style.backgroundPosition="0px 5px";
					} else {
						curul.className = "hide";	
						item.className="anznav_closewidget";
//item.style.background="url(" + backImage[1] + ") no-repeat";
//item.style.backgroundPosition="0px 5px";
					}
					return;
				}
			}
		}		
	}
}

//**Project Satellite login *

//BEAM  (C) Copyright APAK Beam 2008
//Program  : StartupInetANZ
//Function : Javascript Startup Functions for Internet Banking ANZ
//***********************Maintenance History************************************
//29-10-2008 J. Tancev		Created js file
//12-01-2009 J. Tancev               ANZ Renamed windowName to ibWindowName     
//12-03-2009 N. Irwin                  Added ibOutageGroup to redirect login when app unavailable
//******************************************************************************
var ChildWindow = null;
var LogoffWindow = null;
var parameters = "";
var parametersOpen = "";
var resolution = ""
var ibWindowName = "_blankInet";
var browserName = navigator.appName;
var allowMultipleWins = false;

//******************************************************************************

function OpenOnlineBanking(systemUrl, guid, ibOutageLink, ibOutageGroupType) {
	if (ibOutageGroupType=='satellite') {
		if ('off'=='on') {
			OpenNewWindow(ibOutageLink, '995','600');
			return false;
		}
	}
	parameters = "?inetclient=true&Inst=" + guid + "&css=anz";
	parametersOpen = "?terminatesession=true&inetclient=true&Inst=" + guid + "&css=anz";
    resolution = "&resWidth=" + screen.width + "&resHeight=" + screen.height;

	if(!allowMultipleWins){
		if (ChildWindow != null) {
			try{
				ChildWindow.focus();
			}catch(e){
				startApplication(systemUrl + parametersOpen + resolution, ibWindowName);
			}
		}else{
			startApplication(systemUrl + parameters + resolution, ibWindowName);
		}
	}else{
		startApplication(systemUrl + parameters + resolution, "");
	}
	return false;
}

function startApplication(url, name){
	var y = screen.availWidth  - 10;
	var x = screen.availHeight - 50;
	if (screen.availHeight > 768) x = 718;
	if (screen.availWidth > 1024) y = 1024;
	
	ChildWindow = window.open(url, name, "height=" + x + ",width=" + y + 

",directories=no,scrollbars=yes,status=yes,resizable=yes,location=no,menubar=no,titlebar=no,toolbar=no,top=0,left=0");
	
	if (browserName!="Microsoft Internet Explorer"){
		ChildWindow.onunload = distroyChild;	
	}
	
	ChildWindow.focus();
	
	return true;
}

function distroyChild(){
	ChildWindow = null;
}

/**Project Satellite login Area End**/

/**Format Links within a List **/

function formatListLinks()
{	var mainContent = document.getElementById('contentWrapper');	 // Get the contentWrapper ID
	if(!mainContent){					 // if there is no contentWrapper ID dont continue.
		return;
	}

                     var listItem = mainContent.getElementsByTagName('li');                                  // Get all the <li> tags
                     for(i=0; i < listItem.length; i++) {
                            var thisListItem = listItem[i]; 
                            
                            thisListItem.className='BulletNormal';                                                      // Apply the nomal Bullet class so image is used
                     }                                                                                                                              // to fix alignment issues 

//Now override the nomal Bullet if necessary with an arrow or pdf icon

	var links = mainContent.getElementsByTagName('a');	                     // Get all the <a> tags within the contentWrapper ID
	for(i=0; i < links.length; i++) {				// Loop thru all the <a> tags to style accordingly
	    var thisLink = links[i];	    

                         if(thisLink.href!=''){
	          var linkHREF = thisLink.href.toLowerCase();			 // Grab the HREF in the <a> tag convert to lowercase  
	          var linkLocation = thisLink.getAttribute("href", 2); 		 // Grab the HREF to check if bookmark
 	          if(thisLink.parentNode.tagName == "LI"){			 // Check if the <a> tag is part of a list
			var linkHTML = thisLink.parentNode.innerHTML.toLowerCase();  // grab the HTML and convert to lowercase	
			if (linkHTML.indexOf("<a") == 0){		 // check if the <a> tag is first in the HTML 				                     //Apply PDF class				
                                                                                     if (linkHREF.indexOf(".pdf") != -1){ 
                                                                                                         thisLink.parentNode.className = 'PDFLink'; 
				} else if (linkLocation.indexOf("#") == 0) {
		                        	                   thisLink.parentNode.className = 'ArrowLinkDown'; 	//Find Bookmark links
				} 
				else
				{
				//Apply Arrow class
	                                                                                    thisLink.parentNode.className = 'ArrowLink'; 
				}
			}
                                                               	
	                     }
                               }
	}
}

/**End of Format Links within a List **/
// START of code for Dynamic source code project

//security validation
function validateSourceCode(strVal)
{
	var strArr = strVal.split("-"); 
	// at max 5 character length 
	for(var i=0; i<strArr.length; i++)
		if (strArr[i].length > 5) 
			return false;
	// accept only alphabets, numericals and hyphen as value
	for(i=0; i<strVal.length; i++)
	{
		if(!((strVal.charCodeAt(i) > 96 && strVal.charCodeAt(i) < 123) ||(strVal.charCodeAt(i) > 47 && strVal.charCodeAt(i) < 58) || (strVal.charCodeAt(i) > 64 && strVal.charCodeAt(i) < 91) || strVal.charCodeAt(i) == 45 ))
		 return false;
	}
	return true;			
}

function sourceCodeExtract(qS)
{
	var arrQrStr = new Array(); 
	var arr = qS.split("&"); // splits querystring into key and values set
	// splits each of field-value pair 
	for (var i=0;i<arr.length;i++)
	{ 
		var index = arr[i].indexOf("="); 
		var key = arr[i].substring(0,index).toLowerCase(); 
		var val = arr[i].substring(index+1); 
		arrQrStr[key] = val;
	} 
	return arrQrStr["sourcecode_1"];
}



function applySourceCodeFromURL(objLink)
{	
var pageSourcecode="",strLinkSourcecode="";
var boolNewWindow = false;

if (objLink.target.toLowerCase() == "_blank"){
	boolNewWindow = true;
}
var strOrigLinkHref = objLink.href; 

// Check page querystring
var pageQueryString = window.location.search.substring(1); // Get querystring from page URL

if (pageQueryString.length > 0){
	// Check page querystring for sourcecode_1 parameter
	pageSourcecode = sourceCodeExtract(pageQueryString);
	if (pageSourcecode) 
	{
		// Validate sourcecode_1
		if (validateSourceCode(pageSourcecode)) {
			// Check link querystring for sourcecode_1 parameter 
			var linkStrUrl = strOrigLinkHref.split("?");
			if(linkStrUrl[1])
			{	
				var strLinkUrlQs = linkStrUrl[1]; 
			 	strLinkSourcecode = sourceCodeExtract(strLinkUrlQs);
				if (strLinkSourcecode)
					strLinkUrlQs = "?" + strLinkUrlQs.toLowerCase().replace("sourcecode_1=" + strLinkSourcecode.toLowerCase(),"sourcecode_1=" + pageSourcecode);//replace objLink source code with the page source code
				else
					strLinkUrlQs = "?" + strLinkUrlQs + "&sourcecode_1=" + pageSourcecode;//passthe page sourcecode to the url
			} 
			else 
			{
				strLinkUrlQs = "?sourcecode_1=" + pageSourcecode;//append page sourcecode to the url
			}
			if (boolNewWindow)
				window.open(linkStrUrl[0] + strLinkUrlQs);
			else
				window.location.href = linkStrUrl[0] + strLinkUrlQs;
			return false;
		}
	} 
}
// If page sourcecode is invalid or does not exist then load the original link
if (boolNewWindow)
	window.open(strOrigLinkHref);
else
	window.location.href = strOrigLinkHref;
return false;
}
// END of code for Dyanmic source code project

