var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 ); 
 
function autoTab( input, len, e ) 
{ 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	var formName = document.forms[0].id;

	if( input.value.length >= len && !containsElement( filter, keyCode )) 
	{ 
		input.value = input.value.slice( 0, len ); 
		input.form[( getIndex( input ) + 1 ) % input.form.length].focus(); 
	} 
	return true; 
} 

function autoTabNum( input, len, e ) 
{ 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	var formName = document.forms[0].id;
	var IsNumber = IsNumeric(input.value);

	if( input.value.length >= len && !containsElement( filter, keyCode )) 
//	if( input.value.length >= len && !containsElement( filter, keyCode ) && anyIntInputOnly(input.value) == true) 
//	if( input.value.length >= len && !containsElement( filter, keyCode ) && IsNumeric(input.value) == true) 
	{ 
		input.value = input.value.slice( 0, len ); 
		input.form[( getIndex( input ) + 1 ) % input.form.length].focus(); 
	} 
/*	else 
	{
		if(IsNumeric(input.value)== false)
		{
						
//			form.BP_ValidatedPhone1_ReqErrLabel.text = "Only numeric values are accepted!";
//			input.value = input.value.slice( 0, input.value.length -1 );
//			alert(input.value);
		} */
//	}
	return true; 
} 

function anyIntInputOnly(e) { // KEYPRESS event 
// returns true if 0-9, - or BS hit, or can't get key value; otherwise false 

  var k = -1; 

  if (e && e.which) 
  {
    k = e.which; // NS 
    return (k > -1 ? ((k > 47 && k < 58) || k == 8) : true);
  }
  else if (window.event && window.event.keyCode) 
  {
    k = window.event.keyCode; // IE 
    window.event.returnValue = (k > -1 ? ((k > 47 && k < 58) || k == 8) : true);
  }
} // anyIntInputOnly()


   function checkKeyStroke (evt) { 
     var keyCode = evt.keyCode ? evt.keyCode : 
                   evt.charCode ? evt.charCode : evt.which; 
     return /\d/.test(keyCode); 
   } 

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function typedChar( input,len, e ) { 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
//	alert(e.keyCode);
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; 
//	if( input.value.length >= len && !containsElement( filter, keyCode )) { 
//	if( input.value.length >= len && !containsElement( filter, keyCode ) && !checkNumeric(input, 1, len, "", "")) { 
	if( input.value.length >= len && !containsElement( filter, keyCode ) && !checkNumeric(input, 1, len)) { 
	input.value = input.value.slice( 0, len ); 
	input.form[( getIndex( input ) + 1 ) % input.form.length].focus(); 
	} 
	return input.value; 
}  
 
function containsElement( arr, ele ) { 
	var found = false, index = 0; 
	while( !found && index < arr.length ) 
	if( arr[index] == ele ) { 
		found = true; 
	} else { 
		index++; 
	} 
	return found; 
} 
 
function getIndex( input ) { 
	var index = -1, i = 0, found = false; 
	while ( i < input.form.length && index == -1 ) 
	if ( input.form[i] == input ) { 
		index = i; 
	} else { 
		i++; 
	} 
	return index; 
} 

/*

 HTML Implementation

<input onKeyUp="return autoTab( this, 3, event );" size=3> 
<input onKeyUp="return autoTab( this, 3, event );" size=3> 
<input onKeyUp="return autoTab( this, 4, event );" size=4>

*/

// function checkNumeric(objName,minval, maxval,comma,period,hyphen)
function checkNumeric(objName, minval, maxval)
{
	var numberfield = objName;
//	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	if (chkNumeric(objName, minval, maxval) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

// function chkNumeric(objName,minval,maxval,comma,period,hyphen)
function chkNumeric(objName, minval, maxval)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789"; // + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

// alert(checkOK);

for (i = 0;  i < checkStr.value.length;  i++)
{
	ch = checkStr.value.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length)
	{
		allValid = false;
		break;
	}
	if (ch != ",")
	{
		allNum += ch;
	}
if (!allValid)
{	
	alertsay = "Please enter only these values \""
	alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
	alert(alertsay);
	return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
		if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
		{
			alertsay = "Please enter a value greater than or "
			alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
			alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
			alert(alertsay);
			return (false);
		}
	}
}

function ShowDiv(divname)
{
    var divobj = document.getElementById(divname);
    if(divobj != null)
    {
        //alert(divname + ' display = ' + divobj.style.display);
        divobj.style.display = "inline";
    }
}

function HideDiv(divname)
{
    var divobj = document.getElementById(divname);
    if(divobj != null)
    {
        //alert(divname + ' display = ' + divobj.style.display);
        divobj.style.display = "none";
    }
}
