function fAJAXRequest(strTarget, strURL, strName, strValue, strId, strHref) {
	var str_array= strURL.split("?");
//alert(strId);
	var strCustomQS = str_array[1];
	if(strCustomQS == undefined || strCustomQS == "") {
		strURL = escape(str_array[0]) + "?name=" + escape(strName) + "&value=" + escape(strValue) + "&id=" + escape(strId) + "&href=" + escape(strHref);
	} else {
		strURL = escape(str_array[0]) + "?" + strCustomQS + "&name=" + escape(strName) + "&value=" + escape(strValue) + "&id=" + escape(strId) + "&href=" + escape(strHref);
	}
//alert("strURL = " + strURL);
	if(window.XMLHttpRequest) {
		oRequest = new XMLHttpRequest();
		oTarget = strTarget;
		oRequest.onreadystatechange = fAJAXChangeWhenReady;
		oRequest.open("GET", strURL, true);
		oRequest.send(null);
	} else if(window.ActiveXObject) {
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if(oRequest) {
			oTarget = strTarget;
			oRequest.onreadystatechange = fAJAXChangeWhenReady;
			oRequest.open("GET", strURL, true);
			oRequest.send(null);
		}
	}
}

function fAJAXChangeWhenReady() {
  if(oRequest.readyState == 4 || oRequest.readyState=="complete") {
  	if(document.getElementById(oTarget)) {
  		document.getElementById(oTarget).innerHTML = oRequest.responseText;
  	}
  }
}

/*
    Return a string with an HTML "<br />" tag replacing the second to last instance of the space character (" ").
*/
function fBreakLineAtSecondToLastWord(aString) {
var debug = "";

    var output = aString;
    var intIndex = aString.lastIndexOf(" ");
debug += "aString = " + aString + "\nintIndex = " + intIndex + "\n";
    if(intIndex >= 0) {
        intIndex = aString.lastIndexOf(" ", intIndex - 1);
debug += "intIndex = " + intIndex + "\n";
        if(intIndex >= 0) { //  Replace this space with an HTML line break.
            output = aString.substr(0, intIndex) + "<br />" + aString.substr(intIndex + 1);
        }
    }
    
//alert(debug);
    return output;
}

//	Return a css pixel value (eg. 44px) converted to an integer
function fCssPixelToInt(strCssVal) {
	return Number(strCssVal.replace("px", ""));
}

/*
	Return the index of an item in an array, or -1 if it doesn't exist.
	@param aNeedle the item to find in the array
	@param aHaystack the array to search in
*/
function fGetArrayIndex(aNeedle, aHaystack) {
	var intReturn = -1;
	var boolFound = false;
	var i = 0;
	while(!boolFound && i < aHaystack.length) {
		if(aHaystack[i] == aNeedle) {
			intReturn = i;
			boolFound = true;
		}
		i++;
	}
	return intReturn;
}

/*
	Return a list of <option> tags containing Canadian provinces, one of which is 
	selected, if specified.  If not, the first option is selected.
	@param strSelected the selected province
*/
function fGetCanadianProvinceList(strSelected) {
	var strResponse = "";
	var arrProvinces = new Array();
	arrProvinces[0] = new Array("", "Choose Province");
	arrProvinces[1] = new Array("Atlantic", "Atlantic");
	arrProvinces[2] = new Array("Quebec/Eastern Ontario", "Quebec/Eastern Ontario");
	arrProvinces[3] = new Array("Central", "Central");
	arrProvinces[4] = new Array("Northwest Ontario", "Northwest Ontario");
	arrProvinces[5] = new Array("Manitoba", "Manitoba");
	arrProvinces[6] = new Array("Saskatchewan", "Saskatchewan");
	arrProvinces[7] = new Array("Alberta/Eastern BC", "Alberta/Eastern BC");
	arrProvinces[8] = new Array("British Columbia", "British Columbia");
	
	var strValue = "";
	var strDisplay = "";
	for(var i = 0; i < arrProvinces.length; i++) {
		strValue = arrProvinces[i][0];
		strDisplay = arrProvinces[i][1];
		strResponse += "<option value=\"" + strValue + "\"";
		if(strValue == strSelected) {
			strResponse += " selected=\"selected\"";
		}
		strResponse += ">" + strDisplay + "</option>";
	}
	
	return strResponse;
}

/*
 * Append a suffix to the end of a filename directly before the '.' preceding the file extension.
 * @param aFilename the filename to append a suffix to
 * @param aSuffix the suffix to append
 */
function fGetFilenameWithAppendedSuffix(aFilename, aSuffix)
{
    var output = "";
    var intExtensionIndex = aFilename.lastIndexOf('.');
//alert("intExtensionIndex = " + intExtensionIndex + "\n";
    output = aFilename.substr(0, intExtensionIndex) + aSuffix + aFilename.substr(intExtensionIndex);
    return output;
}

/*
	Return the URL with a modified version of the querystring.  The specified 
	querystring variable is searched for in the querystring.  If it is found, 
	the value of it is replaced.  Otherwise, the new querystring variable is 
	appended to the end of the querystring.  If strQSValue is a blank string, the 
	querystring value is excluded from the returned querystring.  If strURL is
	supplied, it is used instead of the current URL.  Note: jquery.js 
	and jqURL.js must be imported prior to using this function.
	@param strQSKey the name of the querystring variable
	@param strQSValue the value of the querystring variable
	@param strURL a specific URL, defaults to the current URL if not supplied
*/
function fGetModifiedURL (strQSKey, strQSValue, strURL) {
	var strDebug = "";
	var strQS = "";
	var boolSpecifiedURL = false;
	if(strURL == undefined || strURL == "") {	  
strDebug += "strURL = " + strURL + "\n";
		strQS = $.jqURL.qs();
		strURL = $.jqURL.strip();
	} else {
		boolSpecifiedURL = true;
		arrURL = strURL.split("?");
		strURL = arrURL[0];
		if(arrURL.length > 1) {
			strQS = arrURL[1];
		}
	}
strDebug += "boolSpecifiedURL = " + boolSpecifiedURL + "\n";
strDebug += "strQS = " + strQS + "\n";

  var intKeyLength = strQSKey.length + 1;	//	includes the equal sign

	var intKeyIndex = -1;
	if(strQS != "" && strQS != undefined) {
		intKeyIndex = strQS.indexOf(strQSKey + "=");
strDebug += "intKeyIndex = " + intKeyIndex + "\n";
	}	
	var intQsValueIndex = intKeyIndex + intKeyLength;
	if (strQS!= "" && strQS != undefined)
  	var intNextQsVarIndex = strQS.indexOf("&", intQsValueIndex);
		
strDebug += "intKeyIndex = " + intKeyIndex + "\n";
	var currentValue = "";
	if(boolSpecifiedURL) {
strDebug += "intKeyIndex = " + intKeyIndex + "\n";
		if(intKeyIndex != -1) {	//	the key exists in the querystring.
			if(intNextQsVarIndex > -1) {	//	get val from in between the '=' and the '&'
				currentValue = strQS.substr(intQsValueIndex, intNextQsVarIndex - intQsValueIndex);
			} else {	//	get val from everything after the '='
				currentValue = strQS.substr(intQsValueIndex);
			}
		}
strDebug += "currentValue = " + currentValue + "\n";
	} else {
strDebug += "$.jqURL.get(\"" + strQSKey + "\") = " + $.jqURL.get(strQSKey) + "\n";
		currentValue = $.jqURL.get(strQSKey);
	}
	var boolDeleteQSVar = strQSValue == "" || strQSValue == undefined ? true : false;
	if(strQS == undefined || strQS == "") {
		strURL += boolDeleteQSVar ? "" : "?" + strQSKey + "=" + strQSValue;
	} else if(currentValue == "" || currentValue == undefined) {
		strURL += boolDeleteQSVar ? "?" + strQS : "?" + strQS + "&" + strQSKey + "=" + strQSValue;
	} else {	//	replace the variable instead of appending it.
		var intStart = boolDeleteQSVar ? intKeyIndex - 1 : intQsValueIndex;
		var intLength = -1;
		if(boolDeleteQSVar) {
			if(intNextQsVarIndex > -1) {	//	there is another qs var following this one
				intLength = strQS.substr(intStart + 1).indexOf("&") + 1;
			}
		} else {
			if(intNextQsVarIndex > -1) {
				intLength = strQS.substr(intStart).indexOf("&");
			}
		}
strDebug += "intStart = " + intStart + "\n";
strDebug += "intNextQsVarIndex = " + intNextQsVarIndex + "\n";
strDebug += "intLength = " + intLength + "\n";
		if(intStart == -1) {	//	it is the first querystring var.
			if(intLength > 0) {	//	more querystring vars follow this one.
				strURL += boolDeleteQSVar ? "?" + strQS.substr(intNextQsVarIndex + 1) : "?" + strQS.substr(0, intStart) + strQSValue + strQS.substr(intStart + intLength);
			}
		} else {
			if(intLength == -1) {	//	it is the last querystring var.
				strURL += boolDeleteQSVar ? "?" + strQS.substr(0, intStart) : "?" + strQS.substr(0, intStart) + strQSValue;
			} else {	//	more querystring vars follow this one.
				strURL += boolDeleteQSVar ? "?" + strQS.substr(0, intStart) + strQS.substr(intNextQsVarIndex) : "?" + strQS.substr(0, intStart) + strQSValue + strQS.substr(intStart + intLength);
strDebug += "strQS = " + strQS + "\n";
strDebug += "strQS.substr(" + intNextQsVarIndex + ") = " + strQS.substr(intNextQsVarIndex) + "\n";
			}
		}
	}	
//alert(strDebug);
	return strURL;
}

/*
	Return a random integer from a starting integer to an ending integer, inclusive.
	@param aMinimum the minimum value
	@param aMaximum the maximum value
*/
function fGetRandomInteger(aMinimum, aMaximum) {
	return Math.floor(Math.random() * aMaximum + aMinimum);
}

/*
	Return a list of <option> tags containing United States of America's states, 
	one of which is selected, if specified.  If not, the first option is selected.
	@param strSelected the selected state
*/
function fGetStateList(strSelected) {
	var strResponse = "";
	var arrStates = new Array();
	arrStates[0] = new Array("", "Choose State");
	arrStates[1] = new Array("AL", "Alabama");
	arrStates[2] = new Array("AK", "Alaska");
	arrStates[3] = new Array("AZ", "Arizona");
	arrStates[4] = new Array("AR", "Arkansas");
	arrStates[5] = new Array("CA", "California");
	arrStates[6] = new Array("CO", "Colorado");
	arrStates[7] = new Array("CT", "Connecticut");
	arrStates[8] = new Array("DE", "Delaware");
	arrStates[9] = new Array("DC", "Washington, DC");
	arrStates[10] = new Array("FL", "Florida");
	arrStates[11] = new Array("GA", "Georgia");
	arrStates[12] = new Array("HA", "Hawaii");
	arrStates[13] = new Array("ID", "Idaho");
	arrStates[14] = new Array("IL", "Illinois");
	arrStates[15] = new Array("IN", "Indiana");
	arrStates[16] = new Array("IA", "Iowa");
	arrStates[17] = new Array("KS", "Kansas");
	arrStates[18] = new Array("KY", "Kentucky");
	arrStates[19] = new Array("LA", "Louisiana");
	arrStates[20] = new Array("ME", "Maine");
	arrStates[21] = new Array("MD", "Maryland");
	arrStates[22] = new Array("MA", "Massachusetts");
	arrStates[23] = new Array("MI", "Michigan");
	arrStates[24] = new Array("MN", "Minnesota");
	arrStates[25] = new Array("MS", "Mississippi");
	arrStates[26] = new Array("MO", "Missouri");
	arrStates[27] = new Array("MT", "Montana");
	arrStates[28] = new Array("NE", "Nebraska");
	arrStates[29] = new Array("NV", "Nevada");
	arrStates[30] = new Array("NH", "New Hampshire");
	arrStates[31] = new Array("NJ", "New Jersey");
	arrStates[32] = new Array("NM", "New Mexico");
	arrStates[33] = new Array("NY", "New York");
	arrStates[34] = new Array("NC", "North Carolina");
	arrStates[35] = new Array("ND", "North Dakota");
	arrStates[36] = new Array("OH", "Ohio");
	arrStates[37] = new Array("OK", "Oklahoma");
	arrStates[38] = new Array("OR", "Oregon");
	arrStates[39] = new Array("PA", "Pennsylvania");
	arrStates[40] = new Array("PR", "Puerto Rico");
	arrStates[41] = new Array("RI", "Rhode Island");
	arrStates[42] = new Array("SC", "South Carolina");
	arrStates[43] = new Array("SD", "South Dakota");
	arrStates[44] = new Array("TN", "Tennessee");
	arrStates[45] = new Array("TX", "Texas");
	arrStates[46] = new Array("UT", "Utah");
	arrStates[47] = new Array("VT", "Vermont");
	arrStates[48] = new Array("VA", "Virginia");
	arrStates[49] = new Array("WA", "Washington");
	arrStates[50] = new Array("WV", "West Virginia");
	arrStates[51] = new Array("WI", "Wisconsin");
	arrStates[52] = new Array("WY", "Wyoming");
	
	var strValue = "";
	var strDisplay = "";
	for(var i = 0; i < arrStates.length; i++) {
		strValue = arrStates[i][0];
		strDisplay = arrStates[i][1];
		strResponse += "<option value=\"" + strValue + "\"";
		if(strValue == strSelected) {
			strResponse += " selected=\"selected\"";
		}
		strResponse += ">" + strDisplay + "</option>";
	}
	
	return strResponse;
}

/*
	Return a boolean indicating whether or not an array contains a specified value.
	@param aNeedle the item to search for in the array.
	@param aHaystack the array to search for
*/
function fInArray(aNeedle, aHaystack) {
	var intIndex = fGetArrayIndex(aNeedle, aHaystack);
	if(intIndex == -1) {
		return false;
	} else {
		return true;
	}
}

/*
	Function to determine if it is a valid Canadian postal code.
	@param aPostalCode the Canadian postal code to test
*/
function fIsValidCanadianPostalCode(aPostalCode) {
    var objRegExp = /^([A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9])$/;
//alert("objRegExp.test(\"" + aPostalCode + "\") = " + objRegExp.test(aPostalCode) + "\n");
    return objRegExp.test(aPostalCode);
}

/*
	Function to determine if it is a valid us zip code
	@param aZip the zipcode to test
	@param shouldAllowNineDigits a boolean which will pass a zipcode such as "06001-1234" if passed as true
*/
function fIsValidUsZip(aZip, shouldAllowNineDigits) {
    var objRegExp;
    if(shouldAllowNineDigits) {
    	objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
    } else {
    	objRegExp = /(^\d{5}$)/;
    }
//alert("objRegExp.test(\"" + aZip + "\") = " + objRegExp.test(aZip) + "\n");
    return objRegExp.test(aZip);
}

/*
	Return a boolean indicating whether or not an input string begins with another input string.
	@param aHaystack the string in which the search will occur
	@param aNeedle the string to search for
*/
function fStartsWith(aHaystack, aNeedle) {
	return aHaystack.indexOf(aNeedle) == 0;
}

//	Recursive function that returns the passed string with leading and trailing white space removed.
function fTrim(aString) {
	var output = aString;
	
	if(aString != undefined && aString != "") {
		var intFirstSpaceIndex = aString.indexOf(" ");
		var intLastSpaceIndex = aString.lastIndexOf(" ");
		var boolLeadingWhiteSpace = intFirstSpaceIndex == 0;
		var intLastCharIndex = aString.length - 1;
		var boolTrailingWhiteSpace = intLastSpaceIndex == intLastCharIndex;
			
	//alert("aString = " + aString + "\nintLastSpaceIndex = " + intLastSpaceIndex + "\nboolTrailingWhiteSpace = " + boolTrailingWhiteSpace + "\n");
		if(boolLeadingWhiteSpace) {
			output = fTrim(aString.substr(1));
		} else if(boolTrailingWhiteSpace) {
			output = fTrim(aString.substr(0, intLastCharIndex));
		} else {	//	The base case: no leading or trailing whitespace exists
			output = aString;
		}
	}
	
	return output;
}

//	Return the supplied string with the first character converted to upper case.
function fTurnFirstToUpper(strInput) {
	return strInput.substr(0, 1).toUpperCase() + strInput.substr(1);
}

//	FORM VALIDATION
function fVerifyEmail(strEmail) {
	var strEmail = document.getElementById(strEmail).value;
	if (/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(strEmail)) {
		return "";
	} else {
		return "Please enter a valid email address.\n";
	}
}

function fVerifyInput(strID, strText) {
	var oInput = document.getElementById(strID);
//alert("strID = " + strID + "\nstrText = " + strText + "\noInput = " + oInput + "\n");
	if(oInput.value == "") {
		oInput.style.background = "#eeeeff";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyInputLength(strID, intLength, strText) {
	var oInput = document.getElementById(strID);
	if(oInput.value.length < intLength) {
		oInput.style.background = "#eeeeff";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyGuiInputMaxLength(strID, intLength, strText) {
	var oInput = document.getElementById(strID);
	var strInput = oInput.value.replace(/(<([^>]+)>)/ig,"");	//	Remove the HTML tags
//alert("strInput.length = " + strInput.length);
	if(strInput.length > intLength) {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

//	This is necessary because the default text of the javascript GUI text areas is not the same across browsers.
function fVerifyGuiInput(strID, strText) {
	var oInput = document.getElementById(strID);
	var arrEmptyValues = new Array();
	arrEmptyValues[0] = "";
	arrEmptyValues[1] = " ";
	arrEmptyValues[2] = "&nbsp;";
	arrEmptyValues[3] = "\n\n";
	var boolIsEmpty = false;
	for(var i = 0; i < arrEmptyValues.length; i++) {
		if(oInput.value == arrEmptyValues[i]) {
			boolIsEmpty = true;
			break;
		}
	}
	if(boolIsEmpty) {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyRadio(strID, strText) {
	var oRadio = document.getElementsByName(strID);
	for(i=0; i<oRadio.length; i++) {
		if(oRadio[i].checked) {
			return "";
		}
	}
	return "Please answer " + strText + ".\n";
}

function fVerifySelect(strID, strText) {
	var oElement = document.getElementById(strID);
	if(oElement.selectedIndex == 0) {
		oElement.style.background = "#eeeeff";
		oElement.focus();
		return strText;
	} else {
		oElement.style.background = "#ffffff";
	}
	return "";
}

function fShow(strDiv) {
	document.getElementById(strDiv).style.visibility = "visible";
	document.getElementById(strDiv).style.display = "block";
}

function fHide(strDiv) {
	document.getElementById(strDiv).style.visibility = "hidden";
	document.getElementById(strDiv).style.display = "none";
}


function fToggle(strID) {
	if(document.getElementById(strID).style.visibility == "hidden") {
		fShow(strID);
	} else {
		fHide(strID);
	}
}

/**************************************************************
PAPER CLICK FUCNTIONS
**************************************************************
function yahoo_ppc()
{
 <!-- Yahoo! Inc.
    window.ysm_customData = new Object();
    window.ysm_customData.conversion = "transId=,currency=,amount=";
    var ysm_accountid  = "13BVUE8CE1TB6MJKQF179IS724G";
    document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " 
    + "SRC=//" + "srv1.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid 
    + "></SCR" + "IPT>");
// -->

}
function msn_ppc()
{
    microsoft_adcenterconversion_domainid = 77392;
    microsoft_adcenterconversion_cp = 5050; 
    document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " 
    + "SRC=https://0.r.msn.com/scripts/microsoft_adcenterconversion.js>"+"</SCR"+"IPT>");
    document.write("<noscript>"
    + "<IMG width=1 height=1 SRC=https://77392.r.msn.com/?type=1&cp=1/>"+"</NOSCR"+"IPT>");
}

function google_ppc()
{
    var google_conversion_id = 1061195156;
    var google_conversion_language = "en";
    var google_conversion_format = "1";
    var google_conversion_color = "666666";
    var google_conversion_label = "lead";
    document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " 
    + "src=http://www.googleadservices.com/pagead/conversion.js></SCR" + "IPT>");
    document.write("<noscript>"
    + "<img height='1' width='1' border='0' src='http://www.googleadservices.com/pagead/conversion/1061195156/?label=lead&amp;guid=ON&amp;script=0\"/>"
    + "</noscript>");
}
*/