﻿function Goto(url) {
    window.location.href = url;
}

function GetCtrl(ctrlId) {
    return document.getElementById(ctrlId);
}

function DoButtonClick(btnId) {
    var btnCtrl = GetCtrl(btnId);

    if (!btnCtrl) return false;

    if (btnCtrl.dispatchEvent) {
        //check if this is an href link
        var linkHref = btnCtrl.getAttribute("href");

        //get event for the normal click functionality
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        btnCtrl.dispatchEvent(e);

        //incase of an link, trigger the link
        if (linkHref) {
            location.href = linkHref;
        }
    }
    else {
        btnCtrl.click();
    }

    return false;
}

// onkeypress="return CheckIfHitEnter(event,'ctl00_page_header_ibt_doLogin')"  />
function CheckIfHitEnter(e, btnId) {
    if (e && e.keyCode == 13) {
        DoButtonClick(btnId);
        return false;
    }

    return true;
}


function HitLogin() {
    //DoButtonClick('ctl00_PlaceHolderMiniConsole_explitLogout_ExplicitLogin');
    var oldURL = window.location.hostname + window.location.pathname;
    var newURL = "https://" + oldURL;
   //alert("newURL: " + newURL );
    window.location = newURL;
}
/*--------------------------------------------------------------------------------------------------------------------------------*/

function autoscroll(id) {
    var mousx = 0;
    var mousy = 0;
    var dobj = GetCtrl(id);
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        mousx = e.pageX;
        mousy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        mousx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        mousy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    var offx = offy = 0;
    while (dobj) // calculate the actual x&y offsets of the element to be scrollled 
    {
        offx += dobj.offsetLeft;
        offy += dobj.offsetTop;
        dobj = dobj.offsetParent;
    }
    relx = mousx - offx; // Relative mouse positions wrt the element
    rely = mousy - offy;
    dobj = GetCtrl(id); ;
    var margn = dobj.offsetWidth / 10;
    if (relx < margn) relx = margn;
    if (relx > (dobj.offsetWidth - margn)) relx = dobj.offsetWidth - margn;
    dobj.finy = parseInt((dobj.scrollHeight - dobj.offsetHeight) * (rely - margn) / (dobj.offsetHeight - 2 * margn));
    dobj.finx = parseInt((dobj.scrollWidth - dobj.offsetWidth) * (relx - margn) / (dobj.offsetWidth - 2 * margn));
    if (!dobj.speedy && !dobj.speedx) // If not already scrolling
    {
        dobj.speedy = 0;
        dobj.speedx = 0;
        scrollToFin(id);
    }
}
function scrollToFin(id) {
    obj = GetCtrl(id);
    //obj.speedy=((obj.finy-obj.scrollTop)/8+obj.speedy)/2; // it tries to bring speed gradually to (distance/4) ......
    obj.speedx = ((obj.finx - obj.scrollLeft) / 8 + obj.speedx) / 6;
    if (Math.abs(obj.scrollTop - obj.finy) < 1) {
        obj.scrollTop = obj.finy;
        obj.speedy = null;
    }
    else obj.scrollTop += parseFloat(obj.speedy);
    if (Math.abs(obj.scrollLeft - obj.finx) < 1) {
        obj.scrollLeft = obj.finx;
        obj.speedx = null;
    }
    else obj.scrollLeft += parseFloat(obj.speedx);
    if (obj.scrollTop != obj.finy || obj.scrollLeft != obj.finx) {
        setTimeout("scrollToFin('" + id + "')", 18);
    }
    else {
        obj.speedy = null;
        obj.speedx = null;
    }
}


/*--------------------------------------------------------------------------------------------------------------------------------*/

var activeSubMenus = new Array();
var activeMenuHideTime = null;

function showSubMenu(controlId, hide, activeCtrlId) {
    hideSubMenus(controlId,null);

    var ctrl = GetCtrl(controlId);
    var activeCtrl = GetCtrl(activeCtrlId);

    if (ctrl == null) {
        if (activeCtrl != null) activeCtrl.style.display = "block";
        return;
    }

    if (!hide) {
        if (activeCtrl != null) activeCtrl.style.display = "none";
        ctrl.style.display = "block";
        
        activeSubMenus[ctrl.id] = {
            Id: ctrl.id,
            Ctrl: ctrl
        };
    }
    else {
        clearTimeout(activeMenuHideTime);
        activeMenuHideTime = setTimeout("hideSubMenus(null,'" + activeCtrlId + "');", 3000);
    }
    
    return;
}

function pinSubMenu(activeCtrlId) {
    clearTimeout(activeMenuHideTime);
    activeMenuHideTime = setTimeout("hideSubMenus(null,'" + activeCtrlId + "');", 3000);
}

function hideSubMenus(controlId, activeCtrlId) { 
    clearTimeout(activeMenuHideTime);
    activeMenuHideTime = null;

    var foundActiveRolloverMenu = false;
    for (var index in activeSubMenus) {
        if (activeSubMenus[index].Ctrl == null) continue;
        
        if (controlId == activeSubMenus[index].Id) {
            foundActiveRolloverMenu = true;
            activeSubMenus[index].Ctrl.style.display = "block";
            continue;
        }
        
        activeSubMenus[index].Ctrl.style.display = "none";
    }

    var activeCtrl = GetCtrl(activeCtrlId);
    if (!foundActiveRolloverMenu)         
        if (activeCtrl != null) activeCtrl.style.display = "block";    
    else
        if (activeCtrl != null) activeCtrl.style.display = "none";    
}

/*--------------------------------------------------------------------------------------------------------------------------------*/

