//<!--
/*  Author          : Object Structure CEM. Functions CMP with a little advice from MFC/SC!
	Date            : 19/06/1998 & 19/07/2002
	Updates
	=======
	17/07/2002 (RHH) Converted functions from Visual Basic
	19/06/2002 (CEM) Put all the functions into a JavaScript Object
	24/05/2006 (RMA) Extended for better browser compatibility
	-------------------------------------------------------------------------------
*/

//Define functions that will be used by the Mask Object

    function Mask_AlphasOnly(e, sValids)
    {
		/*  Author          : CMP with a little advice from MFC/SC!
			Date            : 18/06/1998
			Updates
			=======
			17/07/2002 (RHH)
			Converted from Visual Basic
			24/05/2006 (RMA)
			Removed uppercase / lowercase conversion (wasn't firefox compatible).
			Extended to allow backspace, delete, tab, and cursor keys through.
			-------------------------------------------------------------------------------
			This procedure will only allow characters from A-Z / a-z in a control.
			Will also only allow characters specified in the string sValids.
		*/
		
        if (Mask_IsAlpha(e)) 
			return true;
			
		if (Mask_IsSpecific(e, sValids))
			return true;
			
		if (Mask_IsUsualAllowableControl(e))
			return true;
				
		CancelKeyPressEvent(e);
		return false;
    }

    function Mask_NumbersOnly(e, sValids)
    {
		/*  Author          : CMP with a little advice from MFC/SC!
			Date            : 18/06/1998
			Updates
			=======
			17/07/2002 (RHH)
			Converted from Visual Basic
			24/05/2006 (RMA)
			Removed uppercase / lowercase conversion (wasn't firefox compatible).
			Extended to allow backspace, delete, tab, and cursor keys through.
			-------------------------------------------------------------------------------
			This procedure will only allow characters from 0-9 in a control.
			Will also only allow characters specified in the string sValids.
		*/

        if (Mask_IsNumeric(e)) 
			return true;
			
		if (Mask_IsSpecific(e, sValids))
			return true;
			
		if (Mask_IsUsualAllowableControl(e))
			return true;
				
		CancelKeyPressEvent(e);
		return false;
	}


    function Mask_AlphaNumerics(e, sValids)
    {
		/*  Author          : CMP with a little advice from MFC/SC!
			Date            : 18/06/98
			Updates
			=======
			17/07/2002 (RHH)
			Converted from Visual Basic
			-------------------------------------------------------------------------------
			This procedure will only allow characters from A-Z and 0-9 in a control.
			Will also only allow characters specified in the string sValids.
		*/

        if (Mask_IsNumeric(e)) 
			return true;
			
        if (Mask_IsAlpha(e)) 
			return true;
			
		if (Mask_IsSpecific(e, sValids))
			return true;
			
		if (Mask_IsUsualAllowableControl(e))
			return true;
				
		CancelKeyPressEvent(e);
		return false;
    }
	
	
	//Cancel an event to stop the character reaching the input
	function CancelKeyPressEvent(e)
	{
		//alert('block'+'  key='+e.keyCode+'   char='+e.charCode+'  which='+e.which);
	
		try 
		{
			//clear keyCode in IE 6
			if (e.keyCode)
				e.keyCode=0;
		}
		catch(ex)
		{
			//firefox uses e.keyCode for some 'special' characters,
			// but will not allow e.keyCode to be set.
		}
		if (e.returnValue)
			e.returnValue=false;
			
		if (e.preventDefault)
			e.preventDefault();
	}
		
	function Mask_GetKeyCode(e)
	{
		return (e.charCode?e.charCode:e.keyCode);
	}
	
	function Mask_GetCharCode(e)
	{
		var iCharCode = undefined;
		
		if (!(e.charCode == undefined))
			iCharCode = e.charCode; //FF
		else if (!(e.which == undefined))
			iCharCode = e.which; //NN
		else
			iCharCode = e.keyCode; //IE
			
		return iCharCode;
	}
	
	function Mask_IsReturn(e)
	{
		var iCharCode = Mask_GetKeyCode(e);
		if (iCharCode == 13)
			return true;
		return false;
	}
	
	
	function Mask_IsSpecific(e, sValids)
	{
		if (sValids == undefined)
			return false;
		var iCharCode = Mask_GetCharCode(e);
		if (sValids.indexOf(String.fromCharCode(iCharCode)) != -1)
			return true;
		return false;
	}
	
	function Mask_IsUsualAllowableControl(e)
	{
			
		if (Mask_IsBackspace(e))
			return true;
		
		if (Mask_IsDel(e))
			return true;
		
		if (Mask_IsTab(e))
			return true;
						
		if (Mask_IsCursor(e))
			return true;
			
		if (Mask_IsEscape(e))
			return true;
			
		return false;
	}
	
	function Mask_IsDel(e)
	{
		//must allow del key through in FF, otherwise the delete key cannot remove characters
		
		//Firefox 1.5 : key=46 char=0 which=0
		//IE 6 : No Event
		//IE 7 : No Event
		//Opera 9 : key=0 char=undefined which=0
				
		if (e.keyCode==46 && e.charCode==0 && e.which==0)
			return true;
		return false;
	}
	
	function Mask_IsEscape(e)
	{
		if (e.keyCode==27)
			return true;
		return false;
	}
	
	function Mask_IsBackspace(e)
	{
		//must allow backspace key through in FF
		if (e.keyCode==8)
			return true;
		return false;
	}
	
	function Mask_IsTab(e)
	{
		//must allow tab key through in FF
		if (e.keyCode==9)
			return true;
		return false;
	}
	
	function Mask_IsCursor(e)
	{
		//must allow through cursor keys in FF
		
		// cursor keys in firefox have key 37-40 & char 0 & which 0
		// IE 7 uses key 37-40 & char 37-40 & which undefined
		// IE 6 uses key 37-40 & char undefined & which undefined
		// Opera uses key 37-40 & char 0 & which 0, but blocking the event has no effect
		
		if (e.keyCode==37 && e.charCode == 0 && e.which == 0)
			return true;
		if (e.keyCode==38 && e.charCode == 0 && e.which == 0)
			return true;
		if (e.keyCode==39 && e.charCode == 0 && e.which == 0)
			return true;
		if (e.keyCode==40 && e.charCode == 0 && e.which == 0)
			return true;
		return false;
	}
	
	function Mask_IsNumeric(e)
	{
		var iCharCode = Mask_GetCharCode(e);
		if ((iCharCode >= 48 && iCharCode <= 57)) 
			return true;
		return false;
	}
	
	function Mask_IsAlpha(e)
	{
		var iCharCode = Mask_GetCharCode(e);
				
		if ((iCharCode >= 65 && iCharCode <= 90) 
			 || (iCharCode >= 97 && iCharCode <= 122)) 
			return true;
		return false;
	}
	
	function Mask_WithCapsLockOn(e)
	{
		var bWithShift = Mask_WithShiftKey(e);
		var iCharCode = Mask_GetCharCode(e);
		
		var bWithCapsLockOn = ( iCharCode >= 65 && iCharCode <= 90 && !bWithShift ) 
							|| ( iCharCode >= 97 && iCharCode <= 122 && bWithShift );
							
		return bWithCapsLockOn;
	}
	
	function Mask_WithShiftKey(e)
	{
		if (e.shiftKey)
			return true;
		
		if (e.modifiers && (e.modifiers & 4))
			return true;
		
		return false;
	}
		/*
	function Mask_TelephoneNumber(keyCode, pControl)
    {
		/ *  Author          : CMP with a little advice from MFC/SC!
			Date            : 18/06/98
			Updates
			=======
			17/07/2002 (RHH)
			Converted from Visual Basic
			-------------------------------------------------------------------------------
			This procedure will only allow characters from A-Z and 0-9 in a control.
			Will also only allow characters specified in the string sValids.
		* /

		var objMask = new Mask();
					
		var sOnceOnlyCharacter;
		var curContent;
		var range;
		var sSelectedText;
		var iSelStart;
		var iSelEnd;
		var iSelLength;
			
		curContent = pControl.value;
		
		if (keyCode == 40)  // Open brace character
			iOnceOnlyCharacter = 40;
		else if (keyCode == 41) // Close brace character
			iOnceOnlyCharacter = 41;
		else if (keyCode == 43) // Plus character
			iOnceOnlyCharacter = 43;
		else
			iOnceOnlyCharacter = -1;

// Character that only allowed once detected?			
		if (iOnceOnlyCharacter != -1)
		{			
		
//  Does the character already exist? if so suppress the new one
			if(curContent.indexOf(String.fromCharCode(iOnceOnlyCharacter)) > -1)
				keyCode = 0;

		}
		else
			keyCode = this.numbersOnly(keyCode," ");

        return keyCode;

    }

	function Mask_date(keyCode,pControl)
	{
		/ *  
		Author          : SS
		Date            : 17/06/2005
			
		-------------------------------------------------------------------------------
			Allows Masking to be entered for a date in the format of DDMMYY. To lasy to do the rest
			but might get round to doing it.
		* /
		switch(pControl.value.length)
		{
			case 0:
				if(keyCode < 48 || keyCode > 51)
          			keyCode = 0;
			break;
			case 1:
				if(pControl.value.substring(0,1) == "3")
				{
					if(keyCode < 48 || keyCode > 49)
	          			keyCode = 0;
				}
				else
				{
					if(keyCode < 48 || keyCode > 57)
	          			keyCode = 0;
				}
			break;
			case 2:
				if(keyCode < 48 || keyCode > 49)
	          			keyCode = 0;
			break;
			case 3:
				if(pControl.value.substring(3,2) == "1")
				{
					if(keyCode < 48 || keyCode > 50)
	          			keyCode = 0;
				}
				else
				{
					if(keyCode < 49 || keyCode > 57)
	          			keyCode = 0;
				}
			break;
		}
		return keyCode;
	}
	function Mask_hoursOnly(keyCode, pControl)
	{
		/ *  
		Author          : KMF
		Date            : 24/05/2004
			
		-------------------------------------------------------------------------------
			This process allows only an hour string to be inserted into a HTML text box
			this allows between 0 and 23 to be inserted
		* /
		var curContent = "";
		var range;
		var sSelectedText;
		var iSelStart = 0;
		var iSelEnd;
		var iSelLength;
		
		if (pControl != "")
			curContent = pControl.value;
			
		range = document.selection.createRange();
			
		sSelectedText = range.text;
		
		if(sSelectedText.length > 0)
		{
			iSelStart = curContent.indexOf(sSelectedText);
			iSelEnd = iSelStart + sSelectedText.length;
			iSelLength = sSelectedText.length;
		}
		else
		{
			if (pControl != "")
				iSelStart = curContent.length;
		}
		if(iSelStart == 0)
		{			
			if ((keyCode < 48 || keyCode > 50) && (keyCode != 13))
          			keyCode = 0;
		}
		else if(iSelStart == 1)
		{
			if(curContent.substring(0,1) <= "2")
			{			
				if(curContent <= "1")
				{					
					if ((keyCode < 48 || keyCode > 57) && (keyCode != 13))
           				keyCode = 0;
				}
				else
				{							
					if ((keyCode < 48 || keyCode > 51) && (keyCode != 13))
	           			keyCode = 0;
				}
			}
			else
				keyCode = 0;
		}
		else if(iSelStart == 2)
		{
			if ((keyCode < 48 || keyCode > 53) && (keyCode != 13))
				keyCode = 0;
		}
		return keyCode;
	}
	*/
		
	function Mask()
	{
		/*  Author          : CEM
			Date            : 19/07/2002
			Version			: 1.0
			Updates
			=======
			-------------------------------------------------------------------------------
			This object is to be used when masking keyboard input.
			13/05/04	RHH		Add telephone number mask
			24/05/06	RMA		Removed methods which are not compatible
		*/

		this.sVersion = "2.0";
	
		this.alphaNumerics = Mask_AlphaNumerics;
		this.numbersOnly = Mask_NumbersOnly;
		this.alphasOnly = Mask_AlphasOnly;
		
		this.isReturn = Mask_IsReturn;
		this.isEscape = Mask_IsEscape;
		
		this.isNumeric = Mask_IsNumeric;
		this.isAlpha = Mask_IsAlpha;
		
		this.withCapsLockOn = Mask_WithCapsLockOn;
		this.withShiftKey = Mask_WithShiftKey;
		
		//these need to be rewritten if they are to be included:
		//this.telephoneOnly = Mask_TelephoneNumber;
		//this.hoursOnly = Mask_hoursOnly;
		//this.dateOnly = Mask_date;
		
		
	}
	
	function TestObjMask()
	{
		//exists
	}
	
	
	function checkMovementKeys(iKeyCode)
	{	// always allow movement keys
		var bKeyFound = false;
		
		switch (iKeyCode)
		{
			case 8:
			case 9:
			case 13:
			case 35:
			case 36:
			case 37:
			case 38:
			case 39:
			case 40:
			case 46:
				bKeyFound = true;
			break;
			
			default:
			break;
		}
		
		
		return bKeyFound;
	}
//-->