
// 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 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
// - this version makes on and off states and is most often used for button rollovers

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

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

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

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

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

// leave this here to catch calls to the original preload script

	function makePreloads(names) {
		preloadButtons(names)
	}
	

// 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(form_and_menu,new_date) {
		if (new_date != "-1") {
			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." + 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")
		}
	}


// 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
	}
	
	
// pass arguments into a frameset document to automatically set any of the frame locations
// place  onload=setFrames()  into the frameset tag, then include  framename=location.html  in your URL

	function setFrames() {

		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];
				
				for (j=0; j < frames.length; j++) {
					if (key == frames[j].name) {
						eval(key + ".location = '" + value + "'");
						break;
					}
				}
				
			}

		}

	}

// strips trailing chars




// this is handy for preventing the Return key from submitting forms (set form action to "JavaScript:nothing()")
	
	function nothing() {}
	
	function glossaryJump(letter) {
		var thisPage = parent.glossary_main.document.URL;
		if (thisPage.indexOf("#")!="-1"){ 
			thisPage = thisPage.substr(0,thisPage.indexOf("#"));
		}
		parent.glossary_main.location = thisPage + "#" + letter;

	}

	function glossarySwitch(language) {
		parent.glossary_main.location = "../contemplate/assembler.cgi?page=glossary_" + language;
		parent.glossary_nav.location = "../contemplate/assembler.cgi?page=nav_" + language;
	}

		
