var url = document.location.href;
var dirArray = url.split("/");
var subdir = dirArray[4];
dirArray.reverse();
var page = dirArray[0];
var pageArray = page.split(".");
var pagename = pageArray[0];

//navigation array
var nav = new Array('about','students','teachers','news');
var thisDir;

//match directories w/element names
if (subdir =='ae') { thisDir = 'about';}
else if (subdir =='ft') {thisDir = 'teachers';}
else if (subdir =='fs') {thisDir = 'students';}
else if (subdir =='news') {thisDir = 'news';}

function cookieTime(days){
  var now = new Date();
  var exp = new Date();

  exp.setTime(Date.parse(now) + days*24*60*60*1000);

  return exp.toUTCString().replace('/(\d\d)\s(\w\w\w)\s\d\d(\d\d))/',"$1-$2-$3");
}

function hasNotSeenForm() {
	return (document.cookie.indexOf('CB_YES_REGISTERED=1')<0) ? true : false;
}

//turn on correct button, preload all
function setNav() {

	// this function is being called onload. adding some additional functionality 
	// to present a form when pdfs are downloaded

	if (subdir!='cu') {
		document.images[thisDir].src = '/prod_images/yes/nav_'+thisDir+'_on.gif';
	}
	MM_preloadImages('/prod_images/yes/nav_students_on.gif','/prod_images/yes/nav_teachers_on.gif','/prod_images/yes/nav_news_on.gif','/prod_images/yes/nav_about_on.gif');
	
	
	// present form to teachers downloading a pdf
	if(thisDir == 'teachers'){
		var anchors = document.getElementsByTagName('A');
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].href.match(/\/prod_downloads\/yes\/.*?\.pdf$/)){
				document.cookie      = 'CB_TEST=1; path=/;';
				var hasCookies       = (document.cookie.indexOf('CB_TEST=1')<0) ? false : true;			
				
				if(hasCookies && hasNotSeenForm()){
					anchors[i].onclick = function(){ document.cookie='CB_YES_PDF='+this.href + '; path=/;';window.location=document.location.protocol+'//'+document.location.host+'/yes/ft/contact.html'; return false;} ;
				}
			}
		}
	}
}

//show rollover and dropdown for a section
function switchNavII(item,state) {
	document.images[item].src = '/prod_images/yes/nav_'+item+state+'.gif';
	divName = item+'Nav';
	MM_showHideLayers(divName,'','show','hideAll','','show')
	switchNavRestoreII(item);
}

//restore rollovers and dropdowns
function switchNavRestoreII(except) {
	for (i=0;i<nav.length;i++) {
		if (document.images && nav[i]!=except) {
			if (nav[i]!=thisDir) {
				document.images[nav[i]].src = '/prod_images/yes/nav_'+nav[i]+'_off.gif';
			}
			tmp = nav[i]+'Nav';
			MM_showHideLayers(tmp,'','hide')
		}
	}
	MM_showHideLayers('applyNav','','hide')
}

//show rollover and dropdown on homepage
function switchNav(item) {
	document.images[item].src = '/prod_images/yes/nav_'+item+'_on.gif';
	divName = item+'Nav';
	MM_showHideLayers(divName,'','show','hideAll','','show')
	for (i=0;i<nav.length;i++) {
		if (document.images && nav[i]!=item) {
			document.images[nav[i]].src = '/prod_images/yes/nav_'+nav[i]+'_off.gif';
			temp = nav[i]+'Nav';
			MM_showHideLayers(temp,'','hide')
		}
	}
}

//restore all on homepage
function switchNavRestore() {
	for (i=0;i<nav.length;i++) {
		if (document.images) {
			document.images[nav[i]].src = '/prod_images/yes/nav_'+nav[i]+'_on.gif';
		}
	}
	MM_showHideLayers('aboutNav','','hide','studentsNav','','hide','teachersNav','','hide','newsNav','','hide','applyNav','','hide')
}

function swapCell(cell,state) {
	if (state=='on') { cell.bgColor='#00AFAD' }
	else if (state=='home') { cell.bgColor='#000000' }
	else { cell.bgColor='#ffffff' }
}

//select small images in left_nav and right_nav
//THIS ARRAY MUST HAVE 5 IMAGES
var thumbs = new Array('sm_mosquito.jpg','sm_scientist.jpg','sm_phone.jpg','sm_earth.jpg','sm_mask.jpg');
var cThumbs = new Array();
var k = Math.floor(Math.random()*thumbs.length)
for (i=0;i<thumbs.length;i++) {
	if (k==thumbs.length) {k=0;}
	cThumbs[i]=thumbs[k];k++
}

//glossary popup function
function openGlosWin(term){
	var newWin = window.open('/yes/ae/gloss_pop.html'+term,'Glossary','width=600,height=400,resizable=yes,scrollbars=yes,menubar=no,toolbar=no');
	newWin.focus();
}

//popup
function popup(path) {
var newWin = window.open(path,'popup','width=600,height=500,resizable=yes,scrollbars=yes,menubar=no,toolbar=no');
	newWin.focus();
	return false;
}

//request info popup
function infoPopup(path) {
var newWin = window.open(path,'infopopup','width=285,height=190,resizable=yes,scrollbars=no,menubar=no,toolbar=no');
	newWin.focus();
	return false;
}

//onload request info popup
//popup on ft and fs
function launchPopup(path) {
	if (document.cookie.indexOf('CB_YESFORM')==-1) {//check cookie
		infoPopup(path);
	}
}

//launch form from popup
function openForm() {
	formToUse = '/yes/cu/yes_form.html';
	if (page.indexOf('teacher')!=-1) {
		formToUse = '/yes/cu/yes_form_teachers.html';
	}	
	popup(formToUse);
	window.close();
}

//MM functions
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];}}
}

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_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_showHideLayers() { //v6.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; }
}
 
