var d = document;
var onLoaded=false;
var FM = new Object(); // "namespace" to isolate core template scripts

function setup()
{
}


//***************
//
// PrintMe/PrinterFriendly Functions
//
//***************

//-------------------------
// Variables associated with the page
// to be displayed in a printer-friendly format.
//-------------------------

var filePath="";
var loc=location.pathname;
var pathElements=loc.split("/");
var fileName=pathElements[(pathElements.length-1)];

var fullPath =location.href;
var fullPathQueryElements =fullPath.split("?");
var fullPathQueryString =fullPathQueryElements[1];

var isCGIFile =fileName.indexOf('.cgi') !=-1?true:false;
var isJSPFile =fileName.indexOf('.jsp') !=-1?true:false;
var pathHasQueryString =fullPath.indexOf('?') !=-1?true:false;

var brochure = null;

//***************
// function printMe();
// <no arguments>
//
// This function creates the file path and error-checks
// file variables associated with the page to be displayed in a
// printer-friendly format. It also displays the printMe HTML.
//
//***************

function printMe() {

    var output="";

    //-------------------------
    //Check for instances where a url points to a directory instead
    //of a page. A directory's default page is always index.html.
    //-------------------------

    if (fileName=="" || fileName==null)
    {
        fileName="index.html";
    }

    //-------------------------
    // Determine the file's directory path.
    //-------------------------

    filePath = loc.replace(fileName, "");

    //-------------------------
    // Prepare and write the sweet-smelling output.
    // If the filename contains the string ".cgi", the url will simply call
    // itself, appending the value pair "pf=1". Otherwise, the file is
    // assumed to be .htm or .html and print_page.cgi is called instead.
    //-------------------------
        // approved code will not display this table
    //displayPrintMeDeveloperTable();

    if (printme_enabled == "true")
    {
        if (isCGIFile || isJSPFile)
        {
              var printURL = filePath + fileName +"?pf=1";
              if (pathHasQueryString)
              {
                  printURL +="&" + fullPathQueryString;
              }
        }
        else {
            var printURL = "/cgi-bin/printme/print_page.cgi?fileName="+fileName+"&filePath="+filePath;
        }
        output+='<a href="javascript:openPrintWindow(\'' + printURL + '\');" class="global">';
        output+=printme_text;
        output+='</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;';
        d.write(output);
    }

}//end function

//***************
// function printModule();
// <no arguments>
//
//***************

function printModule() {

    var output="";

    if (printmodule_enabled == "true")
    {
        var printURL = "/cgi-bin/printme/print_module.cgi?fileName="+fileName+"&filePath="+filePath;
        output+='<a href="javascript:openPrintWindow(\'' + printURL + '\');" class="global">';
        output+=printmodule_text;
        output+='</a>';
        d.write(output);
    }

}//end function

//***************
//
// FUNCTION openPrintWindow
// (<no arguments>)
//
// This function opens the printer-friendly or print-module window.
//
//***************
function openPrintWindow (printURL)
 {
   var myLeft = (screen.width - 642)/2;
   var screenBuffer = 100;
   var myHeight = 500;
   var myTop = (screen.height - 580)/2;

   if (!brochure || brochure.closed)
       brochure = window.open(printURL,'showbrochure','location=no,toolbar=no,scrollbars=yes,resizable=yes,width=642,height='+myHeight+',top='+myTop+',left='+myLeft);
   else
     {
       brochure.focus();
       brochure.location.href = printURL;
     }
 }

//***************
//
// FUNCTION hideApps(tf)
// (<tf>)
//
// This function hides an applet on mouseover
//
//***************
function hideApps(tf)
{
    if (!d.getElementsByTagName) return true;
    var app = d.getElementsByTagName("div")["stockTicker"];
    if (app)
    {
        if (tf) d.getElementsByTagName("div")["stockTicker"].style.visibility = "hidden";
        else d.getElementsByTagName("div")["stockTicker"].style.visibility = "visible";
    } else return true;
}
//***************
//
// FUNCTION hideDangerous(tf)
// (<tf>)
//
// This function hides any div with the hiddenClass class
//
//***************
function hideDiv(tf)
{
    if (!d.getElementsByTagName) return true;
    var divList = d.getElementsByTagName("div");
    if (!divList)  return true;
    for (i=0;i< divList.length;i++)
    {
        if (divList[i].className=="hiddenClass")
        {
            if (tf) d.getElementsByTagName("div")[i].style.visibility = "hidden";
            else d.getElementsByTagName("div")[i].style.visibility = "visible";
        }
    }

}
//***************
//
// Popup Functions
//
//***************

function closePopup()
{
    window.close();
}

function validateSearchField(elem)
{
    var str=elem.value;
    if (str==null || str.length==0)
    {
        return false;
    }
    else
    {
        return true;
    }
}

screenBuffer=100;
myLeft=(screen.width - 640)/2;
myTop=(screen.height - 580)/2;
myHeight=500;

function popupWindow(windowType, theURL, winName, width, height, toolbar, scrollbars, resizable, top, left)
{
    if (windowType=="daughter")
    {
            winName="fmDaughter";
            width=800;
            height=520;
            toolbar="yes";
            scrollbars="yes";
            resizable="yes";
            var top=eval((screen.height-height)/2);
            var left=eval((screen.width-width)/2);
    }
    else if (windowType=="offsite")
    {
        winName="fmOffsite";
        width=800;
        height=480;
        toolbar="yes";
        scrollbars="yes";
        resizable="yes";
        var top=eval((screen.height-height)/2);
        var left=eval((screen.width-width)/2);
    }
    else if (windowType=="popup")
    {
        winName="fmPopup";
        width=640;
        height=295;
        toolbar="yes";
        scrollbars="yes";
        resizable="yes";
        var top=eval((screen.height-height)/2);
        var left=eval((screen.width-width)/2);
    }
    else if (windowType=="adobe")
    {
        winName="fmPopup";
        width=640;
        height=445;
        toolbar="yes";
        scrollbars="yes";
        resizable="yes";
        var top=eval((screen.height-height)/2);
        var left=eval((screen.width-width)/2);
    }
    else {
        if (!winName || winName==" ") winName="fmDaughter";
        if (!width || width==" ") width=640;
        if (!height || height==" ") height=480;
        if (!toolbar || toolbar==" ") toolbar="yes";
        if (!scrollbars || scrollbars==" ") scrollbars="yes";
        if (!resizable || resizable==" ") resizable="yes";
        if (!top || top==" ") var top=eval((screen.height-height)/2);
        if (!left || left==" ") var left=eval((screen.width-width)/2);
    }

    if (!popup_window || popup_window.closed){
        var popup_window = window.open(theURL, winName, 'toolbar='+toolbar+', scrollbars='+scrollbars+', resizable='+resizable+', width='+width+', height='+height+', top='+top+', left='+left);
    }else{
        popup_window.focus();
        popup_window.location.href = theURL;
    }
}

