/****
    Set the color to be used in mouseovers based on whether this item is the 
    identifier of the current page (i.e. Music Page).  Then test whether the call
    to setColor is a mouseover or a mouseout.  Based on the bool. value of mouseover, 
    selectedFlag is set to white, grey, or black.
****/
function setColor(category, mouseover){
    if (topicCenter == category){ 
        if (mouseover == true)
            selectedFlag = "_000";  ////Set mouseover to white because you're on the active category.
        else
            selectedFlag = "_fff";  ////Set the mouseout to black because you're on the active category.
    }
    else {
        if (mouseover == true)
            selectedFlag = "_000";  ////Set the mouseover to white because you're NOT on the active category.
        else
            selectedFlag = "_666";  ////Set the mouseout to grey because you're NOT on the active category.
    }
    return selectedFlag;
}

function setLayerName(category){
    layerName = category + "Layer";
    return layerName;
}

function setIcon(category, mouseover){
    layerName = setLayerName(category);
        if (document.getElementById(layerName).style.display=="block"){ ////The category's child layer is NOT displayed
            if (mouseover == true){  ////user is doing a mouseover on the icon, rather than clicking it
                switchIcon = "hide";
            }
            else{  ////user is clicking on the icon, rather than mouse-ing over it
                switchIcon = "show";
            }
        }
        else{////The category's child layer is displayed
            if (mouseover == true){  ////user is doing a mouseover on the icon, rather than clicking it
                switchIcon = "show";
            }
            else{  ////user is clicking on the icon, rather than mouse-ing over it
                switchIcon = "hide";
            }
        }
    return switchIcon;
}

function mouseOverExpand(category,mouseover) {
    selectedFlag = setColor(category, mouseover); ////use proper color scheme for images.  switches between black, grey, and white.
    
    iconFlag = setIcon(category, true); ////use proper image (show/hide) for expanding icon for each category.
 
    /****
        if layer is not shown, then mouseover with the plus icon with the appropriate color.
    ****/
    eval("document.getElementById('" + category + "ExpandImg').src='" + realone + "images/white/icon_" + iconFlag + selectedFlag + ".gif'");
}

function navItemOver(txtLink, category, style) {
    eval("window.status='" + txtLink + "'; document.getElementById('" + category + "Link').className='" + style + "';");
}

function navItemOut(category, style) {
    eval("window.status=''; document.getElementById('" + category + "Link').className='" + style + "';");
}

/****
    Set the Topic Center (i.e. music) navigational elements which aren't already set in the JSP
****/
function setMenuItems(category) {
    if (eval("document.getElementById('" + category + "Icon')")){
        if (eval("document.getElementById('" + category + "Icon').src").indexOf("spacer") == -1)
            eval("document.getElementById('" + category + "Icon').src='" + realone + "images/white/icon_" + category + "_on.gif'");
    }
}


/****
    Turns the layers on and off...
****/
function toggleLayer(category){
    layerName = setLayerName(category);

    selectedFlag = setColor(category, false); ////use proper color scheme for images.  switches between black, grey, and white.
    
    iconFlag = setIcon(category, false); ////use proper image (show/hide) for expanding icon for each category.

    eval('document.getElementById(category + "ExpandImg").src="' + realone + 'images/white/icon_" + iconFlag + selectedFlag + ".gif"');
    if (iconFlag == "hide"){
        document.getElementById(layerName).style.display="block";
        addItem(category); ////if the user wants us to maintain state, do this...
    } else{
        document.getElementById(layerName).style.display="none";
        removeItem(category); ////if the user wants us to maintain state, do this...
    }
} 

/****
    Returns true if item did not exist in cookie.
    false if it is already there.
****/
function addItem(name) {
	if(hasItem(name)){
		return false;
	}
	var cookieVal = getCookieValue(navCookie);
	cookieVal += "|" + name + "|";
	cookieVal = cookieVal.replace(/\|\|/g,"|"); //// remove double pipes
	setCookie( navCookie,cookieVal,navCookieLife);
	return true;
}

/****
    Returns true if actually removing item,
    returns false if item was not already in
    the cookie.
****/
function removeItem(name) {
	if(!hasItem(name)){
		return false;
	}
	var cookieRegX = new RegExp("(^|\\|)"+name+"(\\||$)");
	var cookieVal = getCookieValue(navCookie);
	cookieVal = cookieVal.replace(cookieRegX,"|");
	cookieVal = cookieVal.replace(/\|\|/g,"|"); //// remove double pipes
	setCookie( navCookie,cookieVal,navCookieLife);
}

/****
    Returns true if the item is in the cookie.
	returns false if not.
****/
function hasItem(name) {
	var cookieRegX = new RegExp("(^|\\|)"+name+"(\\||$)");
	var cookieVal = getCookieValue(navCookie);
	return cookieRegX.test(cookieVal);
}

function setCookie( name, value, days )
{
	var exp = new Date();
	var days2Live = exp.getTime() + (24 * 60 * 60 * 1000 * days);
	exp.setTime(days2Live );
	if( document.location.href.indexOf(".real.com") >=0 ) {
		var domname=".real.com";
	}else{
		var domname=".prognet.com";
	}
	document.cookie = name+"="+value+"; expires=" + exp.toGMTString() + "; domain=" + domname+"; path=/";
}

function getCookieValue( cookieName )
{
        var cookieArray = new Array();
        var cRE = new RegExp("(\;|^)[^;]*("+cookieName+")\=([^;]*)(;|$)");
        cookieArray = cRE.exec(document.cookie);
        if( cookieArray != null )
        {
                return cookieArray[3];
        }
        return "";
}
