// set some text when rolling over a graphic link on the company template

	function rollover(txt) {
		document.links.rollover.value = txt
	}
	

// 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) {
		now = new Date()
		window_name = now.getTime()
		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()
	}


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

// 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.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." + 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,sans-serif size="+mac+">")
		} else {
			document.write("<font face=geneva,arial,sans-serif 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
	}
	
// construct Flash object and embed tags
// FlashVars should be a string of name/value pairs separated by ampersands

	function get_flash_tags(filename, width, height, bgcolor, flashvars) {
		name = filename;
		if (name.indexOf("/")) { name = name.substring(name.lastIndexOf("/") + 1); }
		if (name.indexOf(".")) { name = name.substring(0, name.indexOf(".")); }
		
		output = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		output += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"';
		output += ' WIDTH="' + String(width) + '" HEIGHT="' + String(height) + '" id="' + name + '" name="' + name + '" ALIGN="">';
		output += '<PARAM NAME=movie VALUE="' + filename + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=' + bgcolor + '> <PARAM NAME="wmode" value="transparent"> <EMBED src="' + filename + '" wmode="transparent" quality=high bgcolor=' + bgcolor + ' WIDTH="' + String(width) + '" HEIGHT="' + String(height) + '" NAME="' + name + '" ALIGN=""';
		output += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true"';
		output += ' FlashVars="' + flashvars + '"></EMBED>';
		output += '<PARAM NAME="FlashVars" VALUE="' + flashvars + '">';
		output += '</OBJECT>';
		return output;
	}
	
	

