﻿//EVENT HANDLING
function Listen() {
    //listen for events
    if (window.captureEvents) {
        window.captureEvents(Event.CLICK);
        window.onclick = clickHandler;
        window.captureEvents(Event.ONMOUSEOVER);
        window.onmouseover = hoverHandler;
        window.captureEvents(Event.ONMOUSEOUT);
        window.onmouseout = outHandler;
    }
    else {
        document.onclick = clickHandler;
        document.onmouseover = hoverHandler;
        document.onmouseout = outHandler;
    }
}
//click
function clickHandler(e) {
    var el = getElement(e);
    switch (el.className) {
        case "cat": //clicked flyout; redirect
            window.location = "category.aspx?cid=" + el.id.substring(el.id.lastIndexOf('_') + 1);
            break;
    }
}
//mouseover
function hoverHandler(e) {
    var el = getElement(e),
        hdn = document.getElementById('hdnPopId'),
        id;
    switch (el.className) {
        case "hscat": //hovered over menuitem; show submenu (first hide open submenu)
        case "scat":
            id = hdn.value;
            if (id != el.id && id != '')
                document.getElementById(id).style.display = 'none'; ;
            document.getElementById(el.id + '_pop').style.display = 'block';
            hdn.value = el.id + '_pop';
            break;
        case "pop":
        case "hpop":
        case "cat": //hovered over submenu; prevent default case which is to hide submenu
            break;
        case "ComboBoxItem_Vista": //hover over dropdown option; change color (css not working in ie8)
            el.className = "ComboBoxItemHover_Vista";
            //don't break;
        default: //moused over other than menu or submenu; hide open flyout
            if (hdn != null && hdn.value != '' && el.parentNode != null && el.parentNode.className != "cat")
                document.getElementById(hdn.value).style.display = 'none';
    }
}
//mouseout
function outHandler(e) {
    var el = getElement(e);
    switch (el.className) {
        case "ComboBoxItemHover_Vista": //hovered off dropdown option; uncolor (css not working in ie8)
            el.className = "ComboBoxItem_Vista";
            break;
    }
}
//get element associated with event
function getElement(e) {
    return (typeof event !== 'undefined') ? event.srcElement : e.target;
}

//SESSION TIMEOUT
function CheckTime(ms, msg) {
    //redirect if user is idle for more than ms milliseconds. (19.5 minutes==1170000 ms)
    setTimeout('RedirectToDefault(' + ms + ', "' + msg + '");', ms);
}
function RedirectToDefault(ms, msg) {
    if (msg.toString().length > 0)
        alert(msg);

    if (window.XMLHttpRequest) {
        var req = new XMLHttpRequest();
        req.open("GET", "checkTime.aspx", false);
        req.send();

        if (req.readyState == 4) {
            if (req.responseText == "0")
                window.location = "default.aspx"; // "test.htm";
            else
                CheckTime(ms, msg);
        }
    }
}

//OTHER
//used by equipment listing and category pages to remove default text from search box
function Checkbox(ele)
{
    if (ele.value == 'Enter Keyword')
        ele.value = '';
}

//used by cat page to redirect on click of flyout
function CatRedirect(CatId) {
    __doPostBack('cat_redrct', CatId);
}
function SubCatRedirect(subCatId)
{
    __doPostBack('redrct', subCatId);
}

//used by listing page to go to detail page on click of equipno
function GotoDetail(btnId, hdnId, assetId, type, pos)
{
    document.getElementById(hdnId).value = assetId + "," + type + "," + pos;
    document.getElementById(btnId).click();
}

//used by search controls to show help popup on click of info icon
function ShowContextHelp(id)
{
    var top = (screen.height - 270)/2,
        left= (screen.width -350) /2;
    helpWindow = window.open("ContextHelp.aspx?id=" + id, 'Help', 'left=' + left + ',top=' + top + ',width=350,height=270,scrollbars=1,status=1,resize=0');
    if (window.focus) helpWindow.focus();

}
