var exp = new Date();
var expDays = 60; // number of days the cookie should last
var pCount = 3; // number of pages before the popup should occur
var percentOpen = 100;  //The percentage in which the popup will trigger.
var inviteBox = 0; //Activate Invitation Box. 1 = On, 0 = Off.
var link;
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
//var theWidth  = 720;
var theWidth = 950;
var theHeight = 700;

/*if (screen.height >= 1024){
	theHeight = 620;
} else if (screen.height >= 864) {
	theHeight = 620;
} else if (screen.height >= 768) {
	theHeight = 620;
} else if (screen.height >= 600){
	theHeight = 500;
} else {
	theHeight = 620;
}

theTop=(screen.availHeight/2)-(theHeight/2)
theLeft=(screen.availWidth/2)-(theWidth/2)
var features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
*/
var theTop=(screen.availHeight/2)-(theHeight/2);
var theLeft=(screen.availWidth/2)-(theWidth/2);
var features='width='+theWidth+',height='+theHeight+'scrollbars=no,location=no,status=no,menubar=yes,top='+theTop+',left='+theLeft;
var hRange = 100; //Change the upper range to modify the probablity of an eCollector call 

RTPopup(link);
initInviteBox(link); 

function RTPopup(link) //Calling function for the popup window on page load.
{

	var count = GetCookie('Resp');
			
	if (count == null) 
	{
		count=1;
		SetCookie('Resp', count, exp, '/', null,false);
		
	}
	else 
	{
		if (count == pCount)	// This is the number of pages hit before the eCollector is popped up.
		{
			//Institate code to call AJAX window here.
			count++;
			SetCookie('Resp', count, exp, '/', null,false);
			var rndNum; 
	   		rndNum = Math.floor(Math.random()*hRange); 
	   			if (inviteBox == 1 && rndNum <= percentOpen) 
				{
					confirmation()
				}
					
				else if (rndNum <= percentOpen)
				{
					var wOpen;
					wOpen = window.open(link, 'RTCollector', features);
					wOpen.focus();	
				}
		}
		else
		{
			count++;
			SetCookie('Resp', count, exp, '/', null,false);
		}
	}
}

function RTeClick(link) // Activates popup on click and increase count above pCount.
{
	count = pCount + 2;
	SetCookie('Resp', count, exp, '/', null,false);

	var wOpen = window.open(link, 'RTCollector', features);
	wOpen.focus();
}

function confirmation() {
	displayInviteBox();

//			var answer = confirm("We value customer feedback and invite you to complete a short survey about your customer experience.")
//			if (answer){
//			}
//			else{
//				
//			}
}
function initInviteBox(link) {
	jQuery('#inviteBox').css({
		'width': '420px',
		'left': (jQuery(window).width()/2 - 230)
	});
	jQuery('#inviteBox #close_survey').click(function() {
		jQuery('#inviteBox').fadeOut();
	});
	jQuery('#inviteBox #do_survey').click(function() {
		var wOpen;
		jQuery('#inviteBox').fadeOut();
		wOpen = window.open(link, 'RTCollector', features);
		wOpen.focus();
	});
	
}

function displayInviteBox() {
	jQuery('#inviteBox').fadeIn();
}

