//<script language="JavaScript1.1">
// GET-Processing methods
var KEY	= 0;
var FIELD = 1;
var formData = getNVPairs( getRawFormData() );

function getRawKey(form)	{ return (form.split("="))[  KEY  ]; }
function getRawField(form)	{ return (form.split("="))[ FIELD ]; }
function getQueryString() {
	var qString = location.href;
	if(-1==qString.indexOf("?")) qString += "?";
	qString = qString.substring( qString.indexOf("?")+1 );
	return qString;
}
function getRawFormData() {
	var qString = unescape(getQueryString());
	return fixSpaces(qString);
}
function getNVPairs(qString) {
	var formData = qString.split("&");
	return formData;
}
function getFormKeys() {
	var filtered = new Array();
	for(var element in formData) {
		filtered.push( getRawKey(formData[element]) );
	}
	return filtered;
}
function getFormField(key) {
	var fields = new Array();
	var nvPairs = getNVPairs(getQueryString())
	for(var element in formData) {
		if(-1 != formData[element].indexOf(key) ) {
			fields.push( getRawField(formData[element]) );
		}
	}
	if(0 == fields.length) return "";
	if(1 == fields.length) return fields[0];
	/* fields.length > 1*/ return fields; 
}
function fixSpaces(str) {
	var array = str.split("+");
	var fixedStr = "";
	for(var i=0; i < array.length; i++) {
		if(i>0) fixedStr += " ";
		fixedStr += array[i];
	}
	return fixedStr;
} 

// Array methods 
function contains(array, value, key) { // key can be ignored; it will just use the value
	for(var element in array) {
		if(array[element] == value || getValue(array[element],key) == value) {
			return true;
		}
	}
	return false;
}
function filter(array, value, key) { // key can be ignored; it will just use the value
	var filtered = new Array();
	for(var element in array) {
		if(array[element] == value || getValue(array[element],key) == value) {
			filtered.push(array[element]);
		}
	}
	return filtered;
}
function distinct(array) {
	var filtered = new Array();
	for(var element in array) {
		if( !contains(filtered,array[element]) ) {
			filtered.push(array[element]);
		}
	}
	return filtered;
}
function countIf(array, value) {
	var tally = 0;
	for(var element in array) {
		if(array[element] == value) {
			tally++;
		}
	}
	return tally;
}
function shuffle(array, maxCycles) {
	if(null == maxCycles) maxCycles = 1;
	for(var cycles = 0; cycles < maxCycles; cycles++ ) {  
		for(var i = 0; i < array.length; i++) {
			swap( array, i, randomUpTo(array.length-1) );
		} 
	}
	return array;
}
function swap(array, itr1, itr2) {
	var  temp	= array[itr1];
	array[itr1] = array[itr2];
	array[itr2] = temp;
}
function filterWhiteSpaceElements(array) {
	var filtered = new Array();
	for(var element in array) {
		if( !isWhiteSpace(array[element]) ) {
			filtered.push(array[element]);
		}
	}
	return filtered;
}
//CUSTOM METHOD BELOW
function getValue(text, key) {
	return text;
}


//Debug Methods
function define(obj) { for(var prop in obj) document.writeln(prop + ": " + obj[prop] + "<br>");  }

//Utility methods
function isVisible(obj) {return ("" == obj.style.display);}
function hide(obj)		{obj.style.display="none";}
function show(obj)		{obj.style.display="";}
function toggle(obj)	{if(isVisible(obj)) hide(obj); else show(obj);}
function atBoxStart(box){return (0 == box.selectedIndex);} 
function atBoxEnd(box)  {return (box.selectedIndex == box.options.length-1);} 
function getBoxVal(box) {return box.options[box.selectedIndex].value;}
function setBoxVal(box, value, createNew) {
	var opts = box.options;
	for(var i = 0; i < opts.length; i++) {
		if(opts[i].value == value) {
			box.selectedIndex=i;
			return;
		}
	}
	//no val found, make new one?
	if(createNew) {
		box.options[ box.options.length ] = new Option(value, value);
	}
}
function randomUpTo(max) {
	return Math.ceil(Math.random() * max); 
}
function isDigit(c) {
	if( c >= '0' && c <= '9') return true;
	return false;
}
function isWhiteSpace(str) {
	for(var i=0; i < str.length; i++) {
		var c = str.charAt(i);
		if( c >= 'A' && c <= 'Z') return false;
		if( c >= '0' && c <= '9') return false;
		if( c == '!' ) return false;
		if( c == '@' ) return false;
		if( c == '#' ) return false;
		if( c == '$' ) return false;
		if( c == '%' ) return false;
		if( c == '^' ) return false;
		if( c == '&' ) return false;
		if( c == '*' ) return false;
		if( c == '(' ) return false;
		if( c == ')' ) return false;
		if( c == '-' ) return false;
		if( c == '_' ) return false;
		if( c == '=' ) return false;
		if( c == '+' ) return false;
		if( c == '`' ) return false;
		if( c == '~' ) return false;
		if( c == '[' ) return false;
		if( c == ']' ) return false;
		if( c == '{' ) return false;
		if( c == '}' ) return false;
		if( c == '\\') return false;
		if( c == '|' ) return false;
		if( c == ':' ) return false;
		if( c == ';' ) return false;
		if( c == '\"') return false;
		if( c == '\'') return false;
		if( c == ',' ) return false;
		if( c == '<' ) return false;
		if( c == '.' ) return false;
		if( c == '>' ) return false;
		if( c == '/' ) return false;
		if( c == '?' ) return false;
	}
	return true;
}

// Window methods
function showAccessKeyHelp(keyCode) {
	window.status = "Shortcut: Alt+" + keyCode;
}
function clearStatus() {
	window.status = "";
}
function stripHTML(str) {
	return str.replace(/<br>/gi,"\n").replace(/<[^<|>]+?>/gi, "").replace(/&amp;/gi, "&");
}
//</script>
