var  ESC_less_than                  = "&#060;"      //	less than sign
var  ESC_greater_than               = "&#062;"      //	greater than sign
var  ESC_at                         = "&#064;"      //	at sign
var  ESC_left_bracket               = "&#091;"      //	left bracket
var  ESC_right_bracket              = "&#093;"      //	right bracket
var  ESC_back_apostrophe            = "&#096;"      //	back apostrophe
var  ESC_left_curly_brace           = "&#123;"      //	left curly brace
var  ESC_vertical_bar               = "&#124;"      //	vertical bar
var  ESC_right_curly_brace          = "&#125;"      //	right curly brace
var  ESC_tilde                      = "&#126;"      //	tilde
var  ESC_ellipsis                   = "&#133;"      //	ellipsis
var  ESC_dagger                     = "&#134;"      //	dagger
var  ESC_double_dagger              = "&#135;"      //	double dagger
var  ESC_left_single_quote          = "&#145;"      //	left single quote
var  ESC_right_single_quote         = "&#146;"      //	right single quote
var  ESC_left_double_quote          = "&#147;"      //	left double quote
var  ESC_right_double_quote         = "&#148;"      //	right double quote
var  ESC_bullet                     = "&#149;"      //	bullet
var  ESC_short_dash                 = "&#150;"      //	short dash
var  ESC_longer_dash                = "&#151;"      //	longer dash
var  ESC_trademark                  = "&#153;"      //	trademark
var  ESC_inverted_exclamation_point = "&#161;"      //	inverted exclamation point
var  ESC_cent_sign                  = "&#162;"      //	cent sign
var  ESC_English_pound              = "&#163;"      //	English pound sign
var  ESC_yen                        = "&#165;"      //	yen sign
var  ESC_broken_vertical_bar        = "&#166;"      //	broken vertical bar
var  ESC_copyright                  = "&#169;"      //	copyright sign
var  ESC_double_less_than           = "&#171;"      //	double less than sign
var  ESC_logical_not                = "&#172;"      //	logical not sign
var  ESC_registered_trademark       = "&#174;"      //	registered trademark sign
var  ESC_degree                     = "&#176;"      //	degree sign
var  ESC_plus_or_minus              = "&#177;"      //	plus or minus sign
var  ESC_superscript_2              = "&#178;"      //	superscript 2
var  ESC_superscript_3              = "&#179;"      //	superscript 3
var  ESC_superscript_1              = "&#185;"      //	superscript 1
var  ESC_double_greater_than        = "&#187;"      //	double greater than sign
var  ESC_fraction_14                = "&#188;"      //	fraction 1/4
var  ESC_fraction_12                = "&#189;"      //	fraction 1/2
var  ESC_fraction_34                = "&#190;"      //	fraction 3/4
var  ESC_inverted_question_mark     = "&#191;"      //	inverted question mark
var  ESC_division_sign              = "&#247;"      //	division sign
var  ESC_left_double_quote2         = "&#8220;"     //	left double quote
var  ESC_right_double_quote2        = "&#8221;"     //	right double quote
var  ESC_dash                       = "&#8212;"     //	dash

var strSeperator = "~";

var NS4 = (document.layers);    // Which browser?
var IE4 = (document.all);
var win = window;               // window to search.
var n   = 0;

function formatPhone ( PhoneObject )
{
   var strTemp  = PhoneObject.value;
   var strFinal = "";

   if ( strTemp == "" || strTemp.charAt(3) == "-" )
      return;

   //
   //  If it includes the area code then it has to be longer than 7 characters...
   //
   if ( strTemp.length > 7 )
      strFinal = strTemp.substring(0,3) + "-" + strTemp.substring(3,6) + "-" + strTemp.substring(6,10)
   else
      strFinal = strTemp.substring(0,3) + "-" + strTemp.substring(3,7)

   PhoneObject.value = strFinal;
   return;
}

function formatDate ( dateObject )
{
   replaceSingleQuotes( dateObject );

   var strTemp   = dateObject.value;
   var numLength = strTemp.length;
   var strFinal  = "";
   var flagOK_2_format;

   if ( strTemp == "" )
      return;

   if ( strTemp.charAt(1) == "/" || strTemp.charAt(2) == "/" || strTemp == "" )
      flagOK_2_format = true;
   else
      flagOK_2_format = false;

   if ( flagOK_2_format == false && numLength != 6 && numLength != 8 )
      {
      alert ( "Date Format Error --- Date MUST be in the form mmddyy or mmddyyyy" );

      dateObject.value = "";
      dateObject.select();
      dateObject.focus ();
      }
   else
      {
      //
      //  Check to see if the '/' characters need to be entered
      //
      if ( strTemp.charAt(1) == "/" || strTemp.charAt(2) == "/" || strTemp == "" )
         strFinal = strTemp;
      else
         {
         if ( numLength == 6 )
            strFinal = strTemp.substring(0,2) + "/" + strTemp.substring(2,4) + "/" + strTemp.substring(4,6)
         else
            strFinal = strTemp.substring(0,2) + "/" + strTemp.substring(2,4) + "/" + strTemp.substring(4,8)
         }

      var nResults = testDate ( strFinal );
      if ( nResults == 1 )
         {
         alert ( "Date Format Error: " + strFinal );
         dateObject.value = "";
         dateObject.select ();
         dateObject.focus  ();
         }
      else
         dateObject.value = strFinal;
      }

   return;
}

function UpperCase ( String )
{
   var localString = String.toUpperCase();
   return ( localString );
}

function LowerCase ( String )
{
   var localString = String.toLowerCase();
   return ( localString );
}

// -------------------------------------------------------------------------
// Cookie functions

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function cookiesEnabled() {

	var cookieEnabled=(navigator.cookieEnabled)? true : false
	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
	document.cookie="testcookie"
	cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
	}
	return (cookieEnabled);
}

//-----------------------------------------------------------
// Encoding and Decoding routines for client side code
//-----------------------------------------------------------

function UrlFullEncode(str) {
 str = escape(str);
 //str = str.replace('%','%*');
 return str;
}

function UrlFullDecode(str) {
 //str = str.replace('%*','%');
 str = unescape(str);
 return str;
}

//-----------------------------------------------------------
// Window opening functions
//-----------------------------------------------------------

function openWin(URL,name,w,h){
aWindow = window.open(URL, name,"width="+w+",height="+h);
}
function openWin(URL,name,w,h,scroll){
aWindow = window.open(URL, name,"width="+w+",height="+h+",scrollbars="+scroll);
}

//-----------------------------------------------------------
// Color Scheme testing functions
//-----------------------------------------------------------
var DEFAULT_StyleSheet = 'brn.css';

function setSiteStyle(targetStyle,intPopup) {
	
	switch (intPopup)
	{
		// This is the style for popups
		case 1: document.write("<style type='text/css' media='all'> @import '../../styles/" + targetStyle + "'; </style>");
		break;
		// This is the style for the slideshows
		case 2: document.write("<style type='text/css' media='all'> @import '../styles/" + targetStyle + "'; </style>");
		break;
		// This is the style for the main pages
		default: document.write("<style type='text/css' media='all'> @import 'styles/" + targetStyle + "'; </style>");
	}
}

function testTheme(intPopup) {
	// Check if cookies are enabled.  If yes then check if cookie exists else set a cookie with the default style
	// If not then choose the default style by default
	
	if (cookiesEnabled())
	{
		var srcCookie = readCookie('cpwoodstyle');
		if (srcCookie) 
		{
			setSiteStyle(srcCookie,intPopup);
		}
		else
		{
			createCookie('cpwoodstyle',DEFAULT_StyleSheet,30);
			setSiteStyle(DEFAULT_StyleSheet,intPopup);
		}
		
	}
	else
	{
		return DEFAULT_StyleSheet;
	}
}
function ChangeTheme(targetStyle) {
	// Check if cookies are enabled. If yes then create or set the cookie else use the default style
	if (cookiesEnabled())
	{
		createCookie('cpwoodstyle',targetStyle,30);
		window.location.reload();
	}
	else
	{
		alert('To change theme colors cookies must be enabled.\nChange this setting and try again. The default theme will still be used.');
	}
}

function ShowSplash()
{

	var browser=navigator.appName;
	if (browser != "Microsoft Internet Explorer")
		document.write("<embed src='CPwood_Splash.swf' loop='false' quality='high' bgcolor='" + document.body.style.background + "'  width='550' height='400' name='CPwood_Splash' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	else
	{
		document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='550' height='400' id='CPwood_Splash'>");
		document.write("<param name='movie' value='CPwood_Splash.swf' />");
		document.write("<param name='loop' value='false' />");
		document.write("<param name='quality' value='high'>");
		document.write("<param name='bgcolor' value='" + document.body.style.background + "'>");
		document.write("</object>");
	}
}
