			function setpage(curpg) {
                                document.getElementById("page1").style.display="none";
                                document.getElementById("page2").style.display="none";
                                document.getElementById([curpg]).style.display="block";
                        }

			function showElement(elementName) {
				document.getElementById(elementName).style.display='block';
				return false;	
			}

			function hideElement(elementName) {
				document.getElementById(elementName).style.display='none';
				return true;	
			}
						

                        function highlightField(field)  {
               				 field.style.backgroundColor='#FFFEB3';
                			field.style.borderColor='#E1DE05';
							return true;
                        }
                        
			function unhighlightField(field)        {
                		field.style.backgroundColor='#cee3f6';
                		field.style.borderColor='#01519A';
                        }
 
			function disableBtn(field) {
                                document.getElementById([field]).disabled=true;
                                return true;
                        }
	
			function setFieldDisplay(field, backgroundColorBefore, borderColorBefore) {
				field.style.backgroundColor=backgroundColorBefore;
                		field.style.borderColor=borderColorBefore;
			}


			function flashField(field, time) {
				backgroundColorBefore=field.style.backgroundColor;
				borderColorBefore=field.style.borderColor;
				highlightField(field);
				//alert(field.value);	
				var unHighlight = function() {setFieldDisplay(field, backgroundColorBefore, borderColorBefore)};
				//alert (unHighlight);
				setTimeout(unHighlight, time);				
			}

			

/*function validateTheEmail(str) {
		alert("Hello world!");
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		}

 		 return true					
	}*/

				Rules=new Array();
				Rules[0] = ['d_intAssocID', 'Auskick Centre must be selected','1','0'];
				Rules[1] = ['dM_strFirstname', 'Participant Given Name must be filled in','1','0'];
				Rules[2] = ['dM_strSurname', 'Participant Surname must be filled in','1','0'];
				Rules[3] = ['dM_dtDOB', 'Date of Birth must be filled in','1','0'];
				Rules[4] = ['dM_intGender', 'Gender must be selected','1','0'];
				Rules[5] = ['dM_strAddress1', 'Street Address must be filled in','1','0'];
				Rules[6] = ['dM_strSuburb', 'Suburb must be filled in','1','0'];
				Rules[7] = ['dM_strState', 'State must be filled in','1','0'];
				Rules[8] = ['dM_strPostalCode', 'Post Code must be filled in','1','0'];
				Rules[9] = ['dM_intFavNationalTeamID', 'AFL Club Supported must be filled in','1','1000'];
				Rules[10] = ['dM_intFavNationalTeamMember', 'Member of AFL Club Supported must be filled in','1','1000'];
				Rules[11] = ['dM_intAttendSportCount', 'Number of AFL Games attended must be filled in','1','1000'];
				Rules[37] = ['dM_intWatchSportHowOftenID', 'How often you watch AFL on TV must be filled in','1','1000'];
				Rules[12] = ['dM_intNatCustomLU1', 'Will you play in another competition must be selected','2','0'];
				Rules[13] = ['dM_strEmergContName', 'Emergency Contact Name must be filled in','2','1000'];
				Rules[14] = ['dM_strEmergContNo', 'Emergency Contact Phone must be filled in','2','1000'];
				Rules[15] = ['dM_intP1AssistAreaID', 'Parent / Guardian Area of Assistance must be selected','2','0'];
				Rules[16] = ['dM_intAllowMedicalTreatment', 'Allow Medical Treatment must be selected','2','1000'];
				Rules[17] = ['dM_intMailingList', 'Information from AFL must be selected','2','0'];
				Rules[18] = ['dM_intSchoolID', 'School Attended must be selected','1','0'];
				Rules[19] = ['dM_intGradeID', 'School Grade must be selected','1','1000'];
				Rules[20] = ['dM_strEmail', 'Participant Email Address must be filled in','1','0'];
				Rules[21] = ['dM_strP1FName', 'Parent / Guardian Given Name must be filled in','2','0'];
				Rules[22] = ['dM_strP1SName', 'Parent / Guardian Surname must be filled in','2','0'];
				Rules[23] = ['dM_strP1Email', 'Parent / Guardian Email Address must be filled in','2','0'];
				Rules[24] = ['dM_strP1Phone', 'Parent / Guardian Telephone must be filled in','2','0'];
				Rules[25] = ['dM_intMedicialConditions', 'Parent / Guardian Telephone must be filled in','2','0'];
				Rules[26] = ['dM_intAllergies', 'Parent / Guardian Consent (Allergies) must be selected','2','1000'];
				Rules[27] = ['d_strPassword', '','2','1000'];
				Rules[28] = ['d_strPassword2', '','2','1000'];	

				Rules[29] = ['dM_strEmailServer', 'dM_strEmail','1','0'];
				Rules[30] = ['dM_strP1EmailServer', 'dM_strP1Email','2','0'];
				Rules[31] = ['dM_dtDOBServer', 'dM_dtDOB','1','0'];
				Rules[32] = ['dM_strPostalCodeServer', 'dM_strPostalCode','1','0'];
				Rules[33] = ['dM_strP1PhoneServer', 'dM_strP1Phone','2','0']; 
				Rules[34] = ['dM_strEmergContNoServer', 'dM_strEmergContNo','2','1000']; 
				Rules[35] = ['d_strPasswordServer', 'dM_strPassword','2','1000'];
				Rules[36] = ['dM_intAttendSportCountServer', 'dM_intAttendSportCount','1','0'];
				Rules[37] = ['d_rereg', 'Reason for editing data','1','0'];
 


			function submitCheck (whichTab)	{
				//whichTab - Indicates which tab to validate. If 0, validate both tabs.
				var fieldvalue;
				var allFieldsOk;
				allFieldsOk='true';	
			
				for (i = 0; i < Rules.length; i++) {
					if (i == 25 || i == 20 || i == 23 || i == 29 || i== 30 || i==31) {
					}
					else	{
					try {
						fieldvalue = document.testf[Rules[i][0]].value;
					}
					catch (err) {fieldvalue='non-existant field';}
					if ((whichTab==0 || whichTab==Rules[i][2])  && ((! fieldvalue) || (fieldvalue == '')))	{
						invalidFieldPrompt(i, allFieldsOk);	
						allFieldsOk='false';
					}
					else {
						if ((whichTab==1) && (Rules[i][2]>1)) {
						}
						else {
							try {hideElement(Rules[i][0]+'_label');}
							catch (err) {}
						}
					}
					}
				}
				if (allFieldsOk=='true') {
					return true;	
				}
				else {
					return false;
				}			
			}

			function invalidFieldPrompt (fieldarrayelement, firstElement) {
						try {
							if (firstElement=='true') {
								setpage('page'+Rules[fieldarrayelement][2]);
								try {document.testf[Rules[fieldarrayelement][0]].focus();} //Try..Except statement prevents IE complaining when setting focus to a hidden field
								catch (err) {
									try{document.testf[Rules[fieldarrayelement][1]].focus();}	
									catch (err) {}
								}
								try {hideElement('errors');} //Try..Except statement prevents IE complaining when setting focus to a hidden field
								catch (err) {}
								window.scroll(0,Rules[fieldarrayelement][3]);
								hideElement('schoolframe');
								hideElement('centerframe');
							}
						}
						catch (err) {}
						try {showElement(Rules[fieldarrayelement][0]+'_label');}
						catch (err) {}
						return true;
			}

			function nextClick () {
				if (submitCheck(1)) { 
					setpage('page2');
				}
				return true;
			}

			function checkSearchFieldsFilled() {
				searchRules=new Array();
				searchRules[0] = ['strPassword'];
				searchRules[1] = ['strNationalNum'];
				var fieldvalue;
				var allFieldsOk;
				allFieldsOk='true';
				for (i = 0; i < searchRules.length; i++) {
					fieldvalue = document.search[searchRules[i][0]].value;
					if ((! fieldvalue) || (fieldvalue=='')) {
						allFieldsOk='false';
						try {showElement(searchRules[i][0]+'_label');}
						catch (err) {}
					}
					else {
						try {hideElement([searchRules[i][0]+'_label']);}
                                                catch (err) {}	
					}
				}

				if (allFieldsOk=='true') {
					return true;
				}
				else {
					return false;
				}
			}
