function displayAlert(message) {
  if ((typeof message != "undefined") && message.length > 0) alert(message);
}

function isInteger(field, message)
{
  if (/^\d+$/.test(field.value)) return true;
  displayAlert(message);
  return false;
}

function isFloat(field, message)
{
  if (/^\d+\.?\d*$/.test(field.value)) return true;
  displayAlert(message);
  return false;
}

function isEmail(field, message){
  if (/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(field.value)) return true;
  displayAlert(message);
  return false;
} 

function isPhone(field, message){
  with (field) {
    value = value.replace(/(\s|-|\(|\)|\.)/g,"");
    if (/^\d{10}$/.test(value)) return true;
  }
  displayAlert(message);
  return false;
}

function isPostalCode(field, message)
{
  with (field) {
    value = value.toUpperCase().replace(/(\s|-)/g,"");
    if (/[A-Z]\d[A-Z]\d[A-Z]\d/.test(value)) return true;
  }
  displayAlert(message);
  return false;
}

function digitvalidation(entered, min, max, alertbox, datatype)
{
  with (entered)
  {
    checkvalue=parseFloat(value);
    if (datatype) {
	  smalldatatype=datatype.toLowerCase();
      if (smalldatatype.charAt(0)=="i") {
	    checkvalue=parseInt(value); 
		if (value.indexOf(".")!=-1) {
		  checkvalue=checkvalue+1;
		}
      }
    }
    if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue) {
	  displayAlert(alertbox);
	  return false;
	}
  }
  return true;
} 

function isEmpty(field, message)
{
    if (field.value!=null && field.value.length > 0) return false;
	displayAlert(message);
	return true;
} 

//The below code add by Bob Karuppusamy for validating the Postal code for each province
function validatePostalCode()
 {
	 	var province;
		var postalcode;
 		if(window.location.pathname.match(/fr/))
		{
			province = getProvinceID_fr();
			postalcode= getPostalCodeID_fr();
		}
		else
		{
			province = getProvinceID();
			postalcode = getPostalCodeID();
		} 		
		var k = postalcode.substr(0, 1);
    	if (province == "ON") 
 		{
           switch(k)
			{
				case "K":
				  	break;
				case "L":
					break;
				case "M":
				  	break;
				case "N":
					break;
				case "P":
				  	break;
				default:
				  alert("Mismatch postal code for the selected province"); 
			}
             
        }
        else if (province == "AB") 
        {
                if (k != "T") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
         else if (province == "BC") 
        {
                if (k != "V") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
         else if (province == "SK") 
        {
                if (k != "S") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        }
         else if (province == "MB") 
        {
                if (k != "R") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
         else if (province == "QC") 
        {
        switch(k)
			{
				case "G":
				  	break;
				case "H":
					break;
				case "J":
				  	break;
				default:
				  alert("Mismatch postal code for the selected province"); 
			}

                      } 
         else if (province == "NB") 
        {
                if (k != "E") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
         else if (province == "NS") 
        {
                if (k != "B") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
           else if (province == "PE") 
        {
                if (k != "C") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
           else if (province == "NL") 
        {
                if (k != "A") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
   		   else if (province == "YT") 
        {
                if (k != "Y") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        }
     	   else if (province == "NT") 
        {
                if (k != "X") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
   		   else if (province == "NU") 
        {
                if (k != "X") 
                {
                 	alert("Mismatch postal code for the selected province");
                }
        } 
 }  


