function ShowLogin()
{
    var loginLinksLayer = 'loginLinks';
    var loginFieldsLayer = 'loginFields';

    if (document.getElementById(loginLinksLayer).style.display == "block") {
        document.getElementById(loginLinksLayer).style.display = "none";
        document.getElementById(loginFieldsLayer).style.display = "block";
    }
}
function toggleShowLogin()
{
    var loginLinksLayer = 'uloginOut';
    var loginFieldsLayer = 'uloginForm';

    if (document.getElementById(loginLinksLayer).style.display == "block") {
        document.getElementById(loginLinksLayer).style.display = "none";
        document.getElementById(loginFieldsLayer).style.display = "block";
    } else {
        document.getElementById(loginLinksLayer).style.display = "block";
        document.getElementById(loginFieldsLayer).style.display = "none";
    }
}
function goToSeeBenefitsUrl() {
    window.location = 'http://' + location.host + '/1320-20_4-133.html?tag=dhd_why&path=' + urlEncode(location.href);
}
function goToForgotPasswordUrl() {
    window.location = 'http://' + location.host + '/1328-20_4-133.html?tag=dhd_fg&path=' + urlEncode(location.href);
}
function urlEncode(path) {
    if (path.indexOf('%') > -1) {
        return path;
    } else {
        return escape(path);
    }
}

function ShowTab(sTabLayers,sTabs,sImageNameBases,iIndex)
{
    var aTabLayers = sTabLayers.split(",");
    var aTabs = sTabs.split(",");
    var aImageNameBases = sImageNameBases.split(",");
    var i = 0;

    for(i=0;i<aTabLayers.length;i++)
    {
        //turn off all tab sections
        document.getElementById(aTabLayers[i]).style.display = "none";

        //turn off all tabs themselves
        document.getElementById(aTabs[i]).src = "/i/dl/doors/" + aImageNameBases[i] + "_off.gif";
    }

    //display the correct tab section and tab image (according to the arguments passed in to this function)
    var sSectionDivId = aTabLayers[iIndex];
    var sTabImageId = aTabs[iIndex];
    document.getElementById(sSectionDivId).style.display = "block";
    document.getElementById(sTabImageId).src = "/i/dl/doors/" + aImageNameBases[iIndex] + "_on.gif";
}

function MouseOverTab(sTabs, sImageNameBases, iIndex)
{
    var aTabs = sTabs.split(",");
    var aImageNameBases = sImageNameBases.split(",")
    var sTabId = aTabs[iIndex];
    var sTabName = aImageNameBases[iIndex];

    var sImage = document.getElementById(sTabId).src;
    sImage = sImage.substring(sImage.length-6,sImage.length-4)
    if (sImage != "on")
    {
        document.getElementById(sTabId).src = "/i/dl/doors/" + sTabName + "_over.gif";
    }
}

function MouseOutTab(sTabs, sImageNameBases, iIndex)
{

    var aTabs = sTabs.split(",");
    var aImageNameBases = sImageNameBases.split(",")
    var sTabId = aTabs[iIndex];
    var sTabName = aImageNameBases[iIndex];

    var sImage = document.getElementById(sTabId).src;
    sImage = sImage.substring(sImage.length-6,sImage.length-4)
    if (sImage != "on")
    {
        document.getElementById(sTabId).src = "/i/dl/doors/" + sTabName + "_off.gif";
    }
}



//imgExpandCollapse[1..n]  for expand/coll images
//tablayer-result-1          for divs

function ExpandCollapse(sDivIndex)
{
    if (document.getElementById("tablayer-result-" + sDivIndex).style.display == "block")
    {
        document.getElementById("tablayer-result-" + sDivIndex).style.display = "none";
        document.getElementById("tablayer-result-lw-" + sDivIndex).style.display = "none";
        document.getElementById("imgExpandCollapse" + sDivIndex).src = "/i/dl/listings/icon_expand.gif";
    }
    else
    {
        document.getElementById("tablayer-result-" + sDivIndex).style.display = "block";
        document.getElementById("tablayer-result-lw-" + sDivIndex).style.display = "block";
        document.getElementById("imgExpandCollapse" + sDivIndex).src = "/i/dl/listings/icon_collapse.gif";
    }
}


function ExpandAll(max)
{
    var imgExpandAll = document.getElementById("imgExpandAll");
    var sDivState = "";
    var nLinkTop = document.getElementById("nextLinkTop");
    var nLinkBottom = document.getElementById("nextLinkBottom");
    var pLinkTop = document.getElementById("prevLinkTop");
    var pLinkBottom = document.getElementById("prevLinkBottom");

    if (imgExpandAll.src.indexOf("collapseall") > 0)
    {
        // do collapse all
        document.getElementById("imgExpandAll").src ="/i/dl/listings/icon_expandall_EBEBE9.gif";
        sDivState = "none"
        sExpandOrCollapse = "expand";

        // turn off expandAll tag
        if ( nLinkTop && nLinkBottom ) {
            if ( nLinkTop.href.indexOf("expandAll=1") > 0 ) {
                nLinkTop.href = nLinkTop.href.replace("expandAll=1", "expandAll=0");
                nLinkBottom.href = nLinkBottom.href.replace("expandAll=1", "expandAll=0");
            } else {
                nLinkTop.href += "&expandAll=0";
                nLinkBottom.href += "&expandAll=0";
            }
        }
        if ( pLinkTop && pLinkBottom ) {
            if ( pLinkTop.href.indexOf("expandAll=1") > 0 ) {
                pLinkTop.href = pLinkTop.href.replace("expandAll=1", "expandAll=0");
                pLinkBottom.href = pLinkBottom.href.replace("expandAll=1", "expandAll=0");
            } else {
                pLinkTop.href += "&expandAll=0";
                pLinkBottom.href += "&expandAll=0";
            }
        }
        if ( self.location.href.indexOf("expandAll=1") > 0 ) {
            self.location.href = self.location.href.replace("expandAll=1", "expandAll=0");
        }
    } else {
        // do expand all
        document.getElementById("imgExpandAll").src ="/i/dl/listings/icon_collapseall.gif";
        sDivState = "block"
        sExpandOrCollapse = "collapse";

        // turn on expandAll tag
        if ( nLinkTop && nLinkBottom ) {
            if ( nLinkTop.href.indexOf("expandAll=0") > 0 ) {
                nLinkTop.href = nLinkTop.href.replace("expandAll=0", "expandAll=1");
                nLinkBottom.href = nLinkBottom.href.replace("expandAll=0", "expandAll=1");
            } else {
                nLinkTop.href += "&expandAll=1";
                nLinkBottom.href += "&expandAll=1";
            }
        }
        if ( pLinkTop && pLinkBottom ) {
            if ( pLinkTop.href.indexOf("expandAll=0") > 0 ) {
                pLinkTop.href = pLinkTop.href.replace("expandAll=0", "expandAll=1");
                pLinkBottom.href = pLinkBottom.href.replace("expandAll=0", "expandAll=1");
            } else {
                pLinkTop.href += "&expandAll=1";
                pLinkBottom.href += "&expandAll=1";
            }
        }
        if ( self.location.href.indexOf("expandAll=0") > 0 ) {
            self.location.href = self.location.href.replace("expandAll=0", "expandAll=1");
        }
    }

    // update search result items
    for ( i=1; i<=max; i++ )
    {
        document.getElementById("tablayer-result-" + i).style.display = sDivState;
        document.getElementById("tablayer-result-lw-" + i).style.display = sDivState;
        document.getElementById("imgExpandCollapse" + i).src = "/i/dl/listings/icon_" + sExpandOrCollapse + ".gif";
    }
}

function ExpandAllFlag(max) {
    if ( self.location.href.indexOf("expandAll=1") > 0 ) {
        ExpandAll(max);
    }
}

function Expand()
{

}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=838,height=628');");
}


function openPopup(url, name) {
        popupWin = window.open(url, name, 'scrollbars,resizable,width=480,height=320');
        window.self.name = 'cnetParent';
}

function downloadNow(file,redUrl,extUrl) {
    var isIe = (window.navigator.userAgent.toUpperCase().indexOf('MSIE') != -1);
    var isOpera = (window.navigator.userAgent.toUpperCase().indexOf('OPERA') != -1);

    if (isIe && extUrl == 0 && !isOpera) {
        window.open(file,'dlnow','toolbar=0,location=no,directories=0,status=0, scrollbars=no,resizable=0,width=1,height=1,top=0,left=0');
        window.focus();
        location.href = redUrl + '?idl=n';
    } else {
        location.href = redUrl;
    }
}

function dlNow(file,redUrl,extUrl) {
    // skip if external url or old browser
   // if (extUrl == 0 && document.readyState) {
        // first try to download file in same window    
   //     location.href = file;
        // mozilla readyState is always undefined
        // safari readyState is always complete
        // ie readyState is loading -> interactive -> complete
   //     if (document.readyState && document.readyState == 'loading') {
            // possible to detect when download dialog starts
            // check readyState every 250ms and
            // redirect to post download page with initiate download disabled
    //        setTimeout('dlComplete(\'' + redUrl + '%3Fidl=n\')', 250);
    //        return false;
    //    }
    //}
    // not possible to detect when download dialog starts
    // just follow href to post download page and let it initiate the download
    //location.href = redUrl;
    //return true;   
    newDLNow(file,redUrl,extUrl);
    return false;
}	

function dlComplete(redUrl) {
    if (document.readyState == 'loading') {
	/*window.onunload=function(){
		//alert("unloading in dlComplete: " + document.readyState);
		//if (document.readyState == 'loading') {		
			// this means the file url is bad
			// redirect to post download page
			redUrl = redUrl.substring(0,redUrl.indexOf('%3Fidl=n'));			
			location.href = redUrl;
		//}
	} */   
        // still loading, check again in 250ms        
        setTimeout('dlComplete(\'' + redUrl + '\')', 100);
    } else {
        // readyState = interactive or complete means download dialog started
        // redirect to post download page with initiate download disabled        
        location.href = redUrl;
    }    
}

function newDLNow(file,redUrl,extUrl) { 
//file = "ftp://ftp.download.com/pub/ppd/10306590-10415721/htfireman20shasdsfdsfdreeng.exe";
    var isIe = (window.navigator.userAgent.toUpperCase().indexOf('MSIE') != -1);
    var isOpera = (window.navigator.userAgent.toUpperCase().indexOf('OPERA') != -1);   

    if (isIe && extUrl == 0 && !isOpera) {  	
	myDLWindow = window.open(file,'_blank','toolbar=0,location=no,directories=0,status=0, scrollbars=no,resizable=0,width=0,height=0,top=0,left=0');               	     
	location.href = redUrl + '?idl=n';                    
    } else {
    	//alert('this is not ie, is an ext url, or is Opera');
        location.href = redUrl;
    }    
}

//sniffs out Safari
        var isSafari=(navigator.userAgent.indexOf('Safari')>=0)?true:false;
        if (isSafari == true) {
        //alert("Safari");
        document.write("<style>#cobr-header #search-bar .search-fields .input-search {float: left; width: 100px; padding: 0; margin: 2px 5px 0 7px;}</style>");
        }       
               