// ihrfg.js: shared JavaScript for IHRFG 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 that displays status bar message
var showMsg = navigator.userAgent != "Mozilla/4.0 (compatible; MSIE 4.0; Mac_PowerPC)";

function di(id,name){
  if (document.images) {document.images[id].src=eval(name+".src"); }
}

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_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_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

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];}}
}

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];}
}

// initializes dropdown menus from nav bar
function hrLoadMenus() {
  var path = "location='" + getRootPath();
  var font = (is.win ? "Arial, Helvetica, sans-serif" : "Helvetica, Arial, sans-serif");
  var fs = (is.win && is.ns4 ? 12 : 11);
  if (window.fw_menu_0) return;
  window.fw_menu_0 = new Menu("root",132,16,font,fs,1);
  fw_menu_0.addMenuItem("Overview and Services",path+"about/index.html'");
  fw_menu_0.addMenuItem("Join Us",path+"about/join.html'");
  fw_menu_0.addMenuItem("Contact Us",path+"about/contact.html'");
  fw_menu_0.addMenuItem("Feedback",path+"about/feedback.html'");
  fw_menu_0.addMenuItem("Site Map",path+"sitemap.php'");
   fw_menu_0.hideOnMouseOut=true;
  window.fw_menu_1 = new Menu("root",144,16,font,fs,1);
  fw_menu_1.addMenuItem("IHRFG on HR Grantmaking",path+"hrfunding/index.html'");
  fw_menu_1.addMenuItem("FAQ: Human Rights",path+"hrfunding/faq-hr.html'");
  fw_menu_1.addMenuItem("FAQ: HR Grantmaking",path+"hrfunding/faq-hrg.html'");
  fw_menu_1.addMenuItem("Grantmaker News",path+"hrfunding/inthenews.php'");
   fw_menu_1.hideOnMouseOut=true;
  window.fw_menu_2 = new Menu("root",132,16,font,fs,2);
  fw_menu_2.addMenuItem("Human Rights",path+"rights/right.php?right=1'");
  fw_menu_2.addMenuItem("Civil/Political",path+"rights/right.php?right=2'");
  fw_menu_2.addMenuItem("Economic/Social/Cultural",path+"rights/right.php?right=3'");
  fw_menu_2.addMenuItem("Association",path+"rights/right.php?right=4'");
  fw_menu_2.addMenuItem("Children",path+"rights/right.php?right=5'");
  fw_menu_2.addMenuItem("Development",path+"rights/right.php?right=6'");
  fw_menu_2.addMenuItem("Disability",path+"rights/right.php?right=7'");
  fw_menu_2.addMenuItem("Education",path+"rights/right.php?right=8'");
  fw_menu_2.addMenuItem("Elections, Participation",path+"rights/right.php?right=9'");
  fw_menu_2.addMenuItem("Environment",path+"rights/right.php?right=10'");
  fw_menu_2.addMenuItem("Equality",path+"rights/right.php?right=11'");
  fw_menu_2.addMenuItem("Expression",path+"rights/right.php?right=12'");
  fw_menu_2.addMenuItem("Health",path+"rights/right.php?right=13'");
  fw_menu_2.addMenuItem("Housing",path+"rights/right.php?right=14'");
  fw_menu_2.addMenuItem("Immigrants",path+"rights/right.php?right=15'");
  fw_menu_2.addMenuItem("Indigenous Peoples",path+"rights/right.php?right=16'");
  fw_menu_2.addMenuItem("Justice",path+"rights/right.php?right=17'");
  fw_menu_2.addMenuItem("Labor",path+"rights/right.php?right=18'");
  fw_menu_2.addMenuItem("Land",path+"rights/right.php?right=19'");
  fw_menu_2.addMenuItem("Living standard",path+"rights/right.php?right=20'");
  fw_menu_2.addMenuItem("Peace",path+"rights/right.php?right=21'");
  fw_menu_2.addMenuItem("Physical Integrity",path+"rights/right.php?right=22'");
  fw_menu_2.addMenuItem("Prisoners",path+"rights/right.php?right=23'");
  fw_menu_2.addMenuItem("Racial Minorities",path+"rights/right.php?right=24'");
  fw_menu_2.addMenuItem("Refugees",path+"rights/right.php?right=25'");
  fw_menu_2.addMenuItem("Religion",path+"rights/right.php?right=26'");
  fw_menu_2.addMenuItem("Reproductive",path+"rights/right.php?right=27'");
  fw_menu_2.addMenuItem("Self-Determination",path+"rights/right.php?right=28'");
  fw_menu_2.addMenuItem("Sexual Minorities",path+"rights/right.php?right=29'");
  fw_menu_2.addMenuItem("Women",path+"rights/right.php?right=30'");
  fw_menu_2.addMenuItem("Work",path+"rights/right.php?right=31'");
  fw_menu_2.hideOnMouseOut=true;
  window.fw_menu_3 = new Menu("root",132,16,font,fs,1);
  fw_menu_3.addMenuItem("Guide for Grantseekers",path+"funders/index.html'");
  fw_menu_3.addMenuItem("Funders Directory",path+"funders/funder.php?op=list'");
  fw_menu_3.addMenuItem("Find a Funder",path+"funders/funder.php?op=findform'");
  fw_menu_3.addMenuItem("Edit Profile",path+"funders/funder.php?op=editmy'");
  fw_menu_3.addMenuItem("Register",path+"funders/funder.php'");
  fw_menu_3.hideOnMouseOut=true;
  window.fw_menu_4 = new Menu("root",132,16,font,fs,1);
  fw_menu_4.addMenuItem("Overview",path+"resources/index.php'");
  fw_menu_4.addMenuItem("Events",path+"resources/events.php'");
  fw_menu_4.addMenuItem("News",path+"resources/index.php?op=list&type=1'");
  fw_menu_4.addMenuItem("Publications",path+"resources/index.php?op=list&type=2'");
  fw_menu_4.addMenuItem("Reports",path+"resources/index.php?op=list&type=8'");
  fw_menu_4.addMenuItem("Links",path+"resources/links.php'");
  fw_menu_4.addMenuItem("Issues and Strategies",path+"resources/index.php?op=list&type=128'");
  fw_menu_4.addMenuItem("IHRFG Publications",path+"resources/ihrfgpubs.php'");
  fw_menu_4.addMenuItem("Recommended Reading",path+"resources/index.php?op=list&type=32'");
   fw_menu_4.hideOnMouseOut=true;
  window.fw_menu_5 = new Menu("root",110,16,font,fs,1);
  fw_menu_5.addMenuItem("Overview",path+"members/index.php'");
  fw_menu_5.addMenuItem("Working Groups",path+"members/workinggroups.php'");
//  fw_menu_5.addMenuItem("IHRFG Committees",path+"members/committees.php'");
  fw_menu_5.addMenuItem("IHRFG Meetings",path+"members/post.php?op=list&type=3'");
  fw_menu_5.addMenuItem("Jobs",path+"members/post.php?op=list&type=12'");
  fw_menu_5.addMenuItem("Soapbox",path+"members/post.php'");
   fw_menu_5.hideOnMouseOut=true;
  window.fw_menu_6 = new Menu("root",80,16,font,fs,1);
  fw_menu_6.addMenuItem("About",path+"events/index.php'");
  fw_menu_6.addMenuItem("Register",path+"events/register.php?op=new'");
   fw_menu_6.hideOnMouseOut=true;
  window.fw_menu_7 = new Menu("root",110,16,font,fs,1);
  fw_menu_7.addMenuItem("Login",path+"php/start.php'");
  fw_menu_7.addMenuItem("Register",path+"php/start.php?op=new'");
  fw_menu_7.addMenuItem("Forgot Password",path+"php/start.php?op=forgotform'");
  fw_menu_7.addMenuItem("Change Password",path+"php/start.php?op=passform'");
  fw_menu_7.addMenuItem("Edit Account Info",path+"php/start.php?op=view'");
   fw_menu_7.hideOnMouseOut=true;
  fw_menu_7.writeMenus();
} // hrLoadMenus()


// function to hide mailto links from spam bots
// usage <script language="JavaScript" type="text/JavaScript"> writeMailto("user", "domain.org"); </script>
function writeMailto(address, domain)
{
	emailE=(address + '@' + domain);
	document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>');
}


// selects or deselects a set of checkboxes based on the current value of the "select all" checkbox
function selectAll(formname, key, numvalues, newvalue)
{
	for (i = 0; i < numvalues; ++i)
	{
		eval("document." + formname + "." + key + i + ".checked = " + (newvalue ? "true": "false"));
	}
	return false;
}


// returns the path to the root folder of the web site
var hasCustomRootPath = 0;
function getRootPath()
{
	// use this trick to figure out the path to root of the web site
	// assumes the first link on every page is a link to the home page
  	var home = document.links[0].href;
  	var path = (home ? home.substring(0, home.length - 9) : "");
	
	// pages can override the computed value by specifying a value for
	// global var customRootPath and setting hasCustomRootPath to 1.
	if (hasCustomRootPath)
		return customRootPath;

    return path;
}


// simple script to modify navigation bar to show arrow above section name in nav bar

var sections = ["about", "hrfunding", "rights", "funders", "fghr", "links", "events"];

function checkSection(i, section)
{
	if (document.location.href.indexOf("/" + section + "/") > -1)
  	{ 
  		MM_swapImage(section, "../images/nav_" + section + "_f3.gif", "../images/" + section + "_f3.gif");
		return true;
	}
	return false;
}

function setNav()
{
	for (var i = 0; i < sections.length; ++i)
	{
		if (checkSection(i+1, sections[i]))
			return;
	}
}

// should be called by the onLoad handler
function ihrfgInit()
{
    MM_preloadImages('../images/nav_about_up.gif','../images/nav_hrfunding_up.gif','../images/nav_rights_up.gif','../images/nav_funders_up.gif','../images/nav_fghr_up.gif','../images/nav_links_up.gif','../images/nav_events_up.gif');
 	
	// later
	// setNav();
}