// JavaScript Document

function apddec(f){
	
	if(!f.reason[0].checked && !f.reason[1].checked && !f.reason[2].checked && !f.reason[3].checked && !f.reason[4].checked && !f.reason[5].checked){
		alert("Please select your reason for deferement")
		return false
	}
	if(f.reason[5].checked && f.reason_other.value == ""){
		alert("Please specify other reason")
		f.reason_other.focus()
		return false
	}
	if(f.reinsatement.value == ""){
		alert("Please enter an actual reinstatement date in the format of: dd/mm/yyyy")
		f.reinsatement.focus()
		return false
	}
	if(!checkDate(f.reinsatement, f.reinsatement.value))
		return false
		
return true
}

function numeric(v){ 
  	v = Math.round(parseFloat(v) * 100) / 100
	v = v.toString() 
	var p = v.indexOf('.') 
	
	if(p == -1) 
		return v + '.00' 
	
	p = v.length - p 
	
	if(p == 2) 
		return v + '0' 

return v 
}

function calc(){
	
	var o = document.STEPFIVE.membID
	var div = document.getElementById("grandTotal")
	var donation = document.getElementById("donation")
	var myDate = new Date()
	var month = myDate.getMonth()
	var total = o
	
	for(var i = 0; i < o.length  ; i++){
		if(o[i].checked){
		total = o[i].value
		document.STEPFIVE.member_category_id.value = o[i].id
		
		}
	}
		
	total = Math.round(total*100)/100 + Math.round(donation.value*100)/100
	
	if(month < 2)
		total = total-parseInt(document.STEPFIVE.discount.value)

		total = numeric(total)
		
	
	div.innerHTML = "$"+total
	

}

function declaration(id){
	
	id = parseInt(id)
	
	var div = document.getElementById("declaration")
	var content = '<hr><strong>Declaration</strong><br>'	
	
	endContent = 'I will notify the DAA and pay the balance of the appropriate fee for the membership year if my membership category changes.'
	endContent += '<br>I accept <input type="radio" name="APD_AGREE" value="1" onClick="document.STEPFIVE.DEC_AGREE.value = this.value"> I don\'t accept <input type="radio" name="APD_AGREE" value="0" onClick="document.STEPFIVE.DEC_AGREE.value = this.value" checked>'
	endContent += '<hr>'
	
	//Reset declaration accept
	document.STEPFIVE.DEC_AGREE.value = 0
	
	switch(id){
		case 3:
		content += 'I declare that I am <strong>employed part-time (inclusive of all fields of work)</strong> 1 - 20 hours per week. ';
		break;
		
		case 4:
		case 5:
		case 11:
		case 12:
		case 17:
		case 13:
		content += 'I declare that I am not currently employed. ';
		break;
				
		case 6:
		case 10:
		content += 'I wish to advise that I am now retired from the workforce and understand that I am no longer eligible to take part in the APD program. '
		break;
		
		case 14:
		content +='I decalre that I am <strong>not working in a related industry</strong> (i.e. non-nutrition) ';
		break;
		
		default:
		content = "&nbsp;";
		endContent = "";
		//Set declaration accept to true
		document.STEPFIVE.DEC_AGREE.value = 1
		break;
	
	}	
	
	
	div.innerHTML = content+endContent	
	
}

function fulltimestudy(f){

	if(f.diploma.value == ""){
		alert("Please enter your Diploma/Degree name")
		f.diploma.focus()
		return false
	}
	if(f.courselength.value == ""){
		alert("Please enter your course length")
		f.courselength.focus()
		return false
	}
	if(f.Intsitute.value == ""){
		alert("Please enter your Intsitute")
		f.Intsitute.focus()
		return false
	}
	
	if(!checkDate(f.commenced, f.commenced.value)){
		return false
	}
	
	if(!checkDate(f.completion, f.completion.value)){
		return false
	}
	
	if(f.description.value == ""){
		alert("Please indicate how your course relates to dietetics")
		f.description.focus()
		return false
	}
	if(!f.agree[0].checked && !f.agree[1].checked){
		alert("Please agree to the declaration")
		f.agree[0].focus()
		return false
	}

return true
}

function checkDate(name, date){
	//get todays dates
	var today=new Date()
	todayDay = today.getDate()
	todayMonth = today.getMonth() + 1
	todayYear = today.getYear()
	
	var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
	var clientDate=date.split("/");
	clientDay = clientDate[0]
	clientMonth = clientDate[1]
	clientYear = clientDate[2]
	
	if(String(clientYear) == "undefined"){
		alert("Please enter a date")
		return false
	}
	
	if(clientYear < todayYear || (isNaN(clientYear) == true && date.length != 0 ) ){//check year
		alert("Please choose a valid year in the future and keep to this date format:\ndd/mm/yyyy")
		return false
	}
	if(clientMonth > 12 || (isNaN(clientMonth) == true && date.length != 0) ){ //check month
		alert("Please choose a valid month")
		return false
	}
	if((clientDay > monthLength[clientMonth-1]) || (isNaN(clientDay) == true && date.length != 0) ){ //check day
		alert("Please choose a valid day")
		return false
	}
	if(date.indexOf("/") != 2 && date.length != 0){// check format
		alert("Please keep to this date format:\ndd/mm/yyyy")
		return false
	}

return true
} 

function step1(f){
	if(f.COUNTRY.value.toLowerCase() == "australia" || f.COUNTRY.value.toLowerCase() == "au" || f.COUNTRY.value.toLowerCase() == "oz" || f.COUNTRY.value.toLowerCase() == "ozzie"){
			alert("Do not enter a country if you live in Australia")
			f.COUNTRY.focus()
			return false
	}
		
	if(f.COUNTRY.value != "" && f.MAIL_PREFERENCE[0].checked && f.DAA_BRANCH.value != ""){
			alert("Your preferred address is overseas therefore you must leave the Branch selection blank")
			f.DAA_BRANCH.focus()
			return false
	}
return true
}
