// Javascript validation functions


//function to check empty fields

function isEmpty(strfield1, strfield2, strfield3, strfield4, strfield5, strfield6, strfield7, strfield8, strfield9, strfield10) {

strfield1 = document.forms[0].cdeParcNumb1.value
strfield2 = document.forms[0].cdeOwneof0.value
strfield3 = document.forms[0].paymentAmount.value
strfield4 = document.forms[0].firstName.value
strfield5 = document.forms[0].lastName.value
strfield6 = document.forms[0].address1.value
strfield7 = document.forms[0].cityName.value
strfield8 = document.forms[0].provinceCd.value
strfield9 = document.forms[0].postalCd.value
strfield10 = document.forms[0].phoneNum.value

  //Parcel Number field
    if (strfield1 == "" || strfield1 == null || strfield1.charAt(0) == ' ')
    {
    alert("\"Parcel Number\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

    if(strfield1.length < 13)
    {
    alert("\"Parcel Number\" must contain at least 13 characters.");
    return false;
    }

  //Owner of Record field
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
    alert("\"Owner of Record\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //Payment Amount field
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("\"Payment Amount\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //First Name field
    if (strfield4 == "" || strfield4 == null || strfield4.charAt(0) == ' ')
    {
    alert("\"First Name\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //Last Name field
    if (strfield5 == "" || strfield5 == null || strfield5.charAt(0) == ' ')
    {
    alert("\"Last Name\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //Address field
    if (strfield6 == "" || strfield6 == null || strfield6.charAt(0) == ' ')
    {
    alert("\"Address\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //City field
    if (strfield7 == "" || strfield7 == null || strfield7.charAt(0) == ' ')
    {
    alert("\"City\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //State field
    if (strfield8 == "" || strfield8 == null || strfield8.charAt(0) == ' ')
    {
    alert("\"State\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //Zip Code field
    if (strfield9 == "" || strfield9 == null || strfield9.charAt(0) == ' ')
    {
    alert("\"Zip Code\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //Phone Number field
    if (strfield10 == "" || strfield10  == null || strfield10.charAt(0) == ' ')
    {
    alert("\"Phone Number\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }
    return true;
}


//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
   {
      alert('A valid E-mail address is required.\nPlease amend and retry');
      return false;
    }
    return true;
}


//function that performs all functions, defined in the onsubmit event handler

function check(form){
if (isEmpty(form.cdeParcNumb1)){
  if (isEmpty(form.cdeOwneof0)){
    if (isEmpty(form.paymentAmount)){
      if (isEmpty(form.firstName)){
        if (isEmpty(form.lastName)){
          if (isEmpty(form.address1)){
            if (isEmpty(form.cityName)){
              if (isEmpty(form.provinceCd)){
                if (isEmpty(form.postalCd)){
                  if (isEmpty(form.phoneNum)){
      	              if (isValidEmail(form.email)){
		              return true;
		    	    }
		    	  }
		        }
		      }
		    }
		  }
		}
	  }
	}
  }
}
return false;
}
