	var doSurvey = function() {
		ColdFusion.Window.show("survey");
	}

	var setSource = function() {
		var idx = document.frmSurvey.Source.selectedIndex;
		var sel = document.frmSurvey.Source.options[idx].text;
		switch (sel) {
			case "Other":
			case "Print": {
				document.getElementById("sTitle").innerHTML = "Source";
				document.getElementById("sRow").style.visibility="visible";
				break;
			}
			case "Radio":
			case "TV": {
				document.getElementById("sTitle").innerHTML = "Station";
				document.getElementById("sRow").style.visibility="visible";
				break;
			}
			case "Website": {
				document.getElementById("sTitle").innerHTML = "Site";
				document.getElementById("sRow").style.visibility="visible";
				break;
			}
			case "Poster": {
				document.getElementById("sTitle").innerHTML = "Location";
				document.getElementById("sRow").style.visibility="visible";
				break;
			}
			case "Friend": {
				document.getElementById("sRow").style.visibility="hidden";
				break;
			}
		}
	}
	
	var saveSurvey = function() {
		if (!validateSurvey()) return;
		ColdFusion.Ajax.submitForm("frmSurvey", rootDir+"/cfcs/survey.cfc?method=saveSurvey", callBackHandler, errorHandler);
	}
	
	callBackHandler = function(text) {
		text = trim(text);
		var arMsg = text.split("|");
		alert(arMsg[1]);
		if (arMsg[0]=="true") {
			ColdFusion.Window.hide("survey");
		}
	}
	
	errorHandler = function(code, msg) {
		alert("Error!!! " + code + ": " + trim(msg));
	}
	
	var closeSurvey = function() {
		ColdFusion.Window.hide("survey");
	}

	var validateSurvey = function() {
		var errMsg = "";
		var fieldLabel="";
		var detail = document.frmSurvey.detail.value;
		var zip = document.frmSurvey.zipcode;
		var idx = document.frmSurvey.Source.selectedIndex;
		var sel = document.frmSurvey.Source.options[idx].text;
		if (!isInteger(zip.value)||zip.value.length<5) errMsg += "Please enter a valid zip code\n";

		// remove HTML tags and anything between them
		detail = detail.replace(/[<[a-zA-Z\\][^>]*>/g, "");
		detail = trim(detail);

		if (sel!="Friend") {
			switch (sel) {
				case "Other":
				case "Print": {
					fieldLabel = "Source";
					break;
				}
				case "Radio":
				case "TV": {
					fieldLabel = "Station";
					break;
				}
				case "Website": {
					fieldLabel = "Site";
					break;
				}
				case "Poster": {
					fieldLabel = "Location";
					break;
				}
			}
			if (!detail.length) {
				errMsg += "Please enter a valid "+ fieldLabel+"; don't include < or >\n";
			} else {
				document.frmSurvey.detail.value = detail;
			}
		}
		if (errMsg.length) {
			alert(errMsg);
			return false;
		}
		return true;
	}

	var isNumeric = function(x) {
		return (x.length>0 && !isNaN(x));
	}
	
	var isInteger = function(val) {
		return (isNumeric(val)&&val%1==0)
	}

	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
