﻿//
// OnlyAllowLatLong - Called from onkeypress event, rejects non-integers but allows .
//
function OnlyAllowLatLong(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x08\x0D0\x2E\x2D]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}


//
// OnlyAllowPhoneNumbers - Called from onkeypress event, rejects non-integers
//
function OnlyAllowPhoneNumbers(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter},-,.,(,)}
	var reKeyboardChars = /[\x00\x08\x0D\x2D\x2E\x28\x29]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}

//
// OnlyAllowTime - Called from onkeypress event, rejects non-integers but allows :
//
function OnlyAllowTime(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x08\x0D0\x3A]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}

//
// OnlyAllowNumbers - Called from onkeypress event, rejects non-integers
//
function OnlyAllowNumbers(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x08\x0D0]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}

//
// OnlyAllowNumbers - Called from onkeypress event, rejects non-integers and ensures field value is in between the min and max values inclusive
//
function OnlyAllowNumbers(field, e, minValue, maxValue)
{
    var tmpRtn = true;

	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x3a\x08\x0D0]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode(keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
	  tmpRtn = false;
	}  
	else
	{
	     // check if character is in the range
	      // get string representation of the whole number
	     var strNum = field.value + strChar;
	     var value = parseInt (strNum);
	     
	     // number not in range?
	     if(value < minValue || value > maxValue)
	     {
		    // value is not in the range
		    tmpRtn = false;
		}
	}

	// Valid character or special key, allow key press
	return tmpRtn;
}

//
// OnlyAllowMoney - Called from onkeypress event, rejects non-integers but allow . and $
//
function OnlyAllowMoney(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x08\x0D0\x24\x2E]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}

//
// OnlyAllowDateNumbers - Called from onkeypress event, rejects non-integers
//
function OnlyAllowDateNumbers(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter},-,/,.}
	var reKeyboardChars = /[\x00\x08\x0D0\x2D\x2F\x2E]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}
function OnlyAllowUSZip(field, e)
{ 
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}, {-}}
	var reKeyboardChars = /[\x00\x08\x0D0\x2D]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}

//
// OnlyAllowSSN - Called from onkeypress event, rejects non-integers but allows -
//
function OnlyAllowSSN(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x08\x0D\x2D]/;

	// Numeric characters
	var reValidChars = /\d/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);

	// Block non-numeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}

//
// OnlyAllowAlphaNumerics - Called from onkeypress event
//
function OnlyAllowAlphanumerics(field, e)
{
	// Special keyboard keys - Netscape 6 passes these to onkeypress
	// {{Home, End, Delete, Arrow Keys}, {Backspace}, {Enter}}
	var reKeyboardChars = /[\x00\x08\x0D]/;

	// Alphanumeric characters
	var reValidChars = /[0-9,A-Z,a-z]/;

	// Grab event key code and character (method depends on browser)
	var keycode = window.Event ? e.which : e.keyCode;
	var strChar = String.fromCharCode (keycode);
	
	// Block non-alphanumeric characters and non-special keys
	if (!reValidChars.test (strChar) && !reKeyboardChars.test (strChar))
	{
		// Invalid character, reject key press
		return false;
	}  

	// Valid character or special key, allow key press
	return true;
}
