/* *************************************** */
/* 	
	Display the ChannelOne survey 
 	require the survey_config.js for the variable 
	by Tsuen Siu
	02/06/08
*/
/* *************************************** */

/* display the feedback survey */
function displayFeedbackSurvey() {
	if (isDisplaySurvey()) {
		var feedbackSurvey = document.getElementById('feedback_survey');
		var feedbackImg = document.createElement('img');
		feedbackImg.id = 'feedback_img';
		feedbackImg.setAttribute('src',ch1_survey_img);
		feedbackImg.setAttribute('alt','Take the Survey');
		feedbackImg.setAttribute('title','Take the Survey');
		feedbackImg.setAttribute('usemap','#survey_banner',0);
		feedbackSurvey.appendChild(feedbackImg);
		feedbackSurvey.style.display = 'block';
	}
}

/* is it the survey page...  it is only the homepage for now */
function isSurveyPage() {
	if (  ((location.host == "www.channelone.com") || (location.host == "channelone.com")) &&
		  ((location.href == "http://"+location.host+"/") || (location.href == "http://"+location.host+"/index.vm") || (location.href == "http://"+location.host+"/teachers/")) 
		  ){
		return true;
	} else {
		return false;
	}
}

/* is it the preview page for the survey? */
function isSurveyPreviewPage() {
	if (	(location.host != "www.channelone.com") && (location.host != "channelone.com") && 
			((location.href == "http://"+location.host+"/") || (location.href == "http://"+location.host+"/index.vm") || (location.href == "http://"+location.host+"/teachers/"))
		){
		return true;
	} else {
		return false;
	}
}
/* is the survey activated?  1 for on, 0 for off */
function isSurveyActivated() {
	if (ch1_survey==1) {
		return true;
	} else {
		return false;
	}
}

/* is the survey in the preview site actived?  1 for on, 0 for off */
function isSurveyPreviewActivated() {
	if (ch1_survey_preview==1) {
		return true;		
	} else {
		return false;
	}
}

/* am i luck enough to get the survey */
function isSurveyRand() {
	var a=Math.floor(Math.random()*(1/ch1_survey_freq));
	if (a==0) {
		return true;
	} else {
		return false;
	}
}

/* should we display the survey?  it is base on the location, activated and luck */
function isDisplaySurvey() {
	if( (isSurveyPage() && isSurveyActivated()) 
	|| 	(isSurveyPreviewPage() && isSurveyPreviewActivated()) 
	) {
		return isSurveyRand();
	} else {
		return false;
	}
}
