function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

$(document).ready(function() {
	
   // If close button is clicked
   $('.window #close').click(function () {
      $('#mask').hide();
      $('.window').hide();
   });		
	
   // If mask is clicked
   $('#mask').click(function () {
      $(this).hide();
      $('.window').hide();
   });			
	
});

function launchWindow(id, setCookie) {

   // Set the pro tech video cookie if needed
   if (setCookie) {
     document.cookie = 'exp_MsgSent=True; expires=Thu, 31 Dec 2021 23:59:59 UTC; path=/';
   }

   // Get the screen height and width
   var maskHeight = $(document).height();
   var maskWidth = $(window).width();
	
   // Set height and width to mask to fill up the whole screen
   $('#mask').css({'width':maskWidth,'height':maskHeight});
		
   // Transition effect		
   //$('#mask').fadeIn(1000);	
   $('#mask').fadeTo(800,.8);	
	
   // Get the window height and width
   var winH = $(window).height();
   var winW = $(window).width();
              
   // Set the popup window to center
   $(id).css('top',  winH/2-$(id).height());
   $(id).css('left', winW/2-$(id).width()/2);
	
   // Transition effect
   $(id).fadeIn(1000);
}

function checkForCookies() {
   // Display cookie found?
   if (!readCookie("exp_MsgSent")) {
      // Pro cookie found?
      if (readCookie("exp_ProVisits")) {
         // Is cookie equal to the max?
         if (readCookie("exp_ProVisits") == 2) {
            // Display warning and set display cookie
            return(launchWindow('#dialog', true));
         }
      }
   }
}

