//function to check for valid email
function checkEmail(ctlName){
	var myString = new String(""+ctlName.value);
	var isvalid="yes";
	if ((myString.indexOf("@")<0) || (myString.charAt(0)==".") || (myString.charAt(0)=="@") || (myString.length<6) || (myString.indexOf(".")<0) || (myString.charAt(myString.indexOf("@")+1)==".") || (myString.charAt(myString.indexOf("@")-1)==".") || (myString.charAt(myString.length-1)==".") || (checkNumTimes(ctlName,"@")!=1) || (myString.charAt(myString.indexOf(".")+1)==".")){
		isvalid="no";
	}

	return isvalid;
	
}

//checks the number of occurences of strChar within value of intWhich
//used mainly for checking multiple "@" in email
function checkNumTimes(ctlName,strChar){
	var strValue2 = eval(ctlName.value);
	var noFound=0;
	for (var i=0; i<strValue2.length; i++){
		if(strValue2.charAt(i)==strChar){
			noFound++;
		}
	}
	return noFound;
}


// Form validation starts here 

function validate_computershieldform(insform)
{
	myOption = -1;
	for (i=0; i<insform.personal_title.length; i++) {
		if (insform.personal_title[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select your title.");
		return false;
	}
	
	if (insform.personal_name.value=="") {
		window.alert("Please enter your name.");
		insform.personal_name.focus();
		return false;
	}
	if (insform.personal_nric.value=="") {
		window.alert("Please enter your NRIC/passport no.");
		insform.personal_nric.focus();
		return false;
	}
	
	myOption = -1;
	for (i=0; i<insform.personal_gender.length; i++) {
		if (insform.personal_gender[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select your gender.");
		return false;
	}	
	
	if (insform.personal_address1.value=="") {
		window.alert("Please enter your address.");
		insform.personal_address1.focus();
		return false;
	}			
	if (insform.personal_postalcode.value=="") {
		window.alert("Please enter your postal code.");
		insform.personal_postalcode.focus();
		return false;
	}
	
	myOption2 = -1;
	for (i=0; i<insform.personal_occupation.length; i++) {
		if (insform.personal_occupation[i].checked) {
			myOption2 = i;
			if (insform.personal_occupation[i].value=="Staff"){
				if (insform.personal_occupation_designation.value=="") {
					window.alert("Please enter your designation.");
					insform.personal_occupation_designation.focus();
					return false;			
				}
			}
			
		}
	}
	if (myOption2 == -1) {
		alert("Please select your occupation.");
		return false;
	}
	
	if (insform.personal_email.value=="") {
		window.alert("Please enter your email address.");
		insform.personal_email.focus();
		return false;
	}
	
	if (insform.laptop_model.value=="") {
		window.alert("Please enter the manufacturer\'s name and model no.");
		insform.laptop_model.focus();
		return false;
	}

	if (insform.laptop_serial.value=="") {
		window.alert("Please the serial no.");
		insform.laptop_serial.focus();
		return false;
	}			

	
	var sCont = document.insform.personal_email;
	var sContVal = document.insform.personal_email.value;

	var str=new String();
	str=sContVal;
	var span=new RegExp("[ ]","g");
	var rep=str.replace(span,"9");          

	if (sContVal.length != 0)
    {
    	if(sContVal == ''  || isNaN(rep) == false)
        {
		alert("Your email address does not seem to be of a valid format.  Please re-enter.");
        sCont.focus();
        sCont.select();
        return false;
        }                         
                         
        var sAtSym    = sContVal.indexOf('@')
        var sAtSym2       = sContVal.lastIndexOf('@')
        var sPeriod   = sContVal.lastIndexOf('.')
        var sSpace    = sContVal.indexOf(' ')
        var sLength   = sContVal.length - 1   
          
        if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
    	{
        alert("Your email address does not seem to be of a valid format.  Please re-enter.");
        sCont.focus();
        sCont.select();
        return false;
        }

    }
		
}

function validate_enquirycorporateform(insform)
{
	myOption = -1;
	for (i=0; i<insform.enquiry_type.length; i++) {
		if (insform.enquiry_type[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select the type of enquiry you are making - Personal or Corporate.");
		return false;
	}
	else {
		if (insform.enquiry_type[myOption].value == "Personal") {
			if (insform.personal_name.value=="") {
				window.alert("Please enter your name.");
				insform.personal_name.focus();
				return false;
			}
			if (insform.personal_telephone.value=="") {
				window.alert("Please enter your telephone no.");
				insform.personal_telephone.focus();
				return false;
			}	
			if (insform.personal_email.value=="") {
				window.alert("Please enter your email address.");
				insform.personal_email.focus();
				return false;
			}
			
			var sCont = document.insform.personal_email;
			var sContVal = document.insform.personal_email.value;
		
			var str=new String();
			str=sContVal;
			var span=new RegExp("[ ]","g");
			var rep=str.replace(span,"9");          
		
			if (sContVal.length != 0)
			{
				if(sContVal == ''  || isNaN(rep) == false)
				{
				alert("Your email address does not seem to be of a valid format.  Please re-enter.");
				sCont.focus();
				sCont.select();
				return false;
				}                         
								 
				var sAtSym    = sContVal.indexOf('@')
				var sAtSym2   = sContVal.lastIndexOf('@')
				var sPeriod   = sContVal.lastIndexOf('.')
				var sSpace    = sContVal.indexOf(' ')
				var sLength   = sContVal.length - 1   
				  
				if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
				{
				alert("Your email address does not seem to be of a valid format.  Please re-enter.");
				sCont.focus();
				sCont.select();
				return false;
				}
			}			
			
		}
		else {
			if (insform.company_name.value=="") {
				window.alert("Please enter your company name.");
				insform.company_name.focus();
				return false;
			}
			if (insform.company_contactperson.value=="") {
				window.alert("Please enter the name of your contact person.");
				insform.company_contactperson.focus();
				return false;
			}
			if (insform.company_telephone.value=="") {
				window.alert("Please enter the telephone no of your contact person.");
				insform.company_telephone.focus();
				return false;
			}		
			if (insform.company_email.value=="") {
				window.alert("Please enter your company\'s email address.");
				insform.company_email.focus();
				return false;
			}
	
			var sCont = document.insform.company_email;
			var sContVal = document.insform.company_email.value;
		
			var str=new String();
			str=sContVal;
			var span=new RegExp("[ ]","g");
			var rep=str.replace(span,"9");          
		
			if (sContVal.length != 0)
			{
				if(sContVal == ''  || isNaN(rep) == false)
				{
				alert("Your email address does not seem to be of a valid format.  Please re-enter.");
				sCont.focus();
				sCont.select();
				return false;
				}                         
								 
				var sAtSym    = sContVal.indexOf('@')
				var sAtSym2   = sContVal.lastIndexOf('@')
				var sPeriod   = sContVal.lastIndexOf('.')
				var sSpace    = sContVal.indexOf(' ')
				var sLength   = sContVal.length - 1   
				  
				if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
				{
				alert("Your email address does not seem to be of a valid format.  Please re-enter.");
				sCont.focus();
				sCont.select();
				return false;
				}
			}	
		}
	}	
	
		
	if ((insform.enquiry_students_type[insform.enquiry_students_type.selectedIndex].value == "") &&  (insform.enquiry_families_type[insform.enquiry_families_type.selectedIndex].value == "") &&  (insform.enquiry_corporate_type[insform.enquiry_corporate_type.selectedIndex].value == "")) {
	window.alert("Please select the product you are enquiring about.");
	return false;
	}
	
}



function validate_motorenquiryform(insform)
{

	if (insform.personal_name.value=="") {
		window.alert("Please enter your name.");
		insform.personal_name.focus();
		return false;
	}
	if (insform.personal_tel_mobile.value=="") {
		window.alert("Please enter your mobile no.");
		insform.personal_tel_mobile.focus();
		return false;
	}
	if (insform.personal_tel_office.value=="") {
		window.alert("Please enter your office no.");
		insform.personal_tel_office.focus();
		return false;
	}
	
	if (insform.personal_email.value=="") {
		window.alert("Please enter your email address.");
		insform.personal_email.focus();
		return false;
	}
	if (insform.personal_nationality.value=="") {
		window.alert("Please enter your nationality.");
		insform.personal_nationality.focus();
		return false;
	}
	if (insform.personal_nric.value=="") {
		window.alert("Please enter your NRIC/Passport no.");
		insform.personal_nric.focus();
		return false;
	}
	if (insform.personal_dob.value=="") {
		window.alert("Please enter your date of birth.");
		insform.personal_dob.focus();
		return false;
	}
	
	
	myOption = -1;
	for (i=0; i<insform.personal_maritalstatus.length; i++) {
		if (insform.personal_maritalstatus[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select your marital status.");
		return false;
	}	

	myOption = -1;
	for (i=0; i<insform.personal_gender.length; i++) {
		if (insform.personal_gender[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select your gender.");
		return false;
	}	
	
	if (insform.personal_occupation.value=="") {
		window.alert("Please enter your occupation.");
		insform.personal_occupation.focus();
		return false;
	}
	myOption = -1;
	for (i=0; i<insform.personal_occupation_type.length; i++) {
		if (insform.personal_occupation_type[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select whether your occupation is indoor or outdoor.");
		return false;
	}	

	
	if (insform.personal_drivingexp.value=="") {
		window.alert("Please specify your driving experience.");
		insform.personal_drivingexp.focus();
		return false;
	}
	
	myOption = -1;
	for (i=0; i<insform.personal_discount.length; i++) {
		if (insform.personal_discount[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select whether you are entitled to the safe driver discount.");
		return false;
	}	
	
	if (insform.vehicle_model.value=="") {
		window.alert("Please enter your vehicle make & model.");
		insform.vehicle_model.focus();
		return false;
	}
	if (insform.vehicle_engine.value=="") {
		window.alert("Please enter your engine capacity.");
		insform.vehicle_engine.focus();
		return false;
	}
	if (insform.vehicle_seating.value=="") {
		window.alert("Please enter your seating capacity.");
		insform.vehicle_seating.focus();
		return false;
	}
	if (insform.vehicle_manufactureyear.value=="") {
		window.alert("Please enter the year of manufacture.");
		insform.vehicle_manufactureyear.focus();
		return false;
	}
	if (insform.vehicle_registrationdate.value=="") {
		window.alert("Please enter date of registration.");
		insform.vehicle_registrationdate.focus();
		return false;
	}
	if (insform.vehicle_registrationno.value=="") {
		window.alert("Please enter vehicle registration no.");
		insform.vehicle_registrationno.focus();
		return false;
	}
	

	myOption = -1;
	for (i=0; i<insform.vehicle_cover.length; i++) {
		if (insform.vehicle_cover[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select your vehicle cover.");
		return false;
	}
	
	if (insform.vehicle_insured.value=="") {
		window.alert("Please enter the sum insured.");
		insform.vehicle_insured.focus();
		return false;
	}
		
	if (insform.insurance_insurer.value=="") {
		window.alert("Please enter the name of your ex-insurer.");
		insform.insurance_insurer.focus();
		return false;
	}
	if (insform.insurance_registrationno.value=="") {
		window.alert("Please enter the insurance no.");
		insform.insurance_registrationno.focus();
		return false;
	}
	if (insform.insurance_ncd_current.value=="") {
		window.alert("Please enter your existing NCD entitlement.");
		insform.insurance_ncd_current.focus();
		return false;
	}
	if (insform.insurance_ncd_new.value=="") {
		window.alert("Please enter your new NCD entitlement (upon renewal).");
		insform.insurance_ncd_new.focus();
		return false;
	}


	myOption = -1;
	for (i=0; i<insform.insurance_claimsstatus.length; i++) {
		if (insform.insurance_claimsstatus[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select your claim status.");
		return false;
	}
	
	if (insform.insurance_claimsdate.value=="") {
		window.alert("Please enter the claims date");
		insform.insurance_claimsdate.focus();
		return false;
	}
	if (insform.insurance_claimsamount.value=="") {
		window.alert("Please enter the claims amount.");
		insform.insurance_claimsamount.focus();
		return false;
	}
		
	if (insform.driver1_relationship.value=="") {
		window.alert("Please enter the relationship to the named driver.");
		insform.driver1_relationship.focus();
		return false;
	}
	if (insform.driver1_dob.value=="") {
		window.alert("Please enter the date of birth of the named driver.");
		insform.driver1_dob.focus();
		return false;
	}

	myOption = -1;
	for (i=0; i<insform.driver1_maritalstatus.length; i++) {
		if (insform.driver1_maritalstatus[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select the marital status of the named driver.");
		return false;
	}

	myOption = -1;
	for (i=0; i<insform.driver1_gender.length; i++) {
		if (insform.driver1_gender[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select the gender of the named driver.");
		return false;
	}
	
	if (insform.driver1_occupation.value=="") {
		window.alert("Please enter the occupation of the named driver.");
		insform.driver1_occupation.focus();
		return false;
	}
	if (insform.driver1_experience.value=="") {
		window.alert("Please enter the driving experience of the named driver.");
		insform.driver1_experience.focus();
		return false;
	}
	if (insform.driver1_claims.value=="") {
		window.alert("Please enter the no of claims of the named driver.");
		insform.driver1_claims.focus();
		return false;
	}
	

	
	
	var sCont = document.insform.personal_email;
	var sContVal = document.insform.personal_email.value;

	var str=new String();
	str=sContVal;
	var span=new RegExp("[ ]","g");
	var rep=str.replace(span,"9");          

	if (sContVal.length != 0)
    {
    	if(sContVal == ''  || isNaN(rep) == false)
        {
		alert("Your email address does not seem to be of a valid format.  Please re-enter.");
        sCont.focus();
        sCont.select();
        return false;
        }                         
                         
        var sAtSym    = sContVal.indexOf('@')
        var sAtSym2   = sContVal.lastIndexOf('@')
        var sPeriod   = sContVal.lastIndexOf('.')
        var sSpace    = sContVal.indexOf(' ')
        var sLength   = sContVal.length - 1   
          
        if ( (sAtSym < 2) || (sAtSym != sAtSym2) || (sPeriod <= sAtSym+2) || (sPeriod == sLength ) || (sSpace  != -1) )                  
    	{
        alert("Your email address does not seem to be of a valid format.  Please re-enter.");
        sCont.focus();
        sCont.select();
        return false;
        }

    }
		
}

