//Copyright (C) 2002-2004, CodeHouse.com. All rights reserved

NAV_MENU = "Visual Menu";
NAV_RML_REF = "RML Reference";
NAV_VM_DOC = "Technical Documentation";

CK_SIDEBAR_HIDE = "SB_HIDE";


var _IE, _GE, _OP, _SA;

var ua = navigator.userAgent;
   
if( _OP = /Opera/.test(ua) )
   ;
else if( _SA = /Safari|Konqueror/.test(ua) )
   ;    
else if( _GE = /Gecko/.test(ua) )
   ;
else if( _IE = window.ActiveXObject )
   ;

/* Remove if running without server */
if( location.protocol == "file:" && ! _SA )
{
   location.href = location.href.replace(/.*codehouse\/html/i, "http://ed");
}
///

TEMP_COOKIE = new My_CookieUtil("temp", null, "/");


if( TEMP_COOKIE.getSubValue(CK_SIDEBAR_HIDE) || location.search == "?print" )
{
   document.write('<style type="text/css">#sid_sidebar{display:none}</style>');
}
else
{
   document.write('<style type="text/css">#sid_sidebar_show{display:none}</style>');
}


function helpWin(url)
{
   window.open(url,"help","width=600,height=400,resizable,scrollbars,status", true).focus();
}

function newWin(url)
{
   window.open(url,"","width=600,height=400,resizable,scrollbars,status,toolbar,location,menubar");	   	
}

//EJP -- functionality removed for now
function contentInit(){}

//EJP -- functionality removed for now
function writeSidebarLogo(){}

function writeShowSidebarBtn()
{
   if( location.search != "?print" )
	{
	   document.write('<div><input id="sid_sidebar_show" type="button" value="Show Sidebar" onclick="showSidebar(true)"/></div>');
	}
}

function printPage()
{
	newWin("/pop/print.htm?" + location.href);
}

function addShortcut()
{
	if( _IE )
	   external.AddFavorite(location.href, document.title);
	else if( _GE )
	   sidebar.addPanel(document.title, location.href,'');
	else
	   alert("Feature not supported on this browser");	
}


function showSidebar(show)
{
   if( show )
   {
      TEMP_COOKIE.setSubValue(CK_SIDEBAR_HIDE);
      
      if( _IE )
		{
	     document.getElementById("sid_sidebar").style.display = "block";			   
	     document.getElementById("sid_sidebar_show").style.display = "none";
      }
		else
		{
		   location.replace(location.href);
		}
   }
	else
	{
		if( ! navigator.cookieEnabled )
		{
			noCookieMsg();
		}
		else
	   {		
			document.getElementById("sid_sidebar").style.display = "none";			
			document.getElementById("sid_sidebar_show").style.display = "block";

         TEMP_COOKIE.setSubValue(CK_SIDEBAR_HIDE, true);
		}
	}
}

function noCookieMsg()
{
	alert("You need to turn on cookie support for this feature");
}

function setBrowser()
{   
   var ua = navigator.userAgent;
   
   if( _OP = /Opera/.test(ua) )
      ;
   else if( _SA = /Safari|Konqueror/.test(ua) )
      ;    
   else if( _GE = /Gecko/.test(ua) )
      ;
   else if( window.ActiveXObject )
   {
      var ver = Number(ua.match(/MSIE ([^;]+)/)[1]);

	  if( /Win/.test(ua) )
	  {
	     _IE = ver;
	  }
	  else if( /Mac/.test(ua) )
	  {
	     _MIE = ver;
	  }   
   }
}
  
function My_CookieUtil(name, duration, path, domain, secure)
{
   this.affix = "";
   
   if( duration )
   {   	  
      var date = new Date();
	  var curTime = new Date().getTime();

	  date.setTime(curTime + (1000 * 60 * duration));
	  this.affix = "; expires=" + date.toGMTString();
   }
   
   if( path )
   {
      this.affix += "; path=" + path;
   }
   
   if( domain )
   {
      this.affix += "; domain=" + domain;
   }

   if( secure )
   {
      this.affix += "; secure=" + secure;
   }
   
      
   function getValue()
   {
      var m = document.cookie.match(new RegExp("(" + name + "=[^;]*)(;|$)"));

      return m ? m[1] : null;   
   }
      
   this.setSubValue = function(key, value)
   {
      var ck = getValue();

      if( /[;, ]/.test(value) )
      {
         //Mac IE doesn't support encodeURI
		 value = window.encodeURI ? encodeURI(value) : escape(value);
      }
      
      if( value )
      {
         var attrPair = "@" + key + value;

         if( ck )
         {
             if( new RegExp("@" + key).test(ck) )
	         {
		        document.cookie =
				   ck.replace(new RegExp("@" + key + "[^@;]*"), attrPair) + this.affix;
	         }
	         else
	         {
		        document.cookie =
				   ck.replace(new RegExp("(" + name + "=[^;]*)(;|$)"), "$1" + attrPair) + this.affix;
	         }
         }
         else
         {
	        document.cookie = name + "=" + attrPair + this.affix;
         }
      }
      else
      {      
	     if( new RegExp("@" + key).test(ck) )
	     {
	        document.cookie = ck.replace(new RegExp("@" + key + "[^@;]*"), "") + this.affix;
	     }
      }
   }
      
   this.getSubValue = function(key)
   {
      var ck = getValue();

      if( ck )
      {
         var m = ck.match(new RegExp("@" + key + "([^@;]*)"));

	     if( m )
	     {
	        var value = m[1];

	        if( value )
	        { 
	           //Mac IE doesn't support decodeURI
			   return window.decodeURI ? decodeURI(value) : unescape(value);
	        }
	     }
      }
   }
}

function navPath()
{             
   var inner = _IE || _GE ? "&#9668;" : "&#9664;";
   
   var s = "";   

   for(var i = 0; i < arguments.length; i += 2)
   {
      s += '<span class="ss-arrow">&nbsp;' + inner + '&nbsp;</span><a href="' + 
	       arguments[i + 1] + '">' + arguments[i] + '</a>';         
   }
   
   inner += inner + inner;

         
   var t = '<div id="ss-nav-path-cont"><div id="ss-nav-path">\
<a href="/">Home</a>__X__ \
<span class="ss-arrow">' + inner + '</span></div></div>';

   document.write(t.replace("__X__", s));
}


EXCLUDE_HOME = 0;
EXCLUDE_EMAIL = 1;


function writeFooter(option)
{
var s='<div id="ss-footer" class="ss-center">\
<div>\
<div>\
<a href="#">Top <span class="ss-arrow">&#9650;</span></a> | \
__HOME__ | \
__FAV__\
__PRINT__ | \
__EMAIL__\
</div>\
<div id="ss-born">This page was created on: __BORN__</div>\
<div id="ss-legal">\
Copyright &copy; CodeHouse.com, 1997-__YEAR__. All rights reserved. \
CodeHouse&trade; is a registered trademark. \
Use of the CodeHouse&trade; name is prohibited unless \
it is done in conjunction with the trademark symbol and used in reference to \
this company or one of our products. Use of the CodeHouse&trade; \
logo is prohibited without the express written consent of CodeHouse&trade;.\
</div>\
</div>';


   var fav = _IE || _GE
       ? '<a href="javascript:addShortcut()">Bookmark Page</a> | '
	   : "";
	   
   s = s.replace('__FAV__', fav);
   

   var p = option == EXCLUDE_HOME 
       ? '<span id="sid-exclude">Home</span>'
	    : '<a href="/">Home</a>';
   s = s.replace('__HOME__', p);
      
   p = option == EXCLUDE_EMAIL 
       ? '<span id="sid-exclude">Contact</span>'
	    : '<a href="/company/contact.htm">Contact</a>';
   s = s.replace('__EMAIL__', p);
	
   p = location.search == "?print"
       ? '<span id="sid-exclude">Printer Friendly Page</span>'
	    : '<a href="' + "javascript:printPage()" + '">Printer Friendly Page</a>';
   s = s.replace('__PRINT__', p);   	
   
      
   s = s.replace('__BORN__', BORN);
      
   s = s.replace('__YEAR__', new Date().getFullYear());

   document.write(s);
}
