
<!-- 

var letterexp = /[a-z]/i;	//Make sure input has at least a character
var numberexp = "0123456789";	//Make sure input has positive integers entered
var charexp = / /;	//Make sure input has no blanks
//var emailexp = /[a-z][a-z_0-9\.]+\.[a-z]{3}$/i;	//Make sure email has the proper format of name@domain.(com, edu, gov, org, etc)

browser = navigator.appName
IE = false;
NS = false;

if (browser == 'Microsoft Internet Explorer') 
	IE = true;
else
	NS = true;
	 	


function checkMaxInput(field, lngLength) {

	maxLen = lngLength; // max number of characters allowed

	if (field.value == '***Please Complete!') {
		field.value = '';
	}
	else {
		if (field.value.length > maxLen){
			if (IE) 	
				// if too long.... trim it!
				field.value = field.value.substring(0, maxLen);
			else
				// This stops the user from enter single characters, but if they hold down
				// a particular key the entry will continue.
				this.stop();
		}		
	}	
}


function isValid(pattern, str){
	return pattern.test(str);
}

function stripChars(pattern, str) {
	return str.replace(pattern,'');
}

//function validateBlank(field){
//	if (!isValid(charexp,field.value)) {
//		alert('You must enter information in this field!'); 
//		return false;
//	}	
//	else return true;
//}

//function validateEmail(field) {
//	if (!isValid(emailexp,field.value)) return false;
//	else return true;
//}

//Check field to see that negative numbers are not used
function validateNumber(field) {
	var ok = true;
	var temp;
	
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (numberexp.indexOf(temp) == "-1") ok = false;
	}
	
	if (!ok) return false;
	else return true;
}

function checkNum(field) {      // checks if all characters 
	var valid = "0123456789.";     // are valid numbers or a "."
	var ok = true;
	var checktemp;
	
	for (var i=0; i<field.length; i++) {
		checktemp = "" + field.substring(i, i+1);
		if (valid.indexOf(checktemp) == "-1") return false;
		
	}
		return true;
}

//format the field as currency
function formatDollarAmount(field) { 
	Num = field.value;
	Num = stripChars(/\$/, Num);
	dec = Num.indexOf(".");
	end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00");
	Num = "" + parseInt(Num);
	
	var temp1 = "";
	var temp2 = "";
	
    //if not true then the value contained an invalid character
	if (!checkNum(Num)) {
		alert("This does not appear to be a valid number.  Please try again.");
		noGood(field);
	}
	else { 
		if (end.length == 2) end += "0";
		if (end.length == 1) end += "00";
		if (end == "") end += ".00";

		var count = 0;
		for (var k = Num.length-1; k >= 0; k--) {
			var oneChar = Num.charAt(k);
			if (count == 3) {
				temp1 += ",";
				temp1 += oneChar;
				count = 1;
				continue;
			}
			else {
				temp1 += oneChar;
				count ++;
			}
		}
	
		for (var k = temp1.length-1; k >= 0; k--) {
			var oneChar = temp1.charAt(k);
			temp2 += oneChar;
		}
		temp2 = "$" + temp2 + end;
		field.value = temp2;
   }
}


function checkBlanks(field) {
	
	var checktemp;
	var blnFlag = true;
	var j = 0;
	
	if ((field.value.length<1)||(field.value.substring(0,3)=="***")) {
		alert("I'm sorry. This entry must be "
		+"completed before I can submit this form"
		+" for processing.");
		field.value="***Please Complete!";
		noGood(field);
		return false;
	}
	else {
		for (var i=0; i < field.value.length; i++) {
			checktemp = field.value.substring(i, i+1);
			if (isValid(charexp,checktemp)) j++;	
		}
	
		if (j == field.value.length) {
			alert('You cannot leave this field blank.');
			noGood(field);
			return false;
		}
		else return true;
	}
}


function checkEmail(field) {

var emailField = field.value;

/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern represents the range of characters allowed as
   the first character in a valid username or domain.  I just made it
   the same as above, but if you want to add a different constraint,
   you would change it here. */
var firstChars=validChars
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents at atom (basically a series of
   non-special characters.) */
var atom="(" + firstChars + validChars + "*" + ")"
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


var matchArray=emailField.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)");
	noGood(field);	
	return false;
	
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.");
	noGood(field);
	return false;
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!");
	        noGood(field);
			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.");
	noGood(field);
    return false;
}
/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl).
   If there's a country code at the end of the address, the full domain
   must include a hostname and category (e.g. host.co.uk or host.pub.nl).
   If it ends in a .com or something, make sure there's a hostname.*/

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
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) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.");
   noGood(field);
   return false;
}

/* If it ends in a country code, we want to make sure there are at
   least 2 atoms preceding it (representing host and category (i.e.
   com, gov, etc.)) */
if (domArr[domArr.length-1].length==2 && len<3) {
   var errStr="This address ends in two characters, which is a country";
   errStr+=" code.  Country codes must be preceded by ";
   errStr+="a hostname and category (like com, co, pub, pu, etc.)";
   alert(errStr);
   noGood(field);
   return false;
}

/* If it just ends in .com, .gov, etc., make sure there's a host name.
   This case can never actually happen because earlier checks take
   care of this implicitly, but we'll do it anyway. */
if (domArr[domArr.length-1].length==3 && len<2) {
   var errStr="This address is missing a hostname!";
   alert(errStr);
   noGood(field);
   return false;
}
// If we've gotten this far, everything's valid!
return true;
}

function checkZip(field) {
	var valid = "0123456789-";
	var hyphencount = 0;
	
	zipField = field.value;
	
	if (zipField.length!=5 && zipField.length!=10) {
		alert("Please enter your 5 digit or 5 digit+4 zip code.");
		noGood(field);
		return false;
		
	}
	for (var i=0; i < zipField.length; i++) {
		temp = "" + zipField.substring(i, i+1);
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") {
			alert("Invalid characters in your zip code.  Please try again.");
			noGood(field);
			return false;
		}
		if ((hyphencount > 1) || ((zipField.length==10) && ""+zipField.charAt(5)!="-")) {
			alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
			noGood(field);
			return false;
		}
	}
	return true;
}

function checkSSN(field) {

	SSNfield = field.value;

	if (SSNfield.length != 9) {
		alert("Error! A Social Insurance Number must contain exactly 9 digits, please try again.");
		noGood(field);
		return false;
	}
	else
	{
		var num1 = SSNfield.charAt(0);
		var num2 = SSNfield.charAt(1);
		var num3 = SSNfield.charAt(2);
		var num4 = SSNfield.charAt(3);
		var num5 = SSNfield.charAt(4);
		var num6 = SSNfield.charAt(5);
		var num7 = SSNfield.charAt(6);
		var num8 = SSNfield.charAt(7);
		var num9 = SSNfield.charAt(8);

		var step1 = 2 * (num2 + num4 + num6 + num8);
		var step2 = 0;
		var tempNum = Math.floor(step1 / 10000);

		step2 += tempNum;
		step1 -= (tempNum * 10000);
		tempNum = Math.floor(step1 / 1000);
		step2 += tempNum;
		step1 -= (tempNum * 1000);
		tempNum = Math.floor(step1 / 100);
		step2 += tempNum;
		step1 -= (tempNum * 100);
		tempNum = Math.floor(step1 / 10);
		step2 += tempNum;
		step1 -= (tempNum * 10);
		tempNum = Math.floor(step1 / 1)
		step2 += tempNum;
		var step3 = num1 + num3 + num5 + num7;
		tempNum = Math.floor(step3 / 1000);
		step2 += tempNum;
		step3 -= (tempNum * 1000);
		tempNum = Math.floor(step3 / 100);
		step2 += tempNum;
		step3 -= (tempNum * 100);
		tempNum = Math.floor(step3 / 10);
		step2 += tempNum;
		step3 -= (tempNum * 10);
		tempNum = Math.floor(step3 / 1)
		step2 += tempNum;

		tempNum = Math.floor(step2 / 10);
		
		valid = 10 - (step2 - (tempNum * 10));
		var num = num1 + num2 + num3 + "-" + num4 + num5 + "-" + num6 + num7 + num8 + num9;
		if (valid == 10)
			valid -= 10;
		
		return true;
		//alert(valid);
		//alert(num9);
		//if (valid == num9) msg = "is a valid";
		//else msg = "is not a valid";

		//alert(num + "\r\n\r\n" + msg + " Social Security Number.");
   }
}

function checkSelected(field) {
	
	selectField = field.selectedIndex;
	
	if (selectField == 0) {
		alert('You must select an item from the list!');
		field.focus();
		return false;
	}
	else return true;	
}

function checkNumber(field){
	if (!validateNumber(field)) {
		alert('You must enter a number and no other characters');
		noGood(field);
		return false;
	}
	else return true;
}

function checkdatekernel(dateValue) // date validation
{
	var instr=dateValue; // copy for internal reference
	var i=instr.indexOf('/'); // locate month/day delimiter - if present
	var month = parseInt(instr.substring (0,i),10) // parse Month -> integer, base 10
	var j=instr.indexOf('/',i+1) // locate month/year delimiter - if present
	var day = parseInt(instr.substring (i+1, j),10) // parse Day ->integer, base 10
	var k= instr.length // argument length
	var year = parseInt(instr.substring (j+1,k),10) // parse Year ->integer, base 10

	if ( year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 )){
		var intFebDays = 29
	}
	else{
		var intFebDays = 28
	}

	dayspermo = new Array(12);
	dayspermo[0] = 31; // Jan
	dayspermo[1] = intFebDays; // Feb
	dayspermo[2] = 31; // Mar
	dayspermo[3] = 30; // Apr
	dayspermo[4] = 31; // May
	dayspermo[5] = 30; // June
	dayspermo[6] = 31; // July
	dayspermo[7] = 31; // Aug
	dayspermo[8] = 30; // Sep
	dayspermo[9] = 31; // Oct
	dayspermo[10] = 30; // Nov
	dayspermo[11] = 31; // Dec
	
	if ((month >= 1) & // if delimiters or strings are absent in above tests, then
		(month <= 12) & // at least one of these will return false
		(day >= 1) &
		(day <=31) &
		(year >=1900) &
		(year <=3000) &
		(day <=dayspermo[month-1]))
		{return true}
	else
		{return false};
}
function checkdate(txt,field){ // DATE VALIDATION
	
	var str = field.value;
	
	if (checkdatekernel(str))
	{
		return true;
	}
	else
	{
		//alert ('Please enter a valid date format mm/dd/yyyy in the '+txt+' field.');
		alert ('Please enter a valid date format mm/dd/yyyy in the date field.');
		noGood(field);
		return false;
	}
}

function noGood(field) {
	field.focus();
	field.select();
}

//this is the script to check the form for proper data entry
function doValidation(strChecks, form){

	var aryChecks
	var chrSeparator = '/';
			
	aryChecks = strChecks.split(chrSeparator);
	
	for(var j=0;j<aryChecks.length;j++){
		var strString = aryChecks[j];
		var strCheckCode = strString.substr(0,2);
		var strFieldName = strString.substr(3);

		if (strCheckCode != 'FS'){
			var strMatchName = eval('form.' + strFieldName);
		}	
		
		switch (strCheckCode.toLowerCase())
		{
			case 'cn':
				if (checkBlanks(strMatchName)){
					if (checkNumber(strMatchName)) break;	
					else return false;
				}
				else return false;
					
			case 'cb':
				if (checkBlanks(strMatchName)) break;	
				else return false;
				
			case 'ce':
				if (checkBlanks(strMatchName)){
					if (checkEmail(strMatchName)) break;	
					else return false;
				}
				else return false;
				
			case 'cz':	
				if (checkBlanks(strMatchName)){
					if (checkZip(strMatchName)) break;	
					else return false;
				}
				else return false;		
				
			case 'cs':
				if (checkBlanks(strMatchName)){
					if (checkSSN(strMatchName)) break;	
					else return false;
				}
				else return false;
				
			case 'cc':
				if (checkSelected(strMatchName)) break;
				else return false;
				
			case 'cd':
				if (checkBlanks(strMatchName)){
					if (checkdate('', strMatchName)) break;
					else return false;	
				}
				else return false;
				
			case 'cf':
				for (var i=1; i < 4;i++) {
					var strFieldName2 = "txtMore_" + i;
					var strFieldName3 = "selOrder_" + i;
					var strInput = eval('form.' + strFieldName2);
					var strSelect = eval('form.' + strFieldName3);
					
					if ((strInput.value != "") && (strSelect.selectedIndex == 0)) {
						alert('You must select a sort order for this image!');	
						strSelect.focus();
						return false;
					}
				}
				
			case 'fs':
				form.action = strFieldName;
				form.method = "post";
				form.submit();		
		}
	}	
}

//  End -->
