// reset some variables only when explicity called

	function initialize() {
		account = (account != "") ? account : document.URL.substr(7, document.URL.indexOf(".") - 7)
	}


// open a generic popup window, specifying source and size

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


// 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 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')
			}
		}
	}
	

// 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}
		}
	}
	

// 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=arial,helvetica,sans-serif size="+mac+">")
		} else {
			document.write("<font face=arial,helvetica,sans-serif size="+win+">")
		}
	}


// 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 PHP 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")
	}


// 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
	}
	
