var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
 browserType= "gecko"
}

function validate_registration(form1, isOnlineSystem)
{	
	disableallerrormsg(form1);

	if (browserType == "gecko" )
	 document.poppedLayer = 
	     eval('document.getElementById("othersub")');
	else if (browserType == "ie")
	   document.poppedLayer = 
	      eval('document.getElementById("othersub")');
	else
	   document.poppedLayer = 
	       eval('document.layers["othersub"]');
	       
	if (form1.occupation.value == '9')
		document.poppedLayer.style.display = "inline";

	var reqfield = "";
	var subform = true;
	var ic1 = form1.ic1.value;
	var ic2 = form1.ic2.value;
	var ic3 = form1.ic3.value;
//	var passport = form1.passport.value;
	var userid = form1.userid.value;
	var pwd = form1.password.value;
	var address = form1.address1.value;
	var firstName = form1.firstName.value;
	
//	var lastName=form1.lastName.value;
	var city=form1.city.value;
	var postcode=form1.postcode.value;
	var state=form1.state.value;
	var country=form1.country.value;
	var housePhone1=form1.housePhone1.value;
	var housePhone2=form1.housePhone2.value;
	var email=form1.email.value;

	var noofChild = form1.noofChild.value;
	var dobDay = form1.dobDay.value;
	var dobMonth = form1.dobMonth.value;
	var dobYear = form1.dobYear.value;
	var age = form1.age.value;
	var mobilePhone1=form1.mobilePhone1.value;
	var mobilePhone2=form1.mobilePhone2.value;
	var officePhone1=form1.officePhone1.value;
	var officePhone2=form1.officePhone2.value;
	var occupation = form1.occupation.value;
	var otherOccupation = form1.otherOccupation.value;

	var permission=form1.permission.value;
	var requiredMsg ="Required field cannot be left blank";
	

	if ((occupation == 9) && (isEmpty(otherOccupation ))) {
		showErrormsg('occupationError', "Please fill in your occupation");
		subform = false;
	}
	

	if (isEmpty(firstName)) {
		showErrormsg('firstNameError', requiredMsg);
		subform = false;
	}
	
	
/*	if (isEmpty(lastName)) {
		showErrormsg('lastNameError', requiredMsg);
		subform = false;
	}
*/

	if (isEmpty(userid)) {
		showErrormsg('useridError', requiredMsg);
		subform = false;
	}
	if (isEmpty(pwd)) {
		showErrormsg('passwordError', requiredMsg);
		subform = false;
	}
	if (isEmpty(address)) {
		showErrormsg('addressError', requiredMsg);;
		subform = false;
	}
	if (isEmpty(city)) {
		showErrormsg('cityError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(postcode)) {
		showErrormsg('postcodeError', requiredMsg);
		subform = false;
	}
	
	if (!isInteger(postcode)) {
		showErrormsg('postcodeError', "Postcode should consists of numbers");
		subform = false;
	}
	
	
	if (isEmpty(state) || state == 0) {
		showErrormsg('stateError', requiredMsg);
		subform = false;
	}
	
	
	
	if (isEmpty(country) || country == 0) {
		showErrormsg('countryError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(age)) {
		showErrormsg('ageError', requiredMsg);
		subform = false;
	}
	
	if (age < 18) {
		showErrormsg('ageError', "Age under 18 are not allowed!");
		subform = false;
	}
	
	if (isEmpty(mobilePhone1) || isEmpty(mobilePhone2)) {
		showErrormsg('mobilePhoneError', requiredMsg);
		subform = false;
	} else {
			if (!isInteger(mobilePhone1) || (mobilePhone1.length <3)){
				showErrormsg('mobilePhoneError',  "Invalid Phone Number, Please include International Dialing Code (eg.603, 6012)");
				
		 		subform = false;
		
			}	
			if (!isInteger(mobilePhone2) || (mobilePhone2.length <7)){
				showErrormsg('mobilePhoneError', "Invalid Phone Number, should consist of minimum 7 numbers");
				
		 		subform = false;
		
			}		
	
	}
	
	
		
	if (!isEmpty(housePhone1) || !isEmpty(housePhone2)) {
		if (!isInteger(housePhone1) ||(housePhone1.length <3)){
		
				showErrormsg('housePhoneError',  "Invalid Phone Number, Please include International Dialing Code (eg.603, 6012)");
				
		 		subform = false;
		
			}		
	
		if (!isInteger(housePhone2)|| (housePhone2.length <7)){
				showErrormsg('housePhoneError', "Invalid Phone Number, should consist of minimum 7 numbers");
				
		 		subform = false;
		
			}		
		if (isEmpty(housePhone1)){
			showErrormsg('housePhoneError', "Phone 1 cannot be empty");
			subform = false;
		}
		
		if (isEmpty(housePhone2)){
		
			showErrormsg('housePhoneError', "Phone 2 cannot be empty");
			subform = false;
		}
	
	
	} 
	
	if (!isEmpty(officePhone1) || !isEmpty(officePhone2)) {
		if (!isInteger(officePhone1)|| (officePhone1.length <3)){
			
				showErrormsg('officePhoneError', "Invalid Phone Number, International Dialing Code should consists of 3 numbers (eg.603)");
				
		 		subform = false;
		
			}		
	
		if (!isInteger(officePhone2)||(officePhone2.length <7)){
				showErrormsg('officePhoneError', "Invalid Phone Number, should consists minimum 7 numbers");
				
		 		subform = false;
		
			}		
		if (isEmpty(officePhone1)){
			showErrormsg('officePhoneError', "Phone 1 cannot be empty");
			subform = false;
		}
		
		if (isEmpty(officePhone2)){
			showErrormsg('officePhoneError', "Phone 2 cannot be empty");
			subform = false;
		}
	
	
	} 

	
	if (isEmpty(noofChild)) {
		showErrormsg('noOfChildError', requiredMsg);
		
		subform = false;
	}

	if (!isInteger(noofChild)){
		showErrormsg('noOfChildError', "Number of Child should consists of numbers");

	 	subform = false;
	}	
	

	if (isOnlineSystem == "true"){
		if (isEmpty(email)){
			showErrormsg('emailError', requiredMsg);
		
			subform = false;
		}
	}
	
	if (!isEmpty(email)){
		if (!isEmail(email)){
			showErrormsg('emailError', "Invalid email address");
				
			subform = false;
		}
	}

	if (isEmpty(dobDay) || isEmpty(dobMonth) || isEmpty(dobYear)) {
		
		showErrormsg('dobError', requiredMsg);
		subform = false;
	}


	if (dobDay == '31' && (dobMonth == '02' || dobMonth == '04' || dobMonth == '06' || dobMonth == '09' || dobMonth == '11' )) {
		
		showErrormsg('dobError', "Invalid date.");
		subform = false;
	}

	
	if (dobDay == '30' && dobMonth == '02' ) {
		
		showErrormsg('dobError', "Invalid date.");
		subform = false;
	}


	if ( userid.length <6){
		showErrormsg('useridError', "Username must consists at least 6 characters");
		subform = false;
	}	

	if ( pwd.length <6){
		showErrormsg('passwordError', "Password must consists at least 6 characters.<br> IC no. must be in valid format or password cannot be proceeded");
		subform = false;
	}	
	
	if (form1.password.value!=form1.rePassword.value){
		showErrormsg('rePasswordError', "Confirm Password does not match. Please type more carefully");	
		subform = false;
		
	}
		
	/*var identificationValue ="";
	for (i=0, n=form1.identification.length; i<n; i++) {
  		 if (form1.identification[i].checked) {
     		 identificationValue = form1.identification[i].value;
      		break;
   		}
	}
		

	if (identificationValue == 'ic'){*/
		if (ic1 == '' && ic2==''&& ic3=='') {
			showErrormsg('icError', requiredMsg);
			subform = false;
			
		}
		else if ( (ic1.length <6) || !isInteger(ic1)){
			showErrormsg('icError', "Invalid IC Number");
			subform = false;
			
		}	
		else if ( (ic2.length <2) || !isInteger(ic2)){
			showErrormsg('icError', "Invalid IC Number");
			subform = false;
			
		}	
		else if ( (ic3.length <4) || !isInteger(ic3)){
			showErrormsg('icError', "Invalid IC Number");
			subform = false;
			
		}	
		else if (ic1.length == 6 && isInteger(ic1)){
			var now = new Date();
			year = ic1.substring(0,2);
			month = ic1.substring(2,4);
			date = ic1.substring(4,6);
			var dob = new Date("19"+year,month,date);
			
			var today = new Date(now.getYear(),now.getMonth(),now.getDate());
	       
	    	if (now.getFullYear() - dob.getFullYear() > 60){
	    		showErrormsg('icError','Invalid IC Number');
				return false;
	    	
	    	}
	 
			if (month > 13){
				showErrormsg('icError','Invalid IC Number');
				return false;
			}
			
			if (date > 32){
				showErrormsg('icError','Invalid IC Number');
				return false;
			}
		}
	
	/*}else{
		if (isEmpty(passport)){
			showErrormsg('passportError', requiredMsg);
			subform = false;
		}
	}
	*/
	var checkvalue="";

	 for (i=0, n=form1.communication.length; i<n; i++) {
  		 if (form1.communication[i].checked) {
     		 checkvalue = form1.communication[i].value;
      		break;
   		}
	}
	
	if (!(checkvalue)) {
      	showErrormsg('communicationError', requiredMsg);
	 	subform = false;
    	} 
	
 	

	 checkvalue ="";
	for (i=0, n=form1.abbott.length; i<n; i++) {
  	 	if (form1.abbott[i].checked) {
      		checkvalue = form1.abbott[i].value;
      		
      		if (checkvalue == '4'){
      			
      			if (isEmpty(form1.event.value) || form1.event.value == 0){
      				showErrormsg('knowAbbottError', 'Please select a promotional event');
      				subform=false;
      			}
      			
      		}
		if (checkvalue == '5'){
			if (isEmpty(form1.promotionSite.value)){
      				showErrormsg('promotionSiteError', requiredMsg);
      				subform=false;
      			}
      			
      		}
     		
   		}
	}


	if (!form1.permission.checked){
      	showErrormsg('permissionError', requiredMsg);
	 	subform = false;
   	 } 


	 if (!(checkvalue)) {
     	showErrormsg('knowAbbottError2', requiredMsg);
	 	subform = false;
    	} 


	if 	(subform == false)
	{
		return false;
	}

	
	

	
	return true;

}

function validate_registered_data(form1, isOnlineSystem)
{
	disableallerrormsg(form1);
	var reqfield = "";
	var subform = true;
	
	var pwd = form1.password.value;
	var oldPwd = form1.oldPassword.value;
	var address = form1.address1.value;
	
	
	
	var city=form1.city.value;
	var postcode=form1.postcode.value;
	var state=form1.state.value;
	var country=form1.country.value;
	var housePhone1=form1.housePhone1.value;
	var housePhone2=form1.housePhone2.value;
	var email=form1.email.value;


	var noofChild = form1.noofChild.value;
	var dobDay = form1.dobDay.value;
	var dobMonth = form1.dobMonth.value;
	var dobYear = form1.dobYear.value;

	var age = form1.age.value;
	var mobilePhone1=form1.mobilePhone1.value;
	var mobilePhone2=form1.mobilePhone2.value;
	var officePhone1=form1.officePhone1.value;
	var officePhone2=form1.officePhone2.value;
	
	
	var permission=form1.permission.value;
	var requiredMsg ="Required field cannot be left blank";
	
	if (isEmpty(address)) {
		showErrormsg('addressError', requiredMsg);;
		subform = false;
	}
	if (isEmpty(city)) {
		showErrormsg('cityError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(postcode)) {
		showErrormsg('postcodeError', requiredMsg);
		subform = false;
	}
	if (!isInteger(postcode)) {
		showErrormsg('postcodeError', "Postcode should consists of numbers");
		subform = false;
	}
	if (isEmpty(state) || state == 0) {
		showErrormsg('stateError', requiredMsg);
		subform = false;
	}
	if (isEmpty(country) || country == 0) {
		showErrormsg('countryError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(age)) {
		showErrormsg('ageError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(mobilePhone1) || isEmpty(mobilePhone2)) {
		showErrormsg('mobilePhoneError', requiredMsg);
		subform = false;
	} else {
			if (!isInteger(mobilePhone1) || (mobilePhone1.length <4)){
				showErrormsg('mobilePhoneError', "Invalid Mobile Phone Number, International Dialing Code should consists of 4 numbers (eg.6012)");
				
		 		subform = false;
		
			}	
			if (!isInteger(mobilePhone2) || (mobilePhone2.length <7)){
				showErrormsg('mobilePhoneError', "Invalid Mobile Phone Number, should consist of minimum 7 numbers");
				
		 		subform = false;
		
			}		
	
	}
	
		
	if (!isEmpty(housePhone1) || !isEmpty(housePhone2)) {
		if (!isInteger(housePhone1) ||(housePhone1.length <3)){
		
				showErrormsg('housePhoneError', "Invalid House Phone Number,International Dialing Code should should consists of 3 numbers (eg.603)");
				
		 		subform = false;
		
			}		
	
		if (!isInteger(housePhone2)|| (housePhone2.length <7)){
				showErrormsg('housePhoneError', "Invalid House Phone Number, should consist of minimum 7 numbers");
				
		 		subform = false;
		
			}		
		if (isEmpty(housePhone1)){
			showErrormsg('housePhoneError', "House Phone 1 cannot be empty");
			subform = false;
		}
		
		if (isEmpty(housePhone2)){
		
			showErrormsg('housePhoneError', "House Phone 2 cannot be empty");
			subform = false;
		}
	
	
	} 
	
	if (!isEmpty(officePhone1) || !isEmpty(officePhone2)) {
		if (!isInteger(officePhone1)|| (officePhone1.length <3)){
			
				showErrormsg('officePhoneError', "Invalid Office Phone Number, International Dialing Code should consists of 3 numbers (eg.603)");
				
		 		subform = false;
		
			}		
	
		if (!isInteger(officePhone2)||(officePhone2.length <7)){
				showErrormsg('officePhoneError', "Invalid Office Phone Number, should consists minimum 7 numbers");
				
		 		subform = false;
		
			}		
		if (isEmpty(officePhone1)){
			showErrormsg('officePhoneError', "Office Phone 1 cannot be empty");
			subform = false;
		}
		
		if (isEmpty(officePhone2)){
			showErrormsg('officePhoneError', "Office Phone 2 cannot be empty");
			subform = false;
		}
	
	
	} 
				
	
	if (isEmpty(noofChild)) {
		showErrormsg('noOfChildError', requiredMsg);
		
		subform = false;
	}
		
	
	var checkvalue="";
	/* for (i=0, n=form1.communication.length; i<n; i++) {
  		 if (form1.communication[i].checked) {
     		 checkvalue = form1.communication[i].value;
      		break;
   		}
	}
	*/
	checkvalue ="";
	for (i=0, n=form1.abbott.length; i<n; i++) {
  	 	if (form1.abbott[i].checked) {
      		checkvalue = form1.abbott[i].value;
      		
      		if (checkvalue == '3'){
      	
      			if (isEmpty(form1.event.value) || form1.event.value == 0){
      			
      				showErrormsg('knowAbbottError', 'Please select a promotional event');
      				subform=false;
      			}
      			
      		}
     		
   		}
	}
	/* if (!(checkvalue)) {
     	showErrormsg('knowAbbottError', requiredMsg);
	 	subform = false;
    }*/
    

	if (isEmpty(noofChild)){
		showErrormsg('noOfChildError', "Number of Child cannot be empty");
	 	subform = false;
	}	
	
	
	if (isOnlineSystem == "true"){
		if (isEmpty(email)){
			showErrormsg('emailError', requiredMsg);
		
			subform = false;
		}
	}
	
	if (!isEmpty(email)){
		if (!isEmail(email)){
			showErrormsg('emailError', "Invalid email address");
				
			subform = false;
		}
	}
	
	if (isEmpty(dobDay) || isEmpty(dobMonth) || isEmpty(dobYear)) {
		
		showErrormsg('dobError', requiredMsg);
		subform = false;
	}



	if 	(subform == false)
	{
		
		return false;
	}
	
	if (! isEmpty(oldPwd)){
		if (oldPwd.length <6){
			showErrormsg('oldPasswordError', "Old Password must consists at least 6 characters");
			
			return false;
		}	
	
		else if (isEmpty(pwd)){
			showErrormsg('passwordError', requiredMsg);
			
			return false;
		}	
	 	else if (pwd.length <6){
			showErrormsg('passwordError', "Password must consists at least 6 characters");
			
			return false;
		}else if (form1.password.value!=form1.rePassword.value){
			showErrormsg('rePasswordError', "Re-confirm Password does not match. Please type more carefully");
		
			return false;
		
		}
	}
		
	return true;

}

function manipulateEvent(item){

	if (item.checked ==true){	
		document.form1.event.disabled=false;	
	}
	else{	
		document.form1.event.disabled=true;
	}
	
}

function validate_registered_data_admin(form1, isOnlineSystem)
{
	
	disableallerrormsg(form1);
	var reqfield = "";
	var subform = true;
	
	var address = form1.address1.value;
	
	var city=form1.city.value;
	var postcode=form1.postcode.value;
	var state=form1.state.value;
	var country=form1.country.value;
	var housePhone1=form1.housePhone1.value;
	var housePhone2=form1.housePhone2.value;
	var email=form1.email.value;

	var noofChild = form1.noofChild.value;
	var dobDay = form1.dobDay.value;
	var dobMonth = form1.dobMonth.value;
	var dobYear = form1.dobYear.value;
	var age = form1.age.value;
	var mobilePhone1=form1.mobilePhone1.value;
	var mobilePhone2=form1.mobilePhone2.value;
	var officePhone1=form1.officePhone1.value;
	var officePhone2=form1.officePhone2.value;
	var permission=form1.permission.value;
	var requiredMsg ="Required field cannot be left blank";
	

	if (isEmpty(address)) {
		showErrormsg('addressError', requiredMsg);;
		subform = false;
	}
	if (isEmpty(city)) {
		showErrormsg('cityError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(postcode)) {
		showErrormsg('postcodeError', requiredMsg);
		subform = false;
	}
	if (!isInteger(postcode)) {
		showErrormsg('postcodeError', "Postcode should consists of numbers");
		subform = false;
	}
	if (isEmpty(state) || state == 0) {
		showErrormsg('stateError', requiredMsg);
		subform = false;
	}
	if (isEmpty(country) || country == 0) {
		showErrormsg('countryError', requiredMsg);
		subform = false;
	}
	
	if (isEmpty(age)) {
		showErrormsg('ageError', requiredMsg);
		subform = false;
	}
	
	
	if (isEmpty(mobilePhone1) || isEmpty(mobilePhone2)) {
		showErrormsg('mobilePhoneError', requiredMsg);
		subform = false;
	} else {
			if (!isInteger(mobilePhone1) || (mobilePhone1.length <4)){
				showErrormsg('mobilePhoneError', "Invalid Mobile Phone Number, International Dialing Code should consists of 4 numbers (eg.6012)");
				
		 		subform = false;
		
			}	
			if (!isInteger(mobilePhone2) || (mobilePhone2.length <7)){
				showErrormsg('mobilePhoneError', "Invalid Mobile Phone Number, should consist of minimum 7 numbers");
				
		 		subform = false;
		
			}		
	
	}
	
		
	if (!isEmpty(housePhone1) || !isEmpty(housePhone2)) {
		if (!isInteger(housePhone1) ||(housePhone1.length <3)){
		
				showErrormsg('housePhoneError', "Invalid House Phone Number,International Dialing Code should should consists of 3 numbers (eg.603)");
				
		 		subform = false;
		
			}		
	
		if (!isInteger(housePhone2)|| (housePhone2.length <7)){
				showErrormsg('housePhoneError', "Invalid House Phone Number, should consist of minimum 7 numbers");
				
		 		subform = false;
		
			}		
		if (isEmpty(housePhone1)){
			showErrormsg('housePhoneError', "House Phone 1 cannot be empty");
			subform = false;
		}
		
		if (isEmpty(housePhone2)){
		
			showErrormsg('housePhoneError', "House Phone 2 cannot be empty");
			subform = false;
		}
	
	
	} 
	
	if (!isEmpty(officePhone1) || !isEmpty(officePhone2)) {
		if (!isInteger(officePhone1)|| (officePhone1.length <3)){
			
				showErrormsg('officePhoneError', "Invalid Office Phone Number, International Dialing Code should consists of 3 numbers (eg.603)");
				
		 		subform = false;
		
			}		
	
		if (!isInteger(officePhone2)||(officePhone2.length <7)){
				showErrormsg('officePhoneError', "Invalid Office Phone Number, should consists minimum 7 numbers");
				
		 		subform = false;
		
			}		
		if (isEmpty(officePhone1)){
			showErrormsg('officePhoneError', "Office Phone 1 cannot be empty");
			subform = false;
		}
		
		if (isEmpty(officePhone2)){
			showErrormsg('officePhoneError', "Office Phone 2 cannot be empty");
			subform = false;
		}
	
	
	} 
			
			
	
	if (isEmpty(noofChild)) {
		showErrormsg('noOfChildError', requiredMsg);
		
		subform = false;
	}
		
	

	var checkvalue="";
	/* for (i=0, n=form1.communication.length; i<n; i++) {
  		 if (form1.communication[i].checked) {
     		 checkvalue = form1.communication[i].value;
     		 alert('checkValue' +checkvalue);
      		break;
   		}
	}
	
	if (!(checkvalue)) {
      	showErrormsg('communicationError', requiredMsg);
	 	subform = false;
    } 
	
 */

	 checkvalue ="";
	for (i=0, n=form1.abbott.length; i<n; i++) {
  	 	if (form1.abbott[i].checked) {
      		checkvalue = form1.abbott[i].value;
      		
      		if (checkvalue == '3'){
      	
      			if (isEmpty(form1.event.value) || form1.event.value == 0){
      			
      				showErrormsg('knowAbbottError', 'Please select a promotional event');
      				subform=false;
      			}
      			
      		}
     		
   		}
	}
	/* if (!(checkvalue)) {
     	showErrormsg('knowAbbottError', requiredMsg);
	 	subform = false;
    } */

	if (!isInteger(noofChild)){
		showErrormsg('noOfChildError', "Number of Child should consists of numbers");

	 	subform = false;
	}	
	
	
	if (isOnlineSystem == "true"){
		if (isEmpty(email)){
			showErrormsg('emailError', requiredMsg);
		
			subform = false;
		}
	}
	
	if (!isEmpty(email)){
		if (!isEmail(email)){
			showErrormsg('emailError', "Invalid email address");
				
			subform = false;
		}
	}
	
	if (isEmpty(dobDay) || isEmpty(dobMonth) || isEmpty(dobYear)) {
		
		showErrormsg('dobError', requiredMsg);
		subform = false;
	}
	

	if 	(subform == false)
	{
		
		return false;
	}
	
	
	return true;

}
