var nameOfCookie = 'SBSSurvey'; 
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() {
	document.write('<style type="text/css">');
	document.write('#SurveyPopup { background-color:#FFFFFF; filter: alpha(opacity=97); -moz-opacity: 0.97; opacity: 0.97; }');
	document.write('</style><div id="SurveyPopup" style="position: absolute; top: 115px; left: 159px; height: 200; width: 450px; z-index: 999">');
	document.write('<iframe style="z-index: 999;" src="../../html/home/survey_popup.html" height="200" width="450" frameborder="0"></iframe>');
	document.write('</div>');
}


function DoSurvey() {
	
	if (GetCookie(nameOfCookie) == null) {
		rndNum = Math.round(((surveyChance -1) * Math.random()) + 1);
		if (rndNum == 3) {
			SetCookie(nameOfCookie, "SHOWN");
			OpenSurvey();
		} else {
			SetCookie(nameOfCookie, "NOT_SHOWN");
		}
	}
}

DoSurvey();
