




function showTab( id ) {
	e = document.getElementsByTagName("div");
	for( i=0;i<e.length;i++ ) {
		if( e[i].className=='tabActive' )
			e[i].className='tab';
		if( e[i].className=='tab' ) {
			if( e[i].id==id )
				e[i].className='tabActive';
		}
	}
}





function calculateAge( memberNo ) {
	var today = new Date( ), bD, bM, bY;

	with( document.frmApplication ) {
		switch( memberNo ) {
			case 1:
				bD = cboBirthDate1_D.options[cboBirthDate1_D.selectedIndex].value;
				bM = parseInt(cboBirthDate1_M.options.selectedIndex)+1;
				bY = cboBirthDate1_Y.options[cboBirthDate1_Y.selectedIndex].value;
				birthDate = new Date( bY,bM,bD );
				txtAge1.value = datediff(today,birthDate)[0];
				break;
			case 2:
				bD = cboBirthDate2_D.options[cboBirthDate2_D.selectedIndex].value;
				bM = parseInt(cboBirthDate2_M.options.selectedIndex)+1;
				bY = cboBirthDate2_Y.options[cboBirthDate2_Y.selectedIndex].value;
				birthDate = new Date( bY,bM,bD );
				txtAge2.value = datediff(today,birthDate)[0];
				break;
			default:
				return;
		}
	}
}





function toggleOccupation( member, occupation ) {
	switch( occupation ) {
		case "Student":
			document.getElementById('labelOccupation'+member+'A').innerHTML = "School <font class=\"color_Red\">*</font>";
			document.getElementById('labelOccupation'+member+'B').innerHTML = "Year/Course <font class=\"color_Red\">*</font>";
			break;
		case "Professional":
			document.getElementById('labelOccupation'+member+'A').innerHTML = "Company <font class=\"color_Red\">*</font>";
			document.getElementById('labelOccupation'+member+'B').innerHTML = "Position <font class=\"color_Red\">*</font>";
			break;
		default:
			document.getElementById('labelOccupation'+member+'A').innerHTML = "School <font class=\"color_Red\">*</font>";
			document.getElementById('labelOccupation'+member+'B').innerHTML = "Year/Course <font class=\"color_Red\">*</font>";
			break;
	}
}





function showRouteStop( routeStop ) {
	e = document.getElementsByTagName("div");
	
	hideRouteStops( );
	for( i=0;i<e.length;i++ ) {
		if( e[i].id=='raceRoute_'+routeStop )
			e[i].className = "popUp_RaceRoute popUp_Visible";
	}
}
function hideRouteStops( ) {
	e = document.getElementsByTagName("div");
	
	for( i=0;i<e.length;i++ ) {
		if( e[i].className=='popUp_RaceRoute popUp_Visible' )
			e[i].className = "popUp_RaceRoute";
	}
}





function showTeamBox( teamID ) {
	var e = document.getElementsByTagName('div')

	for( x=0;x<e.length;x++ ) {
		if( e[x].className=="teamInfo" ) {
			e[x].style.display = "none";
			e[x].style.visibility = "hidden";
		}
	}
	for( x=0;x<e.length;x++ ) {
		if( e[x].className=="teamInfo" && e[x].id==teamID ) {
			e[x].style.display = "block";
			e[x].style.visibility = "visible";
		}
	}
	document.forms['frmBallot']['TEAM'].value = teamID;
	document.getElementById("teamBox").style.visibility = "visible";
	document.getElementById("titleBar").focus;
}
function hideTeamBox( ) {
	var e = document.getElementsByTagName('div')

	document.getElementById("teamBox").style.visibility = "hidden";
	for( x=0;x<e.length;x++ ) {
		if( e[x].className=="teamInfo" ) {
			e[x].style.display = "none";
			e[x].style.visibility = "hidden";
		}
	}
}





//====================================== validation FeedBack Form ================================//
function validationFeedBack( ) {
	with( document.forms['frmFeedback'] ) {
		var counter = true;
		 if(txtName.value.length == 0){
			 	alert("Please Enter Your Name")
				txtName.focus();
				counter = false;
		 }else if(txtEMail.value.length == 0){
			 	alert("Please Enter Your Email")
				txtName.focus();
				counter = false;
		 }else if(txtSubject.value.length == 0){
			 	alert("Please Enter Your Subject")
				txtSubject.focus();
				counter = false;
		 }else if(txtMessage.value.length == 0){
			 	alert("Please Enter Your Message")
				txtMessage.focus();
				counter = false;
		 }
		if(counter){
			var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
			if(txtEMail.value.match(emailExp)){
				document.forms['frmFeedback'].submit()
			}else{
				alert("Invalid Email");
				txtEMail.value="";
				txtEMail.focus();
			}			
		}
	}
}





//====================================== validation FeedBack Form ================================//
function validateBallot( ) {
	var errorMsg, setFocus;
	var hasErrors=false;

	errorMsg = "";
	with( document.forms['frmBallot'] ) {
		if( txtContactNo_AC.value.length==0 || txtContactNo.value.length==0 || isNaN(txtContactNo_AC.value) || isNaN(txtContactNo.value) ) {
			errorMsg = "Please supply your Contact No.\n"+errorMsg;
			setFocus = "txtContactNo_AC";
			hasErrors = true;
		}
		if( txtEMail.value.length==0 ) {
			errorMsg = "We need a valid Email Address.\n"+errorMsg;
			setFocus = "txtEMail";
			hasErrors = true;
		}
		if( cboProvince.value=="" ) {
			errorMsg = "Which Province are you from?\n"+errorMsg;
			setFocus = "cboProvince";
			hasErrors = true;
		}
		if( txtName.value.length==0 ) {
			errorMsg = "Please tell us your name.\n"+errorMsg;
			setFocus = "txtName";
			hasErrors = true;
		}
		if( hasErrors ) {
			alert( errorMsg );
			document.forms['frmBallot'][setFocus].focus( )
			return;
		} else {
			document.forms['frmBallot'].submit( );			
		}
	}
}





//=================================================Application form validation ============================
function validateApplicationForm( ) {
	var errorMsg, setFocus;
	var hasError_General=false, hasErrors_M1=false, hasErrors_M2=false, hasErrors_QA=false;
	var errorHdr_M1="Member 1, please supply the following information:\n\n";
	var errorHdr_M2="Member 2, please supply the following information:\n\n";
	var errorHdr_QA="Questionnaire\n\nPlease answer the following questions:\n";
	
	errorMsg = "";
	with( document.forms['frmApplication'] ) {
		if( txtRelation.value.length==0 ) {
			errorMsg = "What\'s the relationship between you and your teammate?\n"+errorMsg;
			setFocus = "txtRelation";
			hasError_General = true;
		}
		if( cboProvince.value=="" ) {
			errorMsg = "Select the Province you\'re representing.\n"+errorMsg;
			setFocus = "cboProvince";
			hasError_General = true;
		}
		if( hasError_General ) {
			alert( errorMsg );
			document.forms['frmApplication'][setFocus].focus( )
			return;
		}
		//MEMBER #1 VALIDATION
		if( txtBeneficiaryRelation1.value.length==0 ) {
			errorMsg = "Relationship with your beneficiary\n"+errorMsg;
			setFocus = "txtBeneficiaryRelation1";
			hasErrors_M1 = true;
		}
		if( txtBeneficiary1.value.length==0 ) {
			errorMsg = "Beneficiary\n"+errorMsg;
			setFocus = "txtBeneficiary1";
			hasErrors_M1 = true;
		}
		if( txtTIN1.value.length==0 ) {
			errorMsg = "TIN\n"+errorMsg;
			setFocus = "txtTIN1";
			hasErrors_M1 = true;
		}
		if( txtWeight1.value.length==0 ) {
			errorMsg = "Weight\n"+errorMsg;
			setFocus = "txtWeight1";
			hasErrors_M1 = true;
		}
		if( txtHeight1.value.length==0 ) {
			errorMsg = "Height\n"+errorMsg;
			setFocus = "txtHeight1";
			hasErrors_M1 = true;
		}
		if( txtOccupation1_1.value.length==0 || txtOccupation1_2.value.length==0 ) {
			errorMsg = "Occupation\n"+errorMsg;
			setFocus = "txtOccupation1_1";
			hasErrors_M1 = true;
		}
		if( txtReligion1.value.length==0 ) {
			errorMsg = "Religion\n"+errorMsg;
			setFocus = "txtReligion1";
			hasErrors_M1 = true;
		}
		if( txtEMail1.value.length==0 ) {
			errorMsg = "EMail Address\n"+errorMsg;
			setFocus = "txtEMail1";
			hasErrors_M1 = true;
		}
		if( txtMobile1_MC.value.length==0 || txtMobile1.value.length==0 || isNaN(txtMobile1_MC.value) || isNaN(txtMobile1.value) ) {
			errorMsg = "Mobile No.\n"+errorMsg;
			setFocus = "txtMobile1_MC";
			hasErrors_M1 = true;
		}
		if( txtPhone1_AC.value.length==0 || txtPhone1.value.length==0 || isNaN(txtPhone1_AC.value) || isNaN(txtPhone1.value) ) {
			errorMsg = "Phone No.\n"+errorMsg;
			setFocus = "txtPhone1_AC1";
			hasErrors_M1 = true;
		}
		if( txtAddress1.value.length==0 ) {
			errorMsg = "Address\n"+errorMsg;
			setFocus = "txtAddress1";
			hasErrors_M1 = true;
		}
		if( txtFName1.value.length==0 ) {
			errorMsg = "Complete/Full Name\n"+errorMsg;
			setFocus = "txtFName1";
			hasErrors_M1 = true;
		}
		if( hasErrors_M1 ) {
			alert( errorHdr_M1+errorMsg );
			document.forms['frmApplication'][setFocus].focus( )
			return;
		}
		//MEMBER #2 VALIDATION
		if( txtBeneficiaryRelation2.value.length==0 ) {
			errorMsg = "Relationship with your beneficiary\n"+errorMsg;
			setFocus = "txtBeneficiaryRelation2";
			hasErrors_M2 = true;
		}
		if( txtBeneficiary2.value.length==0 ) {
			errorMsg = "Beneficiary\n"+errorMsg;
			setFocus = "txtBeneficiary2";
			hasErrors_M2 = true;
		}
		if( txtTIN2.value.length==0 ) {
			errorMsg = "TIN\n"+errorMsg;
			setFocus = "txtTIN2";
			hasErrors_M2 = true;
		}
		if( txtWeight2.value.length==0 ) {
			errorMsg = "Weight\n"+errorMsg;
			setFocus = "txtWeight2";
			hasErrors_M2 = true;
		}
		if( txtHeight2.value.length==0 ) {
			errorMsg = "Height\n"+errorMsg;
			setFocus = "txtHeight2";
			hasErrors_M2 = true;
		}
		if( txtOccupation2_1.value.length==0 || txtOccupation2_1.value.length==0 ) {
			errorMsg = "Occupation\n"+errorMsg;
			setFocus = "txtOccupation2_1";
			hasErrors_M2 = true;
		}
		if( txtReligion2.value.length==0 ) {
			errorMsg = "Religion\n"+errorMsg;
			setFocus = "txtReligion2";
			hasErrors_M2 = true;
		}
		if( txtEMail2.value.length==0 ) {
			errorMsg = "EMail Address\n"+errorMsg;
			setFocus = "txtEMail2";
			hasErrors_M2 = true;
		}
		if( txtMobile2_MC.value.length==0 || txtMobile2.value.length==0 || isNaN(txtMobile2_MC.value) || isNaN(txtMobile2.value) ) {
			errorMsg = "Mobile No.\n"+errorMsg;
			setFocus = "txtMobile2_MC";
			hasErrors_M2 = true;
		}
		if( txtPhone2_AC.value.length==0 || txtPhone2.value.length==0 || isNaN(txtPhone2_AC.value) || isNaN(txtPhone2.value) ) {
			errorMsg = "Phone No.\n"+errorMsg;
			setFocus = "txtPhone1_AC2";
			hasErrors_M2 = true;
		}
		if( txtAddress2.value.length==0 ) {
			errorMsg = "Address\n"+errorMsg;
			setFocus = "txtAddress2";
			hasErrors_M2 = true;
		}
		if( txtFName2.value.length==0 ) {
			errorMsg = "Complete/Full Name\n"+errorMsg;
			setFocus = "txtFName2";
			hasErrors_M2 = true;
		}
		if( hasErrors_M2 ) {
			alert( errorHdr_M2+errorMsg );
			document.forms['frmApplication'][setFocus].focus( )
			return;
		}
		//QUESTIONNAIRE VALIDATION
		if( txtQ7.value.length==0 ) {
			errorMsg = "Question #7\n"+errorMsg;
			setFocus = "txtQ7";
			hasErrors_QA = true;
		}
		if( txtQ6.value.length==0 ) {
			errorMsg = "Question #6\n"+errorMsg;
			setFocus = "txtQ6";
			hasErrors_QA = true;
		}
		if( txtQ5.value.length==0 ) {
			errorMsg = "Question #5\n"+errorMsg;
			setFocus = "txtQ5";
			hasErrors_QA = true;
		}
		if( txtQ4.value.length==0 ) {
			errorMsg = "Question #4\n"+errorMsg;
			setFocus = "txtQ4";
			hasErrors_QA = true;
		}
		if( txtQ3a.value.length==0 || txtQ3b.value.length==0 ) {
			errorMsg = "Question #3\n"+errorMsg;
			setFocus = "txtQ3";
			hasErrors_QA = true;
		}
		if( txtQ2.value.length==0 ) {
			errorMsg = "Question #2\n"+errorMsg;
			setFocus = "txtQ2";
			hasErrors_QA = true;
		}
		if( txtQ1a.value.length==0 || txtQ1b.value.length==0 ) {
			errorMsg = "Question #1\n"+errorMsg;
			setFocus = "txtQ1";
			hasErrors_QA = true;
		}
		if( hasErrors_QA ) {
			alert( errorHdr_QA+errorMsg );
			document.forms['frmApplication'][setFocus].focus( )
			return;
		}
		//AGREE
		if( chkAgree.checked )
			document.forms['frmApplication'].submit( );			
		else
			alert( "You must agree to the terms of this contest application." );
	}
}