/*
Some Generic Form/String Validations
Andrew D Foster
09/01/2003
*/
var ns=document.layers?1:0
var ie4=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0
function scrollTo(n)
{
	alert(ns + " " + ns6 + " " + ie4);
	if(ns||ns6)
	{
		//alert("window.pageYOffset = " + n + ";");
		window.pageYOffset = n;
	}
	else
	{
		//alert("document.body.scrollTop = " + n + ";");
		document.body.scrollTop = n;
	}
}
var errorText = "";
function scrollMine(n)
{
	if(errorText != "")
	{
		scrollTo(n);
		errorText = "<TABLE><TR><TD CLASS='message' align='center'>The following errors and/or ommissions were found...</TD></TR><TR><TD CLASS='message'><OL CLASS='message'>" + errorText + "</OL></TD></TR></TABLE>";
		top.focus();
	}
	document.all.errors.innerHTML = errorText;
}

function forceDec(t, p)
{
	dec = false;
	ctr = 0;
	myNumber = "";

	if(t == null || t == "" || t.length == 0)
	{
		myNumber = "0";
		for(a = 0; a < p; a++)
		{
			if(a == 0)
			{
				myNumber += ".";
			}
			myNumber += "0";
		}
		return myNumber;
	}
	
	for(a = 0; a < t.length; a++)
	{
		if(a == 0 && t.charAt(a) == '-')
		{
			myNumber += ""+t.charAt(a);
		}
		else
		{
			if(t.charAt(a) == "." && !dec)
			{
				if(p > 0)
				{
					myNumber += ""+t.charAt(a);
				}
				dec = true;
				ctr = 0;
			}
			if(t.charCodeAt(a) >= 48 && t.charCodeAt(a) <= 57)
			{
				if(dec)
				{
					if(ctr < p)
					{
						myNumber += ""+t.charAt(a);
					}
					ctr++;
				}
				else
				{
					myNumber += ""+t.charAt(a);
				}
			}
		}
	}
	
	if(myNumber == "")
	{
		myNumber = "0";
	}
	for(a = ctr; a < p; a++)
	{
		if(a == 0)
		{
			myNumber += ".";
		}
		myNumber += "0";
	}
	return myNumber;
}


function padNum(frm, n)
{
	frm.value = strMend(frm.value, "1234567890");
	for(a = frm.value.length; a < n; a++)
	{
		frm.value = "0" + frm.value;
	}
}


function getRadioValue(radioObj)
{
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		if(radioObj.checked)
		{
			return radioObj.value;
		}
		else
		{
			return "";
		}
	}
	for(var i = 0; i < radioLength; i++) 
	{
		if(radioObj[i].checked) 
		{
			return radioObj[i].value;
		}
	}
	return "";
}

function webAddressCheck (webStr) 
{
	// ftp://*
	// http://*
	// https://*
	if(webStr.length > 6)
	{
		if(webStr.substr(0, 6) == "ftp://")
		{
			return true;
		}
		else
		if(webStr.length > 7)
		{
			if(webStr.substr(0, 7) == "http://")
			{
				return true;
			}
			else
			if(webStr.length > 8)
			{
				if(webStr.substr(0, 8) == "https://")
				{
					return true;
				}
			}
		}
	}
	return false;
}



function emailCheck (emailStr) 
{
	at = false;
	pos = 0;
	lastDot = -1;
	for (i = 0; i < emailStr.length; i++) 
	{
		theChar = emailStr.charAt(i);
		if(theChar == " ")
		{
			return false;
		}
		else
		if(theChar == "@")
		{
			if(i == 0)
			{	// first char is "@"
				return false;
			}
			if(at == true)
			{	// already found
				return false;
			}
			else
			{	// OK, now look for a "."
				if(lastDot == i)
				{
					// previous cycle found a dot, so we have .@ = BAD!
					return false;
				}
				lastDot = 0;
				pos = i+1;
				at = true;
			}
		}
		else
		if(theChar == "." && at == true)
		{
			if(i == pos)
			{	// "." is directly after "@"
				return false;
			}
			else
			{	// setup ready to check for last character being a . = BAD!
				if(lastDot == i)
				{
					// previous cycle also found a dot
					return false;
				}
				lastDot = i+1;
			}
		}
		else
		if(theChar == ".")
		{
			if(lastDot == i || i == 0)
			{
				// previous cycle also found a dot
				return false;
			}
			lastDot = i+1;
		}
	}
	if(at == false)
	{	// No @ found
		return false;
	}
	else
	if(lastDot == i || lastDot < 1)
	{	// Last Character is a dot or haven't even had a dot
		return false;
	}
	else
	{	// We at least have *@*.* (* being any number of any characters (except .))
		return true;
	}
}



function strCheck(str, validchars)
{
	for (i=0; i < str.length; i++) 
	{
		thechar = str.charAt(i);
		if(validchars.indexOf(thechar) == -1)
		{
			return false;
		}
	}
	return true;
}

function checkVowel(st)
{
	checkVstr = st.toUpperCase();
	if(strCheck(checkVstr.charAt(0), "AEIOU"))
	{
		return "n";
	}
	else
	{
		return "";
	}
}


function formatCheck(str, formatString)
{
	if(str.length != formatString.length)
	{
		return false;
	}

	for (j=0; j < formatString.length; j++) 
	{
		formatstrchar = formatString.charAt(j);
		strchar = str.charAt(j);
		if(formatstrchar == '9')
		{
			if(!strCheck(strchar, "0123456789"))
			{
				return false;
			}
		}
		else
		if(formatstrchar == 'X')
		{
			if(!strCheck(strchar, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
			{
				return false;
			}
		}
		else
		if(formatstrchar != strchar)
		{
			return false;
		}
	}
	return true;
}


function strMend(str, validchars)
{
	retStr = "";
	for (i=0; i < str.length; i++) 
	{
		thechar = str.charAt(i);
		if(validchars.indexOf(thechar) == -1)
		{
		}
		else
		{
			retStr += thechar;
		}
	}
	return retStr;
}


function formatNumber(val, fraction, places, allowNegatives, leaveBlank)
{
	var searchString = "01234567890.";
	if(allowNegatives)
	{
		searchString += "-";
	}
	var tt = strMend(""+val, searchString);
	var ss = "";
	var punct = false;
	var ok = false;
	var ch = '';

	// First Ensure there is only one minus sign at the beginning (if at all) and one punct.
	for(a = 0; a < tt.length; a++)
	{
		ch = tt.charAt(a);
		ok = true;
		if(ch == '-' && a != 0)
		{
			ok = false;
		}
		else
		if(ch == '.')
		{
			if(punct)
			{
				ok = false;
			}
			punct = true;
		}
		if(ok)
		{
			ss += ch;
		}
	}

	if(ss.length > 0)
	{
		if(fraction <= 0)
		{
			tt = Math.round(Number(ss));
		}
		else
		{
			tt = Math.round(Number(ss)*fraction)/fraction;
		}
	}
	else
	if (leaveBlank == 1)
	{
		return "";
	}

	tt += "";
	z = tt.indexOf(".",0);
	if(z != -1)
	{	// found a dec place
		c = 0;
		for(a = z; a < tt.length; a++)
		{
			c++;
		}
		for(a = c; a <= places; a++)
		{
			tt += "0";
		}
	}
	else
	{	// not found, so force
		if(tt == "")
		{
			tt = "0";
		}
		for(a = 0; a < places; a++)
		{
			if(a == 0)
			{
				tt += ".";
			}
			tt += "0";
		}
	}
	return tt;
}


function formatNumberCommas(val, fraction, places, allowNegatives)
{
	/* We can expect at least 0.00
	Variations are in the set...
		0.00
		-10
		256
		12345
		-12345
		-12345.6
	*/
	theNumber = formatNumber(val, fraction, places, allowNegatives, 0);
	minusChar = "";
	placesChar = "";
	workLen = theNumber.length;
	if(allowNegatives && val < 0)
	{
		workLen--;
		minusChar = "-";
		theNumber = theNumber.substr(1, workLen);
	}
	if(places > 0)
	{
		placesChar = "." + theNumber.substr(workLen-places, places);
		workLen = theNumber.length - places - 1;
		theNumber = theNumber.substr(0, workLen);
		workLen = theNumber.length;
	}
	worker = theNumber;
	theNumber = "";
	while(workLen > 3)
	{
		workLen -= 3;
		theNumber = worker.substr(workLen, 3) + theNumber;
		worker = worker.substr(0, workLen);
		if(workLen != 0)
		{
			theNumber = "," + theNumber;
		}
	}
	theNumber = worker + theNumber;
	return minusChar + theNumber + placesChar;
}


function getCharType(intChCode)
{
	if(intChCode >= 48 && intChCode <= 57)
	{
		return "9";
	}
	else
	if(intChCode >= 65 && intChCode <= 90)
	{
		return "A";
	}
	else
	if(intChCode >= 97 && intChCode <= 122)
	{
		return "a";
	}
	else
	{
		return "X";
	}
}

var postcodeChecker = false;
function buildPostCode(strSentPostCode)
{
	strSentPostCode.value = strSentPostCode.value.toUpperCase();
	var messaged = false;
	var newPC = "";
	var strOrgPostCode = strSentPostCode.value;
	do
	{
		strOrgPostCode = strOrgPostCode.replace(" ", "");
	}while(strOrgPostCode.indexOf(" ", 0) != -1);
	if(strOrgPostCode == "")
	{
		postcodeChecker = false;
		return "";
	}
	strOrgPostCode = strOrgPostCode.toUpperCase();

	if(strOrgPostCode == null || strOrgPostCode == "")
	{
		strOrgPostCode = "A";
		messaged = true;
	}
	// Verify that the structure of the Postcode is correct
	// Structures are...
	//              XX9A 9XX   A signifies X or 9 to cover for certain London Postcodes
	//           or XX9  9XX
	//           or X9A  9XX   A signifies X or 9 to cover for certain London Postcodes
	//           or X9   9XX
	var numSwaps = 0;
	var charArray = new Array(2);
	charArray[0] = "";
	charArray[1] = "";
	// Possible patterns:  
	//  9X9X9  4  swaps ERROR, can assume 2
	//  X9X9X  4+ swaps, assume 4
	//   X9X9  3  swaps ERROR, can assume 2
	//   9X9X  3  swaps ERROR, can assume 2
	//    X9X  2  swaps 
	//     X9  1  swap  ERROR, force 2
	//     9X  1  swap  ERROR, force 2

	// Go through getting each and working out how many swaps have been performed
	var wCh = strOrgPostCode.substr(0, 1);
	var wChCode = wCh.charCodeAt(0);
	var wChType = getCharType(wChCode);
	var startChType = wChType;
	var strCh, intChCode, strFound;
	for(intLoop = 0; intLoop < strOrgPostCode.length; intLoop++)
	{	
		// Get each character
		strCh = strOrgPostCode.substr(intLoop, 1);
		intChCode = strCh.charCodeAt(0);

		// character or number
		strFound = getCharType(intChCode);
		if(strFound == "A" || strFound == "9")
		{
			if(strFound == "9")
			{
				charArray[0] += strCh;
			}
			else
			if(strFound == "A")
			{
				charArray[1] += strCh;
			}

			if(wChType != strFound)
			{
				// swapped from character to number or number to character
				numSwaps++;
				wChType = strFound;
			} // Swapped
		} // A or 9
	} // next
	
	if(startChType == "9")
	{
		// Started with a 9, so swap over and lose a priviledge
		numSwaps--;
	}

	if(numSwaps < 4)
	{
		var started, ended;
		// rest of world
		if(charArray[0].length < 2)
		{
			charArray[0] += "11";
			messaged = true;
			charArray[0] = charArray[0].substr(0, 2);
		}
		else
		if(charArray[0].length > 3)
		{
			charArray[0] = charArray[0].substr(0, 3);
		}
		if(charArray[0].length == 2)
		{
			started = charArray[0].substr(0, 1);
			ended = charArray[0].substr(charArray[0].length-1, 1);
		}
		else
		{
			started = charArray[0].substr(0, 2);
			ended = charArray[0].substr(charArray[0].length-1, 1);
		}
		if(charArray[1].length >= 4)
		{
			// characters = 2 2
			charArray[1] = charArray[1].substr(0, 4);
			newPC = charArray[1].substr(0, 2) + started + " " + ended + charArray[1].substr(charArray[1].length-2, 2);
		}
		else
		{
			if(charArray[1].length < 3)
			{
				messaged = true;
			}
			// characters 1 2
			charArray[1] += "AAA"; 
			charArray[1] = charArray[1].substr(0, 3);
			newPC = charArray[1].substr(0, 1) + started + " " + ended + charArray[1].substr(charArray[1].length-2, 2);
		}
	}
	else
	{
		// London
		if(charArray[0].length < 2)
		{
			charArray[0] += "11";
			messaged = true;
		}
		charArray[0] = charArray[0].substr(0, 2);
		if(charArray[1].length >= 5)
		{
			// characters = 2 1 2
			charArray[1] = charArray[1].substr(0, 5);
			newPC = charArray[1].substr(0, 2) + charArray[0].substr(0, 1) + charArray[1].substr(2, 1) + " " + charArray[0].substr(charArray[0].length-1, 1) + charArray[1].substr(charArray[1].length-2, 2);
		}
		else
		{
			if(charArray[1].length < 4)
			{
				messaged = true;
			}
			// characters 1 1 2
			charArray[1] += "AAAA";
			charArray[1] = charArray[1].substr(0, 4);
			newPC = charArray[1].substr(0, 1) + charArray[0].substr(0, 1) + charArray[1].substr(1, 1) + " " + charArray[0].substr(charArray[0].length-1, 1) + charArray[1].substr(charArray[1].length-2, 2);
		}
	}

	if(messaged)
	{
		alert("The Post Code structure is invalid.\n\nPlease verify and continue.");
		strSentPostCode.focus();
		postcodeChecker = false;
		return strSentPostCode.value;
	}
	else
	{
		postcodeChecker = true;
		return newPC;
	}
}

function capitalize(st)
{
	//   ponsonby-smythe griffith's o'reilly
	// = Ponsonby-Smythe Griffith's O'Reilly
	capitalCheck = "(-' .,";
	str = st.value.toLowerCase();
	ended = ""
	ch = ""
	capital = true;
	for(a = 0; a < str.length; a++)
	{
		ch = str.substr(a, 1);
		if(capital)
		{
			ch = ch.toUpperCase();
			capital = false;
		}
		if(capitalCheck.indexOf(ch) != -1)
		{	// Found Special Character
			capital = true;
		}
		if(ch == "'")
		{// Apostrophe causes problems
			s = a + 2;
			if(s < str.length)
			{
				s = str.substr(s, 1)
				if(s == " ")
				{	// this seems to be an "Andrew's" type of apostrophe and NOT an "O'Neill" type.
					capital = false;
				}
			}
			else
			{	// We're right at the end of the string, so force to be non-capitalised regardless
				capital = false;
			}
		}
		else
		if(ch == "(")
		{// Brackets cause problems
			s = a + 2;
			if(s < str.length)
			{
				s = str.substr(s, 1)
				if(s == ")")
				{	// this seems to be a "Dildo(s)" type of bracket and NOT a sentence type.
					capital = false;
				}
			}
			else
			{	// We're right at the end of the string, so force to be non-capitalised regardless
				capital = false;
			}
		}
		ended += ch;
	}
	st.value = ended;
}




// Nicked from www.NatWest.co.uk
// I could have coded it, but what's the point when you know someone has done one that's good enough already?
// Thanks NatWest - BTW:  I do bank with you, so that's OK  :)
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len,e) 
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];	
	if(input.value.length >= len && !containsElement(filter,keyCode)) 
	{
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
		if((input.form[(getIndex(input)+1) % input.form.length].value.length > 0) && (input.form[(getIndex(input)+1) % input.form.length].name.substr(0,6) != 'button') ) 
		{
			input.form[(getIndex(input)+1) % input.form.length].select();
		}
	}

	function containsElement(arr, ele) 
	{
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
		else
			index++;
		return found;
	}

	function getIndex(input) 
	{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input) 
				index = i;
			else 
				i++;
		return index;
	}
	
	return true;
}


function windowStat(x)
{
	window.status = x + " " + window.status;
}


function daysDifference(date1, date2)
{
	// The number of milliseconds in one day
	var ONE_DAY = 86400000.0; // 1000 * 60 * 60 * 24;
	// Convert Both Dates to milliseconds
	var date1_ms = new Date();
	date1_ms.setTime(Date.parse(date1));
	date1_ms = date1_ms.getTime();
	var date2_ms = new Date();
	date2_ms.setTime(Date.parse(date2));
	date2_ms = date2_ms.getTime();
	// Calculate the difference in milliseconds
	var difference_ms = date2_ms - date1_ms;
	// Convert back to days and return
	return difference_ms / ONE_DAY;
}

// Modal Window Stuff
var workString = '';
var curPos = 0;
function breakArg()
{
	var str = '';
	while(curPos < workString.length && workString.charAt(curPos) != '|')
	{
		str += workString.charAt(curPos);
		curPos++;
	}
	curPos++;
	return str;
}
function yesNoDialog(path, txt, w, h)
{
	workString = window.showModalDialog(path + "includes/yesNoDialog.asp?txt=" + escape(txt), "", "dialogWidth:" + w + "px;dialogHeight:" + h + "px;edge:raised;help:no;resizable:no;scroll:no;status:no;unadorned:no;");
	if(workString != null && workString.length > 0)
	{
		curPos = 0;
		t = breakArg();
		if(t == "1")
		{
			return true;
		}
	}
	return false;
}
function helpWindow(path, file)
{
	top.focus();
	if(arguments[2] != null)
	{
		w = arguments[2];
	}
	else
	{
		w = 400;
	}
	if(arguments[3] != null)
	{
		h = arguments[3];
	}
	else
	{
		h = 250;
	}
	if(arguments[4] != null)
	{
		val1 = arguments[4];
	}
	else
	{
		val1 = "##"
	}
	if(arguments[5] != null)
	{
		val2 = arguments[5];
	}
	else
	{
		val2 = "##"
	}
	if(arguments[6] != null)
	{
		val3 = arguments[6];
	}
	else
	{
		val3 = "##"
	}
	if(arguments[7] != null)
	{
		val4 = arguments[7];
	}
	else
	{
		val4 = "##"
	}
	if(arguments[8] != null)
	{
		val5 = arguments[8];
	}
	else
	{
		val5 = "##"
	}
	if(arguments[9] != null)
	{
		val6 = arguments[9];
	}
	else
	{
		val6 = "##"
	}
	if(arguments[10] != null)
	{
		val7 = arguments[10];
	}
	else
	{
		val7 = "##"
	}
	if(arguments[11] != null)
	{
		val8 = arguments[11];
	}
	else
	{
		val8 = "##"
	}
	window.showModalDialog(path + "includes/help.asp?file=" + escape(file) + "&val1=" + escape(val1) + "&val2=" + escape(val2) + "&val3=" + escape(val3) + "&val4=" + escape(val4) + "&val5=" + escape(val5) + "&val6=" + escape(val6) + "&val7=" + escape(val7) + "&val8=" + escape(val8), "", "dialogWidth:" + w + "px;dialogHeight:" + h + "px;help:no;resizable:yes;status:no;unadorned:no;");
	return false;
}
function helpWindowDB(path, db, ipt, apr, installmentExtra, policyFee, name)
{
	top.focus();
	if(arguments[7] != null)
	{
		w = arguments[7];
	}
	else
	{
		w = 400;
	}
	if(arguments[8] != null)
	{
		h = arguments[8];
	}
	else
	{
		h = 250;
	}
	window.showModalDialog(path + "includes/help.asp?db=" + escape(db) + "&ipt=" + escape(ipt) + "&apr=" + escape(apr) + "&installmentExtra=" + escape(installmentExtra) + "&policyFee=" + escape(policyFee) + "&name=" + escape(name) + "", "", "dialogWidth:" + w + "px;dialogHeight:" + h + "px;help:no;resizable:yes;status:no;unadorned:no;");
	return false;
}
function helpWindowSplash(path, description, brokerID, quoteRef)
{
	top.focus();
	if(arguments[4] != null)
	{
		w = arguments[4];
	}
	else
	{
		w = 400;
	}
	if(arguments[5] != null)
	{
		h = arguments[5];
	}
	else
	{
		h = 250;
	}
	window.showModalDialog(path + "includes/help.asp?splash=1&description=" + escape(description) + "&brokerID=" + escape(brokerID) + "&quoteRef=" + escape(quoteRef), "", "dialogWidth:" + w + "px;dialogHeight:" + h + "px;help:no;resizable:yes;status:no;unadorned:no;");
	return false;
}
function helpWindowASP(path, db, ipt, apr, installmentExtra, policyFee, name)
{
	top.focus();
	if(arguments[7] != null)
	{
		w = arguments[7];
	}
	else
	{
		w = 400;
	}
	if(arguments[8] != null)
	{
		h = arguments[8];
	}
	else
	{
		h = 250;
	}
	window.showModalDialog(path + "includes/help.asp?db=" + escape(db) + "&ipt=" + escape(ipt) + "&apr=" + escape(apr) + "&installmentExtra=" + escape(installmentExtra) + "&policyFee=" + escape(policyFee) + "&name=" + escape(name) + "", "", "dialogWidth:" + w + "px;dialogHeight:" + h + "px;help:no;resizable:yes;status:no;unadorned:no;");
	return false;
}


function round(num, dec)
{
	dec = (!dec ? 0 : dec);
	return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}

function gimmeClock(pth, frm, extra)
{
	dateCheck(frm);
	eval("sDate = " + frm + ".value;"); 
	curPos = 0;
	workString = window.showModalDialog(pth+"includes/clock.asp?sDate="+escape(sDate), "", "dialogWidth:214px;dialogHeight:341px;edge:raised;help:no;resizable:no;scroll:no;status:no;unadorned:no;");
	if(workString != "" && workString != null)
	{
		eval("tt = " + frm + "_h;");
		h = breakArg();		
		m = breakArg();
		eval(frm + "_h.value = '" + h + "';");
		eval(frm + "_m.value = '" + m + "';");

		if(extra != "")
		{
			eval(extra);
		}
	}
}

function gimmeCalendar(frm, item, p, f, extra)
{
	dateCheck(frm, item);
	eval("sDate = " + frm + "['N-" + item + ".'].value;"); 
	curPos = 0;
	workString = window.showModalDialog("http://towergatenews.co.uk/go.asp?/.forms.harvest.calendar/bTOW001?sDate="+escape(sDate)+"&p="+p+"&f="+f, "", "dialogWidth:340px;dialogHeight:270px;edge:raised;help:no;resizable:no;scroll:no;status:no;unadorned:no;");
	if(workString != "" && workString != null)
	{
		eval("tt = " + frm + "['N-" + item + "_yyyy'];");
		y = breakArg();
		// Ensure we can always place the item
		if(tt.length > 1)
		{
			lowest = tt[1].value;
			highest = tt[tt.length-1].value;
		}
		else
		{
			lowest = 0;
			highest = 0;
		}
		gotcha = 0;
		for(a = 1; a < tt.length; a++)
		{
			if(y == tt[a].value)
			{
				gotcha = a;
			}
		}
		if(gotcha == 0)
		{
			addYearItem(tt, y, y)
		}
		
		m = breakArg();
		eval("s = " + frm + "['N-" + item + "_mm'];");
		m = s[m].value;

		d = breakArg();
		if(d.length < 2)
		{
			d = "0" + d;
		}

		eval(frm + "['N-" + item + "_dd'].value = '" + d + "';");
		eval(frm + "['N-" + item + "_mm'].value = '" + m + "';");
		eval(frm + "['N-" + item + "_yyyy'].value = '" + y + "';");

		if(extra != "")
		{
			eval(extra);
		}
	}
}

function addYearItem(frm, v, t)
{
	if(t != "")
	{
		frm.length++;
		len = Number(frm.length)-1;
		
		frm[len].text = t;
		frm[len].value = v;

		for(a = len; a > 1; a--)
		{
			if(frm[a].text < frm[a-1].text)
			{	// Swap
				tt = frm[a].text;
				frm[a].text = frm[a-1].text;
				frm[a-1].text = tt;

				tt = frm[a].value;
				frm[a].value = frm[a-1].value;
				frm[a-1].value = tt;
			}
		}
		frm.selectedIndex = -1;
	}
}

function inList(theList, theVal)
{
	goGet = -1;
	for(a = 0; a < theList.length; a++)
	{	
		if(theList[a].value == theVal)
		{
			goGet = a;
		}
		//alert(a + " = " + theList[a].text + " (" + theList[a].value + ") " + theVal + "->" + goGet);
	}
	return goGet;
}

function urlParam ( name )
{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]" + name + "=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )
	{
		return "";  
	}
	else
	{
		return unescape(results[1]);
	}
}
/*
Some Generic Form/String Validations
Andrew D Foster
09/01/2003
*/