<!--
/**************************************************************************************************************
Author:				Ian Grimes,Paul Ash
Description:			This javascript include file contains edit-mask functions for the application, which 
						control what characters can be input into a given field
Type:					Javascript client-side script include
Version:				1.2
Last Modified:		15/01/2002
Changes Made:			Changed fInputValAlphaNumSpacesSpecial and fInputValAlphaSpacesSpecial so that user's can 
						input "/" character.
						Made slight change to fix bug with input of forward-slashes in validated fields.
Included In:			Various places throughout the application.
**************************************************************************************************************/

//--------------------------------------------------------------------------------
// Purpose		Validates keypresses to only allow positive numeric values
//			with only one decimal place permitted.
//	
// Parameters		strContents - text string
//			intKey - 
//
// Returns 		-1 , -  Not a valid key			
//
// History		PA 06-Nov-2002 v0.1 (Created) 
//
// Comment		NS6.2.3 and NS7 Only.Dependences : NSkeypress_valdecEVENT
//			,NSkeypress_valdec, regexpr
//--------------------------------------------------------------------------------
function NSkeypress_valdec(strContents,intKey) 
{
	var intBSkey = 8; //Back space key
	var intSysKey = 0; //Delete, Tab keys etc
	var strDp = "[.]"; //Decimal point
	var strValidKeys = "[0-9]|[.]|[" + String.fromCharCode(intBSkey) + "]|[" + String.fromCharCode(intSysKey)+"]";//allowable keys

	//Check for numbers only
	if (regexpr(String.fromCharCode(intKey),strValidKeys)==null)
	{
		return "-1"; //not valid
	}
			
	//check for already existing decimal point 
	if (regexpr(strContents,strDp)!=null && String.fromCharCode(intKey)==".")
	{
		return "-1"; //not valid
	}
}
//--------------------------------------------------------------------------------
// Purpose		Validates keypresses to only allow positive numeric values
//			with no decimal place permitted.
//	
// Parameters		strContents - text string
//			intKey - 
//
// Returns 		-1 , -  Not a valid key			
//
// History		PA 06-Nov-2002 v0.1 (Created) 
//
// Comment		NS6.2.3 and NS7 Only.Dependences : NSkeypress_valdecEVENT
//			,NSkeypress_valdec, regexpr
//--------------------------------------------------------------------------------
function NSkeypress_valnum(strContents,intKey) 
{
	var intBSkey = 8; //Back space key
	var intSysKey = 0; //Delete, Tab keys etc
	var strDp = "[.]"; //Decimal point
	var strValidKeys = "[0-9]|[" + String.fromCharCode(intBSkey) + "]|[" + String.fromCharCode(intSysKey)+"]";//allowable keys

	//Check for numbers only
	if (regexpr(String.fromCharCode(intKey),strValidKeys)==null)
	{
		return "-1"; //not valid
	}
			
}
//--------------------------------------------------------------------------------
// Purpose		Interface which routes/manages the event 
//	
// Parameters		e - event
//
// Returns 		Empty string (Success)
//			Populated string (Fail) - String contains error description.			
//
// History		PA 06-Nov-2002 v0.1 (Created) 
//
// Comment		NS6.2.3 and NS7 Only.Dependences : NSkeypress_valdecEVENT
//			,NSkeypress_valdec, regexpr
//--------------------------------------------------------------------------------
function NSkeypress_valdecEVENT(e)
{
	//get the name of the control causing the event
	var objSourceCtrl = e.target;
	if(NSkeypress_valdec(document.getElementById(objSourceCtrl.id).value,e.which)=="-1")
	{return false;}
}
//--------------------------------------------------------------------------------
// Purpose		Interface which routes/manages the event 
//	
// Parameters		e - event
//
// Returns 		Empty string (Success)
//			Populated string (Fail) - String contains error description.			
//
// History		PA 08-Nov-2002 v0.1 (Created) 
//
// Comment		NS6.2.3 and NS7 Only.Dependences : NSkeypress_valnumEVENT
//			,NSkeypress_valnum, regexpr
//--------------------------------------------------------------------------------
function NSkeypress_valnumEVENT(e)
{
	//get the name of the control causing the event
	var objSourceCtrl = e.target;
	if(NSkeypress_valnum(document.getElementById(objSourceCtrl.id).value,e.which)=="-1")
	{return false;}
}
//--------------------------------------------------------------------------------
// Purpose		Performs a regular expression match
//	
// Parameters		strString - Source of characters
//			strPattern - Regular expression pattern
//
// Returns 		strFound - Contains null if not found, vice versa		
//
// History		PA 06-Nov-2002 v0.1 (Created) 
//
// Comment		NS6.2.3 and NS7 Only. Dependences : NSkeypress_valdecEVENT
//			,NSkeypress_valdec, regexpr
//--------------------------------------------------------------------------------
function regexpr(strString,strPattern)
{
		var strRe = new RegExp(strPattern,'i');
		var strFound = strString.match(strRe);
		
		return strFound;
}

//--------------------------------------------------------------------------------
// Purpose		Performs a regular expression match and returns a array
//			of all occurances in a global search of the string.
//	
// Parameters		strString - Source of characters
//			strPattern - Regular expression pattern
//
// Returns 		aMatches - Array containing the matches	
//
// History		PA 14-Nov-2002 v0.1 (Created) 
//
// Comment		NS6.2.3, NS7 and IE 5x.
//--------------------------------------------------------------------------------
function regexprG(strString,strPattern)
{
		var strRe = new RegExp(strPattern,'gi');
		var aMatches = strString.match(strRe);
		if(aMatches==null) 
			{return 0;}
		else	
			return aMatches.length;
}

/**function for preventing user from entering anything but alphanumeric characters into a field**/
function inputValAlpha( sStr, key, shift ){
	if( key == 13 ){
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 65 && key <= 90 ){												///alpha characters
      	return true; }
	else{
		return false; }
}

/**function for preventing user from entering anything but alphanumeric characters into a field**/
function fInputValAlphaNum( sStr, key, shift ){
	if( key == 13 ){
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 48 && key <= 57 ){												///numeric characters - normal keys
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
   else if( key >= 96 && key <= 105 ){											///numeric characters - numeric keypad
      	return true; }       
   else if( key >= 65 && key <= 90 ){												///alpha characters
      	return true; }
	else{
		return false; }
}

/**function for preventing user from entering anything but numeric characters into a field**/
function fInputValNumeric( sStr, key, shift ){
	if( key == 13 ){
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 48 && key <= 57 ){												///numeric characters - normal keys
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
   else if( key >= 96 && key <= 105 ){											///numeric characters - numeric keypad
      	return true; }       	 
	else{
		return false; }
}

/**function for preventing user from entering anything but decimal values into a field**/
function fInputValDecimal( sStr, key, shift ){
	var reStr = new RegExp( "[\.]{1}" );						//reg exp for checking if user already entered decimal point
	var bIsStrValid = reStr.test( sStr );						//check if user already entered decimal point

	if( key == 13 ){
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
	else if( key >= 48 && key <= 57 ){												///numeric characters - normal keys
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
	else if( key >= 96 && key <= 105 && key != 190 && key != 110 ){			///numeric characters - numeric keypad
      	return true; }       	 
	else if( key == 190 || key == 110 ){											///decimal point "."
		if( shift ){										//check that user is not trying to enter ">" into field
			return false; }
		else{
			if( bIsStrValid ){							//if user has already entered decimal point. prevent user from entering another decimal point
				return false; }
			else{
				return true; } } }
	else{
		return false; }
}

/**function for preventing user from entering anything but numeric characters and spaces into a field**/
function fInputValNumericSpaces( sStr, key, shift ){
	if( key == 13 ){																	///return key
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 48 && key <= 57 ){												///numeric characters - normal keys
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
   else if( key >= 96 && key <= 105 ){											///numeric characters - numeric keypad
      	return true; }       	      	
	else if( key == 32 ){															///space bar
		return true; }
	else{
		return false; }
}

/**function for preventing user from entering anything but 
		alpha characters, spaces and certain special characters into a field**/
function inputValAlphaSpacesSpecial( sStr, key, shift ){
	if( key == 13 ){																///return key
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 65 && key <= 90 ){											///alpha characters
      	return true; }
	else if( key == 32 ){														///space bar
		return true; }
	else if( key == 55 || key == 57 || key == 48 ){							///"&", "(", ")"
		if( shift ){
			return true; }
		else{
			return false; } }
	else if( key >= 188 && key <= 192 ){										///",", "-", ".", "/", "'"
		if( !shift ){
			return true; }
		else{
			return false; } }
	else if( key == 187 ){														///"+"
		if( shift ){
			return true; }
		else{
			return false; } }
	else{
		return false; }
}

/**function for preventing user from entering anything but 
		alpha characters, spaces and certain special characters into a field**/
function inputValAlphaNumSpacesSpecial( sStr, key, shift ){
	if( key == 13 ){																///return key
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 65 && key <= 90 ){											///alpha characters
      	return true; }
	else if( key == 32 ){														///space bar
		return true; }
	else if( key == 49 || key == 50 || key == 55 || key == 57 || key == 48 ){			///1 2 7 9 0 ! " & ( ) characters
		return true; }
   else if( key >= 51 && key <= 54 || key == 56 ){							///other numeric characters
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
   else if( key >= 96 && key <= 105 ){										///numeric characters - numeric keypad
      	return true; }
   else if( key == 191 ){														/// ? and / characters
   		return true; }
	else if( key >= 188 && key <= 190 || key == 192 ){										///, - . ' characters
		if( !shift ){
			return true; }
		else{
			return false; } }
	else{
		return false; }
}

/**function for preventing user from entering anything but numeric characters and spaces into a field**/
function fInputValNumericSpacesBracketsDash( sStr, key, shift ){
	if( key == 13 ){																	///return key
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 49 && key <= 56 ){												///numeric characters - normal keys
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
   else if( key >= 96 && key <= 105 ){											///numeric characters - numeric keypad
      	return true; }       
	else if( key == 57 || key == 48 ){												///"9", "0", "(", ")"
			return true; }
	else if( key == 189 ){															///"-"
		if( shift ){
			return false; }
		else{
			return true; } }
	else if( key == 32 ){															///space bar
		return true; }
	else{
		return false; }
}

/**no single quotes**/
function fInputValNoSingleQuotes( sStr, key, shift ){
	if( key == 192 && shift == false){									 			///"'"
		return false; }
	else{
		return true; }
}

/**function for preventing user from entering anything but numeric characters and spaces into a field**/
function fInputValTime( sStr, key, shift ){
	var reStr = new RegExp( "[:]{1}" );						//reg exp for checking if user already entered decimal point
	var bIsStrValid = reStr.test( sStr );						//check if user already entered decimal point

	if( key == 13 ){																	///return key
		return true; }
  	else if( key == 8 || key == 9 || key == 20 || key == 39 || key == 45 || key == 46 || key == 112 || key == 122 ){
      	return true; }
	else if( key >= 16 && key <= 18 ){
		return true; }
	else if( key >= 33 && key <= 37 ){
		return true; }
	else if( key >= 114 && key <= 117 ){
		return true; }
   else if( key >= 48 && key <= 57 ){												///numeric characters - normal keys
   		if( shift ){
   			return false; }
   		else{
	      	return true; } }       
   else if( key >= 96 && key <= 105 ){											///numeric characters - numeric keypad
      	return true; }       	      	
	else if( key == 186 ){															/// : character
		if( !shift ){										//check that user is not trying to enter ">" into field
			return false; }
		else{
			if( bIsStrValid ){							//if user has already entered decimal point. prevent user from entering another decimal point
				return false; }
			else{
				return true; } } }
	else if( key == 32 ){															///space bar
		return true; }
	else{
		return false; }
}
// -->