// foei.js: shared JavaScript for FoEI web site

// -----------------------------------------------------------------------------------
// BrowserCheck Object
// provides most commonly needed browser checking variables
// 19990326
// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/
function BrowserCheck() {
    var agt=navigator.userAgent.toLowerCase(); 
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
    this.mac = (agt.indexOf("mac")!=-1);
	this.win = (agt.indexOf("win")!=-1);
    this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	this.ie55 = (navigator.userAgent.indexOf('MSIE 5.5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie); // this.ie && this.win;
}

// automatically create the "is" object
var is = new BrowserCheck()
// end BrowserCheck Object;
// -----------------------------------------------------------------------------------

// Functions from Fireworks to handle rollovers
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// this links a page to the CSS file for the platform.  Since pages can be at different directory
// levels, this has to try to figure out the correct path when not on the production server.
// (on the production server, it can just look for the CSS file in the root folder)
function writeCSSFile()
{
	document.writeln('<style type="text/css">');
	document.writeln('<!--');

	// write platform-dependent styles here (mainly font sizes)
	if (is.mac) 
	{
		// macintosh
		document.writeln("p { font-size:10pt } ");
		document.writeln("td { font-size:10pt } ");
		document.writeln("li { font-size:10pt } ");
		document.writeln("h1 { font-size:18pt } ");
		document.writeln("h2 { font-size:14pt } ");
		document.writeln("h3 { font-size:12pt } ");
		document.writeln("h4 { font-size:10pt } ");
		document.writeln("h5 { font-size:9pt } ");
		document.writeln("h6 { font-size:8pt } ");
		document.writeln(".fineprint { font-size:9pt } ");
		document.writeln(".legal { font-size:8pt } ");
		document.writeln(".copyright { font-size:8pt } ");
		document.writeln(".caption { font-size:9pt } ");
		document.writeln(".address { font-size:9pt } ");
		document.writeln(".dropdown { font-size:10pt } ");
		document.writeln(".breadcrumb { font-size:9pt } ");
		document.writeln(".pageheading { font-size:14pt } ");
		document.writeln(".subheading { font-size:12pt } ");
	}
	else 
	{
		// windows
		document.writeln("p { font-size:9pt } ");
		document.writeln("td { font-size:9pt } ");
		document.writeln("li { font-size:9pt } ");
		document.writeln("h1 { font-size:18pt } ");
		document.writeln("h2 { font-size:14pt } ");
		document.writeln("h3 { font-size:12pt } ");
		document.writeln("h4 { font-size:10pt } ");
		document.writeln("h5 { font-size:9pt } ");
		document.writeln("h6 { font-size:8pt } ");
		document.writeln(".fineprint { font-size:8pt } ");
		document.writeln(".legal { font-size:7pt } ");
		document.writeln(".copyright { font-size:7pt } ");
		document.writeln(".caption { font-size:8pt } ");
		document.writeln(".address { font-size:8pt } ");
		document.writeln(".dropdown { font-size:8pt } ");
		document.writeln(".breadcrumb { font-size:8pt } ");
		document.writeln(".pageheading { font-size:14pt } ");
		document.writeln(".subheading { font-size:12pt } ");
	}
	
	document.writeln('-->');
	document.writeln('</style>');
}

// simple script to modify navigation bar to show arrow above section name in nav bar
var sections = ["campaign", "groups", "publications", "media"];

function checkSection(i, section)
{
	if (document.location.href.indexOf("/" + section + "/") > -1)
  	{ 
  		di("Nnav_02_0" + i, "Inav_02_0" + i + "o");
  		eval("Inav_02_0" + i + ".src = Inav_02_0" + i + "o.src");
		return true;
	}
	return false;
}

function setNav()
{
	for (var i = 0; i < sections.length; ++i)
	{
		if (checkSection(i+1, sections[i]))
			return;
	}
}


// returns value of specified cookie
function getCookieValue(cName)
{
	var result = null;
	var pValue;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + cName + "=";
	var cStart = myCookie.indexOf(searchName);
	var cEnd;

	if (cStart != -1)
	{
		cStart += searchName.length;
		cEnd = myCookie.indexOf(";", cStart);
		result = unescape(myCookie.substring(cStart, cEnd));

		return result;
	}

	return "";
}

function getIntCookie(cName, defaultValue)
{
	var value = getCookieValue(cName);
	return (value.length > 0 ? parseInt(value) : defaultValue);
}

// sets value of the specified cookie
function setCookieValue(cName, value)
{
	var cookieStr = value;
	var expDate = new Date();
	var oneYear = 12 * 31 * 24 * 60 * 60 * 1000;

	expDate.setTime(expDate.getTime() + oneYear);

	cookieStr += "; expires=" + expDate.toGMTString();
	cookieStr += "; path=/";

	document.cookie = cName + "=" + cookieStr;
}

// returns a random integer less than max
function randomInt(max)
{
	return Math.floor(Math.random() * max * 0.99999);
}

// for handling popup menus
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  var url=selObj.options[selObj.selectedIndex].value;
  if (url.length > 0) eval(targ+".location='"+url+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
  return false;
}


