﻿// JScript File

// Included to prevent the FTS from being fired when the FTS text input box does not have focus.
// The exception to this rule is when the control is the username /password input control.
//
// If the Enter key is pressed, but the input is not set to the FTS 
// input control, then cancel the event
//
function validateEnterKey(evt)
{
    // Get the event
    evt = (evt) ? evt : ((window.event) ? window.event : "")

    // Set the source element
    var source = (evt.srcElement) ? evt.srcElement : evt.target;

    // If enter/return        
    if ( evt.keyCode == 13 )
    {
        // If within the login form
        if ( source.id.indexOf('_LoginPart_LoginControl_') != -1 )
        {
            // Find the submit button
            var inputs = document.getElementsByTagName('input');
            for ( var i = 0; i < inputs.length; i ++ )
            {
                if ( inputs[i].id.indexOf('_LoginPart_LoginControl_LoginButton') != -1 )
                {
                    // Simulate the login click and cancel page submit
                    inputs[i].click();
                    if ( window.event )
                    {
                        window.event.cancelBubble = true;
                    }
                    return false;
                }
            }
        }
        // Catch other enter/return clicks in IE
        else if ( window.event )
        {
            // If not in Free Text Search
            if ( window.event.srcElement.id.indexOf('_FullTextSearchTextBox') == -1 )
            {
                // Cancel page submit
                window.event.cancelBubble = true;
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    else
    {
        return true;
    }
}
