

function goodkeys(event,good,alarm){
	kp = (window.event) ? window.event.keyCode : event.which;

	if ((kp==0)||(kp==8)||(kp==9)||(kp==13)||(kp==27)) return true
    if (event.ctrlKey) return true

	kp=String.fromCharCode(kp);

	alpha='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	num='0123456789';

	if(good=='alpha') good=alpha;
	else if(good=='num') good=num;
	else if(good=='name') good=alpha+' ';
	else if(good=='zip') good=num+'-';
	else if(good=='zipi') good=alpha+num+'-';
	else if(good=='email') good='_@.-='+alpha+num;
	else if(good=='alphanum')good=alpha+num;
	else if(!good) good=' */+-.=&()$-"_:;\'?.,'.toUpperCase()+alpha+num;
	if ( (good.indexOf(kp) >-1) )
      return true;
	else{
		if (alarm) alert("the character \""+kp+"\" is not allowed.\n\nPlease use only the following characters for this field :\n\n"+good)
		return false;
	}
}





	// This file contains the data validation JavaScript functions
	// It is included in the HTML pages with forms that need these
	// data validation routines.


// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";




/****************************************************************/

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}


/****************************************************************/

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

/****************************************************************/


function ForceEmail(objField, FieldName)
{
	var strField = new String(objField.value);
	if (!isEmail(strField)) {
		alert("The value you have entered for '" + FieldName + "' does not appear to be a valid email address.");
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}


// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) 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 = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

/****************************************************************/

// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...

function ForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert("The '" + FieldName + "' field may not be blank.\nPlease enter a value and try again.");
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}
		

/****************************************************************/

// This function determines if the string passed in is a valid
// US zip code.  It accepts either ##### or #####-####.  If the
// string is valid, it returns true, else false.

function isZipcode(strZip)
{
	var s = new String(strZip);

	if (s.length != 5 && s.length != 10)
		// inappropriate length
		return false;


	for (var i=0; i < s.length; i++)
		if ((s.charAt(i) < '0' || s.charAt(s) > '9') && s.charAt(i) != '-')
			return false;

	return true;
}

/****************************************************************/

// This function ensures that a field is less than or equal to the
// Length passed in.  You must call this function with the element
// name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
// If the field's value is too large, an error message is displayed
// and false is returned, else true is returned.

function ForceLength(objField, minLength, maxLength, strWarning)
{
	var strField = new String(objField.value);

	if (strField.length < minLength || strField.length > maxLength) {
		alert(strWarning);
		objField.focus();
		objField.select();
		return false;
	} else
		return true;
}


function ForceEqual(objField1, objField2, strWarning)
{
	var strField1 = new String(objField1.value);
	var strField2 = new String(objField2.value);
    var l1 = strField1.length;
    var l2 = strField2.length;

	if (l1 != l2 ) {
		alert(strWarning);
		objField1.focus();
		objField1.select();
		return false;
	} else {
      var n;
      for (n = 0; n < l1; n++) {
        if (strField1.charAt(n) != strField2.charAt(n)) {
  		  alert(strWarning);
	  	  objField1.focus();
		  objField1.select();
		  return false;
        }
      }
    }
    return true;
}


function ForceZip(objField1, strWarning)
{
	var strField = new String(objField1.value);
	if (!isZipcode(strField)) {
		alert(strWarning);
		objField1.focus();
		objField1.select();
		return false;
	} else
		return true;
}
