var hostRemove = "/aaas"; // remove this string from the scriptstring every pageload.


function goSearch() {
	var q = "";
	if ( document.getElementById ) {
		q = document.getElementById("text").value;
	}
	if (q != "") {
		document.location="http://vivo.aaas.org/vivisimo/cgi-bin/query-meta?v:project=aaas-website&query=" + q;
	}
	else {
		alert("Enter a search term first, or use the \"Advanced Search\" link.");
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //added by Nina Tovish for home page pop-up
  window.open(theURL,winName,features);
}

function toggleMenuActive(intCell) {
	// reset current active root-meny cell
	if ( document.getElementById ) {
		var ointCell = document.currentCell;
		if ( ointCell != null ) {
			var oObjC = MM_findObj("m"+ointCell);
			var oSep1 = MM_findObj("sep"+ointCell);
			var oSep2 = MM_findObj("sep"+(ointCell+1));

			oObjC.style.backgroundColor = '#307EC0';
			if ( ointCell<2  ) {
				oSep1.src = 'http://www.aaas.org/images/topmenu_left_off.gif';
			} else {
				oSep1.src = 'http://www.aaas.org/images/topmenu_sep1.gif';
			}
			if ( ointCell==7 ) {
				oSep2.src = 'http://www.aaas.org/images/topmenu_right_off.gif';
			} else {
				oSep2.src = 'http://www.aaas.org/images/topmenu_sep1.gif';
			}
		}

		// set new cell as active
		var oObjC = MM_findObj("m"+intCell);
		var oSep1 = MM_findObj("sep"+intCell);
		var oSep2 = MM_findObj("sep"+(intCell+1));
		oObjC.style.backgroundColor = '#0A599B';

		if ( intCell<2  ) {
			oSep1.src = 'http://www.aaas.org/images/topmenu_left_on.gif';
		} else {
			oSep1.src = 'http://www.aaas.org/images/topmenu_sep2.gif';
		}
		if ( intCell==7 ) {
			oSep2.src = 'http://www.aaas.org/images/topmenu_right_on.gif';
		} else {
			oSep2.src = 'http://www.aaas.org/images/topmenu_sep3.gif';
		}

		document.currentCell = intCell;
	}
}
document.currentCell = 1;

function togglePageMenu(intPid, bolClose) {
	var imgObj = MM_findObj("img"+intPid);
	var spanObj = MM_findObj("p"+intPid);


	var ointPid = document.intPid ;

	// --- hide current load subpage menu --- //
	if ( ointPid != null ) {
		if ( ointPid != intPid ) {
			togglePageMenu(ointPid, true);
		}
	}

	// --- toggle arrow image right next to the menu item itself --- //
	if ( imgObj != null ) {
		if ( imgObj.src.substring(imgObj.src.lastIndexOf('/')+1, imgObj.src.length) == "pixel.gif" && !bolClose) {
			imgObj.src = "http://www.aaas.org/images/submenu_arrow_down.gif";
		} else {
			imgObj.src = "http://www.aaas.org/images/pixel.gif";
		}
	}
	// --- toggle display for the level 4 menu-items --- //
	if ( spanObj != null ) {
		if ( (spanObj.style.display == "" || spanObj.style.display == "none") && !bolClose) {
			spanObj.style.display = "block";
		} else {
			spanObj.style.display = "none";
		}
	}

	document.intPid = intPid;
}

// CUSTOMIZED FOR SHAREPOINT
_spBodyOnLoadFunctionNames.push('CUSTOMonload');
function CUSTOMonload() {
	initFoldout();

	var hostString = document.location.pathname; // get current path for current loaded page
	hostString = hostString.replace(hostRemove, ""); // strip any unwanted folders if specified
	
	// HACK JR FOR THIS SITE
	hostString = "/meetings/";

	var levelIndex = 1;
	var folderPointer = 1;
	while ( hostString.indexOf('/', folderPointer)>-1 ) { // loop while there are more sub-folders present
		eval("var level"+levelIndex+"id = leve"+levelIndex+"Menus[hostString.substring(1, hostString.indexOf('/', folderPointer))];"); // set variable-name depeding on level to corresponding path
		folderPointer = hostString.indexOf('/', folderPointer)+1; // move "pointer" to following folder
		levelIndex++;
	}

	if ( !(typeof(level1id) == "undefined") ) {
		toggleMenuActive(parseInt(level1id)); // mark root-menu as active
		MM_showHideLayers('sub'+level1id,'','show'); // display submenu for current root-menu
	}
	
	if ( !(typeof(level2id) == "undefined") ) {
		if ( !(browser == 'Netscape' && version >= 4.0) )
			MM_findObj("s"+level1id+"c"+level2id).style.backgroundColor = '#3B8ACC'; // mark current submenu-item as active
	}
	
	if ( !(typeof(level3id) == "undefined") ) {
		menu(level3id); // show current subpage-menu (to the left) if any...
	}

	// Hack by Patrick 6/30/04
	// Allows pages in any directory to show left sidebar submenus
	if ( !(typeof(showMenu) == "undefined") ) {
      if(showMenu >= 0) {
        menu(showMenu);
	  }
    }
}


/* Start: cookies.js */
/*
     Originally: Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
*/

// utility function to retrieve a future expiration date in proper format;
// pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire; all three
// parameters required, so use zeros where appropriate
function getExpDate(days, hours, minutes) {
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

// utility function called by getCookie()
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return null;
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/* End: cookies.js */