/*
** --------------------------------------------------------------------------------------------------------------------
**  This is the logic that will build the header and menu found at the top of the page. 
**  The code is dependent upon a variable that must be defined in every web page (ColorRef).  This variable will be the
**  pointer into the array (see below) that contains all the background colors that are used across the various pages. 
**  Because this value is so important, a default value of 1 is established in the event that the variable is not found 
**  on the originating page.
** --------------------------------------------------------------------------------------------------------------------
*/

if (typeof HdrRef == 'undefined')   var HdrRef = 1.00;     // default to Home Page template

var T = 0;  // template pointer - defaults to zero
var x = 0;  // misc array pointer

/*
** ************************************************************************************************** 
**                          This block will hold system wide "variables"
** ************************************************************************************************** 
*/

var sysYear = 2006;

var sysCopyRightNotice = "Copyright Miami County Health District - 2006 ";


/*
** -----------------------------------------------------------------------------------------------------------------------------------------
**  Locate the requested template in the above array.  Default to first item (T = 0) in array if not found.
** -----------------------------------------------------------------------------------------------------------------------------------------
*/

T = 0;
for(x = 0; x< MCHDTemplate.length; x++)
    {
    if (MCHDTemplate[x].key == HdrRef)
        {
        T = x;
        }
    }
    
var TempDepartmentKey   = MCHDTemplate[T].key;
var TempBanner          = MCHDTemplate[T].banner;
var TempDepartment      = MCHDTemplate[T].dept;
var TempBackGroundColor = MCHDTemplate[T].bgc;
var TempText            = MCHDTemplate[T].text;
var TempRuler           = MCHDTemplate[T].ruler;
var TempHeader          = MCHDTemplate[T].header;

if (TempBanner == "") TempBanner = "mchdbanner.jpg";  

/*
** -----------------------------------------------------------------------------------------------------------------------------------------
**
** -----------------------------------------------------------------------------------------------------------------------------------------
*/

// defines overall page size - closed in footer
document.write('<div align=center style="width:800;height:903;background-Color:' + TempBackGroundColor + '">')  
document.write('<span style="background-color:#00539F; width:800; height:103;">')  // 116
//document.write('<img src="mchdbanner.jpg" name="banner" width="800" height="79" border="0">')
document.write('<img src="' + TempBanner + '" name="banner" width="800" height="79" border="0">')
document.write('</span>');

if (TempDepartment != "")
    {
    document.write('<img src="' + TempDepartment + '" width="175" height="800" alt="" style="position:absolute;left:0;top:103;">');    
    // defines body size and characteristics - closed in footer
    document.write('<div align=left class=body2 style="position:relative;left:90;top:0;width:580;"><br>');  
    }
else
    {
    document.write('<div align=left class=body2 style="position:relative;left:0;top:0;width:790;"><br>');  
    }

document.body.style.backgroundColor = "#00539F";     // spread MCHD blue behind excess of page

var nbrofrules = document.styleSheets[0].rules.length

/*
** -----------------------------------------------------------------------------------------------------------------------------------------
**  This code will override the document's text color setting in the MCHD Stylesheet
** -----------------------------------------------------------------------------------------------------------------------------------------
*/

if (TempText != "#000000")              // reset document text color if other than black
    {
    for (x=0; x<nbrofrules;x++)document.styleSheets[0].rules[x].style.color=TempText;	
    }
    
/*
** -----------------------------------------------------------------------------------------------------------------------------------------
**  This code will override the document's <h1> - <h6> color settings in the MCHD Stylesheet
**  Please note: If only the first header is given a color, all 6 headers will be defaulted to this color
** -----------------------------------------------------------------------------------------------------------------------------------------
*/

if (TempHeader.length > 0)                   // reset document header text colors if used
    {
    if (TempHeader.length == 1 && TempHeader[0] != "") 
        for (x=1; x<7;x++) document.styleSheets[0].rules[x].style.color=TempHeader[0];	
    else
        for (x=1; x<7;x++) if (TempHeader[x-1] != "")document.styleSheets[0].rules[x].style.color=TempHeader[x-1];	
    }

/*
** -----------------------------------------------------------------------------------------------------------------------------------------
**  Use the HTML <title> as the screen heading
**  Determine whether or not a " - " (dash) is used in the title.  The dash subdefines the page's title.
**  If a dash is found, remove the dash and substitute a line break for it. ("<br>").  This will then create a multi-line heading. 
** -----------------------------------------------------------------------------------------------------------------------------------------
*/

var idx = 0;                                // -1 = no dash found

var title1 = document.title                 // 
var title2 = "";                            // clear the title work area

while (idx != -1) headingBreaker();

if (title1 != "Miami County Health District<br>Home Page")    
    document.write('<div align="center"><h3><nobr>' + title1 + '</nobr></h3></div>');  

    
    
function headingBreaker()
    {
    idx = title1.indexOf('-')           // search for the dash
    
    if (idx != -1)                      // if found, change it to a line break and reconcatenate the title
        title2 = title1.substr(0,idx-1) + "<br>" + title1.substr(idx+2);
    else
        title2 = title1;                // else use the title as found

    title1 = title2;                    // reset and search for additional line breaks
    }


