// SurveyMonkey survey functions
// Created 08.07.07 DHE
// Last modified 08/09/07

/*
To enable a survey, you must first set up a survey on SurveyMonkey and obtain the survey url.

On the page where you want the survey to appear:

1) Add this script library: <script src="/includes/surveys/surveymonkey.js"></script>
2) Define variables in a script block for smurl and survey
3) Call popupSurvey: popupSurvey("/includes/surveys/smsurvey.asp","tpsurvey",smurl,survey);
4) Create an inline scriptblock and call showSurveyLink: showSurveyLink(smurl,survey);

*/

/*
Creates and opens the survey intro window
*/
function popupSurvey(url,winName,smurl,survey) {
	var w = 550;
	var h = 400;
	//for testing: ,toolbar=yes,location=yes
	var features = "width=" + w + ",height=" + h + ",scrollbars=yes";
	var aspurl = url;
	if (aspurl.indexOf(".asp") > -1) {
		aspurl += "?" + "smurl=" + smurl;
		aspurl += "&" + "survey=" + survey;
	}
	surveyWindow = window.open(aspurl, winName, features);
}

/*
checks to see if popup was blocked
*/
function checkForPopup() {
	if (typeof(surveyWindow)!="undefined" && surveyWindow) {
		return true;
	}
	else {
		return false;
	}
}
/*
Used as an alternative if popups are being blocked.
*/
function showSurveyLink(url,survey) {
	//#e4e9f3 (pale blue)
	//#990000 (deep red)
	//#132744 (dark blue)
	if (!checkForPopup()) {
		//<tr><td colspan=\"3\">
		var surveyLink = "<div style=\"border:1px solid #3f4f6d; background-color:#990000; padding:5px 5px 5px 5px; margin:10px 10px 5px 5px; color: white; \">";
        surveyLink += "Your feedback is the most valuable tool we have. Please take a few moments to " +  "<a style=\"color: white;font-weight: bold;\" href=\"" + url + "\">take our survey. " + "</a>";
		//</td></tr>
		surveyLink +="</div>";
		document.writeln(surveyLink);
	}		
}

/*
This function will close down a calling page in a popup window. Used to
close the popup window after the survey returns. It works as long as the
survey is set up to return to the same page that the survey is announced on.
*/
function closeIfPopup() {
	if (window.opener) {
		window.close();
	}
}
