
<!--
/* Header
**
** Author: Lee Chastain
**
** Purpose:  The purpose of this file is to provide a common repository of the
**			javascript needed for specific keyboard validations.
**
** Known Using Context(s):
**		MOST of the .aspx pages in CMW
**
** Filename: validations.js
**
** Change Log:
**
** Date		   Change												Initials
** ----------  -------------------------------------	 			--------- 
** 08/17/2007  Added the header, allowed numeric keypad 				LC
**				within the 'isNumValid' function.
** 08/21/2007  Added the isAlphanum() function.							LC
*/

	
var keys = new Array (8, 9, 13, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 116);

function isNumValid()
{
	var keyCode = window.event.keyCode;
	if(window.event.shiftKey) return false;  // Disallow 'Shift'
	if(window.event.altKey) return false;    // Disallow 'Alt'
	return (
		((keyCode >= 48 && keyCode <= 57) || (keyCode >=96 && keyCode <= 105))
		|| isAuxKey(keyCode)
	);

}
		
function isAlphanum()
{
	var test1 = isNumValid();
	var test2 = isLetterValid();
	
	return( test1 | test2 );
}
		
function isAuxKey(keyCode)
{
	for (i=0; i<keys.length; i++)
	{
		if (keyCode == keys[i])
		{						
			return true;
		}
	}	
		
	//allow the control key for ctrl+c, v, x, etc
	if (window.event.ctrlKey)
	{				
		return true;					
	}			
	
	return false;				
}

function isLetterValid()
{
	var keyCode = window.event.keyCode;

	return (
				(keyCode >= 65 && keyCode <= 90)  || 
				(keyCode >= 97 && keyCode <= 122) || 
				isAuxKey(keyCode)
			);

}


function FormatWithCommas(objNum)
{
    var num = objNum.value;
    var ent, dec;
    if (num != '' && num != objNum.oldvalue)
    {
          num = MoneyToNumber(num);
          if (isNaN(num))
          {
                objNum.value = objNum.oldvalue;
          }
          else
          {
                var ev = (navigator.appName.indexOf('Netscape') != -1)?Event:event;
                if (ev.keyCode == 190 || !isNaN(num.split('.')[1]))
                {
                      objNum.value = AddCommas(num.split('.')[0])+'.'+num.split('.')[1];
                }
                else
                {
                      objNum.value = AddCommas(num.split('.')[0]);
                }
                objNum.oldvalue = objNum.value;
          }
    }
}

function MoneyToNumber(num)
{
    return (num.replace(/,/g, ''));
    
}

function AddCommas(num)
{
    numArr=new String(num).split('').reverse();
    for (i=3;i<numArr.length;i+=3)
    {
          numArr[i]+=',';
    }
    return numArr.reverse().join('');
}

function roll_over(img_name, img_src)
{
    document[img_name].src = img_src;
}

//-->
