/*******************/
//ahbc.js
/*******************/
var dateNow=""
var timenow=""
var yearNow = new Date() 


var thisYear=yearNow.getYear()
var mm = yearNow.getMonth()
var dd = yearNow.getDate()
var inputErrorMsg="The following data or fields are incomplete or inaccurate: \n"

if (thisYear< 2000) {
	thisYear=1900+thisYear
   //alert(thisYear) 
}
var yyyy=thisYear
//begin animation css
var maxA=210




var logoDir
if (logoDir=="")
{
	logoDir="dn"
}

//-----------browser details------------------//

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
   fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}


//-----------end browser details------------------//





function goDown(d) {
	
	var oScroller		=	document.getElementById(d)
	var i				=	parseInt(oScroller.style.pixelTop)
	var moveUnit		=	14 
	oScroller.pixelTop		=	i - moveUnit+"px"
	if (- oScroller.style.pixelTop >= oScroller.offsetHeight-oScroller.offsetParent.offsetHeight)
			oScroller.style.pixelTop =- oScroller.offsetHeight + oScroller.offsetParent.offsetHeight	
	
	alert(oScroller.pixelTop)
	
}
function goUp(d) {
	
	var oScroller		=	document.getElementById(d)
	var i				=	parseInt(oScroller.style.pixelTop)
	var moveUnit		=	14 
	oScroller.pixelTop		=	i + moveUnit+"px"
	if (oScroller.style.pixelTop > 0)
			oScroller.style.pixelTop = 0
	alert(oScroller.pixelTop)
}



function changeOpacity(id, op)
{
	var obj  = document.getElementById(id);
	//var brzr = obj.filters ? "ie" : typeof obj.style.MozOpacity=="string"? "mozilla" : ""
	//alert(browserName)
	
	
	
	if (browserName == "Microsoft Internet Explorer")
		obj.filters.alpha.opacity=parseInt(op);
	else {
	
		if (browserName == "Firefox")
			obj.style.MozOpacity=op/100;
		else
			obj.style.opacity = parseInt(op)/100;
		
	}
}




function showDivById(divNo, divNamePrefix, nStart, nEnd)
{
	var str = new String(divNo)
	hideAllDivsById(divNamePrefix, nStart, nEnd);
	document.getElementById(divNamePrefix+str).style.visibility="visible";
}


function show(y)
{
	document.getElementById(y).style.visibility="visible";
}
													
function hide(y)
{
	document.getElementById(y).style.visibility="hidden";
}

	
function hideAllDivsById(divNamePrefix,minD,maxD)	
{
	var str
	for (var i=minD; i<=maxD;i++)  {
		str = new String(i)
		document.getElementById(divNamePrefix+str).style.visibility="hidden";
	}
}
function hideAllDivs(minDivNo,maxDivisions)	
{
	var str
	for (var i=minDivNo;i<=maxDivisions;i++) {
		str = new String(i)
		document.getElementById("d"+str).style.visibility="hidden";
	}
}



function showAsSelected(menuItem)
{
	document.getElementById(menuItem).style.color="#ffffff"
	document.getElementById(menuItem).style.backgroundColor="#f08000"
}

function hideMenu(mId)
{
	document.getElementById(mId).style.visibility="hidden";
}

function delayHideMenu(mId)
{
	setTimeout("hideMenu('" + mId + "')",3000)
}


var MAXADVERT;
var currentDivNo;
function advert()
{
	var thisDiv, nextDiv, x;
	x = (typeof(currentDivNo)==='undefined') ? 1 : currentDivNo;
	thisDiv="dv" + x;
	//now next (first or incremented) x
	x = (x == MAXADVERT) ? 1 : x + 1;
	currentDivNo = x; 
	nextDiv="dv" + currentDivNo;

	//alert("this Div: " + thisDiv + ", next Div: " + nextDiv)
	if (document.getElementById(thisDiv) && document.getElementById(thisDiv).style.visibility=="visible") { 
		document.getElementById(thisDiv).style.visibility="hidden";
		if (document.getElementById(nextDiv)) 
			document.getElementById(nextDiv).style.visibility="visible";
	}	
	showAdvert();
}




function showAdvert()
{
	setTimeout("advert()",4000)
}



function anObject(parentId, selfRef, width, height, id, xDir, yDir, title, href, html)
{
	this.parentId		= parentId;
	this.selRef			= selfRef;
	this.size			= selfRef.size;
    this.width			= parseInt(width);
    this.height			= parseInt(height);
	this.id				= id;
	this.xDir			= xDir; //note: 0=no movement; 1=left->right; 2=right->left;
	this.yDir			= yDir; //note: 0=no movement; 1=top->bottom; 2=bottom->top;  
	this.title			= title;
	this.href			= href;
	this.html			= html;
	this.nHops			= this.height*2; //iterations required
	this.xLeap			= Math.round(this.width/this.nHops)
	this.yLeap			= Math.round(this.height/this.nHops)
	switch (this.xDir) {
		case 0:
			this.xMin = 0;
			this.xMax = 0;
			break;
		case 1:
			this.xMin = 0
			this.xMax = width;
			break;
		case 2:
			this.xMin = width * -1;
			this.xMax = width;
			break;
	}
			
	switch (this.yDir) {
		case 0:
			this.yMin = 0;
			this.yMax = 0;
			break;
		case 1:
			this.yMin = 0
			this.yMax = height;
			break;
	 	case 2: 
			this.yMin = height * -1;
			this.yMax = height;
			break;
	}

	this.show	= '<div id=' + id + ' style="position:relative;' + ((width=='')? '': ' width:' + width + 'px; ') +  ((height=='')? '': ' height:' + height + 'px; ') + ' visibility:hidden;">' +
				   ((href=="")? title : '<a href="' + href + '"><img height=13 border=0 align=absmiddle src="/images/navigate.jpg" /> '+ title + '</a>') + '<br />' + html +'</div>';
		   
}


function createAndMoveAnObject(o)
{
	var hText = "";
	for (var x=0; x<o.length; x++){
		hText += o[x].show
	}
	document.write(hText);
	animateObject(o)
}


function animateObject(oRef) 
{
	this.oRef			= oRef;
	this.size			= oRef.length;
	this.currentElement	= 0;
	this.iterationCount = 0;
	
	
	var myObj			= this;
	var o, oCanvas, oParent;
	var xLoc, yLoc;
	var canvasWidth, parentWidth, halfWidthDefference ;
	
	
	this.animate = window.setInterval(function()
	{
		if (this.iterationCount==0) 
		{
			
			//do not move these 2 lines above where they are
			o = this.oRef[this.currentElement];
			oCanvas	= document.getElementById(o.id);
			oParent = document.getElementById(o.parentId);
			canvasWidth = parseInt(oCanvas.style.width);
			parentWidth = parseInt(oParent.style.width);
			parentHeight = parseInt(oParent.style.height);
			
			
			halfWidthDifference=(parentWidth - canvasWidth)/2;
		
		
			//oCanvas.style.zIndex= (this.currentElement + 1);
			//Start with the initial position
			
			if (o.xDir==2){oCanvas.style.left = o.xMax + "px";}
			else{oCanvas.style.left = o.xMin + "px";}
			if (o.yDir==2){oCanvas.style.top  = o.yMax + "px";}
			else{oCanvas.style.top  = o.yMin + "px";}
			
			
			if (o.width > parentWidth && o.xDir==2) {
				oCanvas.style.left = parentWidth;
				this.iterationCount = parentWidth;
				//o.xMax = parentWidth;
			}
				
				
			if (o.height > parentHeight && o.yDir==2) {
				oCanvas.style.top=parentHeight;
				this.iterationCount = parentHeight;
				//o.yMax=parentHeight;
			}
		}
		
		
		xLoc = parseInt(oCanvas.style.left);
		yLoc = parseInt(oCanvas.style.top);
		switch (o.xDir) {
			case 0:
				xLoc = 0;
				break;
			case 1:
				xLoc += o.xLeap;
				if (xLoc > o.xMax) {xLoc = o.xMax;}
				break;
			case 2:
				xLoc -= o.xLeap;
				if (xLoc < o.xMin) {xLoc = o.xMin;}
				break;
		}
		switch (o.yDir) {
			case 0:
				yLoc = 0;
				break;
			case 1:
				yLoc += o.yLeap;
				if (yLoc > o.yMax) {yLoc = o.yMax;}
				break;
			case 2:
				yLoc -= o.yLeap;
				if (yLoc < o.yMin) {yLoc = o.yMin;}
				break;
		}
		
		
		
		xLoc = halfWidthDifference + xLoc
		oCanvas.style.left = xLoc + "px";
		oCanvas.style.top  = yLoc + "px";
		oCanvas.style.visibility="visible";	
		
		
		
		
		//change index and start with the next element in line
		this.iterationCount++;	
		if (this.iterationCount == o.nHops) {
			oCanvas.style.visibility="hidden";
			this.currentElement ++;
			if (this.currentElement == this.size) {this.currentElement = 0;	}
			
			
			/*
			alert("iCount: " + this.iterationCount + "\nElement...: " + (parseInt(this.currentElement) + 1) + "\nId...: " + o.id +  "\nLeft...: " + oCanvas.style.left +   "\nTop...: " + oCanvas.style.top +  "\nVisibility...: " + oCanvas.style.visibility +
				"\n [xMin: " + o.xMin + " xMax: " + o.xMax + " yMin: " + o.yMin + " yMax: " + o.yMax + " xLeap: " + o.xLeap + " yLeap: " + o.yLeap + "]" + 
					"\nxLoc: " + xLoc + "\nyLoc: " + yLoc );
			*/
			
			
			this.iterationCount = 0;
		}
		
		this.animate; // GO TO THE BEGINNING (a reference to this proc)
	}, 25);
	
}




function moveAnObject(oRef) 
{
	this.oRef			= oRef;
	this.size			= oRef.length;
	this.currentElement	= 0;
	this.iterationCount = 0;

				
	
	var myObj			= this;
	
	
	
	var o, oCanvas, oParent;
	var xLoc, yLoc;
	this.animate	= window.setInterval(function()
	{
		//change index and start with the next element in line
		if (myObj.iterationCount == myObj.oRef[myObj.currentElement].nHops) {
			document.getElementById(myObj.oRef[myObj.currentElement].id).style.visibility="hidden";
			myObj.currentElement ++;
			
			if (myObj.currentElement == myObj.size) {
				myObj.currentElement = 0;
			}
			//alert("iCount: " + myObj.iterationCount + "\nElement: " + (parseInt(myObj.currentElement) + 1) + "/" + myObj.size + "\nParent: " + myObj.oRef[myObj.currentElement].parentId );	
			myObj.iterationCount = 0;

		}	
		//document.getElementById(myObj.oRef[myObj.currentElement].id).style.visibility="visible";
			
			
			
		
		
		
		//do not move these 2 lines above where they are
		o = myObj.oRef[myObj.currentElement];
		oCanvas	= document.getElementById(o.id);
		oParent = document.getElementById(o.parentId);
		var canvasWidth, parentWidth, halfWidthDefference ;
		canvasWidth = parseInt(oCanvas.style.width);
		parentWidth = parseInt(oParent.style.width);
		halfWidthDifference=(parentWidth - canvasWidth)/2;
		oCanvas.style.zIndex= (myObj.currentElement + 1);
		
		
		
		
			
		if (myObj.iterationCount==0) 
		{	//initialLocation
			if (o.xDir==2)
				{oCanvas.style.left = o.xMax + "px";}
			else
				{oCanvas.style.left = o.xMin + "px";}
			if (o.yDir==2)
				{oCanvas.style.top  = o.yMax+"px";}
			else
				{oCanvas.style.top  = o.yMin+"px";}
			
			
			//alert("ParentId: " + o.parentId + "\nparentWidth:" + parentWidth  + "\ncanvasWidth:" + canvasWidth + "\nhalfWidthDifference:" + halfWidthDifference);
			//alert("iCount: " + myObj.iterationCount + "\nElement...: " + (parseInt(myObj.currentElement) + 1) + "\nId...: " + o.id +  "\nLeft...: " + oCanvas.style.left +   "\nTop...: " + oCanvas.style.top +  "\nVisibility...: " + oCanvas.style.visibility +
			//	"\n [xLoc: " + o.xLoc + " xMax: " + o.xMax + " yMin: " + o.yMin + " yMax: " + o.yMax + " xLeap: " + o.xLeap + " yLeap: " + o.yLeap + "]") 
		}
		xLoc = parseInt(oCanvas.style.left);
		yLoc = parseInt(oCanvas.style.top);
		
		
		
	
		switch (o.xDir) {
			case 0:
				xLoc = 0;
				break;
			case 1:
				xLoc += o.xLeap;
				if (xLoc > o.xMax) {xLoc = o.xMax;}
				break;
			case 2:
				xLoc -= o.xLeap;
				if (xLoc < o.xMin) {xLoc = o.xMin;}
				break;
		}

		switch (o.yDir) {
			case 0:
				yLoc = 0;
				break;
			case 1:
				yLoc += o.yLeap;
				if (yLoc > o.yMax) {yLoc = o.yMax;}
				break;
			case 2:
				yLoc -= o.yLeap;
				if (yLoc < o.yMin) {yLoc = o.yMin;}
				break;
		}

		oCanvas.style.left = halfWidthDifference + xLoc +"px";
		oCanvas.style.top  = yLoc +"px";
		
		oCanvas.style.visibility="visible";	
		myObj.iterationCount++;
		
			
		myObj.animate; //a reference to this proc

	}, 70);
	
}







function animateBanner()
{
	var i=parseInt(document.getElementById('bb').style.left)

	logoDir=(i==0)?"up":((i==maxA)?"dn":logoDir)
	if (logoDir=="dn") {
		i=i-1
	}
	else
	{
		i=i+1
	}
	
	
	document.getElementById('bb').style.left=i
	moveThings()
}
function moveThings()
{
	setTimeout("animateBanner()",30)
}
//end animation css


function TimeMessage()
{
	var len = 4
	var today=new Date()
	var sec = today.getSeconds()
	var mins=today.getMinutes()
		mins=(mins<10)?"0"+mins:mins
	var hrs=today.getHours()
	var days=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
	var mths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	var mssg=(hrs<12)?"Good Morning":(hrs>16)?"Good Evening":"Good Afternoon"
	var dateRightNow=today.getDate()+' '+mths[today.getMonth()]+' '+thisYear
	var timeRightNow=hrs+":"+mins
	var ap=(hrs>11)?"pm ":"am "

	
	return(days[today.getDay()]+' '+dateRightNow+' '+timeRightNow+':'+ap+'<br><b>'+mssg+'</b>')
}


function currentDate() {
	
	
	dd=yearNow.getDate()
	mm=yearNow.getMonth()+1
	return(thisYear+"/"+mm+"/"+dd);
	
}
dateNow=currentDate();
function isEmpty(s) {
	if (s==null || s=="") {
		return true
	}
	else {
		return false
	}
}

function isEmail(e) {
	if (e==null || e=="" || e.indexOf("@")== -1) {
		return false;
	}
	else {
		return true;
	}
}

function isNumeric(e) {
	theDecimal= false
	inStr=e.toString()
	if (inStr=="") {
		inStr=0
	}	
	for (var i=0; i<inStr.length;i++) {
		var theChar=inStr.charAt(i)
		if(i==0 && theChar=="."){
			continue
		}
		if (theChar=="." && !theDecimal) {
			theDecimal=true
			continue
		}
		if (theChar <"0" || theChar>"9") {	
			return false
		}	
	}	
	return true;
}

function isDigit(e) {
	
	inStr=e.toString()
	if (inStr=="") {
		return false
	}	
	for (var i=0; i<inStr.length;i++) {
		var theChar=inStr.charAt(i)
		if (theChar <"0" || theChar>"9") {	
			return false
		}	
	}	
	return true;
}

function isYear(e) {
	if (!isDigit(e)) {
		return false
	}	
	else {
		inStr=e.toString()
		if (inStr.length !=4){
			return false
		}	
		return true	
	}
}
	
function isPassword(p) {
	if (p==null || p=="" || p.length < 6) {
		alert("Password must have 6 characters or digits")
		return false
	}
	else {
		return true
	}
}
var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
function checkDaysInMonth(y,m,d) {
	leapyr= (y % 4 > 0)?false:true
	daysInMonth[1]=(leapyr)?29:28
	return (d > daysInMonth[m - 1])?false:true	
}		    
		
			
function isValid_DMY_Date(d) {
	//alert("date: " + d)
	if (isEmpty(d)) {
		//alert(d +" " +"Date is empty")
		return false
	}
	if (d.length != 10) {
		return false
	}
	var dd=d.substring(0,2)
	var mm=d.substring(3,5)
	var yyyy=d.substring(6, d.length)
	
	
	
	if (dd.length >2) {
		//alert("Day part of date must be two digits")
		return false
	}
	
	if (mm.length > 2 || mm < 1 || mm >12) {
		//alert("Month must be two digits and one of 01, 02... to 12")
		return false	
	}
	
	if (yyyy.length !=4) {
		//alert("Year must be 4 digits")
		return false
	}	
	
	if (!checkDaysInMonth(yyyy, mm, dd)) {
		//alert("Wrong date in month")
		return false
	}
	delim1=d.charAt(2)
	delim2=d.charAt(5)
	
	if (delim1 !="/" && delim1 !="-"){
		//alert("Invalid delimiters")	
		return false
	}
	if (delim1 != delim2 ) {
		//alert("Two delimiters are different")	
		return false	
	}	
	else
		return true
}

/* proofing online visitor is not a form submit bot */
var botProofString
var grafxFontArr=new Array(36)
grafxFontArr[0]="0.gif"
grafxFontArr[1]="1.gif"
grafxFontArr[2]="2.gif"
grafxFontArr[3]="3.gif"
grafxFontArr[4]="4.gif"
grafxFontArr[5]="5.gif"
grafxFontArr[6]="6.gif"
grafxFontArr[7]="7.gif"
grafxFontArr[8]="8.gif"
grafxFontArr[9]="9.gif"
grafxFontArr[10]="a.gif"
grafxFontArr[11]="b.gif"
grafxFontArr[12]="c.gif"
grafxFontArr[13]="d.gif"
grafxFontArr[14]="e.gif"
grafxFontArr[15]="f.gif"
grafxFontArr[16]="g.gif"
grafxFontArr[17]="h.gif"
grafxFontArr[18]="i.gif"
grafxFontArr[19]="j.gif"
grafxFontArr[20]="k.gif"
grafxFontArr[21]="l.gif"
grafxFontArr[22]="m.gif"
grafxFontArr[23]="n.gif"
grafxFontArr[24]="o.gif"
grafxFontArr[25]="p.gif"
grafxFontArr[26]="q.gif"
grafxFontArr[27]="r.gif"
grafxFontArr[28]="s.gif"
grafxFontArr[29]="t.gif"
grafxFontArr[30]="u.gif"
grafxFontArr[31]="v.gif"
grafxFontArr[32]="w.gif"
grafxFontArr[33]="x.gif"
grafxFontArr[34]="y.gif"
grafxFontArr[35]="z.gif"

function proofUserEntry(frm,entry)
{
	if (entry != botProofString) {
		frm.ovs.value=""
		alert("Verification string entered does not match the one displayed.")
		//location.reload()
	}
	else {
		//document.getElementById("actualForm").style.visibility="visible"
		//isHuman(frm)
		//frm.vfd.value=botProofString +'<%=checkASPValue4This%>'
		frm.vfd.value=frm.ovs.value + frm.ftype.value
	}
}

function printGrafxNumber(nmb)
{
	var asciiCode,ndx,grafxHtml=""
	for (x=0;x<6;x++) {
		asciiCode=nmb.charCodeAt(x)
		if (asciiCode > 96) 
			ndx=asciiCode-87 // take 96 and add 10
		else
			ndx=asciiCode-48
		grafxHtml=grafxHtml+'<img src="/images/grafx/'+grafxFontArr[ndx]+'" width="30" height="30" alt="">'
	}
	document.write(grafxHtml)	
}

function genrateAlphaNumericRandomString()
{
	var chr,ndx,ANRString=""
	for (x=0;x<6;x++) {
		ndx=Math.round(Math.random()* 35)
		chr=grafxFontArr[ndx].charAt(0)
		ANRString=ANRString+chr
	}
	botProofString=ANRString
}
function isHuman(f)
{
	f.vfd.value=botProofString +'<%=checkASPValue4This%>'
}

/* eop: proofing online visitor is not a form submit bot */

function submitContactDetails()
{
	var v = 0;
	f = "document.forms['contactForm']." 
	msg = ""
	fn=eval(f+"first_name.value")
	if (isEmpty(fn)) {
		v++;
		msg += "\nFirst Name empty"
	}
	fn=eval(f+"last_name.value")
	if (isEmpty(fn)) {
		v++;
		msg += "\nLast Name empty"
	}
	fn=eval(f+"email.value")
	if (!isEmail(fn)) {
		v++;
		msg += "\nIncorrect or empty email address"
	}
	fn=eval(f+"street.value")
	if (isEmpty(fn)) {
		v++;
		msg += "\nStreet Address empty"
	}
	fn=eval(f+"city.value")
	if (isEmpty(fn)) {
		v++;
		msg += "\nSuburb/City empty"
	}
	fn=eval(f+"postcode.value")
	if (isEmpty(fn)) {
		v++;
		msg += "\nPostCode/Zip empty"
	}
	fn=eval(f+"ovs.value")
	if (fn!= botProofString) {
		msg += "\nVerification string entered does not match the one displayed.\n"
	}
	document.forms['contactForm'].password.value=document.forms['contactForm'].lop1.value
	
	if (v > 0) {
		alert(inputErrorMsg +"\n" + msg)	
	}
	else {
		document.forms['contactForm'].submit();
	}
}


function submitContactForm()
{
	var f = document.forms['roi'] 
	var msg = ""
	
	if (isEmpty(f.FirstName.value)) {
		msg += "\n. First Name empty"
	}
	
	if (isEmpty(f.LastName.value)) {
		msg += "\n. Last Name empty"
	}

	if (!isEmail(f.Email.value)) {
		msg += "\n. Incorrect or empty email address"
	}
	
	if (!isValid_DMY_Date(f.DOB.value)) {
		msg += "\n. Date of birth empty or inaccurate"
	}

	if (isEmpty(f.Message.value)) {
		msg += "\n. No message or question entered"
	}
	if (f.ovs.value != botProofString) {
		f.ovs.value=""
		msg += "\n. Verification string does not match with the one displayed."
	}
	if (msg != "") {
		alert("Incorrect or invalid input in the following fields:\n" + msg)	
	}
	else {
		f.submit();
	}
}


function submitApplication()
{
	var v = 0,p,r,n;
	f=document.forms['Enrol'] 
	msg = ""
	
	if (f.ovs.value != botProofString) {
		f.ovs.value=""
		v++;
		msg += "\nVerification string does not match with the one displayed."
	}
	if (isEmpty(f.first_name.value)) {
		v++;
		msg += "\nFirstname empty"
	}
	if (isEmpty(f.last_name.value)) {
		v++;
		msg += "\nLastname empty"
	}
	if (isEmpty(f.address.value)) {
		v++;
		msg += "\nAddress empty"
	}
	if (isEmpty(f.dob.value) || !isValid_DMY_Date(f.dob.value)) {
		v++;
		msg += "\nDate of birth empty or not valid"
	}
	if (isEmpty(f.countryofbirth.value)) {
		v++;
		msg += "\nCountry of birth empty"
	}
	
	n= f.nationality.value.toLowerCase()
	n=n.substr(0,9)
	
	if (isEmpty(n)) {
		v++;
		msg += "\nNationality empty"
	}

	r = getRadioButtonSelectedValue(f.resident)
	if ((n != "australia") && isEmpty(r)) {
		v++;
		msg += "\nResidence status empty"
	}
	if (r=="No" && isEmpty(f.visatype.value)) {
		v++;
		msg += "\nOverseas student must enter visa type"
	}
	if (isEmpty(f.email.value)) {
		v++;
		msg += "\nEmail address empty"
	}
	
	/*
	if (isEmpty(f.commencing.value)  || !isValid_DMY_Date(f.commencing.value)) {
		v++;
		msg += "\nCourse start date empty or not valid"
	}
	*/
	p= getRadioButtonSelectedValue(f.course)
	if (isEmpty(p)) {
		v++;
		msg += "\nStudy course not selected"
	}
	
	
	/*
	p = getRadioButtonSelectedValue(f.paying_by)
	if (isEmpty(p)) {
		v++;
		msg += "\nPayment method not selected"
	}
	*/
	
	
	if (n != "australia") {
		if (isEmpty(f.passportnumber.value)) {
			v++;
			msg += "\nPassport number empty"
		}
		/*if (isEmpty(getRadioButtonSelectedValue(f.ozvisa))) {
			v++;
			msg += "\nEver held an Australian visa - not entered"
		}
		*/
		if (isEmpty(getRadioButtonSelectedValue(f.hasconsultant))) {
			v++;
			msg += "\nNo entry for consultant/lawyer"
		}
		if (isEmpty(getRadioButtonSelectedValue(f.oshealthcover))) {
			v++;
			msg += "\nOS Student must select health cover"
		}
	}
	if (isEmpty(getRadioButtonSelectedValue(f.studentdec))) {
		v++;
		msg += "\nDeclaration statement agreed empty"
	}
	
	
	if (v > 0) {
		alert(inputErrorMsg +"\n" + msg)	
	}
	else {
		document.forms['Enrol'].submit();
	}
}
function getRadioButtonSelectedValue(rb)
{
	if (!rb)
		return ""
	
	if(rb == undefined)
		if(rb.checked)
			return rb.value;
		else
			return "";

	for (var i=0; i<rb.length; i++){
		if (rb[i].checked)
			return(rb[i].value)
	}
	return ""
			
}
function radioButtonSelected(f) //f=field
{
	var r=""
	f=eval(f)
	for (var i=0; i < f.length; i++) {
		if (f[i].checked) {
			r=f[i].value;
			break;
		}
	}
	return r
}


function getCBSelectedValue(n)
{
	var cbItems = ""
	n=eval(n)
	for (var i=0; i<n.length; i++){
			if (cbItems=="")
				cbItems = n[i].value
			else
				cbItems += ", " + n[i].value
	}
	document.forms["0"].selected_modules.value=cbItems
	return cbItems
}


function recordNationality()
{
	var f,c,nat
	
	f=document.forms['0']
	nat=f.nationality.value.toLowerCase()
	if (nat=="australia" || nat=="australian") {
		f.osStudent.value="False"
		//alert("Local students skip this box.")
	}
	else {
		f.osStudent.value="True"
		//alert("Local students skip this box.")
	}	
}

function checkPr()
{
	var f,c,nat,spr
	f=document.forms[0]
	spr=getRadioButtonSelectedValue(f.pr)
	nat=f.nationality.value.toLowerCase()
	osS=f.osStudent.value
	if ((spr=="Yes" && (nat != "australia" || nat != "australian")) || (nat == "australia" || nat == "australian") ) {
		f.osStudent.value="False"
		f.kin_lname.focus()
	}
	else
		f.osStudent.value="True"	
	//f.kin_lname.focus()
}

function checkIfAustralian(fld,nxt)
{
	var f,c,nat,osS
	f=document.forms[0]
	nat=f.nationality.value
	osS=f.osStudent.value
	//alert("osS->"+osS)
	if (osS=="False") {
		alert("Local students skip this box.")
		if (fld.name==f.pr) {
			if (nat=="australia" || nat=="australian"){
				fld.blur()
				eval("f."+nxt+".focus()")
			}
		}	
		else {
			fld.blur()
			eval("f."+nxt+".focus()")
		}	
		
	}	
}
function entryLocalExempt(fld,nxt)
{
	var f,osS
	f=document.forms[0]
	osS=f.osStudent.value
	//alert("osS->"+osS)
	if (osS=="False") {
		alert("Local students skip this box.")
		fld.blur()
		eval("f."+nxt+".focus()")
	}	
}
			
function checkIfRequired()
{
	var f,c
	f=document.forms['EnrolPg2']
	c=getRadioButtonSelectedValue(f.paying_by)
	
	if (c !="American Express") 
	{
		f.amex_id.value=""
		f.amex_id.blur()
		f.cc_holder.focus()
	}
	else {
		f.amex_id.focus()	
	}	
}

function computeTotal(min_deposit)
{
	var d,b,h,pay
	
	//alert(min_deposit)
	min_deposit=parseFloat(min_deposit)
	
	f=document.forms['EnrolPg2']
	d=parseFloat(f.course_deposit.value)
	b=parseFloat(f.balance_tuition.value)
	h=parseFloat(f.os_healthcover.value)
	if (d < min_deposit) {
		alert("Course deposit cannot be reduced below " + min_deposit)
		f.course_deposit.value=min_deposit
	}
	else {
		b=min_deposit/30*100-d
		f.balance_tuition.value=b
	}	
	f.paying_amount.value=d + h
	
	f.total.value=d + b + h
}

function gotoPage2()
{
	var f,fn,ln,db,sx,nat,ocp,st,ct,stt,pc,cty,eml,ph,hca,kf,kl,kr,ka,crs,subj,cm,m,om
	
	m=""
	om=""
	f=document.forms['EnrolPg1']
	fn=f.fname.value
	ln=f.lname.value
	db=f.dob.value
	sx=getRadioButtonSelectedValue(f.sex)
	nat=f.nationality.value
	ocp=f.occupation.value
	st=f.street.value
	ct=f.city.value
	stt=f.state.value
	pc=f.postcode.value
	cty=f.country.value
	eml=f.email.value
	ph=f.phone.value
	hca=f.hmcountry_address.value
	kf=f.kin_fname.value
	kl=f.kin_lname.value
	kr=f.kin_relation.value
	ka=f.kin_address.value
	crs=getRadioButtonSelectedValue(f.course)
	//subj=getCBSelectedValue(f.subjects)
	cm=f.commencing.value
	
	if (isEmpty(fn))
		m+=". student given names empty\n"
	if (isEmpty(ln))
		m+=". student last name empty\n"
	if (!isValid_DMY_Date(db))
		m+=". date of birth empty or invalid\n"
	if (isEmpty(sx))
		m+=". check empty\n"
	if (isEmpty(nat))
		m+=". nationality empty\n"
	//if (isEmpty(ocp))
	//	m+=". occupation empty\n"
	if (isEmpty(st))
		m+=". street address empty\n"
	if (isEmpty(ct))
		m+=". city empty\n"
	if (isEmpty(stt))
		m+=". state empty\n"
	if ( isEmpty(pc) || !isDigit(pc) )
		m+=". postcode empty or not digits\n"
	if (isEmpty(cty))
		m+=". country empty\n"
	if ( isEmpty(eml) ||  !isEmail(eml) )
		m+=". email empty or invalid\n"
	if (isEmpty(ph))
		om+=". phone empty\n"
	if (hca.length==122 && f.osStudent.value=="True")
		om+=". international students must supply home country address\n" 
	if (isEmpty(kf))
		om+=". Next of kin first name empty\n"
	if (isEmpty(kl))
		om+=". Next of kin last name empty\n"
	if (isEmpty(kr))
		om+=". Next of kin relation empty\n"
	if (ka.length==122)
		om+=". Next of kin address empty\n" 
		
	if (isEmpty(crs))
		m+=". must select a course\n" 
	//if (crs=='Modules' && (isEmpty(subj)))
	//	m+=". at least one study module must be selected if you choose selected units\n"
	//if (crs!='Modules' && (!isEmpty(subj)))
	//	m+=". you've ticked units without choosing any units...\n"
	if (isEmpty(cm) || !isValid_DMY_Date(cm))
		m+=". preferred course start date empty or invalid\n"
	if (m !="")
		m="R E Q U I R E D  D A T A\n - the form cannot be submitted\n - the following items must be completed correctly:\n\n"+m
	if (om!="") {
		if (m=="")
			om= "W A R N I N G\n - the form can be submitted with these warnings:\n\n" + om
		else
			om= "W A R N I N G\n - you may wish to correct or supply these optional items:\n\n" + om
	}			
	if (m=="") {
		if (om=="")
			f.submit()
		else {
			alert(om)
			var confirm=prompt("Submit page without correcting/completing optional items? [Yes/No]:","Yes")
			if (confirm.toLowerCase()=="yes")
				f.submit()
		}
	}
	else {
		alert( m + "\n\n" + om)
	}		
				
}
function getCourseFees(crs)
{

}

function finish()
{	
	var f=document.forms['EnrolPg2']
	var cch = f.cc_holder.value
	var cc = f.cc_number.value
	
	
	var amt = f.paying_amount.value
	var x = f.xm.value
	var y = f.xy.value
	
	
	var pn= f.passport.value
	var pv= getRadioButtonSelectedValue(f.prev_visa)
	var va= getRadioButtonSelectedValue(f.visa_agent)
	var aa=	f.agent_address.value
	var dep=f.course_deposit.value
	var bt= f.balance_tuition.value
	var hcf=f.os_healthcover.value
	var tot=f.total.value
	var bpm=getRadioButtonSelectedValue(f.balance_paymethod)
	var payby=getRadioButtonSelectedValue(f.paying_by)
	var amx=f.amex_id.value
	var ref=getRadioButtonSelectedValue(f.referer)
	var refs=f.referer_source.value
	var pay=f.paying_amount.value
	var osS=f.osStudent.value
	
	var m =""
	var om=""
	var dt = new Date()
	var yr = dt.getYear()
	
	
	if (isEmpty(pn) && osS=="True")
		om += ". passport empty\n"
	if (va="Yes" && isEmpty(aa))
		m += ". education consultant/immigration lawyer empty\n"
	if (isEmpty(payby))
		m += ". method of fund transfer empty\n"
	else {
		if (payby=="Mastercard" || payby=="Visa card" || payby=="Diner's club" ||payby=="American Express") {
			if (isEmpty(cc) || (cc.length > 16))
				m += ". card number empty or has too many characters\n"
				
			if (isEmpty(cch))
				m += ". name on card empty\n"
				
			if (pay=="")
				pay="<%=courseDepositFees%>"
				
				
			if ( (y < yr) || (x < dt.getMonth() && yr==y) )
				m += ". card expiry date not correct\n" 
		}
	}
	if (isEmpty(refs) && ref=='Other')
		om+=". you found out about AH+BC from what 'Other' source?\n"
		
	if (m !="")
		m="R E Q U I R E D  D A T A\n - the form cannot be submitted\n - the following items must be completed correctly:\n\n"+m
	if (om!="") {
		if (m=="")
			om= "W A R N I N G\n - the form can be submitted with these warnings:\n\n" + om
		else
			om= "W A R N I N G\n - you may wish to correct or supply these optional items:\n\n" + om
	}
	if (m=="") {
		if (om=="")
			f.submit()
		else {
			alert(om)
			var confirm=prompt("Submit page without correcting/completing optional items? [Yes/No]:","Yes")
			if (confirm.toLowerCase()=="yes")
				f.submit()
		}
	}
	else {
		alert( m + "\n\n" + om)
	}		
}
