/*******************/
//validation.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"
}






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 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)
}

function advert()
{
	//alert(document.getElementById("dv1").style.visibility) 
	if (document.getElementById("dv1").style.visibility=="hidden") {
		document.getElementById("dv1").style.visibility="visible";
		document.getElementById("dv2").style.visibility="hidden";
	}
	else {
		document.getElementById("dv1").style.visibility="hidden";
		document.getElementById("dv2").style.visibility="visible";
	}
	showAdvert();
}
function showAdvert()
{
	setTimeout("advert()",9000)
}









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) {
		frm.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(n)
{
	for (var i=0; i<n.length; i++){
		if (n[i].checked)
			return(n[i].value)
	}
	return ""
			
}


function getCBSelectedValue(n)
{
	var cbItems = ""
	
	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 AHBC 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)
	}		
}