// grab name/value pairs from the URL and set JavaScript variables accordingly
// - PHP does this automatically

	function getVars() {
	
		if (document.URL.indexOf('?') != -1) {
		
			queryString = document.URL.substring(document.URL.indexOf('?') + 1, document.URL.length);
			queryPairs = queryString.split("&")
			
			for (i=0; i < queryPairs.length; i++) {
				pair = queryPairs[i].split("=")
				key = pair[0]
				value = pair[1]
				eval(key + " = '" + value + "'")
			}
			
			if (queryString.indexOf("args=") != -1 ){
				argsPieces = args.split(",")
				for (i=0; i < argsPieces.length; i++) {
					j = i + 1
					eval("arg" + j + " = '" + argsPieces[i] + "'")
				}
			}
		
		} else {
			queryString = ""; queryPairs = ""; template = ""; args = ""
		}
			
	}
	

// 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 generic popup window, specifying source and size

	function popup(source,width,height) {
		popup_window = window.open(source,"popup_window","width="+String(width)+",height="+String(height)+",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes");
		popup_window.focus()
	}


// write a random element from the specified array

	function writeRandom(arrayName) {
		which = (Math.round(Math.random() * (arrayName.length - 1)))
		document.write(arrayName[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 stickySwap(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 labelSwap(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
// - used at the top of any page that contains rollovers

	function makePreloads(names) {
	
		names = names.split(",")
		for (i=0; i < names.length; i++) {
			thisName = names[i]
			eval(thisName+"_0 = new Image()")
			eval(thisName+"_0.src = '../graphics/"+thisName+"_0.gif'")
			eval(thisName+"_1 = new Image()")
			eval(thisName+"_1.src = '../graphics/"+thisName+"_1.gif'")
		}
	}
	

// returns the index of an array element, something that ought to be built into JavaScript but isn't!
// returns "" if not present

	function getPosition(string, array) {
		for (i=0; i < array.length; i++) {
			if (array[i] == string) {
				return i
				break
			}
		}
		return ""
	}


// set date menus to a new SQL-standard date
// leave date blank to select today's date

	function selectDate(menu_name,new_date) {
		if (new_date == "") {
			date = new Date()
			
			day = date.getDate()
			month = date.getMonth() + 1
			year = date.getYear()
			
		} 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." + menu_name + "_month.selectedIndex = month")
		eval("document." + menu_name + "_day.selectedIndex = day")
		eval("document." + menu_name + "_year.selectedIndex = year - document." + menu_name + "_year.options[1].value + 1")
	}


// 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 textSize(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+">")
		}
	}


// jumble up some text for safer transfer in places where cookies or PHP encryption can't go

	function pseudoCrypt(input,direction,key) { 
		output = ""
		input = (input.split(" ")).join("+") // remove spaces so it's URL safe
		palette = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+&=:/" // any other characters will be untouched
		key = "everygoodboydeservesfudge" // can only contain members of palette
		keyPosition = 0
		for (i = 0; i < input.length; i++) {
			inputChar = palette.indexOf(input.charAt(i))
			if (inputChar != -1) {
				keyChar = key.charAt(keyPosition)
				offset = palette.indexOf(keyChar)
				if (direction == 1) {
					offset = ((inputChar + offset) > (palette.length - 1)) ? offset - palette.length : offset
					output += palette.charAt(inputChar + offset)
				} else {
					offset = ((inputChar - offset) < 0) ? offset - palette.length : offset
					output += palette.charAt(inputChar - offset)
				}
				keyPosition++
				keyPosition = (keyPosition > key.length) ? 0 : keyPosition
			} else {
				output += input.charAt(i)
			}
		}
		output = (output.split("+")).join(" ")
		return output
	}
	
	
// validate a form

	function checkForm() {
	alert ("hello");
	//	var i,val,args=checkForm.arguments;
		//for (i=0;i<(args.length);i++){
		//	val=document.email_form.args[i].value;
	//		if (!val){
	  //			alert("Field: " + args[i] + " is a required field.");
	  //		}
	  //	}
	  } 
