﻿//United's header rollover effect
var imageURL = new Array("images/United/nav_find_equipment_on.gif", "images/United/nav_find_equipment.gif", "images/United/nav_find_supplies_on.gif", "images/United/nav_find_supplies.gif", "images/United/nav_urdata_on.gif", "images/United/nav_urdata.gif", "images/United/nav_locate_store_on.gif", "images/United/nav_locate_store.gif");
var imageInfo = new Array();
for (i = 0; i < imageURL.length; i++)
{
    imageInfo[i] = new Image();
    imageInfo[i].src = imageURL[i];
}
function rollon(iid, xid)
{
    var element = document.getElementById(iid);
    element.src = eval("imageInfo[" + xid * 2 + "].src");
}
function rolloff(iid, xid)
{
    var element = document.getElementById(iid);
    element.src = eval("imageInfo[" + (xid * 2 + 1) + "].src");
}

//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
            var loc = "category.aspx?cid=" + el.id.substring(el.id.lastIndexOf('_') + 1);
            if (el.id.indexOf("h_") == 0) //if cat clicked from header nav, switch to all tab
                loc += '&tabId=1';
            window.location = loc;
            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.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;
}

function Checkbox(ele)
{
    //used by equipment listing and category pages.
    if (ele.value == 'Enter Keyword')
        ele.value = '';
}
function CatRedirect(CatId) {
    __doPostBack('cat_redrct', CatId);
}

function SubCatRedirect(subCatId)
{
    __doPostBack('redrct', subCatId);
}
function GotoDetail(btnId, hdnId, assetId, type, pos)
{
    //called by equipment listing and auction listing page to go to detail pages.
    document.getElementById(hdnId).value = assetId + "," + type + "," + pos;
    document.getElementById(btnId).click();    
}
function ShowContextHelp(id)
{
    var top = (screen.height - 270)/2;
    var 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();

}
/* ==================== following two functions are for Image rotator control ========================= */
function RotateImages(hdnIds, imgId, interval)
{
    if (interval >0)
    {
        //no need to rotate if there's only one image.
        if (document.getElementById(hdnIds) != null  && document.getElementById(hdnIds).value.indexOf(';')>0)
            setInterval('SetImage("' + hdnIds + '", "' + imgId + '");', interval*1000);
    }
}

var current_img_idx = 0;

function SetImage(hdnIds, imgId)
{
    if (document.getElementById(hdnIds)!= null && document.getElementById(imgId)!= null)
    {
        if (document.getElementById(hdnIds).value != "")
        {
            var imgs = document.getElementById(hdnIds).value.split(';');
            if (imgs.length >1)
            {
                do
                {
                    //var pos =Math.round(Math.random() * (imgs.length-1));
                    if (current_img_idx == (imgs.length - 1))
                        current_img_idx = 0;
                    else
                        current_img_idx++;

                    var url = imgs[current_img_idx];

                }while(document.getElementById(imgId).src.indexOf(url)>-1)

                document.getElementById(imgId).src = url;       
            }
        }
    }
}
/*================== end of functions for Image rotator control ==================*/

