function ButArray() {
	NAVarr = new Array("home", "applynow", "formz", "maxbenefits", "faqs", "school", "aboutmax", "contact");
	if (document.images) {
		for (var NAVitem in NAVarr) { 
			for (var NAVicount=0; NAVicount < 2; NAVicount++) {
					//alert('b' + NAVarr[NAVitem] + NAVicount + ' = new Image();');
					eval('b' + NAVarr[NAVitem] + NAVicount + ' = new Image();');
					eval("b" + NAVarr[NAVitem] + NAVicount + ".src = '/_images/swap_" + NAVarr[NAVitem] + "_" + NAVicount + ".gif';");
			} 
		} 
	}
}

function BturnOn(imageName) {
	if (document.images) { document [imageName].src = eval("b" +imageName + "1.src");	}
}

function BturnOff(imageName) {
	if (document.images) { document [imageName].src = eval("b" + imageName + "0.src");	}
}

function imgPopup(path) {
	if (path) {
		window.open("utils_imagepopup.aspx?path=" + path, "popup", "width=400, height=300, toolbar=no, status=no, scrollbars=yes, resizable=yes");
	}
}

function infoPopup(view,width,height) {
	//alert( width +", "+ height );
	width = typeof(width) != 'undefined' ? width : 450;
	height = typeof(height) != 'undefined' ? height : 500;
	
	if (view) {
		window.open("help.php?view=" + view, "help", "width="+width+", height="+height+", toolbar=no, status=no, scrollbars=yes, resizable=yes");
	}
}

//#################
//##	Calculator
//#################

function checkNumb(pnumb, pname) {
	var numb = pnumb.value.replace(/[^0-9]/g, '')
	var message
	var indx
	var status = false
	
	/* the field should contain at least one digit */
	for (var indx = 0; indx < numb.length; indx++) {
		if (numb.charAt(indx)>= "0" && numb.charAt(indx) <= "9") {
			status = true
		}
	}
	for (var indx = 0; indx < numb.length; indx++) {
		if (!(numb.charAt(indx)>= "0" && numb.charAt(indx) <= "9")) {
			status = false
		}
	}
	if (!status) {
		pnumb.value = "";
		msg = "The " + pname + " field must be a number eg. $50,000";
		alert(msg);
		pnumb.focus();
	}
	return status
}

function checkCalculator() {
//######### idiot check #########

if((document.Calculator.death_protection.checked!=true) && (document.Calculator.insurance_protection.checked!=true)) {
	alert("You have not chosen an insurance type.");
	document.Calculator.death_protection.focus();
	return false;
}

//######### DTPD checks #########
	if (document.Calculator.death_protection.checked==true) {
		if (document.Calculator.insurance_cover.value != "") {
			if (checkNumb(document.Calculator.insurance_cover,"Death / Death & TPD Cover value") == false) {
				return false;
			} else if (document.Calculator.insurance_cover.value.replace(/[^0-9]/g, '') < 50000) {
				alert("There is a minimum 'Death / Death & TPD Cover value' of $50,000.");
				document.Calculator.insurance_cover.focus();
				return false;
			}
		} else {
			alert("How much insurance cover do you need?");
			document.Calculator.insurance_cover.focus();
			return false;
		}
		if ((document.Calculator.insurance_type[0].checked == false) && (document.Calculator.insurance_type[1].checked == false)) {
			alert("Please choose an insurance type.");
			document.Calculator.insurance_type[0].focus();
			return false;
		}
	}

//######### Income Protection checks #########
if (document.Calculator.insurance_protection.checked==true) {
		if (document.Calculator.insurance_protection.value != "") {
			if (checkNumb(document.Calculator.current_wage,"Income Before Tax") == false) {
				return false;
			} else if (document.Calculator.current_wage.value.replace(/[^0-9]/g, '') < 1) {
				alert("Your income is set to zero.");
				document.Calculator.current_wage.focus();
				return false;
			}
		} else {
			alert("Please complete the 'Income Before Tax' field.");
			document.Calculator.current_wage.focus();
			return false;
		}
		if ((document.Calculator.pay_frequency[0].checked == false) && (document.Calculator.pay_frequency[1].checked == false)) {
			alert("Is that your annual salary, or a monthly figure?");
			document.Calculator.pay_frequency[0].focus();
			return false;
		}
	}
	
if(document.Calculator.insurance_age.value == '') {
	alert("Please tell us how old you'll be at your next birthday.");
	document.Calculator.insurance_age.focus();
	return false;
}

if(document.Calculator.insurance_sex.value == '') {
	alert("Please tell us if you're a guy or a girl.");
	document.Calculator.insurance_sex.focus();
	return false;
}

if(document.Calculator.insurance_smoker.value == '') {
	alert("Are you a smoker?");
	document.Calculator.insurance_smoker.focus();
	return false;
}

if(document.Calculator.insurance_occupation.value == '') {
	alert("You have not selected an occupation type.");
	document.Calculator.insurance_occupation.focus();
	return false;
}


//######### Age Test ##########	
	if (document.Calculator.insurance_age.options.selectedIndex == 0) { 
		alert("One sec! We didn't get your age.");
		document.Calculator.insurance_age.focus();
		return false;
	}
	
	if ((document.Calculator.insurance_sex[0].checked == false) && (document.Calculator.insurance_sex[1].checked == false)) {
		alert("Girl or Boy?");
		document.Calculator.insurance_sex[0].focus();
		return false;
	}
	
if (document.Calculator.member_type[0].checked == true && ((document.Calculator.insurance_smoker[0].checked == false) && (document.Calculator.insurance_smoker[1].checked == false))) {
		alert("Cough up - are you a smoker?");
		document.Calculator.insurance_smoker[0].focus();
		return false;
	}

if ((document.Calculator.insurance_occupation[0].checked == false) && (document.Calculator.insurance_occupation[1].checked == false) && (document.Calculator.insurance_occupation[2].checked == false) && (document.Calculator.insurance_occupation[3].checked == false)) {
		alert("Occupation type? If you are unsure, try the orange info button.");
		document.Calculator.insurance_occupation[0].focus();
		return false;
	}

 document.Calculator.submit();				// Submit the page
 return true;

}


//##################################
//##	Calculator div foldouts
//##################################


function ip_submit(){
	if( (document.forms[0].current_wage.value!=0 && document.forms[0].current_wage.value!='') &&
		document.forms[0].pay_frequency.value != '' &&
		document.forms[0].submit_test.value == 1)
	{
		document.forms[0].submit();
	}
}

function show_rows(row_id){
	row = document.getElementById(row_id);
	if(row.style.display !="none")
	{
		row.style.display ="none";

	}
	else
	{
		row.style.display ="block";
		row.style.display ="table-row";
	}
}


//##################################
//##	Ally's functions
//##################################

// Retrieves and element by it's ID
// (Should work on most browsers).
function getElementById(itemId)
{
	var ie = document.all
	var dom = document.getElementById
	var itemObj = ie ? document.all(itemId) : document.getElementById(itemId)
	return itemObj
}

// Increases the z-index of the given element
// (identified by itemId) to be 1 greater than the
// highest z-index already on the page.
function raise(itemId)
{
	var highestZIndex = 0;
	for (i = 1; i < raise.arguments.length; i++)
	{
		tempObj = getElementById(raise.arguments[i]);
		highestZIndex = Math.max(tempObj.style.zIndex, highestZIndex);
	}
	raiseItemObj = getElementById(raise.arguments[0]);
	if (raiseItemObj.style.zIndex <= highestZIndex)
	{
		raiseItemObj.style.zIndex = highestZIndex + 1;
	}
}

// Toggles the display of the given element
// (identified by itemId) between 'none' and toggleValue.
function toggleDisplay(itemId, toggleValue)
{
  itemObj = document.getElementById(itemId);
  if (itemObj.style.display == 'none')
  {
    itemObj.style.display = toggleValue;
  }
  else
  {
    itemObj.style.display = 'none';
  }
}

// Changes a CSS style attached to the given element
// (identified by itemId). e.g. setStyle(itemId, 'color', 'red')
function setStyle(itemId, style, value)
{
  itemObj = document.getElementById(itemId);
  eval('itemObj.style.'+style+' = "'+value+'"');
}

// Gets the CSS style attached to the given element
// (identified by itemId).
// E.g. getStyle(itemId, 'color') returns 'red'.
function getStyle(itemId, style)
{
  itemObj = document.getElementById(itemId);
  return eval('itemObj.style.'+style);
}

// Change the display style of the the specified item
// (identified by itemId) based on the outcome of the
// comparing the 2nd and 3rd arguments with the operator
// specified by the fth argument.
function displayIf(subjectId, testData, testCmpData, testType)
{
	var testType = (testType == null) ? 'eq' : testType;
	var testOperator = 'eq';
	if (testType == 'eq') {testOperator = '==';}
	else if  (testType == 'gt') {testOperator = '>';}
	else if  (testType == 'gteq') {testOperator = '>=';}
	else if  (testType == 'lt') {testOperator = '<';}
	else if  (testType == 'lteq') {testOperator = '<=';}
	else if  (testType == 'ne') {testOperator = '!=';}

	var evalStr = 'testData ' + testOperator + ' testCmpData';
	//alert (eval(testData) + ' ' + testOperator + ' ' +  testCmpData + ' = ' + eval(evalStr));
	if (eval(evalStr))
	{
	// setStyle(subjectId, 'display', 'block');
	if (getStyle(subjectId, 'display') == 'none') Effect.BlindDown(subjectId, {Duration: .5});
	}
	else
	{
	//setStyle(subjectId, 'display', 'none');
	if (getStyle(subjectId, 'display') != 'none') Effect.BlindUp(subjectId, {Duration: .5});
	}
}

// Set a cookie:
//	- name = the cookie's name
//	- value = the cookie's value
//	- days = the cookie's expiry in days
function setCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// Get the value of a given cookie
function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Clear a cookie of a given name
function clearCookie(name)
{
  createCookie(name,"",-1);
}

function showHelp(helpId)
{
	  helpObj = getElementById(helpId);
	  eval('helpObj.style.display = "block"');
}