
// JAVASCRIPT


// SHOW VIDEO - MOVE TO VIDEO PAGE


function showvideo(which,section)				// which video from the array, into which section page
	{
	var fmdirectory = "/review/sgvmwd.org";
	var myhost = location.host;
	if(myhost.indexOf("freethmoroz.com") > 0)
		{
		myhost += fmdirectory ;
		}

	// THESE ARE THE VIDEO FILES	

	var whichvideo = which;

	var whichsection = section;

	var localserver = "http://" + myhost + "/";
 
	var video = new Array();
	video[0] = "vid_start.htm";
	video[1] = "education/saving_water_at_home.htm";
	video[2] = "about/darin_mission.htm";
	video[3] = "about/rough_history-Reichenberger_1.htm";
	video[4] = "about/history_at_a_glance.htm";
	video[5] = "education/long_term_solutions.htm";
	video[6] = "education/saving_water_at_home_chinese.htm";
	video[7] = "education/paulson_education.htm";
	video[8] = "education/montoya_discuss_qualitiy.htm";
	video[9] = "education/reichenberger_energy.htm";
	video[10] = "education/love_fragile_water.htm";
	video[11] = "pilot_projects/alhambra_gateway.htm";
	video[12] = "pilot_projects/azusa_landscaping.htm";
	video[13] = "pilot_projects/monterey_park_amr.htm";
	video[14] = "pilot_projects/monterey_park_planters.htm";
	video[15] = "pilot_projects/sierra_madre_landscaping.htm";
	video[16] = "supply_quality/sierra_madre_mira_monte.htm";
	video[17] = "supply_quality/alhambra_groundwater.htm";
	video[18] = "pilot_projects/sierra_madre_school_project.htm";
	video[19] = "pilot_projects/sierra_madre_school_project.htm";
	video[20] = "education/Mascott_English_Master.htm";
	video[21] = "education/Mascott_Mandarin_Master.htm";
	



	video[1000] = "vid_placeholder.htm";


	// THESE ARE THE SECTION PAGES
	var mysection = new Array();
	mysection[0] = "index.htm";
	mysection[1] = "vidAbout.htm";
	mysection[2] = "vidPublicEducation.htm";
	mysection[3] = "vidPilotProjects.htm";
	mysection[4] = "vidSupplyQuality.htm";
	
	
	if(location.search)		// IF THERE'S A LOCAL SEARCH VALUE, THIS MUST NOT BE THE VIDEO INTERFACE
		{
		document.getElementById("videowindow").src = video[whichvideo];
		return;
		}
		else			// otherwise, it *is* THE VIDEO INTERFACE
		{
		var myredirect = localserver + "video/" + mysection[whichsection] + "?videonumber=" + whichvideo;

		win=window.open(myredirect, "vidwindow", "toolbar=no,location=no,directories=no,status=0,statusbar=0,menubar=no,scrollbars=no,resizable=no,height=680,width=800");
		return;
		}
	}



// CONTROL VIDEO

// controls video; also shows or hides container div or layer
// parameters: video ID, control action, container id, and action (none, block, hidden, visibile; the action implies whether div or layer)
//             only the first two parameters are required

function vidControl(vidID,act,containerid,containeraction)
	{
	var videoID = vidID;
	var action = act;
	var temp="";

	if(containerid)
		{
		var container_id = containerid;
		var container_action = containeraction;
		if(container_action == "block" || container_action == "none")		// must be display
			{
			temp = "document.getElementById('" + container_id + "').style.display='" + container_action + "'";
			}
		if(container_action == "hidden" || container_action == "visible")		// must be visibility
			{
			temp = "document.getElementById('" + container_id + "').style.display='" + container_action + "'";
			}
		eval(temp);
		}

	var movie = "window.document." + videoID;
//	var movie = document.getElementById(videoID);

	movie.Play();
	}




function doCounter()
	{
	var currentTime = "";
	var cookieTime = "";
	var temp = "";
	var myDate = "";

	// TEST COOKIE CAPABILITY

	SetCookie("testcookie",1);
	if(GetCookie("testcookie"))
		{
		DeleteCookie("testcookie");

		// MAKE CURRENT TIME, IN MINUTES
		myDate = new Date();
		currentTime = (myDate.getTime() / 60000);				// MILLNEUM TIME IN MINUTES
		currentTime = currentTime.toFixed(0);				// ROUND TO DECIMAL

		// GET COOKIE TIME
		cookieTime = GetCookie("storedcookie");

		// MORE THAN 30 MINUTES SINCE CLICKING AN ENTRY PAGE, OR, WE'RE VIRGIN TO THE SITE AND THERE'S NO STORED TIME YET
		if((currentTime - cookieTime > 30) || (cookieTime == null))	
			{
			SetCookie("storedcookie",currentTime);			// ESTABLISH THE NEW COOKIE TIME (RESTART COUNTER, STORED IN COOKIE)
			document.write("<img src='/cgi/sgvmwd/counter.cgi'>");		// WRITE IN THE CALL TO THE CGI. 
			}
		else	{
			return;								// FEWER THAN 30 MINUTES HAVE PASSED FOR THIS 'SURFER'. NOT A NEWLY-ENTERED USER
			}
		}
	else	{
		return;
		}
	}


/* This is not a function, but rather it sets some variables on page load
   The elements of the 'mainSection' array are the names of the first level folders in the site. */

	//GET THE NAME OF THIS LOADING FILE'S FIRST LEVEL FOLDER ("home", etc).
	var tem;
	tem="" + location;
	var locparts = tem.split("/");
	temp=locparts.length-2;				// the folder name will be the next to last member
	testsection = locparts[temp];
	var mainSection = new Array();			// USE THE FIRST LEVEL FOLDER NAMES
	mainSection[1] = "home";
	mainSection[2] = "about";
	mainSection[3] = "services_facilities";
	mainSection[4] = "partners_programs";
	mainSection[5] = "public_education";
	mainSection[6] = "save";
	mainSection[7] = "legislation";
	mainSection[8] = "news_media";
	mainSection[9] = "supply_solutions";
	// mainSection[10] = "template";				// ************** FOR TESTING ONLY CHANGE

	sectionLimit = mainSection.length;

	for(i=1;i<sectionLimit;i++)
		{
		if(mainSection[i]==testsection)
			{
			thissection=i;
			break;
			}
		}
// LOAD DRIP as appropriate when page loads (drip marks the page's section. Also, change background color
// THESE FUNCTIONS CONTROL THE BEHAVIOR AND APPEARANCE OF THE MAIN NAVIGATION LINKS

function setupPage()
	{
	if(thissection == 10){selectedcell=10; return;	}	// ********* SKIP PLACING DROP FOR TEST 'TEMPLATE' SECTION
	if(thissection==""){return;}		// No section given
	// SET THE DRIP
	thispagedrip="drip" + thissection;
	document.getElementById(thispagedrip).src="../image/drop.gif";
	// SET THE BACKGROUND COLOR OF THE SELECTED SECTION CELL
	selectedcell="navcell" + thissection;
	document.getElementById(selectedcell).className="mainMenuDark";
	}
	
// THIS FUNCTION CHANGES THE NAVIGATION TOOL BAR DYNAMICALLY ON MOUSING; Uses 'selectecell" from setuppage()

function changemenu(acell,theact)
	{
	whichcell=acell.id;
	theaction=theact;
	if(theaction==0)							// WE'RE TAKING THE MOUSE OFF
		{
		if(whichcell != selectedcell)			// THAT IS, DON'T CHANGE THE SELECTED PAGE CELL
			{
			//	document.getElementById(whichsub).style.visibility="hidden";
			document.getElementById(whichcell).className="mainMenuLight";
			return;
			}
		}
		if(theaction==1)							// WE'RE PUTTING THE MOUSE OVER
			{
			// document.getElementById(whichsub).style.visibility="visible";
			document.getElementById(whichcell).className="mainMenuDark";
			return;
			}
	}
	
	
// THIS SWITCHES VISIBILITY BETWEEN SIMILARLY NAMED DIVS. ALL DIVS START WITH NAME AND HAVE A NUMBER: mydiv1, mydiv2, etc.
// Parameters: nameroot = the word part of the divs   howmany = howmany divs    showdiv = number which one to show
function switchDiv(nameroot,howmany,showdiv)
	{
	var temp, nr, hm, sd;
	nr = nameroot;
	hm = howmany;
	sd = showdiv;
	hm = hm + 1;
	for(i=1;i<hm;i++)
		{
		temp = nr + i;
		document.getElementById(temp).style.display="none";
//		eval('document.getElementById("' + temp + '").style.display="none"');
		temp="";
		}
	temp = nr + sd;
	document.getElementById(temp).style.display="block";
}


function board(which)			// thumbnails to full bios for board members
	{
	var i, temp, selectedlarge;
	selectedlarge=which;
	for(i=1;i<6;i++)
		{
		temp = "tableLarge" + i;
		document.getElementById(temp).style.display="none";					// HIDE ALL BIGS
		temp = "tableSmall" + i;
		document.getElementById(temp).style.display="block";				// SHOW ALL SMALLS
		}
	temp = "tableSmall" + selectedlarge;									// THE ONE SELECTED BY THE FUNCTIONS PARAMETER
	document.getElementById(temp).style.display="none";
	temp = "tableLarge" + selectedlarge;									// THE ONE SELECTED BY THE FUNCTIONS PARAMETER
	document.getElementById(temp).style.display="block";
//	temp = "#" + selectedlarge;
//	location = temp;
	}
	
	
function switchPic(obj,pic)											// SWITCH THEobjects picture	
	{
	//var temp, newPic;
	newPic=pic;
	temp=obj;
	document.getElementById(temp).src=newPic;
	}
	
	
// ==================================================================================================================================
// SWITCH VISIBLE DIVS
// ==================================================================================================================================

/*   SWITCHDIVS: Switches visible divs
     divs must be named "div1, div2, div3, etc."

     Parameters:
     wo = the number of the div to change
     hm = how many divs there are, total
*/

function switchDivs(wo,hm)
	{
	howmany=hm;
	whichone=wo;

	// reset all
	for(x=1;x<howmany+1;x++)
		{
		temp="div" + x;
		document.getElementById(temp).style.display="none";
		}

	// set specified div and arrow (if requested)
	temp="div" + whichone;
	document.getElementById(temp).style.display="block";
	}

function switchonediv(hd,sd)		// name the div to hide, and div to show
	{
	var hidediv=hd;
	var showdiv=sd;

	document.getElementById(hidediv).style.display="none";
	document.getElementById(showdiv).style.display="block";
	}

function showhidediv(wd)
	{
	var whichdiv=wd;
	var temp;
	temp = document.getElementById(whichdiv).style.display;
	if(temp=="block")
		{
		document.getElementById(whichdiv).style.display="none";
		}
		else
			{
			document.getElementById(whichdiv).style.display="block";
			}
		
	}
	
	
function showLayer(wl,hml)
	{
	whichlayer=wl;
	hideLayers(hml)
	temp="layer2" + whichlayer;
	document.getElementById(temp).style.visibility="visible";
	}
	
	
function hideLayers(hml)
	{
	howmanylayers=hml;
	for(x=1;x<howmanylayers+1;x++)
		{
		temp="layer2" + x;
		document.getElementById(temp).style.visibility="hidden";
		}
	}

	// -------------------------------------------COOKIE FUNCTIONS  ---------------------------------------

function SetCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function GetCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function DeleteCookie(name) {
	SetCookie(name,"",-1);
}
	
	// -----------------------------------------END COOKIE FUNCTIONS  -----------------------



