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 = '/LogIn/Welcome.aspx' + 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";
    }
}

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>");
        }       
               