// JavaScript Documentwindow.onLoad = addLoadListener(initPage);var linque = "";var baklinque = "";var subButton = "";	// submit button on forms// initializations for tipdownsvar className = "tipDown";		// element class of tipdownvar rootPath = "giffer/";			// base url of location of files referred to in these routinesvar openTriangle = "arrow_down.gif";		// image file of the "open" triangle imagevar closedTriangle = "arrow_right.gif";	// image file of the "closed" triangle image// initializations for color management of navigation tabsvar navBlockName = "navLink";	// class name of nav block// these colors should be the same as those specified in the style sheet, as they will replace style sheet colorsvar navTabColor = "#9999FF";	// default background colorvar navTabText = "#000033";	// default text color// active tabs are same color as contentvar contentColor = "#330066";	// content background colorvar contentText = "#FFCC33";	// content text color//var default_ID = "about";	// default content block if one is not specified// onLoad function: set up onClick handlers for nav buttons. Each button calls toggleContent, passing the name of the button pressedfunction initPage() {// set up onclick handlers for nav links	var lnx = document.getElementById("nav").getElementsByTagName("a");	for (lnk in lnx) {		lnx[lnk].onclick = toggleContent;	}		// determine if an anchor is part of the calling url, if so, toggleContent to that anchor	toggleContent();	// set up routines for tip-down text lists	initTipdowns();		// initialize contact form ajaxification	initContact();		// warn user if she is using an unsupported browser	if (!goodBrowser()) {		// put a nastygram into the news box		nz = document.getElementById("news");		np = nz.getElementsByTagName("p");		np[0].innerHTML = "Your browser may behave badly on this site. We recommend Firefox or Safari.<br />If you use Internet Explorer, please upgrade to version 7 or greater.";		nz.style.display = "block";	}}//toggleContent: given the name of the button pressed, use that name to deactivate present content and activate the div with the desired name. //	If invalid id is passed with linque, default to "#about"function toggleContent() {	var sane = false;	// sanity flag	if(linque) {	// if a parameter was passed, use it		idName = linque;	} else {		// parse idName to get rid of the leading '#'				if(this.href) { 			idName = /(?:#)\w+/.exec(this.href)[0];		} else {			docref =  /(?:#)\w+/.exec(document.location.href);			if (docref) {				idName = docref[0];			} else {				idName = default_ID;	// fall back if bad 			}		}					}		if(idName) {	// if there is no anchor specified, skip the following code		idName = /\w+/.exec(idName)[0];			// get the list of div's in column 2		var dvs = document.getElementById("column2").getElementsByTagName("div");				// for each div in the list		for (blk in dvs) {			if (dvs[blk].className == "content") {	// is the class content?				if (dvs[blk].id == idName) {		// is the id = idName?					dvs[blk].style.display = "block";	// yes, set display to "block"					sane = true;				} else {					if (dvs[blk].style.display == "block") {						baklinque = dvs[blk].id;	// remember where we are										}					dvs[blk].style.display = "none";	// no, set display to "none"				}			}		}		// change all link tabs to default colors		var navs = document.getElementById("nav").getElementsByTagName("li");		for (lnkNbr = 0; lnkNbr < navs.length; lnkNbr++) {			navs[lnkNbr].style.backgroundColor = navTabColor;			anchors = navs[lnkNbr].getElementsByTagName("a");			for (anchorNbr = 0; anchorNbr < anchors.length; anchorNbr++) {				anchors[anchorNbr].style.color = navTabText;			}		}				// now change the selected link to the "active" color		activeLink = idName + "Link";		activeTab = document.getElementById(activeLink);		activeTab.style.backgroundColor = contentColor;		anchors = activeTab.getElementsByTagName("a");		for (anchorNbr = 0; anchorNbr < anchors.length; anchorNbr++) {			anchors[anchorNbr].style.color = contentText;		}	}			if(!sane) {		// idName does not exist, default to "about" block		document.getElementById(default_ID).style.display = "block";		baklinque = default_ID;	// remember where we are	}		if (!baklinque) {		baklinque = default_ID;	}	linque= "";	return false;}/* ================= tipdown text handling ==================== */function initTipdowns() {		// the following code should go into the initialization routines	var objList = getElementByClass("ul", className, document);	// make sure obj is a <ul>		for (objNbr=0; objNbr<objList.length; objNbr++) {	// for each object we found...				obj = objList[objNbr];				// if there is a span with class=instr, make instruction text visible		instr = getElementByClass("span", "instr", obj);		if (instr.length) {			instr[0].innerHTML = "Click on an item below for more info.";			}				// get array of <li>s		var lst = obj.getElementsByTagName("li");				// instead of the code above (which includes sub-lists), assemble lst from only the current level//		var lst = obj.children;		//		var lst = getElementByClass("span", "liHeading", obj);		var lstLength = lst.length;		if (lstLength > 0) {	// make sure there's a positive number of <li>s			for (lItem=0; lItem<lstLength; lItem++) {	// for each <li>				hdgList = getElementByClass("span", "liHeading", lst[lItem]); 				for (hdgNbr=0; hdgNbr < hdgList.length; hdgNbr++) {	// for each liHeading span in this li					hdgList[hdgNbr].onclick = openClose;	//	set onclick handler for the text to toggle the open/closed status					hdgList[hdgNbr].onmouseover = function() {this.style.cursor = "pointer"; }; // set onmouseover handler to change the cursor to a hand/pointer					hdgList[hdgNbr].onmouseout =function() {this.style.cursor = "default"; } ; // set onmouseout handler to change the cursor to a pointer				}						// set the bullet image to closedTriangle				lst[lItem].style.listStyleImage = "url('" + rootPath + closedTriangle + "')";								paraList = lst[lItem].getElementsByTagName("p");	// get the list of <p>s in this <li>				var paraListLength = paraList.length;				if (paraListLength>0) {					for (paraListItem=0; paraListItem<paraListLength; paraListItem++) {		//	set the <p>s to display:none						paraList[paraListItem].style.display = "none";					}				}								//	initialize a status property to closed				lst[lItem].status = false;			}		}	}}// function that's triggered when a list item gets clickedfunction openClose() {	me = this.parentNode;	if (me.status) {		// status=true: tip-down is open, so close it		me.status = false; // toggle the status		me.style.listStyleImage = "url('" + rootPath + closedTriangle + "')"; // toggle the bullet image				// toggle the visibility status of the <p>		paraList = me.getElementsByTagName("p");	// get the list of <p>s in this <li>		var paraListLength = paraList.length;		if (paraListLength>0) {			for (paraListItem=0; paraListItem<paraListLength; paraListItem++) {		//	set the <p>s to display:none				paraList[paraListItem].style.display = "none";			}		}	} else {				// status=false: tip-down is closed, so open it		me.status = true; // toggle the status		me.style.listStyleImage = "url('" + rootPath + openTriangle + "')"; // toggle the bullet image				// toggle the visibility status of the <p>		paraList = me.getElementsByTagName("p");	// get the list of <p>s in this <li>		var paraListLength = paraList.length;		if (paraListLength>0) {			for (paraListItem=0; paraListItem<paraListLength; paraListItem++) {		//	set the <p>s to display:none				paraList[paraListItem].style.display = "block";			}		}	}}/* ================= form processing ====================== */function initContact() {	// set action of contact form to be '#'	block = document.getElementById("contact");	forms = block.getElementsByTagName("form");	for (i=0; i<forms.length; i++) {				// set up action for message form		if (forms[i].name == "message") {			//delete forms[i].action;			forms[i].action = '';			forms[i].onsubmit = contactProcess;			forms[i].onReset = contactReset;			// hide and build the "thank you" block			tanks = document.getElementById("thankYou");			tanks.style.display = "none";			// wrap-around div//console.log(tanks);			div = document.createElement('div');			div.setAttribute('align', 'center');			tanks.appendChild(div);			// thank you message			msg = document.createElement('p');			msg.innerHTML = "Your message has been sent.<br />Thank You.";			div.appendChild(msg);			// "You're Welcome" button			btn = document.createElement('input');			//name="submit" type="submit" value="You're Welcome" onclick="subButton='reload'">			btn.setAttribute('name','submit');			btn.setAttribute('type','submit');			btn.setAttribute('value',"You're Welcome");			btn.setAttribute('onclick',"setSubButton('reload');");			btn.onclick = function() {setSubButton('reload');};			div.appendChild(btn);		}				}	// create new fieldset within contact form for "thank you" screen} // initContactfunction setSubButton(blah) {	subButton = blah;}function contactProcess() {//console.log(subButton);		if(block = document.getElementById("contact")) {		if (forms = block.getElementsByTagName("form")) {			for (i=0; i<forms.length; i++) {				if (forms[i].name == "message") {					thisForm = forms[i];				}			}		}	}		// test for subButton to be defined. If not, fall thru to PHP	if (!subButton) {		temp = window.location;		temp +="#contact";//		alert(temp);		window.location = temp;//		alert(window.location);		return true;	}	//console.log(thisForm);		switch (subButton) { // what was the value of the Submit button?			// Never Mind:		case "fuquette": {			// reset the form//alert("fuquette!");			// reset the error message			errBlock = document.getElementById("errorMsg");			errBlock.innerHTML = "";			thisForm.reset();						// try to go back to where we came from			if (baklinque) {				linque = baklinque;				} else {				linque = default_ID;				}			toggleContent();			return false;		}		// You're Welcome:		case "reload": {			// reset the form, hide the thank you block, show the form			document.getElementById("contactTo").style.display="block";			document.getElementById("contactForm").style.display="block";			document.getElementById("contactButtons").style.display="block";			document.getElementById("thankYou").style.display="none";			thisForm.reset();			// redirect to the url in the hidden field "reefer"			// try to go back to where we came from			if (baklinque) {				linque = baklinque;				} else {				linque = default_ID;				}			toggleContent();			return false;		}				// Send:		case "send": {			// assemble form data			dataString = formdata2query(this);//console.log(dataString);			// prepare and submit XMLHttpRequest			if (ajaxReq("ajaxcontact.php", dataString, contactReply)) return false;		}	}	linque = "contact";}function contactReply(resultStr) {//console.log(resultStr);	if (resultStr == "OK") {	// if the reply indicates no errors:		// hide all form elements visible before (including/especially error message)		// make the "thankYou" fieldset visible		document.getElementById("errorMsg").style.display="none";		document.getElementById("contactTo").style.display="none";		document.getElementById("contactForm").style.display="none";		document.getElementById("contactButtons").style.display="none";		document.getElementById("thankYou").style.display="block";//console.log("boo!");			} else {		// put the error message in its field, make sure it's visible		errBlock = document.getElementById("errorMsg");		errBlock.innerHTML = resultStr;	} // if (resultStr == "OK")		linque = "contact";}function contactReset() {		// when message form is reset, we also need to reset the error message/*block = document.getElementById("contact");	forms = block.getElementsByTagName("form");	for (i=0; i<forms.length; i++) {		if (forms[i].name == "message") {			forms[i].reset;		}	}*/		// reset the error message	errBlock = document.getElementById("errorMsg");	errBlock.innerHTML = "";//	errBlock.style.display="none";	}/* ================= Utility Functions ==================== */function getElementByClass(tName, cName, obj) {		// return arrray of objects of the class cName of tag tName	if ((typeof tName == 'string') || ((typeof tName == 'object') && (tName.constructor.toString().match(/string/i) != null))) {		// is tName a string or an array?		tName = Array(tName);//	string: convert to array of one element	} 	var result = new Array();	// initialization	//console.log(this);	for (ti=0; ti<tName.length; ti++) {	// for each tag we're checking		var tagList = collectionToArray(obj.getElementsByTagName(tName[ti]));		for (itemNbr=0; itemNbr<tagList.length; itemNbr++) {	// check the class of each element of the tagList array.			if (tagList[itemNbr].className == cName) { // if the class is NOT cName, 				result.push(tagList[itemNbr]);	// then eliminate that element from the array			}		}					}	return result;}function collectionToArray(collection)// from http://www.sitepoint.com/blogs/2008/03/19/a-collection-is-not-an-array/{	var ary = [];	for(var i=0, len = collection.length; i < len; i++)	{		ary.push(collection[i]);	}	return ary;}/* given formObject, get all of the data and return a query string */function formdata2query(formObject) {//console.log(formObject);	var queryStr = "";		// initialize the query string//	var chex = new array;	elemCount = formObject.elements.length;	if (!elemCount) return "";		// if the form has no elements, return an empty string	for (i=0; i<elemCount; i++)	 {	// tick thru the elements and build the query string		thisElem = formObject.elements[i];		switch (thisElem.type) {			case 'text':			case 'select-one':			case 'hidden':			case 'password':			case 'textarea': {            	if (thisElem.value) {					if (i) queryStr += "&";					queryStr += thisElem.name + "=" + escape(thisElem.value);				}			}			case 'radio' : {				if (thisElem.checked) {	                if (i) queryStr += "&";					 queryStr += thisElem.name + "=" + escape(thisElem.value);				}			}			case 'checkbox': {				// does chex[thisElem.name] exist?					// no, create it as a sub-array				// Is it checked?					// yes, add value to chex[thisElem.name] array			}		} // switch	} // for each element		// add the check boxes to our query string here		return queryStr;}/* generic ajax request function */function ajaxReq(url, params, processor) {//console.log(params);	var xhr = false;        	// IE	if (window.ActiveXObject) {		xhr = new ActiveXObject("Microsoft.XMLHTTP");	}	// Mozilla/Safari	else if (window.XMLHttpRequest) {		xhr = new XMLHttpRequest();		xhr.overrideMimeType('text/xml');	}		if (xhr) {		xhr.open('POST', url, true);		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');		xhr.onreadystatechange = function() {			if (xhr.readyState == 4) {								// test and handle 404 and 500 errors here					result = xhr.responseText;				try {					processor(result);				} catch (e) {					return false;				}	//console.log(this);						}		}			xhr.send(params);	}		return xhr;}	function ajaxProxyReq(url, params, processor) {//console.log(params);	var xhr = false;	url = 'feedproxy.php?url=' + url;        	// IE	if (window.ActiveXObject) {		xhr = new ActiveXObject("Microsoft.XMLHTTP");	}	// Mozilla/Safari	else if (window.XMLHttpRequest) {		xhr = new XMLHttpRequest();		xhr.overrideMimeType('text/xml');	}		if (xhr) {		xhr.open('GET', "", true);		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');		xhr.onreadystatechange = function() {			if (xhr.readyState == 4) {								// test and handle 404 and 500 errors here					result = xhr.responseText;				try {					processor(result);				} catch (e) {					return false;				}	//console.log(this);						}		}			xhr.send(params);	}		return xhr;}	/* This function makes sure our pages are loaded before we try to manipulate the DOM */function addLoadListener(fn) {//mozilla and friends  if (typeof window.addEventListener != 'undefined') {    window.addEventListener('load', fn, false);  }//opera  else if (typeof document.addEventListener != 'undefined') {    document.addEventListener('load', fn, false);  }//innernetz exploder  else if (typeof window.attachEvent != 'undefined') {    window.attachEvent('onload', fn);  }//the rest is pretty much for browsers that I doubt your //CSS or anything else still supports like IE/Mac  else {    var oldfn = window.onload;    if (typeof window.onload != 'function') {      window.onload = fn;    }    else {      window.onload = function() {        oldfn();        fn();      };    }  }}/* test the user agent, return true if it's one of our supported browsers */function goodBrowser() {	var ua = navigator.userAgent;	console.log(ua);		// check for IE	offst = ua.indexOf("MSIE ");	console.log(ua);	console.log(offst);	if (offst > 0) {		vsn = parseFloat(ua.substring(offst+5, ua.indexOf(";",offst)));		if (vsn < 7) {			return false;		} else {			return true;		}	}		// check for Safari (WebKit)	else {		offst = ua.indexOf("AppleWebKit");		if (offst > 0) {			return true;		}				// check for Firefox (Gecko)		else {			offst = ua.indexOf("Gecko");			if (offst > 0) {				return true;			}			// check for Opera			else {				offst = ua.indexOf("Opera");				if (offst >= 0) {					return true;				}				else {					return false;				}			}		}			}	}/* this is useful for debugging */function dump_props(obj, obj_name) {     var result = "";     for (var i in obj) {        result += obj_name + "." + i + " = " + obj[i] + "\n";     }     result += "--------\n";     console.log(result);  }  
