// JavaScript Document
function CheckValidateForm()
{
  
  //alert("calling Validation Checker");
  
  var i, pricevar, priceElement;
  
  // Regular Expression Pattern for Company  
  var rePatternFL = /[^a-z\x80-\xFF .',-]/i;

  var rePatternexFL = new RegExp(rePatternFL);
  //alert(document.getElementById('divCompanytext').value);
  
  var Fnametext = document.getElementById('txtFirstName2').value;  
  
   if ((rePatternexFL.test(Fnametext)) || (Fnametext == 0)) { 
		alert("Invalid 'First Name'.");
		//form["divCompanytext"].focus();
		document.getElementById('txtFirstName2').focus();
		return false;
  
  }  
  
  var Lnametext = document.getElementById('txtLastName').value;  
  
   if ((rePatternexFL.test(Lnametext)) || (Lnametext == 0)) { 
		alert("Invalid 'Last Name'.");
		//form["divCompanytext"].focus();
		document.getElementById('txtLastName').focus();
		return false;
  
  }  
  
  var rePattern = /[^a-z0-9\x80-\xFF .',-]/i;

  var rePatternex = new RegExp(rePattern);
  
  var Comptext = document.getElementById('txtCompanyName').value;

  // check if valid company and not null	  
  if ((rePatternex.test(Comptext)) || (Comptext.length == 0)) { 
		alert("Invalid 'Company Name'.");
		//form["divCompanytext"].focus();
		document.getElementById('txtCompanyName').focus();
		return false;
  
  } 
  
 var selsegment = document.getElementById('intSegment').value;
 
 //alert(selsegment);
 
 if (selsegment == "#") {
	 
	    alert("Invalid 'Category'.");
		//form["divCompanytext"].focus();
		document.getElementById('intSegment').focus();
		return false
 }
  
  var Citytext = document.getElementById('txtCity').value;  
  
   if ((rePatternexFL.test(Citytext)) || (Citytext == 0)) { 
		alert("Invalid 'City Name'.");
		//form["divCompanytext"].focus();
		document.getElementById('txtCity').focus();
		return false;
  
  }
 
 //alert(document.getElementById('divAddresstext').value);
 
 // Regular Expression Pattern for Address 
 var addresstxt = document.getElementById('txtAddress').value;
 
 var reAddPattern = /[^a-z0-9#\x80-\xFF .',-]/i;

 var reAddPatternex = new RegExp(reAddPattern);
 
 // check if address is valid and not null
 if ((reAddPatternex.test(addresstxt)) || (addresstxt.length == 0)) { 
		alert("Invalid 'Address'.");
		//form["divCompanytext"].focus();
		document.getElementById('txtAddress').focus();
		return false;
  
  }

 
 //alert(document.getElementById('divPhonetext').value);
 
 if (!isValidPostalcode(document.getElementById('txtPostal').value)){
      return false	 
	 
    } 
 
 var selprovince = document.getElementById('intProvince').value;
 
 if (selprovince == "#") {
	 
	    alert("Invalid 'Province'.");
		//form["divCompanytext"].focus();
		document.getElementById('intProvince').focus();
		return false
 }
  
 var phonenumtxt = document.getElementById('txtPhone').value;
 
 // define Regular Expression for Phone Number
 // Pattern matches (999)-999-9999, (999) 999-9999, (999)999-9999, etc.
 var reValidChar = /^((\((\d{3})\)|(\d{3}))[- ]?)?(\d{3})[- ]?(\d{4})$/;
	//                /(\(?\d{3}\)?)?(\-| )?\d{3}(\-| )?\d{4}/
 
 var rePhonePatternex = new RegExp(reValidChar);

 // check if valid phone number and not null 
 if (!(rePhonePatternex.test(phonenumtxt)) || (phonenumtxt.length == 0)) { 
		alert("Invalid 'Phone Number'.");
		//form["divCompanytext"].focus();
		document.getElementById('txtPhone').focus();
		return false;
  
  }
  
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById('txtEmail2').value;
   if(reg.test(address) == false) {
      alert("Invalid 'Email Address'.");
	  document.getElementById('txtEmail2').focus();
      return false;
   }
   
   
  
 // Regular expression pattern for web address
/* var reWebAddPattern = /^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?.(com)|(org)|(edu)|(net)$/;
 
 var webaddtxt = document.getElementById('webaddress2').value;
 
 var reWebaddPatternex = new RegExp(reWebAddPattern);
 
 // check if valid web address and not null
 if (!(reWebaddPatternex.test(webaddtxt)) || ( webaddtxt.length == 0)) { 
		alert("Invalid 'Web Address'.");
		//form["divCompanytext"].focus();
		document.getElementById('webaddress2').focus();
		return false;
   }
 
  // get the total number of price variables
  var pricetotal = document.getElementById('pricetotal').value;
  
  //alert(pricetotal);
  
  // loop through all price elements
  for (var i = 1; i <= pricetotal; i++)
  {
   // obtain the price variable
   pricevar = 'price'+i;
   priceElement = document.getElementById(pricevar).value;
   
   // ignore if CALL US
   if (priceElement == "CALL US")
   {
   
   }
   else
   {
   //check if number is a number, positive, float
   if ((isNaN(priceElement)) || (priceElement.length == 0) || (parseInt(priceElement) <= 0) || (parseFloat(priceElement) <= 0.00)) { 
		alert("Invalid 'Price'.");
		document.getElementById(pricevar).focus();
		return false;
   
   }
   }   
  } */
// submit the form if all validation checks pass    
//document.getElementById('form1').submit();
}

function isValidPostalcode(postalcode) {
      if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
      else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z](-|\s)\d[a-zA-Z]\d$/) != -1) return true;
      else { 
	      alert("Invalid 'Postal Code'.");
		  document.getElementById('txtPostal').focus();
	      return false;
	  }
    
}