/* 	author: Georg Apitz
	version: 1.0
	date: 8/12/2008
	script to pop-up and exitSurvey modal dialog,
	in collaboration with Michael Nolan    
	modified 11/19/2008 by geapi to include session cookie
	and reduce sample rate to 5% for site wide distribution*/
$(document).ready(function() { 
  $('#okbutt').click(function() {
    $.unblockUI();
	openExitSurveyPopup();
    return false;
  }); 
  $('#cancelbutt').click(function() { 
    $.unblockUI(); 
	setCookie('surveycookie', 'no', 720, '/');
    return false; 
  }); 
});
function showExitSurveyPopUp(){
	/* KC 7/1/09: Reduced to 1% */
	var odds = 1;
	var chance = Math.floor(Math.random() * 101);
	if (chance <= odds){
		if(getCookieValue('surveycookie')==null && getCookieValue('exitSurvey')==null){
				$.blockUI({ message: $('#exitSurvey'), css: { width: '400px', background:'#f2f5f4' } }); 
		}
	}
	/*if(getCookieValue('exitSurvey')!=null){
	 	alert("already made choice for exit survey, not again!");
	}*/
	var cookietext = "exitSurvey = shown";
	document.cookie = cookietext;
}
var popupWin = null;
function openExitSurveyPopup() {
	var url = "/pop-ups/exitSurveyPopup.htm"
	popupWin = open("", "popupWin", "width=500,height=400, location=no,dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=yes" );
	//placing a cookie valid six months in future for people who say YES
	setCookie('surveycookie', 'yes', 180, '/');
	if( !popupWin || popupWin.closed || !popupWin.doSomething ) {
		popupWin = window.open( url, "popupWin", "width=500,height=400,location=yes" );
	}
	else popupWin.focus();
}
