// set a cookie		// 02/15/03 - initial development	// 05/14/04 - expanded to allow saving multiple values within a single cookie	function set_cookie_OLD(name, value) {		// specify a default key-name prefix for this project		name_prefix = "projectname_";				// the following are cookie parameters are optional ... change values to null if you don't need them		hours = 43800;		path = "/";								domain = null;				key = name_prefix + name;				(hours) ? expiration_date = new Date((new Date()).getTime() + hours*3600000).toGMTString() : expiration_date = false;		cookie_string = key + '=' + escape(value) + ((expiration_date)?(';expires=' +expiration_date):'') + ((path)?(';path='+path):'') + ((domain)?(';domain='+domain):'');		document.cookie = cookie_string;	}		function set_cookie(name, key, value) {		// specify a default cookie name prefix for this project, to group cookies together		name_prefix = "project_";		value_exists = 0;				// the following cookie parameters are optional ... change values to null if you don't need them		hours = 43800;		path = "/";								domain = null;				cookie_value = get_cookie(name, "all"); // get the entire cookie string so we can update the values		key_value_array = cookie_value.split("&"); // split the cookie string into an array of key=value strings				// search through the list of key=value strings for the presence of the specified key		for (key_value=0; key_value<key_value_array.length; key_value++) {			if (key_value_array[key_value].indexOf(key + "=") == 0) {							// when we find it, overwrite the value of that array element				key_value_pair = key_value_array[key_value].split("=");				key_value_key = key_value_pair[0];				key_value_array[key_value] = key_value_key + "=" + escape(value);								// then combine the key=value strings back into a single string				cookie_value = key_value_array.join('&');				value_exists = 1; // flag this key as already being in the cookie string so that you don't add it to the cookie string again				break;			}		}				// if the cookie string doesn't already contain this key, add the key=value string		if (value_exists == 0) {			ampersand = (cookie_value != "") ? "&" : "" ;			cookie_value += ampersand + key + "=" + escape(value);		}				expiration_date = (hours) ? new Date((new Date()).getTime() + hours*3600000).toGMTString() : false ;		cookie_string = name_prefix + name + "=" + escape(cookie_value) + ((expiration_date)?(';expires=' +expiration_date):'') + ((path)?(';path='+path):'') + ((domain)?(';domain='+domain):'');		document.cookie = cookie_string;		}// get values from a cookie	// 02/15/03 - initial development	// 05/14/04 - expanded to allow saving multiple values within a single cookie	function get_cookie_OLD(name) {		var output_value;		if (document.cookie != "") {			// specify a default key-name prefix for this project			name_prefix = "projectname_";			cookie_array = document.cookie.split("; ");			for (i = 0; i < cookie_array.length; i++) {				cookie_pair = cookie_array[i].split("=");				key = cookie_pair[0];				value = cookie_pair[1];										if (key == (name_prefix + name)) {					output_value = unescape(value);					break;				} else {					output_value = "";				}			}		} else {			output_value = "";		}		return output_value;	}		function get_cookie(name, key) {			name_prefix = "project_"; // specify a default cookie name prefix for this project, to group cookies together		output_value = "";				if (document.cookie != "") {			cookie_array = document.cookie.split("; ");			// search for the cookie with this name			for (cookie=0; cookie < cookie_array.length; cookie++) {				if (cookie_array[cookie].indexOf(name_prefix + name + "=") == 0) {					cookie_pair = cookie_array[cookie].split("=");					cookie_value = unescape(cookie_pair[1]); // the value is the list of key=value strings that we saved into this cookie						if (key == "all") {						output_value = cookie_value;						break;					} else {						key_value_array = cookie_value.split("&");											// search through the list of key=value strings for the value of the requested key						for (key_value=0; key_value<key_value_array.length; key_value++) {							if (key_value_array[key_value].indexOf(key + "=") == 0) {															key_value_pair = key_value_array[key_value].split("=");								output_value = unescape(key_value_pair[1]);								break;																	}							}											}									}			}					}				return output_value;			}		// grab all name/value pairs from the URL and create JavaScript variables from them	function get_vars() {			if (location.href.indexOf('?') != -1) {					query_string = location.href.substring(location.href.indexOf('?') + 1, location.href.length);			query_pairs = query_string.split("&");						for (n=0; n < query_pairs.length; n++) {				pair = query_pairs[n].split("=");				key = pair[0];				value = pair[1];				eval(key + " = '" + value + "'");			}						if (query_string.indexOf("args=") != -1) {				args_pieces = args.split(",");				for (n=0; n < args_pieces.length; n++) {					j = n + 1;					eval("arg" + j + " = '" + args_pieces[n] + "'");				}			}				} else {			query_string = ""; query_pairs = ""; template = ""; args = "";		}				}	// decide whether we've been flattened or not	function is_flattened() {		return ((location.href.indexOf("flattened") != -1)&&(location.href.indexOf(".html") != -1));	}// return a path to a page, given a page name, in either a flattened or unflattened format// change script_extension depending on what version of Contemplate we're using	function format_page_name(page_name) {		script_extension = "php";		if (is_flattened()) {			page_name_formatted = "../flattened/" + page_name + ".html";		} else {			page_name_formatted = "../contemplate/assembler." + script_extension + "?page=" + page_name;		}		return page_name_formatted;	}			// gets the name of the current page, even if we're rewriting URLs	function get_page_name() {		if (location.href.indexOf("page=") != -1) {			page_name = location.href.substring(location.href.indexOf('page=') + 5, location.href.length);		} else {			page_name = location.href.substring(location.href.lastIndexOf('/') + 1, location.href.indexOf('.htm'));		}		return page_name;	}		// trim whitespace from before and after a string	function trim(string) {		string = String(string);		//string = string.replace(/^\s*(.*?)\s*$/, "$1"); // this single line should work instead of the following two lines, but the ? to make the middle part less greedy throws an error in Mac IE, where that modifier is apparently not supported		string = string.replace(/^\s*/, "");		string = string.replace(/\s*$/, "");		return string;	}		// return a value up to the delimiter, or the original value if the delimiter isn't there// - this is used most often when parsing an argstring to set button states	function crop(value, delimiter) {		result = (value.indexOf(delimiter) != -1) ? value.substring(0, value.indexOf(delimiter)) : value ;		return result;	}	// open a popup window, specifying source, width, and height, and optionally a name; if no name, choose a random one	function popup(source, width, height, window_name) {		if (! window_name) { 			now = new Date();			window_name = now.getTime();		} else {			window_name = window_name.replace(/ /g, "_");		}		popup_window = window.open(source, window_name, "width=" + String(width) + ",height=" + String(height) + ",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes");		popup_window.focus();	}// show an email link on a page in a way that spam harvesters can't see	function email(user, domain, tld) {		location = "mailto:" + user + "@" + domain + "." + tld;	}// write a random element from the specified array	function write_random(array_name) {		which = (Math.round(Math.random() * (arrayName.length - 1)));		document.write(array_name[which]);	}// the simplest possible rollover function	function swap(name, state) {		eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');	}	// rollovers with sticky highlights// - used in navigation frames where the buttons persist but other pages are changing	var previous = null;	var current = null;	function sticky_swap(name, state, hold) {		if (hold == 1) {			// set previously lit button to normal			previous = current;			if (previous != null) {				eval('document.images.' + previous + '.src = ' + previous + '_0.src');			}		}		if ((name != null) && (name != current)) {			// set new button state			eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');			if (hold == 1) { current = name; }		}	}	// rollovers with separate but linked button and label graphics// - highlights both the button and label if you mouse over either one // - requires graphics to be named like "button_0.gif" and "button_label_0.gif"	function label_swap(name, state) {		eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');				// change the label if one exists		if (eval('document.images.' + name + '_label')) {			eval('document.images.' + name + '_label.src = ' + name + '_label_' + String(state) + '.src');		}				// change the button if this is a label		if (name.indexOf("_label") != -1) {			name = name.substr(0, (name.length - 6));			if (eval('document.images.' + name)) {				eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');			}		}	}	// write a block of code that preloads a list of graphics// - this version makes on and off states and is most often used for button rollovers// names - a comma-delimited list of button names (e.g. "home,about,contact")// path - the path to the graphics; defaults to "../graphics" if not set (e.g. "../graphics/menus/home")// extension - the file extension of the graphics files; defaults to "gif" if not set (e.g. "jpg")	function preload_buttons(names, path, extension) {		names = names.split(",");		path = (path) ? path : "../graphics" ;		extension = (extension) ? extension : "gif" ;		for (n=0; n < names.length; n++) {			this_name = names[n];			this_path = path + "/" + this_name;			eval(this_name + "_0 = new Image()");			eval(this_name + "_0.src = '" + this_path + "_0." + extension + "'");			eval(this_name + "_1 = new Image()");			eval(this_name + "_1.src = '" + this_path + "_1." + extension + "'");		}	}	// write a block of code that preloads a list of graphics// - this version just makes an on state and is most often used for tips associated with button rollovers// names - a comma-delimited list of button names (e.g. "home,about,contact")// path - the path to the graphics; defaults to "../graphics" if not set (e.g. "../graphics/menus/home")// extension - the file extension of the graphics files; defaults to "gif" if not set (e.g. "jpg")	function preload_tips(names, path, extension) {		names = names.split(",");		path = (path) ? path : "../graphics" ;		extension = (extension) ? extension : "gif" ;		for (n=0; n < names.length; n++) {			this_name = names[n];			this_path = path + "/" + this_name;			eval(this_name + " = new Image()");			eval(this_name + ".src = '" + this_path + "." + extension + "'");		}	}	// write a block of code that preloads a list of graphics// - this version uses the same source file for each instance and is most often used for markers associated with button rollovers// names - a comma-delimited list of instance names (e.g. "home_marker,about_marker,contact_marker")// marker_name - the base name of the marker graphic// path - the path to the graphics; defaults to "../graphics" if not set (e.g. "../graphics/menus/home")// extension - the file extension of the graphics files; defaults to "gif" if not set (e.g. "jpg")	function preload_markers(names, marker_name, path, extension) {		names = names.split(",");		path = (path) ? path : "../graphics" ;		extension = (extension) ? extension : "gif" ;		for (n=0; n < names.length; n++) {			this_name = names[n];			this_path = path + "/" + marker_name;			eval(this_name + "_0 = new Image()");			eval(this_name + "_0.src = '" + this_path + "_0." + extension + "'");			eval(this_name + "_1 = new Image()");			eval(this_name + "_1.src = '" + this_path + "_1." + extension + "'");		}	}	// leave this here to catch calls to the original preload script	function make_preloads(names, path) {		preload_buttons(names, path);	}	// figure out whether a variable has been set or not without generating an undefined error if it hasn't	function isset(variable) {		eval("result = (typeof(" + variable + ") != 'undefined')");		return result;	}	// returns the index of an array element, something that ought to be built into JavaScript but isn't!// returns -1 if not present	function get_position(string, array) {		for (n=0; n < array.length; n++) {			if (array[n] == string) {				return n;				break;			}		}		return -1;	}// sets a menu to a given text or value	function set_menu(form_name, field_name, text_or_value, key) {		eval("these_options = document." + form_name + "." + field_name + ".options");		for (n=0; n < these_options.length; n++) {			eval("this_text_or_value = these_options[n]." + text_or_value);			if (this_text_or_value == key) {				eval("document." + form_name + "." + field_name + ".selectedIndex = " + n);				break;			}		}		return "";	}// set date menus to a new SQL-standard date// leave date blank to select today's date// set to -1 to clear the menu	function select_date(form_and_menu, new_date) {		if (new_date != "-1") {			if (new_date == "") {				date = new Date();								day = date.getDate();				month = date.getMonth() + 1;				year = date.getFullYear();							} else {				date = new_date;								year = date.substring(0, date.indexOf("-"));				month = date.substring(date.indexOf("-") + 1, date.lastIndexOf("-"));				day = date.substring(date.lastIndexOf("-") + 1);							}								eval("document." + form_and_menu + "_month.selectedIndex = month");			eval("document." + form_and_menu + "_day.selectedIndex = day");			eval("document." + form_and_menu + "_year.selectedIndex = year - document." + form_and_menu + "_year.options[1].value + 1");		} else {			eval("document." + form_and_menu + "_month.selectedIndex = 0");			eval("document." + form_and_menu + "_day.selectedIndex = 0");			eval("document." + form_and_menu + "_year.selectedIndex = 0");		}	}// set time menus to a new SQL-standard time// leave time blank to select the current time	function select_time(form_and_menu, new_time) {		if (new_time != "-1") {			if (new_time == "") {				time = new Date();								hours = time.getHours();				minutes = time.getMinutes();				seconds = time.getSeconds();							} else {				time = new_time;								hours = time.substring(0, time.indexOf(":"));				minutes = time.substring(time.indexOf(":") + 1, time.lastIndexOf(":"));				seconds = time.substring(time.lastIndexOf(":") + 1);							}								if (hours >= 12) {				ampm_index = 2;				if (hours > 12) {					hours = hours - 12;				}			} else {				ampm_index = 1;				if (hours == 0) {					hours = 12;				}			}			eval("document." + form_and_menu + "_hours.selectedIndex = hours");			eval("document." + form_and_menu + "_minutes.selectedIndex = minutes + 1");			eval("document." + form_and_menu + "_seconds.selectedIndex = seconds + 1");			eval("document." + form_and_menu + "_ampm.selectedIndex = " + ampm_index);		}	}// set a base text size for each platform; can be used in conjunction with static font tags for face and color// remember to close this tag with a static </font> later in your document		function text_size(mac, win) {		if (navigator.appVersion.indexOf("Mac") != -1) {			document.write("<font face=geneva,arial size=" + mac + ">");		} else {			document.write("<font face=geneva,arial size=" + win + ">");		}	}