/* ***************************************
* Javascript File: styleCookie.js
* Purpose: Style switcher.
* Updated: 2005-05-11
* Authors: David McCracken
* .............. notes ..........................
* All of the uberCookie.js code can serve any cookie purpose. The code in this 
* file serves the specific very common purpose of style sheet switching. It 
* hard-wires a number of names and relationships to allow a pages to include 
* this file without having to embed any javascript code other than
* anchors' hrefs, e.g. <a href="javascript:setStyle( 'red' )">RED</a>
* Assumptions are:
* - The cookie is called "style" and it can be accessed only by pages in the
* directory in which it is created. 
* - The value is the root name of the style sheet, e.g. 'red' -> red.css. It 
* may include a path.
* - The page may define StyleRoot as a path prefix to the style value for 
* subdirectories to reach the same relative style sheets as the main.
* e.g. <script type="text/javascript">StyleRoot = "../../"</script> 
* - The lifetime is 30 days, after which time the browser may delete the cookie.
* - The page is reloaded if the style sheet selection changes.
* 
* ******************************************/
StyleCookie = "style"

/*****************************************************
* Function: setStyle
* Description: Set the style cookie.
* Returns: nothing
* Arguments: 
* - val (string) is the root name of the css style sheet to be loaded. If this 
* is null (or 0), the style cookie is in effect deleted. 
* - idAlert (string) optional ID of an alert box (usually div) to change from
* display none to block to remain on the page if automatic reload fails. 
* ............................................... */
function setStyle( val, idAlert )
{
  setCookie( StyleCookie, val, 30, 3, idAlert == null ? "" : idAlert );
}

/**** Automatic statements. These execute as the file is loaded. *******/

var styleVal = getCookie( StyleCookie );  

/* The following must be located at the end of a script block. It will screw
* up any subsequent script code in the same block because it writes HTML code 
* immediately into the page. */
if( styleVal ) 
  document.write( '<link rel="stylesheet" type="text/css" href="' + 
    ( typeof StyleRoot == "undefined" ? "" : StyleRoot ) + styleVal + '.css" >'); 
