//This file added to support SBS's survey.

var surveyCookie = 'BESurvey_'; 
var surveyChance = 5;

function GetCookie(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
	return null;
}

function SetCookie (name, value) {
	document.cookie = name + "=" + escape (value) + '; path=/';
	//should expire at end of session
}

function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function closePopup() {
	var popupWindow = document.getElementById("SurveyPopup");
	popupWindow.style.visibility = "hidden";
	popupWindow.style.display = "none";
}

function OpenSurvey(theSurvey) {
	document.write('<style type="text/css">');
	document.write('#SurveyPopup { background-color:#FFFFFF; filter: alpha(opacity=99); -moz-opacity: 0.99; opacity: 0.99; }');
	document.write('</style><div id="SurveyPopup" style="position: absolute; top: 350px; left: 261px; height: 200; width: 450px; z-index: 999">');
	document.write('<iframe style="z-index: 999;" src="/html/sbs/html/biz_express/survey_popup_'+theSurvey+'.html" height="200" width="450" frameborder="0"></iframe>');
	document.write('</div>');
}
function DoSurvey(surveySelect) {
	var tmpCookie = surveyCookie;
	
	if (!surveySelect){
		tmpCookie = tmpCookie + "home"
		if (GetCookie(tmpCookie) == null) {
		    rndNum = Math.round(((surveyChance -1) * Math.random()) + 1);
		    //rndNum = 3;
		    if (rndNum == 3) {
		        SetCookie(tmpCookie, "SHOWN");
		        OpenSurvey("home");
		    } else {
		        SetCookie(tmpCookie, "NOT_SHOWN");
		    }
		}
	} else if (surveySelect == "wizard") {
		tmpCookie = tmpCookie + "wizard"
		if (GetCookie(tmpCookie) == null) {
			SetCookie(tmpCookie, "VISITED");
	    }else if(GetCookie(tmpCookie)=="VISITED"){
		    rndNum = Math.round(((surveyChance -1) * Math.random()) + 1);
		    //rndNum = 3;
		    if (rndNum >= 3) {
		        SetCookie(tmpCookie, "SHOWN");
		        OpenSurvey("wizard");
		    } else {
		        SetCookie(tmpCookie, "NOT_SHOWN");
		    }
		}
	} else if (surveySelect == "estimator") {
		//alert("estimator");
	} else if (surveySelect == "intake") {
		//alert("intake");
	} else if (surveySelect == "create") {
		//alert("create");
	}
}

