
function GetURLParam(sParamName) {
// Returns a value from the URL query string.  Pass it the name.
	
	var sParamString;
	var iStartPos;
	var iEndPos;
	var sValue;

	sParamString = location.search + '&'; //Now, all values are followed by "&" (simplifies parsing)
	iStartPos = sParamString.indexOf(sParamName + '=');

	if (iStartPos > -1) {
		// Set iStartPos to beginning of the value
		iStartPos += sParamName.length + 1;
		iEndPos = location.search.indexOf('&', iStartPos);
		sValue = location.search.substring(iStartPos, iEndPos);
	}
	else {
		sValue = '';
	}
	sValue = sValue.replace(/\+/g, ' '); //replace plus signs with spaces
	return sValue;
}


function SaveCookie(pv_sName, pv_sValue) {

	document.cookie = pv_sName + '=' + escape(pv_sValue);
}


function DeleteCookie (pv_sName) {

	var dtmLastYear = new Date();

	//You must expire the cookie to delete it
	dtmLastYear.setFullYear(dtmLastYear.getFullYear() - 1);
	document.cookie = pv_sName + '=x; expires=' + dtmLastYear.toGMTString();
}


function GetCookie(pv_sName) {

	var a_sCookies = new Array();
	var a_sOneCookie = new Array();
	var sCookies = unescape(document.cookie);

	a_sCookies = sCookies.split('; ');

	for (var i=0; i < a_sCookies.length; i++) {
		a_sOneCookie = a_sCookies[i].split('=');
		if (a_sOneCookie[0] == pv_sName) {
			return a_sOneCookie[1];
		}
	}
	return '';
}


function ValidateRadioButton(pv_TheObject) {
/*
Validates that one of the radio buttons this group have been selected.
Returns the index of the control selected, or -1 if no button selected.
*/

	if (pv_TheObject.length == undefined) { // only one radio button
		if (pv_TheObject.checked) {
			return -2;
		}
	}
	else {
		for (var i=0;  i < pv_TheObject.length; i++) {
			if (pv_TheObject[i].checked) {
				return i;
			}
		}
	}

	return -1;
}


function FormatCurrency(pv_fAmount) {

	// pass in a number or a string: 7524.99874
	// returns a string formatted as currency: $7,524.99

	var sAmount;
	var iDecimal;
	var i = 6;

	pv_fAmount = Math.round(100*pv_fAmount)
	sAmount = (pv_fAmount / 100).toFixed(2);

	// reverse the string
	var a_sAmount = sAmount.split(''); // convert the string into an array
	a_sAmount.reverse();
	sAmount = a_sAmount.join('');

	while (i < sAmount.length) {
		sAmount = sAmount.slice(0, i) + ',' + sAmount.slice(i);
		i += 4
	}
	
	// reverse the string
	a_sAmount = sAmount.split(''); // convert the string into an array
	a_sAmount.reverse();
	sAmount = '$' + a_sAmount.join('');

	return sAmount;
}


function prt (pv_sString) {
	document.write (pv_sString);
}
