﻿// JScript File
// Copyright 2009 - Frog Haven Enterprises & Larry Bilodeau
// all rights reserved

// menu popup-collapse (toggles)
// must be used in conjucntion with a properly configured Cascade Style Sheet
// reference page 78 - "CSS Cookbook" first Edition by Christopher Schmitt - pub: O'Reilly
//
// define a global array that will contain a list of the mouseHint items 
// on the current page. This list is used to cloak or reviel the items 
// as needed.

var mouseHintList =new Array();
var referer = document.referrer.toString();

function setCookie(name,value,days) {
      if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
      }
      else expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
    }

var lidx = document.cookie.lastIndexOf("MouseHints");
    if (lidx != -1) {
        if (document.cookie.indexOf("Off") != -1) {
            // cookie is on
            // document.cookie = "MouseHints='Off'; path='" & referer & "'";
            setCookie("MouseHints","Off")
        } else {
        // cookie is off
            //document.cookie = "MouseHints='On'; path='" & referer & "'";
            setCookie("MouseHints","On")
        }
    }
         // if (idx != lidx) { idx = lidx; }        // check for multiple cookies with the same name
        

function collopup(box) {
        var objectStyle = document.getElementById(box).style
        if (objectStyle.display == "block"){
            objectStyle.display = "none";
        }else{
            objectStyle.display = "block";
        }
        return false;
        }
        
         
function BuildURI(daHref) {
  
	// concatinates the current pages URL to the target URI so report can tell what
	// page the user is commenting on
	// added code to include any frame contents that is part of the page
	var finalURL
	finalURL = daHref + "?page=" + encodeURIComponent(location.href)
	if (document.frames.length > 0){

	    for (idx = 0; idx < document.frames.length; idx++)
	    {
            frameURL = document.frames[0].location.href
            frameSrc = frameURL
	        finalURL = finalURL + "&frame=" + encodeURIComponent(frameURL)
	    }
	}
	location.href=finalURL
}
function setIframeContent( src, destination, frameColor) {
    // loads specified iframe by settings it's source attribute to the destination
    // alert(frameColor.toString());
    var target = document.getElementById(destination)
    target.src = src;
    showcaseContainer.style.backgroundColor = frameColor;
    target.style.borderColor = frameColor;
    
}
function cloak_Decloak(itemList,ptr) {
    function setDisplayModes(itemList,value){
        for ( idx = 0; idx < itemList.length; idx++)
        {
            var obj = itemList[idx];
            document.getElementById(obj).style.visibility = value;
        }
        // next check if there are any frames and if so set those frame(s) mouse hints
        if (document.frames.length > 0){
            for (i = 0; i< document.frames.length; i++)
            {
                if (document.frames[i].mouseHintList != null) { // does the frame contain mousehints
                    for (idx = 0; idx < document.frames[i].mouseHintList.length; idx++)
                    {
                        obj = document.frames[i].mouseHintList[idx];
                        document.frames[i].document.getElementById(obj).style.visibility = value;
                    }
                }
            }
        }
    }
    if ( ptr.parentElement.id == "mouseHintsItem")
        { 
            var testString = ptr.getAdjacentText("afterBegin").toLowerCase()
            if(testString.indexOf("disable") >= 0)
                {
                    ptr.replaceAdjacentText("afterBegin","Enable mouse hints")
                    setDisplayModes(itemList, "hidden");
                    //document.cookie = "MouseHints='Off'; path='" & referer & "'";
                    setCookie("MouseHints","Off")
                } else {
                    ptr.replaceAdjacentText("afterBegin","Disable mouse hints")
                    setDisplayModes(itemList, "visible");
                    //document.cookie = "MouseHints='On'; path='" & referer & "'";
                    setCookie("MouseHints","On")
                }
        }
}
function addHint2List( ptr) {
    mouseHintList[mouseHintList.length] = ptr.parentElement.id;
    // alert(mouseHintList.length.toString());
    // alert('got here');
}

function setStoredPreferences() {
    // first deal with the mouseHints
    var menuItem = document.getElementById("mouseHintsItem");
    var MenuElements = menuItem.getElementsByTagName("a");
    var idx = document.cookie.lastIndexOf("MouseHints");
    if (idx != -1) {
        idx = idx + 11;
        if ( document.cookie.indexOf("Off",idx) == idx){
             // document.cookie = "MouseHints=Off"; // this assures that if the calling page set the cookie off this version is off
            MenuElements[0].replaceAdjacentText("afterBegin", "Enable mouse hints");
            for ( idx = 0; idx < mouseHintList.length; idx++)
            {
                obj = mouseHintList[idx];
                document.getElementById(obj).style.visibility = "hidden";             //display = "none";
            };            
        }
        else {
            MenuElements[0].replaceAdjacentText("afterBegin", "Disable mouse hints");
                for ( idx = 0; idx < mouseHintList.length; idx++)
                {
                    obj = mouseHintList[idx];
                    document.getElementById(obj).style.visibility = "visible";  //display = "none";
                };            
             // document.cookie = "MouseHints=On"; // this assures that if the calling page set the cookie on thien this version is set on
        }
    }
    // now deal with the soapbox preference
    idx = document.cookie.indexOf("Soapbox");
    if (idx != -1){
        idx =idx + 8;   // length of the word soapbox=
        if (document.cookie.indexOf("On",idx) == idx){
            soapBox();
        }
    }
}
function soapBox() {
    collopup('soapbox')
    var objectStyle = document.getElementById("soapbox").style
        if (objectStyle.display == "block"){
            //document.cookie = "Soapbox=On"
            setCookie("Soapbox","On")
            } else {
            //document.cookie = "Soapbox=Off"
            setCookie("Soapbox","Off")
        }
}
