<!--
function checkForm() {
  var check = "";
  check += checkFname();
  check += checkComments();
  //check += checkPhone();

  check += checkEmail();

  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}

function checkRegForm() {
  var check = "";
  check += checkFname();
  check += checkLname();
  check += checkAddr();
  check += checkCity();
  check += checkProv();
  check += checkPostal();
  //check += checkCountry();
  check += checkPhone();
  check += checkEmail();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}

function checkRegForm2() {
  var check = "";
  check += checkFname();
  check += checkLname();
  check += checkAddr();
  check += checkCity();
  check += checkProv();
  check += checkPostal();
  //check += checkCountry();
  check += checkPhone();
  check += checkEmail();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}

function checkBuyForm() {
  var check = "";
  check += checkFname();
  check += checkLname();
  check += checkCompany();
  check += checkAddr();
  check += checkCity();
  check += checkProv();
  check += checkPostal();
  //check += checkCountry();
  //check += checkPhone();
  check += checkEmail();
  check += checkPwd();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}


function checkInvoiceForm() {
  var check = "";
  check += checkFname();
  check += checkLname();
  check += checkEmail();
  check += checkInvoice();
  check += checkAmount();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}

function checkClientMail() {
  var check = "";
  check += checkFname();
  check += checkLname();
  check += checkAddr();
  check += checkCity();
  check += checkProv();
  check += checkPostal();
  //check += checkCountry();
  //check += checkPhone();
  //check += checkEmail();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}

function checkClientAdd() {
  var check = "";
  //check += checkFname();
  //check += checkLname();
  check += checkCompany();
  check += checkProv();
  check += checkEmail();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}


function checkQuiz() {
  var check = "";
  check += checkQuizEmail();
  checkres = true;
    if (check != "") {
       alert("There is a problem with your form.\n\n"+check);
	   checkres = false;
	}
    if(checkres) {document.forms[0].submit();}
}

function isEmpty(inputStr) {
	if(inputStr == null || inputStr == "" || inputStr == " "){
   		return true
   }
   return false
}

function checkInvoice () {
 var error = "";
 if (isEmpty(document.forms[0].invoice.value)) {
    error = "Please enter Invoice Number\n";
 	}
 	return error;
}

function checkAmount () {
 var error = "";
 if (isEmpty(document.forms[0].amount.value)) {
    error = "Please enter Invoice Amount\n";
 	}
 	return error;
}


function checkPwd () {
 var error = "";
 if (isEmpty(document.forms[0].pwd.value)) {
    error = "Please enter Password\n";
 	}
 	return error;
}

function checkAddr () {
 var error = "";
 if (isEmpty(document.forms[0].address.value)) {
    error = "Please enter Address\n";
 	}
 	return error;
}

function checkCompany () {
 var error = "";
 if (isEmpty(document.forms[0].company.value)) {
    error = "Please enter Organization\n";
 	}
 	return error;
}

function checkFname () {
 var error = "";
 if (isEmpty(document.forms[0].name.value)) {
    error = "Please enter Name\n";
 	}
 	return error;
}

function checkLname () {
 var error = "";
 if (isEmpty(document.forms[0].lastname.value)) {
    error = "Please enter Last Name\n";
 	}
 	return error;
}


function checkComments () {
 var error = "";
 if (isEmpty(document.forms[0].comments.value)) {
    error = "Please enter Comments\n";
 	}
 	return error;
}

function inspectBox () {
  if (document.forms[0].agree.checked) {
     document.forms[0].submit()
		}else {
		alert ("You have to agree to the terms!")
 }
}

function checkCity () {
 var error = "";
 if (isEmpty(document.forms[0].city.value)) {
    error = "Please enter City\n";
 }
 return error
}

//if the value of country in the select list is NA (the user purposely selected no country)
function countryNull(inputStr) {
	if(inputStr == "NA") {
		return true
	}
	return false
}

//if the user selected Canada in the select list, save the value for later use
function countryCan(inputStr) {
	if(inputStr == "CA") {
		return true
	}
	return false
}

//if the user selected US in the select list, save the value for later use
function countryUS(inputStr) {
	if(inputStr == "US") {
		return true
	}
	return false
}

//if the user selected no province or state in the select list, save the value for later use
function provNull(inputStr) {
	if(inputStr == "--") {
		return true
	}
	return false
}

//check to see if the user selected a province, and save the value for later use
function provCan(inputStr) {
	var prov = new Array("AB", "BC", "MB", "NB", "NF", "NT", "NS", "NU", "ON", "PE", "QC", "SK", "YT");
	for (var i=0; i<prov.length; i++) {
		var provName = prov[i];
		if(inputStr == provName) {
		return true
		break;
		}
	}
	return false

}

function checkProv () {
 var error = "";
 if (provNull(document.forms[0].prov.options[document.forms[0].prov.selectedIndex].value)) {
        error = "Please enter Province\n";
 	//if (countryCan(document.forms[0].country.options[document.forms[0].country.selectedIndex].value)) {
	//	error = "Please enter Province\n";
	//} else if (countryUS(document.forms[0].country.options[document.forms[0].country.selectedIndex].value)) {
	//	error = "Please enter State\n";
	//}
 }
 return error
}

//building on the last function - compare the values of previous functions to make sure that the user selected Canada and //provinces or the US and states
function checkProvandCountry () {
 var error = "";
 var provinceSelect = document.forms[0].prov;
 var countrySelect = document.forms[0].country;
 var selectedProvince = document.forms[0].prov.selectedIndex;
 var selectedCountry = document.forms[0].country.selectedIndex;
 if (!provCan(provinceSelect.options[selectedProvince].value)) {
 	if (countryCan(countrySelect.options[selectedCountry].value)) {
		error = "Please choose a province.\n";
	}
 } else if (provCan(provinceSelect.options[selectedProvince].value)) {
 	if (countryUS(countrySelect.options[selectedCountry].value)) {
		error = "The United States does not have provinces. Please choose a state.\n";
	}
 }
 return error
}

/*
initiated with onClick - if country other than US or Canada is chosen, change prov select list to option 70 (the Null value)
REM: this statement must be triggered! It can not be done automatically (ie placed in the checkProvandCountry function
as a separate "else if" statement
*/
function setProvtoNull() {
	var error = "";
	var provinceSelect = document.forms[0].prov;
	var countrySelect = document.forms[0].country;
	var selectedProvince = document.forms[0].prov.selectedIndex;
	var selectedCountry = document.forms[0].country.selectedIndex;
	if ((!countryCan(countrySelect.options[selectedCountry].value)) && (!countryUS(countrySelect.options[selectedCountry].value))) {
		provinceSelect.options[70].selected = true
	}
}

//below is the complete string for a select list (I created variables in other functions as shorthand)
function checkCountry () {
 var error = "";
 if (countryNull(document.forms[0].country.options[document.forms[0].country.selectedIndex].value)) {
    error = "Please enter a new country.\n";
 }
 return error
}

function checkPhone () {
	var error = "";
	if (isEmpty(document.forms[0].phone.value)) {
		error = "Please enter Phone number\n";
	}
	return error
}

function isPhone(string) {
	if (string.search(/^\d{3}-\d{3}-\d{4}$/) != -1)
		return true;
	else
		return false;
}

function checkisPhone() {
	var error = "";
	if (!isEmpty(document.forms[0].phone.value)) {
		if (!isPhone(document.forms[0].phone.value)) {
			error = "Your phone number is incomplete.\n";
		}
	}
	return error
}

function phoneMask()
  {
	var sMask = "01234567890";
	var KeyTyped = String.fromCharCode(window.event.keyCode);
	var srcObject = window.event.srcElement;
	if (window.event.keyCode != 8)
	window.status = "";
	{
	 if (sMask.indexOf(KeyTyped.toString()) == -1)
		{
		 		window.event.keyCode = 0;
				window.status = "Please enter a valid phone number";
				return false;
		}
	}
   /*
    * The varible "frigger is used because" the friggen DOM
    *does not expose length via window.event.srcElement.length
    */
	frigger = document.getElementById(window.event.srcElement.id);
	keyCount = frigger.value.length;
    //var tmpStr = "(";

    keyEntered = KeyTyped;
    keyCount++;
    switch (keyCount)
    {
    /*case 2:?
      tmpStr += srcObject.value;
      srcObject.value = tmpStr;
      break;
	*/
    case 4:
      srcObject.value += "-";
      break;
    case 8:
      srcObject.value += "-";
      break;
      }
 }

function checkPostal () {
	var error = "";
	if (isEmpty(document.forms[0].postalcode.value)) {
		error = "Please enter Postal Code\n";
	}
	return error
}

function checkEmail () {
	var error = "";
	if (isEmpty(document.forms[0].email.value)) {
		error = "Please enter Email address\n";
	}
	return error
}

function checkQuizEmail () {
	var error = "";
	if (isEmpty(document.forms[0].email.value)) {
		error = "Please enter Email address\n";
	}
	return error
}


function ValidateEmailAddress (emailStr) {

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Your email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid
	if (user.match(userPat)==null) {
	    alert("The username doesn't seem to be valid.")
	    return false
	}

	/* if the e-mail address is at an IP address  */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("The destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.")
	    return false
	}

	/* Make sure that it ends in a three-letter word or a two-letter word, and that hostname preceding domain or country. */

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
	    domArr[domArr.length-1].length>3) {
	   alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   alert(errStr)
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
	}


	//======  Check numbers

	function PositiveInteger(objName)
	{
		if (objName.value != "")
		{
			if (IsPosNumeric(objName.value) == false)
			{
				//objName.focus()
				//objName.select()
				return false
			}
			else
			{
				return true
			}
		}
		return true
	}

	function IsNumeric(sNumber) {
		var decimal = 0;
		sNumber += "";
		if (sNumber.length == 0) return false;
		for (x = 0; x < sNumber.length; x++) {
			if (!(sNumber.charCodeAt(x) >= 48 && sNumber.charCodeAt(x) <= 57)) {
				switch (sNumber.charAt(x)) {
					case ".":
						if (decimal++ != 0) return false;
						break;
					case "-":
						if (x > 0) return false;
						if (sNumber.length == 1) return false;
						break;
					default:
						return false;
				}
			}
		}
		return true;
	}


	function IsPosNumeric(sNumber) {
		sNumber += "";
		return (sNumber.charAt(0) != "-" && IsNumeric(sNumber));
	}

	function RequireNumericOnly(editBox, defaultValue) {
		if( editBox.value != '' && !IsNumeric(editBox.value) ) {
			editBox.value = defaultValue;
			alert('Please enter only Positive numeric values');
			editBox.focus();
		}
		else
		{
			if (PositiveInteger(editBox) == false)
			{
			  alert('Please enter only Positive numeric values');
			  editBox.focus();
			}
		}
	}

//-->