﻿// JScript File
<!-- 

   
  function PersonalSubmit(objSName,objName,objContactNo,objCellNo,objEmail,objDD,objMM,objYY,objGender,objSmoker,objEdu,objIncome,objOcc,objHeight,objWeight)
  {
	  var word = /( BITCH | FUCK | CUNT | ASSHOLE | ASS | ARSE | POES | SHIT | DICK HEAD | DICKHEAD | PUSSY | WHORE | FAGGAT | BUTT | TWAT | RAPE | PORN | PISS)/;
	  var msg = "";
  
    msg += CheckSurname(objSName, word, true);
	  msg += CheckName(objName, word, true);
	  msg += CheckContactNo(objContactNo, false);
	  msg += CheckCellNo(objCellNo, false);
	  msg += IsOneContactNumber(objContactNo, objCellNo);
	  msg += CheckEmail(objEmail, word, true);
	  msg += ValidateAge(objDD, objMM, objYY);
	  msg += CheckGender(objGender);
	  msg += CheckSmoker(objSmoker);
	  
	  //msg += CheckHeight(objHeight);
	  //msg += CheckWeight(objWeight);
	  
	  msg += CheckEducation(objEdu);
	  msg += CheckIncome(objIncome);
	  msg += CheckOccupation(objOcc, true);
	  
	  msg += CheckNameValid(objName);
	  
	  if (msg == "") {
		  return true;
	  } else {
		  alert("The following errors were encountered.\n-------------------------------------------------\n" + msg);
		  return false;
	  }
  }
  
  function CoverSubmit(objTerm,objLife)
  {
    var msg = "";

  	//msg += CheckTerm(objTerm, true);
	  msg += CheckLife(objLife, true);
	  
	  if (msg == "") {
		  return true;
	  } else { 
		  alert("The following errors were encountered.\n-------------------------------------------------\n" + msg);
		  return false;
	  }
  }
  
  function OccupationSubmit(objOcc) 
  {
	  var msg = "";
	  var occ = objOcc.value;
  	
	  //Trim all data
  	
	  occ = occ.replace(/^\s+|\s+$\ \,\&\.\*\#\!\(\)\_\-\+\=\`\~\>\<\[\]\"\'\;\:\?\%\/\\/g,''); 
  					
	  if (occ==""){
			  msg += "- Please enter your occupation.\n";
	  }
	  if (occ.length < 3){
			  msg += "- Please enter three or more characters for the occupation search.\n";
	  }						
	  if (msg == "") {
		  return true;
	  } else {
		  alert("The following errors were encountered.\n-------------------------------------------------\n" + msg);
		  return false;
	  }
  }
  
  function CheckSurname(objSName, word, isReq)
  {
    var SName = objSName.value;
    var msg = "";
    
    SName = SName.replace(/^\s+|\s+$/g,'');
    
    if (SName == "")
    {
      if (isReq == true)
        msg += "- Please enter your surname.\n";
    }
    else
    {
      if (SName.length < 2 )
        msg += "- Please enter two or more characters for surname.\n";
  	
      var VName = " " + SName.toUpperCase() + " ";
      if (VName.match(word))
        msg += "- No vulgarity allowed, please re-enter surname.\n";
    }
  	
    return msg;
  }
  
  function CheckName(objName, word, isReq)
  {
    var Name = objName.value;
    var msg = "";
    
    Name = Name.replace(/^\s+|\s+$/g,'');
    
    if (Name == "")
    {
      if (isReq == true)
        msg += "- Please enter your name.\n";
    }
    else
    {
      if (Name.length < 2 )
        msg += "- Please enter two or more characters for name.\n";
  	
      var VName = " " + Name.toUpperCase() + " ";
      if (VName.match(word))
        msg += "- No vulgarity allowed, please re-enter name.\n";
    }
  	
    return msg;
  }
  
  function CheckNameValid(objName)
  {
    var Name = objName.value;
    var msg = "";
    var iChars = "*|,\":<>[]{}`';()!@&$#%^_~+/?=\\";
    for (var i = 0; i < Name.length; i++) 
    {
        if (iChars.indexOf(Name.charAt(i)) != -1)
            {
                msg += "- Remove special character from name\n"
                break;
            }
     }
     return msg;
  }
  
  function CheckContactNo(objFullContactNo, isReq)
  {
    var RexTelno = /0[1-9]\d{8}/;
    var ContactNo = objFullContactNo.value;
    var msg = "";
    
    ContactNo = ContactNo.replace(/^\s+|\s+$\ \,\&\.\*\#\!\(\)\_\-\+\=\`\~\>\<\[\]\"\'\;\:\?\%\/\\/g,'');
	  if (ContactNo != "") {
		  if (!(ContactNo.match(RexTelno))) {
			  msg += "- Please enter a valid telephone number without spaces and characters eg: 0114890000 .\n";
		  }
	  }
    else
    {
      if (isReq == true)
        msg += "- Please enter valid telephone number eg: 0114890000.\n";
    }
    
    return msg;
  }
  
  function CheckCellNo(objCellNo, isReq)
  {
    var RexCellno = /0(71|72|73|74|76|78|79|82|83|84)\d{7}/;
    var CellNo = objCellNo.value;
    var msg = "";
    
    CellNo = CellNo.replace(/^\s+|\s+$\ \,\&\.\*\#\!\(\)\_\-\+\=\`\~\>\<\[\]\"\'\;\:\?\%\/\\/g,'');
    if (CellNo != "") 
    {
      if (!(CellNo.match(RexCellno))) {
        msg += "- Please enter a valid cellphone number without spaces and characters eg: 0721234567.\n";
      }
    }
    else
    {
      if (isReq == true)
         msg += "- Please enter a cellphone number eg: 0721234567.\n";
    }
    
    return msg;
  }
  
  function CheckEmail(objEmail, word, isReq)
  {
    var Email=objEmail.value;
    var RexEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var invalidChars = ',;:\'\/\\ "?!()[]\{\}^|`';
    var msg = "";
    
    Email = Email.replace(/^\s+|\s+$/g,''); 
    
    if (Email == "") {
      if (isReq == true)
        msg += "- Please enter email address.\n";
    }
    else {
      if (!(Email.match(RexEmail)) || Email.charAt(Email.length - 1) == "." || Email.indexOf("..",0) > -1 || Email.indexOf('@',Email.indexOf('@',0)+1) > -1 ) {
        msg += "- Please enter a valid e-mail address.\n";
      }
      else {
        for (i=0; i<invalidChars.length; i++) {
          if (Email.indexOf(invalidChars.charAt(i),0) > -1) {
            msg += "- E-mail address contains invalid characters. eg: " + invalidChars + "\n";
            return msg;
          }
        }
      }
  	  
      var UEmail = Email.toUpperCase();
      if (UEmail.match(word))
      {
        msg += "- No vulgarity allowed, please re-enter e-mail.\n";
      }
    }
    
    return msg;
  }
  
  function checkDate(d, m, y)
  {
    var test;
    
    try {
      test = new Date(y, m-1, d);
    }
    catch(err) {
      return false;
    }
    
    if (test.toString()=="NaN" || test.toString()=="Invalid Date")
      return false;
    else
      return true;
  }
  
  function ValidateAge(objDD,objMM,objYY)
  {
    var msg = "";
    var age = -1;
    
    var mm = objMM.value;
    var dd = objDD.value;
    var yyyy = objYY.value;
    
    if (mm != "" && dd != "" && yyyy != "" && yyyy.length == 4)
    {
      var valMM = parseInt(mm, 10);
      var valDD = parseInt(dd, 10);
      var valYY = parseInt(yyyy, 10);
      
      if (checkDate(valMM, valDD, valYY)){
        var today = new Date();
        var todayMM = today.getMonth() + 1;
        var todayDD = today.getDate();
        var todayYY = today.getFullYear();
        
        if (todayYY < 100) todayYY += 1900;
        if (valYY < 100) valYY += 1900;
        
        age = todayYY - valYY;
        
        if ((valMM > todayMM) || ((valMM == todayMM) && (valDD > todayDD)))
          age--;
      }
    }

    if (age < 0)
      msg += '- Please enter a valid date of birth.\n';
    else if (age < 17)
      msg += '- Sorry, can\'t calculate if younger than 17 years of age.\n';
    else if (age > 64)
      msg += '- Sorry, can\'t calculate if over 64 years of age.\n';

    return msg;
  }
  
  function CheckGender(objGender)
  {
    var gender = document.getElementsByName(objGender);
    for (var i=0; i<gender.length; i++)
    {
      if (gender[i].checked)
        return '';
    }
    
    return '- Please select gender.\n';
  }
  
  function CheckSmoker(objSmoker)
  {
    var smoker = document.getElementsByName(objSmoker);
    for (var i=0; i<smoker.length; i++)
    {
      if (smoker[i].checked)
        return '';
    }
    
    return '- Please select smoker status.\n';
  }
  
  function CheckEducation(objEdu)
  {
    var edu = objEdu.selectedIndex;
    var msg = "";

    if (edu <= 0) {
        msg += "- Please select highest education.\n";
    }
    
    return msg;
  }
  
  function CheckIncome(objIncome)
  {
    var income = objIncome.value;    
    var test = /^[1-9]\d{0,6}$/;
    var msg = "";

    if (income == "") {
      msg += "- Please enter an income.\n";
    }
    else {
      if (income.match(test)) {
        var incomeInt = parseInt(income, 10)
        if (!(incomeInt > 0 && income < 100000))
          msg += "- Income must be between 1 and 99999.\n";
      }
      else {
        msg += "- Please enter a valid income; Income must be numeric (No spaces).\n";
      }
    }

    return msg;
  }
    
  function CheckOccupation(objOcc, isReq)
  {
    var occ = objOcc.selectedIndex;
    var msg = "";

    if (occ < 0) {
      if (isReq == true)
        msg += "- Please search for an occupation and confirm it.\n";
    }
    
    return msg;
  }
  
  function IsOneContactNumber(objContactNo, objCellNo)
  {
    var ContactNo = objContactNo.value;
    var CellNo = objCellNo.value;
    var msg = "";
    
    ContactNo = ContactNo.replace(/^\s+|\s+$\ \,\&\.\*\#\!\(\)\_\-\+\=\`\~\>\<\[\]\"\'\;\:\?\%\/\\/g,'');
    CellNo = CellNo.replace(/^\s+|\s+$\ \,\&\.\*\#\!\(\)\_\-\+\=\`\~\>\<\[\]\"\'\;\:\?\%\/\\/g,'');
    
    if (ContactNo == "" && CellNo == "")
    {
      msg += "- Please enter either a cellphone number or a telephone number.\n";
    }
   
    return msg;
  } 

  function CheckTerm(objTerm, isReq)
  {
    var term = objTerm.selectedIndex;
    var msg = "";

    if (term <= 0) {
      if (isReq == true)
        msg += "- Please select the policy term.\n";
    }
    
    return msg;
  }
  
  function CheckLife(objLife, isReq)
  {
    var life = objLife.selectedIndex;
    var msg = "";

    if (life <= 0) {
      if (isReq == true)
        msg += "- Please select the sum assured.\n";
    }
    
    return msg;
  }

  function CheckHeight(objHeight)
  {
    var height = objHeight.value;
    var msg = "";
    var test = /^[1-9]\d{0,3}$/;       //^[1-9]\d{0,6}$/;
    if (height == "") {
      msg += "- Please enter height.\n";
    }
    else {
      if (height.match(test)) {
        var heightInt = parseInt(height, 10)
        if (!(heightInt > 40 && height < 100000))
          msg += "- Height must be between 40 and 250.\n";
      }
      else {
        msg += "- Please enter a valid height; Height must be numeric (No spaces).\n";
      }
    }

    return msg;
  }
  
  function CheckWeight(objWeight)
  {
   var weight = objWeight.value;
    var msg = "";
    var test = /^[1-9]\d{0,3}$/;
     if (weight == "") {
      msg += "- Please enter weight.\n";
    }
      else {
      if (weight.match(test)) {
        var weightInt = parseInt(weight, 10)
        if (!(weightInt > 2 && weight < 200))
          msg += "- Weight must be between 2 and 200.\n";
      }
      else {
        msg += "- Please enter a valid weight; Weight must be numeric (No spaces).\n";
      }
    }

    return msg;
  }

 
 //-->