var winTbl = new Array();
var menuShown = false;

function toggle_hide(id) {
    var e = document.getElementById(id);

    if (e.style.display == 'block')
    {
        winTbl[id] = setTimeout('toggle_hide2("' + id + '");', 200);
    }
        menuShown = false;
    try { setTopNavigationTab(); } catch (e) {};
}

function toggle_hide2(id) {
    var e = document.getElementById(id);

    if(e.style.display == 'block')
    {
        e.style.display = 'none';
        winTbl[id] = null;
        if (!menuShown)
        {
        toggleListBoxes("inline");        
        }
    }
}

function toggle_show(id) {
    var e = document.getElementById(id);

    if (winTbl[id] != null)
    {
        clearTimeout(winTbl[id]);
        winTbl[id] = null;
    }

    if (e.style.display == 'none')
    {
        var t = document.getElementById(id + "_SPAN");
        var m = e; // document.getElementById("WA_dropdown_menu");

        m.style.top = t.offsetTop;
        m.style.left = t.offsetLeft;
        winTbl[id] = null;
        e.style.display = 'block';
        toggleListBoxes("none");
    }
        menuShown = true;
}

function toggleListBoxes(state) {
    try
    {
    if (document.location.href.substr(document.location.href.length-4).toLowerCase() == ".htm")
        return;
    if (document.location.href.substr(document.location.href.length-1).toLowerCase() == "/")
        return;        
    if (document.location.href.substr(document.location.href.length-4).toLowerCase() == ".com")
        return;    

    var list = document.getElementsByTagName("SELECT");
    
    // the one is the region drop down list
    if (list.length <= 1)
        return;
        
    for (var i=0; i < list.length; i++)
    {
        if (list[i].id != "regionList")
        {
        list[i].style.display = state;
        }
    }
    } catch(e) {}
}   

function navigateAway(object) {
    window.location.href = object.options[object.selectedIndex].value;
}

function submitform(value) {
    window.location.href = "/apps/search/search_results.jsp?qt=" + escape(value);
}


function watchForEnterKey(e)
{
        var keynum

        if(window.event) // IE
        {
        e = window.event;
        keynum = e.keyCode;
        }
        else if(e.which) // Netscape/Firefox/Opera
        {
        keynum = e.which
        }
        if (keynum == 13)
        {
            try { e.returnValue = false; } catch(e) {};
            try { e.cancelBubble = true; } catch(e) {};
            try { e.preventDefault(); } catch(e) {};
            submitform(document.getElementById('searchBox').value);
        }
   
}

function setRegionOptions()
{
	var href = getRelativeUrl(location.href.toString());
	var url = getPartialUrl(location.href.toString());
	var list = document.getElementById("regionList");
	if (list != null)
	{
		var found = false;


		// check for exact match
		for (var ndx = 0; ndx < list.length && !found ; ndx++)
		{
			regionUrl = list.options[ndx].value.toLowerCase();
			if (regionUrl.length > 1 && href.toLowerCase() == regionUrl)
			{
				list.options[ndx].selected = true;
				found = true;
			}
		}


        if (!found)
        {
            var foundUrl = "";
		    for (var ndx = 0; ndx < list.length; ndx++)
		    {
			    regionUrl = getPartialUrl(list.options[ndx].value);
			    if (regionUrl.length > 1 && url.indexOf(regionUrl) > -1)
			    {
			        if (regionUrl.length > foundUrl.length)
			        {
				    list.options[ndx].selected = true;
				    found = true;
				    foundUrl = regionUrl;
				    }
			    }
		    }
		}

	
	}
}

function setTopNavigationTab()
{
    var url = "";
    var bcObj = document.getElementById("mainBCsWNav");
    if (bcObj != null)
    {
        if (bcObj.children.length >= 2)
        {
            url = bcObj.children[1].href;
            if (url.indexOf("#") > -1) url = "";
        }
    }
    if (url.length == 0)
    {
	    url = getPartialUrl(location.href.toString());
	}
    for(var i = 0; i <= 10; i++)
    {
        var tdObj = document.getElementById("topMenuItem" + i);
        var lnkObj = document.getElementById("topMenuLink" + i);
        if (tdObj == null || lnkObj == null) return;
        if (setTopNavigation(url, lnkObj.href, tdObj)) return;
    }
}

function setTopNavigation(url, menuUrl, object)
{
    if (menuUrl.length > 1 && url.length > 1)
    {
	    menuUrl = getPartialUrl(menuUrl);
	    if (url.indexOf(menuUrl) > -1)
	    {
	        object.className = "WA_navDown";
	        return true;
	    }
	}
	return false;
}

function getRelativeUrl(url)
{
	var i = url.indexOf("//");
	if (i > 0) url = url.substring(i+2);
	var i = url.indexOf("/");
	if (i > 0) url = url.substring(i+1);
	if (url.substring(0,1) != "/") url = "/" + url;
	return url.toLowerCase();
}

function getPartialUrl(url)
{
	var i = url.indexOf("//");
	if (i > 0) url = url.substring(i+2);
	var i = url.indexOf("/");
	if (i > 0) url = url.substring(i+1);
	var i = url.lastIndexOf("/");
	if (i > 0) url = url.substring(0,i+1);
	if (url.substring(0,1) != "/") url = "/" + url;
	return url.toLowerCase();
}

	function openPopup(url, target, width, height)
	{
		features = "height=" + height + ",width=" + width + ",scrollbars=1,resizable=1,titlebar=1,toolbar=0,menubar=1,top=10,left=10"
		window.open(url, target, features);
	}
	
	function popupDuraShock()
{
testwindow= window.open ("/durashock/durashock_popup.htm", "DuraShock_Interactive",
    "location=0,status=0,scrollbars=0,menubar=0,toolbar=0,directories=0,resizable=0,width=800,height=600");
testwindow.moveTo(0,0);
}