
var OTSSurvey = {
	screener : null
};
OTSSurvey.load = function() {
	if (!OTSSurvey.isAllowed()) return;
	var n = parseInt(OTSSurvey.getCookie('survey_visited'));
	if (isNaN(n)) n = 0;
	if (n > 1) {
		OTSSurvey.show();
	} else {
		n++;
	}
	//OTSSurvey.setCookie('survey_visited', n, 30);
	OTSSurvey.setCookie('survey_visited', n, 7);
}
OTSSurvey.show = function() {
	OTSSurvey.screener = document.createElement('div');
	OTSSurvey.screener.style.background = 'none';
	OTSSurvey.screener.style.border = 'none';
	OTSSurvey.screener.style.margin = '0';
	OTSSurvey.screener.style.padding = '0';
	OTSSurvey.screener.style.display = 'block';
	OTSSurvey.screener.style.float = 'none';
	OTSSurvey.screener.style.position = 'absolute';
	OTSSurvey.screener.style.top = '150px';
	OTSSurvey.screener.style.left = '100px';
	OTSSurvey.screener.style.zIndex = '1000';
	
	var x = document.createElement('a');
	x.href = '#';
	x.title = 'Close';
	x.innerHTML = '<img src="http://images.onthesnow.com/ots/images/survey_close.gif" alt="" border="0" />';
	x.onclick = function() {
		OTSSurvey.hide();
	}
	OTSSurvey.screener.appendChild(x);
	
	var o = document.createElement('iframe');
	o.src = '/ajax/survey_thankyou.html';
	o.style.width = '440px';
	o.style.height = '460px';
	o.style.background = 'none';
	o.style.border = 0;
	o.style.margin = '0';
	o.style.padding = '0';
	o.style.display = 'block';
	o.style.float = 'none';
	o.setAttribute('frameBorder', '0');
	o.setAttribute('allowTransparency', 'true');
	o.setAttribute('scrolling', 'no');
	OTSSurvey.screener.appendChild(o);
	
	document.body.appendChild(OTSSurvey.screener);
	
	//OTSSurvey.setCookie('survey_seen', 'yes', 30);
	OTSSurvey.setCookie('survey_seen', 'yes', 7);
}
OTSSurvey.hide = function() {
	document.body.removeChild(OTSSurvey.screener);
}
OTSSurvey.setCookie = function(n, v, l) {
	var d = new Date();
	var x = new Date(d.getTime() + (l * 24) * 3600 * 1000);
	document.cookie = n + '=' + v + ';expires=' + x.toGMTString() + ';path=/;';
}
OTSSurvey.getCookie = function(n) {
	var c = document.cookie.match('(^|;) ?' + n + '=([^;]*)(;|$)');
	return (c) ? (unescape(c[2])) : null;
}
OTSSurvey.isSeen = function() {
	return (OTSSurvey.getCookie('survey_seen') == 'yes');
}
OTSSurvey.isRandom = function() { 
	var w = Math.floor(Math.random() * 1);
	return (w == 0);
}
OTSSurvey.isAllowed = function() {
	//return (OTSSurvey.isRandom() && !OTSSurvey.isSeen());
	return (!OTSSurvey.isSeen());
}
OTSSurvey.addEvent = function(o, e, m) {
	if (o.addEventListener) {
		o.addEventListener(e, m, false);
	} else {
		o.attachEvent('on' + e, m);
	}
}
OTSSurvey.addEvent(window, 'load', function() { 
	OTSSurvey.load();
});
