﻿var hasFocus = null; // Used to indicate which control has the focus at any given time

function setFocus(obj) //sets the hasFocus variable to the element which has received the focus (via onfocus event)
{
    hasFocus = obj;
}
function loseFocus() // clears the hasFocus variable when the element loses focus (via onblur event)
{
    hasFocus = null;
}

document.onkeypress =
function checkKeyPress(e)
{
    if(!e)
        e = window.event;
    
    var key = (typeof e.which == 'number') ? e.which : e.keyCode;
    
    if(key == 13)
    {
        handleKP();
        return (false);
    }
}

function handleKP()
{
    if (hasFocus == null) return (false);
    
    switch (hasFocus.id)
    {
        case "ctl00_TextBoxSearch":
        case "ctl00_TextBoxSearchAge":
        case "ctl00_TextBoxSearchPriceStart":
        case "ctl00_TextBoxSearchPriceEnd":
            document.getElementById('ctl00_btnSearch').click();
            break;
        case "ctl00_LoginView1_Login1_UserName":
        case "ctl00_LoginView1_Login1_Password":
            document.getElementById('ctl00_LoginView1_Login1_LoginButton').click();
            break;
        default:
            break;
    }
    return (false);
}

