
<!-- ============== Form Validation Routine #1 ====================== -->
//This is used to validate the forms w/ business logic
var allowTags = false;

//- This function gives the field focus
	function ffocus(field, myForm) { myForm.elements[field].focus() };

//- This function checks a value to ensure it is not an HTML tag
	function isTag (t)
	{	return ((t != ">") && (t != "<"))   }
 
 	function fchecktag(val)
	{
		if (allowTags)
		{return true;}

		var j
	    for (j = 0; j < val.length; j++)
	   {   
	       var t = val.charAt(j);
	       if (!isTag(t)) return false;
	   }
	   // All characters are valid.
	   return true;
	} 


//- This function checks for the double quote mark in a string
	function isQuote (t)
	{	return (t != "\"")   }

		function fCheckQuote(val)
	{
		var j
	    for (j = 0; j < val.length; j++)
	   {   
	       var t = val.charAt(j);
	       if (!isQuote(t)) return false;
	   }
	   // All characters are valid.
	   return true;
	}


//- This function makes sure that all characters in a string are numeric
	function isDigit (c)
	{   return ((c >= "0") && (c <= "9")) }
			
	function fchecknum(val)
	 {
		var i
	     for (i = 0; i < val.length; i++)
	    {   
	        // Check that current character is a number.
	        var c = val.charAt(i);
	        if (!isDigit(c)) return false;
	    }
	    // All characters are numbers.
	    return true;
	 }			



//- This function checks to make sure string is not made up entirely of spaces
	function fcheckspaces(strValue)
	{
		var cntChar
	    for (cntChar = 0; cntChar < strValue.length; cntChar++)
	   {   
	       // Check to see if current character is a space
	       var vChar = strValue.charAt(cntChar);
	       if (vChar != ' ') return true;
	   }
	   return false;
	}

//- This function checks to make sure that there was data entered into a field
	function fcheckBlank(myForm, field) {
		var val = myForm.elements[field].value;
			if (!fchecktag(val))
		{ return false }
			
		if (val.length == 0)
		{ return false }
					
		if (!fcheckspaces(val))
		{ return false }
				
		else
		{ return true }
	}
			
	function fcheckBlankItem(myForm, field) {
		var indexvalue = myForm.elements[field].selectedIndex

		if (myForm.elements[field].size == 0 || myForm.elements[field][indexvalue].value==''
			|| myForm.elements[field][indexvalue].value == 0) {
			//false
//			return (myForm.elements[field].selectedIndex > 0)
			return (false)
		}
		else {
			//true
			return (true)
//			return (myForm.elements[field].selectedIndex > -1)
		}
	}			

	// checks to make sure that a checkbox in a list is selected
	function fcheckCheckbox(myForm, field) {
		var cntCheck
		var fieldLength = myForm.elements[field].length
		
		if (!fieldLength) {fieldLength = 1}
				
		for(cntCheck = 0; cntCheck < fieldLength; cntCheck++) {
			if (fieldLength == 1 )	{
				if (myForm.elements[field].checked) {return true}
			}
			else {
				if (myForm.elements[field][cntCheck].checked) {return true};
			}
		}
		
		return (false);
	}			
			
// checks for valid phone number

function checkPhone (myForm, field) {

// strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }

	// check for 10 digits
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return (false);
}

// ***************************************************************************************
// Additional functions for area code, prefix and exchange added on 04/12/2007 by RM
// ***************************************************************************************
function checkAreaCode (myForm, field) {

// strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }

	// check for 3 digits
    if (!(stripped.length == 3)) {
	error = "The area code is the wrong length.\n";
    } 
return (false);
}

function checkPrefix (myForm, field) {

// strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }

	// check for 3 digits
    if (!(stripped.length == 3)) {
	error = "The phone prefix is the wrong length.\n";
    } 
return (false);
}

function checkExchange (myForm, field) {

// strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }

	// check for 4 digits
    if (!(stripped.length == 4)) {
	error = "The phone exchange is the wrong length.\n";
    } 
return (false);
}

// ***************************************************************************************
// End additional functions added on 04/12/07 by RM
// ***************************************************************************************


//- This function accepts a string variable and verifies if it is a
	// proper date or not. It validates format matching either
	// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
	// has the proper number of days, based on which month it is.

    // The function returns true if a valid date, false if not.
	// ******************************************************************

	function isDate(dateStr) {
		
	    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	    var matchArray = dateStr.match(datePat); // is the format ok?

		if (dateStr == null || dateStr == '') 
			{ return 0 } // do not check if blank
		 				
		if (matchArray == null) 
			{ return 1 }
				
	    month = matchArray[1]; // parse date into variables
	    day = matchArray[3];
	    year = matchArray[5];

	    if (month < 1 || month > 12) 
			{ return 2 }

	    if (day < 1 || day > 31) 
			{ return 3 }

	    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
			{ return 4 }

	    if (month == 2) { // check for february 29th
	        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	        if (day > 29 || (day==29 && !isleap)) 
	        { return 5 }
	    }
			    
			    
	    return 0; // date is valid
	}
			

	function vfyDate(myForm, field, title) {
	
		var dateStr = myForm.elements[field].value
		
		var dateType = isDate(dateStr)

		if (dateType == 0)
			{ return true } //date is valid
		else if (dateType == 1) { 
			alert(title + " is not a valid date.")
			myForm.elements[field].focus()
			return false
		}
		else if (dateType == 2) { 
			alert(title + ": Month must be between 1 and 12.")
			myForm.elements[field].focus()
			return false
		}
		else if (dateType == 3) { 
			alert(title + ': Day must be between 1 and 31.')
			myForm.elements[field].focus()
			return false
		}
		else if (dateType == 4) { 
			alert(title + ": Month "+month+" doesn't have 31 days.")
			myForm.elements[field].focus()
			return false
		}
		else if (dateType == 5) { 
			alert(title + ": February " + year + " doesn't have " + day + " days.")
			myForm.elements[field].focus()
			return false
		}																
	}



//- This function checks to make sure that there was data entered into a field
	function vfyBlank(myForm, field, title)
	{
		var val = myForm.elements[field].value;

		if (!fcheckBlank(myForm, field))
		{
			alert('Please complete the ' + title + ' field.');
			ffocus(field, myForm);
			return false;
		}
		else
		{ return true }
	}
			
//- This function makes sure that an item was selected
	function vfyBlankItem(myForm, field, title)
	{
		if (!fcheckBlankItem(myForm, field)) {
			alert('Please complete the ' + title + ' field.')
			return false
		}
		else
		{ return true }; 
	}

//- This function makes sure that a checkbox in a list was selected
	function vfyBlankCheckbox(myForm, field, title)
	{
		if (!fcheckCheckbox(myForm, field)) {
			alert('Please select an option in the ' + title + ' field.')
			return false
		}
		else
		{ return true }; 
	}
	
/**********************************************************************************************/

//- This function checks to make sure that an item was selected
//- 8/22/2008 RM
	function vfyBlankSelect(myForm, field, title)
	{
		var val = myForm.elements[field].value;

		if (!fcheckBlank(myForm, field))
		{
			alert('Please select the ' + title + ' field.');
			ffocus(field, myForm);
			return false;
		}
		else
		{ return true }
	}

//- This function prompts the user before a delete is made
	function fDelete(id)	{
		if (confirm('These records will be deleted. Continue?')) {
			return (true)
			
			//var Location = document.location.href
			//var Del = "&Delete=True"
			//var SecondaryId = "&SecondaryID=" + id;
			
			// RegExp to get rid of parameters already in location, 
			// otherwise they are added twice
			//DeleteExp = /&Delete=True/gi;
			//IdExp = /&SecondaryID=[0-9a-z]*/gi;
			//Location = Location.replace(DeleteExp, "")
			//Location = Location.replace(IdExp, "")
			
			// redirect location
			//document.location.href = Location + Del + SecondaryId;
		}
		return (false)
	}


//- This fucntion is used to submit a form
	function fSubmitForm(formname)	{
		document.forms[formname].submit()
	}
	
	
	
//- This function checks to make sure that there was data entered is a valid Email address
function vfyEmail (myForm, field, title)
{   
		var val = myForm.elements[field].value;
		
		if (!fcheckBlank(myForm, field))
		{
			alert('Please enter a vaild E-mail address in the ' + title + ' field.');
			ffocus(field, myForm);
			return false;
		}
   
    // is s whitespace?
    if (!fcheckspaces(val))
    {
			alert('Please enter a vaild E-mail address in the ' + title + ' field.');
			ffocus(field, myForm);
			return false;
		}
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = val.length;

    // look for @
    while ((i < sLength) && (val.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (val.charAt(i) != "@")) 
    {
				alert('Please enter a vaild E-mail address in the ' + title + ' field.');
				return false;
		}
    else i += 2;

    // look for .
    while ((i < sLength) && (val.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (val.charAt(i) != ".")) 
    {
				alert('Please enter a vaild E-mail address in the ' + title + ' field.');
				return false;
		}
    else return true;
    
    
}

<!-- ============== Form Validation Routine #2 ====================== -->
//This is used to validate the forms w/ business logic

// https://webcaster.calyxsoftware.com/signup/order1.asp

function isAlphaNumeric(s) {
  var test= /[^A-Za-z0-9\@\.\,\#\-\_ ]+/i;
	if (s.match(test)) {  
		return false;
	} else {
		return true;
	}
}

function isNumeric(s) {
  var test= /[^0-9]+/i;
	if (s.match(test)) {  
		return false;
	} else {
		return true;
	}
}

function isZip(s) {
  var test= /[^0-9\-]+/i;
	if (s.match(test)) {  
		return false;
	} else {
		return true;
	}
}

function IsValidEmail(emailad) {
var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,4}$/;	

  if(((emailad.search(exclude) != -1) 
       || (emailad.search(check)) == -1)
       ||	(emailad.search(checkend) == -1)) {
         return false;
 	}	else {
 	  return true;	
 	}
}

function GoPressed(e, sourceName, param1)
{
	var key;

	if (document.all) { e = window.event; }
  if (document.layers) {
    key = e.which;		// assume netscape
	} else {
    key = e.keyCode;	// assume ie
	}
	if (key == 13)
	{
		if (ValidatePage()) {
		  SubmitMe();
		}
	}
  return false;			//cancel the event
}

function ValidatePage() {
var strError="";
var strError2;
var strTitle="";
var iChoice;

	var d = document.frmMain;	

	if (d.txtContactName.value=='') {
	  strError = strError + '  - Empty Contact Name.\n';
	 	d.txtContactName.focus();
	} else {
		if (!isAlphaNumeric(d.txtContactName.value)) {
			strError = strError + "  - Invalid Contact Name\n     -> it should only contain numbers, letters, '@', '.', '-' or space.\n";
	 		d.txtContactName.focus();
	 	}
	}

	if (d.txtSiteID.value=='') {
	  strError = strError + '  - Empty Account ID.\n';
	 	d.txtSiteID.focus();
	}

	if (d.txtCompanyName.value=='') {
	  strError = strError + '  - Empty Company Name.\n';
	 	d.txtCompanyName.focus();
	} else {
		if (!isAlphaNumeric(d.txtCompanyName.value)) {
			strError = strError + "  - Invalid Company Name\n     -> it should only contain numbers, letters, '@', '.', '-' or space.\n";
	 		d.txtCompanyName.focus();
	 	}
	}

	if (d.txtEmailAddress.value=='') {
	  strError = strError + '  - Empty Email Address.\n';
	 	d.txtEmailAddress.focus();
	} else {
		if (!IsValidEmail(d.txtEmailAddress.value)) {
		  strError = strError + '  - Invalid Email Address.\n';
		 	d.txtEmailAddress.focus();
		}	
	}

	var sPhone = d.txtPhone1.value + d.txtPhone2.value + d.txtPhone3.value;

	if (sPhone=='') {
	  strError = strError + '  - Empty Phone Number.\n';
	 	d.txtPhone1.focus();
	} else {
		if (isNaN(sPhone)) {
			strError = strError + '  - Invalid Phone Number - it must only contain digits.\n';
	 		d.txtPhone1.focus();
		} else {
			if (sPhone.length!=10) {
			  strError = strError + '  - Invalid Phone Number - it must contain exactly 10 digits.\n';
			 	d.txtPhone1.focus();
			}
		}
	}
	
	if (d.txtAddress.value=='') {
	  strError = strError + '  - Empty Address.\n';
	 	d.txtAddress.focus();
	} else {
		if (!isAlphaNumeric(d.txtAddress.value)) {
			strError = strError + "  - Invalid Address\n     -> it should only contain numbers, letters, period, comma, '@', '-' or space.\n";
	 		d.txtAddress.focus();
	 	}
	}

	if (d.txtCity.value=='') {
	  strError = strError + '  - Empty City.\n';
	 	d.txtCity.focus();
	} else {
		if (!isAlphaNumeric(d.txtCity.value)) {
			strError = strError + "  - Invalid City\n     -> it should only contain numbers, letters, period, comma, '@', '-' or space.\n";
	 		d.txtCity.focus();
	 	}
	}

	if (d.drpState.value=='NA') {
	  strError = strError + '  - Invalid State.\n';
	 	d.drpState.focus();
	}

	if (d.txtZipCode.value=='') {
	  strError = strError + '  - Empty Zip Code.\n';
	 	d.txtZipCode.focus();
	} else {
		if (!isZip(d.txtZipCode.value)) {
			strError = strError + "  - Invalid Zip Code\n     -> it should only contain numbers or '-'.\n";
	 		d.txtZipCode.focus();
		} else {
			if (d.txtZipCode.value.length < 5) { 
			  strError = strError + '  - Invalid Zip Code: at least 5 digits must be entered.\n';
				d.txtZipCode.focus();
			}
		}
	}
	
	if (strError=="") {
		d.process.value = "1";
		return true;
	} else {
	  strError2 = "There was a problem with the information you provided.\nPlease check the following:\n\n";
	  strError2 = strError2 + strError;
	  alert(strError2);
	  return false;
	}

}

function GoPressed1(e, sourcetextbox)
{
	var d = document.frmMain;	
	var key;

	if (document.all) { e = window.event; }
  if (document.layers) {
    key = e.which;		// assume netscape
	} else {
    key = e.keyCode;	// assume ie
	}
	if (key == 13)
	{
		if (ValidatePage()) {
		  SubmitMe();
		}
	}
  return false;			//cancel the event
}

function SubmitMe() {
	document.frmMain.submit();
}

function ClickSubmit() {
	var d = document.frmMain;	

	if (ValidatePage()) {
		d.butNext.disabled = true;
	  SubmitMe();
	}
}

function Cancel() {
	if (confirm("Are you sure you\nwish to cancel?")) {
	  window.location = "http://www.calyxsoftware.com";
	}
}


