// Partial Client Sniffer
// Backwards compatible to NN2.0
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_webtv, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_mac, is_mac68k, is_macppc


    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 6));
    var is_nav6up = (is_nav && (is_major >= 6));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie6  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5); //is_ie+' - '+!is_ie3+' - '+!is_ie4+' - '+!is_ie5
    var is_ie6up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5&& !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1); 

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

var IsBrowserOk = "NO";

	//variables below used by hideself() in hiermenu script pages to control buttonOn/Off
var CI_Btn_ID = 99; //initialize global variable for current Button Number (addition to hiermenus by CI)
var CI_Btn_Hold = '';
var MenuBtnNameOn = '';
var MenuBtnColorOn = '';
var CI_IMAGENAMES = new Array('','Home','MyCouncil','Educate','Develop','Inspire');
var CI_BTN_LEFT = new Array();
var CI_BTN_TOP = new Array();

function SetImageCoords()
{
	for(i=1;i<CI_IMAGENAMES.length;i++)
	{	CI_BTN_LEFT['HM_MENU'+i] = findPosX(GetObject(CI_IMAGENAMES[i]));
		CI_BTN_TOP['HM_MENU'+i] = findPosY(GetObject(CI_IMAGENAMES[i]))+GetObject(CI_IMAGENAMES[i]).height+1;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


	//	Convert object name string or object reference into a valid object reference
function GetObject(ThisRef)
{
	var Temp = '';
		Range = '';
		StyleObj = '';
		
	if(is_ie4up)
	{	Range = "all.";
		StyleObj = "";
	}
	if(is_nav6up || is_gecko) //DOM compliant
	{	Range = "getElementById('";
		StyleObj = "')";
	}
	if (typeof ThisRef == "string")
	{	Temp = eval("document." + Range + ThisRef + StyleObj)	}
	else	{	Temp = ThisRef	}
	return Temp;
}

//this function has been adapted for use with hiermenus
function ButtonOn(ThisName,ThisColor,IndexNum)
{	if(CI_Btn_ID != 99 )
	{	if (CI_Btn_Hold == ''){CI_Btn_Hold = ThisName}
		ButtonOff(CI_Btn_ID,'');
	}
	//ThisObject = GetObject(ThisName);
	//if(is_ie4up){ThisObject.style.backgroundColor = ThisColor}
	//else if(is_nav6up || is_gecko){ThisObject.style.backgroundColor = ThisColor}
	//else if(document.all){document.all.IndexNum.style.backgroundColor = ThisColor}
	//else if(document.getElementById)
	//{document.getElementById(ThisName).style.backgroundColor = ThisColor}
	CI_Btn_ID = ThisName; 
}

//this function has been adapted for use with hiermenus
function ButtonOff(ThisName,ThisColor,ThisMenu)
{	
	if (ThisName != 99  )
	{	//ThisObject = GetObject(ThisName);
		//if(is_ie4up){ThisObject.style.backgroundColor = ThisColor}
		//else if(is_nav6up || is_gecko){ThisObject.style.backgroundColor = ThisColor}
		//else if(document.all){document.all.IndexNum.style.backgroundColor = ThisColor}
		//else if(document.getElementById)
		//{document.getElementById(ThisName).style.backgroundColor = ThisColor}
		CI_Btn_ID = 99;
		CI_Btn_Hold = '';
	}
}


//this function has been adapted for use with hiermenus
function ButtonOn2()
{	if(CI_Btn_ID != 99 )
	{	if (CI_Btn_Hold == ''){CI_Btn_Hold = MenuBtnNameOn}
		ButtonOff(CI_Btn_ID,'');
	} 
	//ThisObject = GetObject(MenuBtnNameOn);
	//if(is_ie4up){ThisObject.style.backgroundColor = MenuBtnColorOn}
	//else if(is_nav6up || is_gecko){ThisObject.style.backgroundColor = MenuBtnColorOn}
	//else if(document.all){document.all.IndexNum.style.backgroundColor = MenuBtnColorOn}
	//else if(document.getElementById)
	//{document.getElementById(MenuBtnNameOn).style.backgroundColor = MenuBtnColorOn}
	CI_Btn_ID = MenuBtnNameOn;
}

//GET THE CORRECT ON-BUTTON;
function TurnPointerOn(ThisName,PointerType)
{	
	if (document.images)
	{	document[ThisName].src = PointerOver[PointerType].src}
};

//GET THE CORRECT OFF-BUTTON;
function TurnPointerOff(ThisName,PointerType)
{	
	if (document.images)
	{	document[ThisName].src = ImageFolder + Pointers[PointerType] + "-off.gif"}
};

//GET THE CORRECT OFF-BUTTON;
function SetBtnOnDelay(ThisName,ThisColor)
{	setTimeout("ButtonOn2()",100)	}

function ChangeButton(ThisName,ThisColor,IndexNum)
{	
	ThisObject = GetObject(ThisName);
	if(is_ie4up){ThisObject.style.backgroundColor = ThisColor}
	else if(is_nav6up || is_gecko){ThisObject.style.backgroundColor = ThisColor}
	else if(document.all){document.all.IndexNum.style.backgroundColor = ThisColor}
	else if(document.getElementById)
	{document.getElementById(ThisName).style.backgroundColor = ThisColor}
}

//these functions "ChangeButton" and "ChangeBackground" are the same for now but 
//we may need to add some additional features to "ChangeButton" at some later date

function ChangeBackground(ThisName,ThisColor,IndexNum)
{	
	ThisObject = GetObject(ThisName);
	if(is_ie4up){ThisObject.style.backgroundColor = ThisColor}
	else if(is_nav6up || is_gecko){ThisObject.style.backgroundColor = ThisColor}
	else if(document.all){document.all.IndexNum.style.backgroundColor = ThisColor}
	else if(document.getElementById)
	{document.getElementById(ThisName).style.backgroundColor = ThisColor}
}

function ChangeClass(ThisName,ThisClass)
{	
	ThisObject = GetObject(ThisName);
	if(is_ie4up){ThisObject.className = ThisClass}
	else if(is_nav6up || is_gecko){ThisObject.className = ThisClass}
	else if(document.all){document.all.ThisName.className = ThisClass}
	else if(document.getElementById)
	{document.getElementById(ThisName).className = ThisClass}
}


function PopPoll(FormObj)
	{	if(FormObj != '')
		{	var PollId = FormObj.Id.value;
			var Mem = FormObj.Mem.value;
			var SelectedIndex = SelectedRadio(FormObj.answer);
			var Choice = '';
			if(SelectedIndex >= 0)
			{	Choice = FormObj.answer[SelectedIndex].value;
			};
			OpenWindow(DC_BaseUrl+'resources?Action=PollResults;Id='+PollId+';Mem='+Mem+';answer='+Choice,400,350,'SurveyWindow',100,100,'','');
		}
		else
		{	alert('no form object');
		}
	};


function PopOptIn(FormObj)
	{	if(FormObj != '')
		{	var EmailAddr = FormObj.Email.value;
			//var NameFirst = FormObj.NameFirst.value;
			//var NameLast = FormObj.NameLast.value;
			//var Choice = '';
			//if(SelectedIndex >= 0)
			//{	Choice = FormObj.answer[SelectedIndex].value;	}
			if(EmailAddr)
			{	OpenWindow(DC_BaseUrl+'resources?Action=OptIn;Email='+EmailAddr,400,200,'NewsletterWindow',50,50,'','');
			}
			else
			{	alert('Email address is required.');
			}
		}
		else
		{	alert('no form object');
		}
	};

function SelectedRadio(ButtonGroup)
	{	if(ButtonGroup.length == undefined)
		{	if(ButtonGroup.checked)
			{ return 0}
		}
		else
		{	for(var i=0;i<=ButtonGroup.length-1;i++)
			{	if(ButtonGroup[i].checked){return i}
			}
		}
		return -1;
	};

function OpenWindow(WindowHREF,Width,Height,Name,ScreenX,ScreenY,LocationBar,ToolBar)
	{	
		if (Name == null || Name == ""){Name="DataWindow"} 
		if (WindowHREF == null || WindowHREF == ""){WindowHREF='""'} 
		if (Width != null && Width != "")
		{	Width=",Width="+(Width)}
		if (Height != null || Height != "")
		{	Height=",Height="+(Height)}
		if (ScreenX == null || ScreenX == ""){ScreenX = ""} else{ScreenX=",ScreenX="+ScreenX+",left="+ScreenX}
		if (ScreenY == null || ScreenY == ""){ScreenY = ""} else{ScreenY=",ScreenY="+ScreenY+",top="+ScreenY}
		if (LocationBar == null || LocationBar == ""){LocationBar = ""} else{LocationBar=",Location=yes"}
		if (ToolBar == null || ToolBar == ""){ToolBar = ""} else{ToolBar=",ToolBar=yes"}
		
		Options = Width+Height+ScreenX+ScreenY+LocationBar+ToolBar+',resizable=yes'+',scrollbars=yes';
		//Options += ',menubar,status,scrollbars,resizable,titlebar';
		DataWindow = window.open("",Name,Options);
		if (DataWindow.opener == null){DataWindow.opener = self};
		DataWindow.location = WindowHREF;
		DataWindow.focus();
	};
	
	
		// GLOBAL FUNCTION TO VIEW LARGE FORMAT PRODUCT IMAGE
function MakeImageWindow(ImageLink,ImageName,ImageWidth,ImageHeight)
	{	WindowSpecs = "resizable,width=" + ImageWidth + ",height=" + ImageHeight + ",ScreenX=50,Left=50,ScreenY=50,Top=50";
		if(top.ImageWindow){top.ImageWindow.close()};
		ImageWindow = window.open("","ImageWindow",WindowSpecs);
		if (ImageWindow.opener == null){ImageWindow.opener = self};
		NewContent = '<html><head><title>' + ImageName + '</title></head>';
		NewContent += '<BODY bgcolor="#ffffff" LEFTMARGIN="0" TOPMARGIN="0" marginheight="0" marginwidth="0">';
		NewContent += '<center><IMG src="' + ImageLink + '" >';
		NewContent += '</body></html>';
		ImageWindow.document.open();
		ImageWindow.document.write(NewContent);
		ImageWindow.document.close();
		top.ImageWindow.focus();
	};
	
	
function getQueryVariable(variable)
{	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{	return pair[1];
		}
	} 
	return '';
}

	

// This function goes through the options for the given
// drop down box and removes them in preparation for
// a new set of values
function emptyList( box ) {
	// Set each option to null thus removing it
	while ( box.options.length ) box.options[0] = null;
}

// This function assigns new drop down options to the given
// drop down box from the list of lists specified
function fillList( box, arr ) {
	// arr[0] holds the display text
	// arr[1] are the values
	for ( i = 0; i < arr[0].length; i++ )
	{	// Create a new drop down option with the
		// display text and value from arr
		option = new Option( arr[0][i], arr[1][i] );
		box.options[box.length] = option;	// Add to the end of the existing options
	}
	box.selectedIndex=0;	// Preselect option 0
}

// This function performs a drop down list option change by first
// emptying the existing option list and then assigning a new set
function changeList( box )
{	// Isolate the appropriate list by using the value of the currently selected option
	list = SearchParams[box.options[box.selectedIndex].value];
	emptyList( box.form.SearchField );	// Next empty the slave list
	fillList( box.form.SearchField, list );	// Then assign the new list values
}


function setCookie(name, value, expires, path, domain, secure) {
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}



function getCookie(name) {
/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}



function deleteCookie(name, path, domain) {
/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function fixDate(date) {
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

/* 
Webmonkey GET Parsing Module 
Language: JavaScript 1.0 

The parsing of GET queries is fundamental 
to the basic functionality of HTTP/1.0. 
This module parses GET with JavaScript 1.0. 

Source: Webmonkey Code Library 
(http://www.hotwired.com/webmonkey/javascript/code_library/) 

Author: Patrick Corcoran 
Author Email: patrick@taylor.org 
*/ 

function createRequestObject() { 

  FORM_DATA = new Object(); 
    // The Object ("Array") where our data will be stored. 

  separator = ','; 
    // The token used to separate data from multi-select inputs 

  query = '' + this.location; 
  qu = query 
    // Get the current URL so we can parse out the data. 
    // Adding a null-string '' forces an implicit type cast 
    // from property to string, for NS2 compatibility. 

  query = query.substring((query.indexOf('?')) + 1); 
    // Keep everything after the question mark '?'. 

  if (query.length < 1) { return false; }  // Perhaps we got some bad data? 

  keypairs = new Object(); 
  numKP = 1; 
    // Local vars used to store and keep track of name/value pairs 
    // as we parse them back into a usable form. 

  while (query.indexOf('&') > -1) { 
    keypairs[numKP] = query.substring(0,query.indexOf('&')); 
    query = query.substring((query.indexOf('&')) + 1); 
    numKP++; 
      // Split the query string at each '&', storing the left-hand side 
      // of the split in a new keypairs[] holder, and chopping the query 
      // so that it gets the value of the right-hand string. 
  } 

  keypairs[numKP] = query; 
    // Store what's left in the query string as the final keypairs[] data. 

  for (i in keypairs) { 
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('=')); 
      // Left of '=' is name. 
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1); 
      // Right of '=' is value. 
    while (keyValue.indexOf('+') > -1) { 
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1); 
        // Replace each '+' in data string with a space. 
    } 

    keyValue = unescape(keyValue); 
      // Unescape non-alphanumerics 

    if (FORM_DATA[keyName]) { 
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue; 
        // Object already exists, it is probably a multi-select input, 
        // and we need to generate a separator-delimited string 
        // by appending to what we already have stored. 
    } else { 
      FORM_DATA[keyName] = keyValue; 
        // Normal case: name gets value. 
    } 
  } 

  return FORM_DATA; 
} 


  // This is the array/object containing the GET data. 
  // Retrieve information with 'FORM_DATA [ key ] = value'. 
FORM_DATA = createRequestObject();
if(FORM_DATA["Cmp"]){
	setCookie("Cmp",FORM_DATA["Cmp"],"","/")
}
  

