﻿// JScript File



function fieldAdvance( e, ctrlid, ctrlIdToFocus, ctrlidprev ) 
{
    //event codes values
    //9 = tab
    //16 = shift + tab
    //37 = left arrow
    //39 = right arrow
    //13 = enter button
    //if none of these keys are pressed then go inside the if and proceed
    
    var myKeyCode
    
    if ( e.which != null)
        myKeyCode = e.which;
    else
        myKeyCode = e.keyCode;
    
    if ( myKeyCode != 9 && myKeyCode != 16 && myKeyCode != 37 && myKeyCode != 39)
    {   
        //keycode 8 = backspace
        //if the backsapce was not pressed check the length of the textbox and go forward
        if ( myKeyCode != 8 )
        {
            var ctrlToFocus = document.getElementById( ctrlIdToFocus );       
            if ( document.getElementById( ctrlid ).value.length == document.getElementById( ctrlid ).maxLength ) 
            {
                ctrlToFocus.focus();   
                ctrlToFocus.value = ctrlToFocus.value;         
            }
        }
        //if the backspace was pressed check the lenght of the textbox and go backwards
        else
        {
            var ctrlToFocus = document.getElementById( ctrlidprev ); 
            if ( document.getElementById( ctrlid ).value.length == 0 ) 
            {
                ctrlToFocus.focus();
                ctrlToFocus.value = ctrlToFocus.value;
            }
        }    
    }
}    

function ValidateNumbers(e)
{
    if (e.which != null)
    {
        //mozilla
        //do not allow anything but numbers
        if ( (e.which < 48 || e.which > 57) && e.which != 8 && e.which != 0 && e.which != 13 )
        {
            e.preventDefault(); 
        }
    }
    else
    {
        //ie
        //do not allow anything but numbers
        if ( (e.keyCode < 48 || e.keyCode > 57) && e.keyCode != 13 )
        {       
            e.keyCode = 0;
        }
    }
}