// ------------ //
// flash movies //
// ------------ //
var movies=new Array();
movies[168] = new Array();
movies[168][0]="calculator_168X100.swf";
movies[168][1]="eCash_rate4-15.swf";
/*movies[168][2]="hoax.swf";
movies[168][3]="hoax.swf";
movies[168][4]="hoax.swf";*/
movies[465] = new Array();
movies[465][0]="asgardrollercoaster_banner.swf"; 

function display_flash(size){
	var adFlash = getRandom(size);
	var wdth=size;
	if (wdth=='168') var hght='100';	
	else if(wdth=='465') var hght='131';
	flashfile = "/flash/"+movies[size][adFlash];
	return flashPlayer(flashfile, wdth, hght);
}
function flashPlayer(flashfile, wdth, hght){
	document.write ("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' width='"+wdth+"' height='"+hght+"'>\n");
	document.write ("	<param name='movie' value='" + flashfile + "'\/>\n");
	document.write ("	<param name='quality' value='high'\/>\n");
	document.write ("	<param name='scale' value='exactfit'\/>\n");
	document.write ("	<param name='wmode' value='transparent'\/>\n");
	document.write ("	<embed src='" + flashfile + "' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+wdth+"' height='"+hght+"' scale='exactfit' wmode='transparent'><\/embed>");
	document.write ("<\/object>"); 
}

function getRandom(size) {
	var amt = (movies[size].length) - 1; // counts the number of diff movies for set size
	var ranNum= Math.round(Math.random()*amt);
	return ranNum;
}
// ----end flash----- //


// ----------- //
// search form //
// ----------- //
function checkKeywords(keywords, defaultTxt){
	if(keywords.value==defaultTxt){
		keywords.value='';
		keywords.className='input_txt';
	}else if(keywords.value.length==0){
		keywords.value=defaultTxt;
		keywords.className='text';
	}
}
// ----end search----- //

// URL path as array used in breadcrumbs and nav//
function pathArray(){
	var aURL = location.href;
	aURL = aURL.slice(7,aURL.length);
	return aURL.split("/");
}

// ------------ //
// NAVIMAGATION //
// ------------ //
var tar;
var toggleTmr;
var clearTmr;
var sURL = pathArray();
var showTime = "100";
var clearTime = "400";

function nav(){
	//checks if url has a nav id and changes nav items to active	
	if (sURL[1]){
		var bodyTar = sURL[1].toLowerCase();//first folder of the url
		var folder = bodyTar.split("_");
		folder[0] == "for" ? bodyTar = "n"+folder[1] : bodyTar = "n"+folder[0];//ignore for as a prefix for the id
	}
	// figures out the active link in the sub nav based on url and link of subnav
	if(secondaryNav = changeClass(bodyTar,"active")){
		var subs = secondaryNav.getElementsByTagName('a');
		var thisUrl = "http://"+sURL[0]+"/"+sURL[1]+"/"+sURL[2];// host name + folder + file
		var thisUrl2 = thisUrl+"/";
		for (var j=0; j < subs.length; j++){
			if (subs[j] == thisUrl || subs[j] == thisUrl2) { subs[j].className = "current"; break;}
		}
	}
	// figures out the active link in the leftCol nav based on url and link of subnav
	
	if(1==1){
		leftCola = new Object(document.getElementById('leftCol').getElementsByTagName('a'));
		var thisUrl3 = thisUrl2+sURL[3];
		var thisUrl4 = thisUrl3+"/";
		var thisUrl5 = thisUrl4+sURL[4];
		for (var j=0; j < leftCola.length; j++){
			if (leftCola[j] == thisUrl || leftCola[j] == thisUrl2 || leftCola[j] == thisUrl3 || leftCola[j] == thisUrl4 || leftCola[j] == thisUrl5) 
				leftCola[j].parentNode.className = "current";
		}
	}	/**/
	//add on mouse over event to each li to show subs
	if (document.getElementById('nprimary')){ //checks to make sure menu exists
		var navli = document.getElementById('nprimary').getElementsByTagName('li');
		for (var i=0; i < navli.length; i++) {
			if (navli[i].parentNode.parentNode.nodeName=="DIV"){//gets top level li's only
				navli[i].onmouseover = startToggle; 
			}
		}
	}
	/* do clear if mouseout or click away */
	document.getElementById('nav').onmouseout = startClear;
	//document.getElementById('page').onmouseup = clearAll;
}
function changeClass(elementId,newClass){
	if (sectionId = document.getElementById(elementId)){
		if (sectionId.className == "active") newClass += " active";
		if (sectionId.className == "hover active") newClass = "active";
		sectionId.className = newClass;
		var secondaryNav = sectionId.getElementsByTagName('ul');
		secondaryNav = secondaryNav[0];
		secondaryNav.className = newClass;
		return secondaryNav;
	}
}
function startToggle(){
	clearTimeout(clearTmr);
	clearTimeout(toggleTmr);
	if (tar = this)	toggleTmr = setTimeout('toggleView()',showTime);	
}
function startClear(e) {
	clearTimeout(clearTmr);
	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if(reltg) if (reltg.parentNode.parentNode.className != "hover" || reltg.parentNode.parentNode.className != "primary") clearTmr = setTimeout('clearAll()',clearTime);
}

function toggleView(){
	clearTimeout(toggleTmr);
	clearAll(); //resets all li's and uls to default
	changeClass(tar.id,"hover"); 
}
function clearAll(){
	var navli = document.getElementById('nprimary').getElementsByTagName('li');
	for (var i=0; i < navli.length; i++){
		if (navli[i].className != "active" && navli[i].className != "") {// makes sure its not resetting the active link or a link that is already off
			changeClass(navli[i].id,"");
		}
	}
}
// ----end nav----- //


// ---------- //
// new window //
// ---------- //
function openNew(url,wdth,hght) {
	newWindow = window.open(url,url,"height="+hght+", width="+wdth)	
	newWindow.focus();
}


// ---------- //
// Quicklinks //
// ---------- //
quickLearn = new Array();
quickLearn = Array(	
			"/For_investors/td_calculator/",
			"/For_investors/Investor_online.html",
			"/Products_&_Services/eCASH.html",
			"",			
			"/For_advisers/About_adviserNET.html",
			"/For_advisers/AdviserNETgain.html",
			"/For_employers/Employer_Online.html",
			"/For_employers/Employer_Online_Transact.html",	
			"/About_us/",
			"");
quickGo = new Array();
quickGo = Array(
			"/For_investors/td_calculator/term_deposits_calculator.html",
			"https://www.investoronline.info",
			"http://webapps.stgeorge.com.au/asgard_ecash/", 
			"/advisersearch.do",
			"https://www.advisernet.com.au",
			"https://www.advisernetgain.com.au",
			"https://www.employeronline.com.au/",
			"https://www.employeronline.com.au/transact/",			
			"http://www.asgardwealthsolutions.com.au",			
			"https://www.fundmanageronline.com.au");
			
function subQuick(){
	i = subForm();
	var url = quickLearn[i];
	goUrl(url);
}
function subGo(){
	i = subForm();
	var url = quickGo[i];
	goUrl(url);
}
function goUrl(url) {
	if (url){
		var checkhttp = url.split("://");
		if(checkhttp[1]) window.open(url);	//is an external link so open in new window
		else location.href=url;
	}		
}
function subForm(){
	for (i=0;i<document.quickLinks.quick.length;i++) if (document.quickLinks.quick[i].checked==true) return i;
}
function checkLink(){
	i = subForm();
	if (!quickLearn[i]) document.quickLinks.btnLearn.disabled = true; else document.quickLinks.btnLearn.disabled = false;
	if (!quickGo[i]) document.quickLinks.btnGo.disabled = true;	 else document.quickLinks.btnGo.disabled = false;	
}


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;
}

//form validator
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


//show hide content

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
