﻿function vieweventsIni()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
}

function endRequest(sender, e)
{
    if(e.get_error())
    {
       //if there was an error during the ajaxpost back reset the page
       window.location = window.location;
    }
    else 
    {
        //move the page to the top of the results
        var sLocation = new String(window.location)
        if(sLocation.indexOf("#results") == -1)
            window.location = window.location + "#results"
        else
            window.location = window.location
    }
}

function addListener(a, b, c, d) { if (a.addEventListener) { a.addEventListener(b, c, d); return true; } else if (a.attachEvent) { var e = a.attachEvent("on" + b, c); return e; }}

function bind(a, b, c, d) { return window.addListener(a, b, function() { d.apply(c, arguments) }); }
function handleKeystroke(evt) {
    // Grab the cross browser event
    if (!evt) evt = window.event;
    // Character code of key pressed
    var asc = !evt.keyCode ? (!evt.which ? evt.charCode : evt.which) : evt.keyCode;
    // ASCII character of above code
    var chr = String.fromCharCode(asc).toLowerCase();
    for (var i in this) {
        if (asc == i) {
            this[i](evt);
            break;
        }
    }
}
function cancelEvent(evt) {
    evt.cancelBubble = true;
    evt.returnValue = false;
    if (evt.preventDefault) evt.preventDefault();
    if (evt.stopPropagation) evt.stopPropagation();
    return false;
}
//
// KEY COMMANDS
var keyMap = new Array();
var Enter = 13;
keyMap[Enter] = test;
//
function test(evt) {    
    searchEvents();
}
bind(document, 'keydown', keyMap, handleKeystroke);
