var strAlertMessage = "";
var strAlertMessageId = "";
var blnTestMode = false;

$(document).ready(function() 
{
   if(strAlertMessage != "")
   {
      boolVisited = checkCookie();
      if ( !boolVisited ) 
      {
         $('.overlay').show();
         $('#popup').show();
         $('html').css( {
            "overflow-x" : 'hidden'
         });
      }
   }
});

$(function() 
{
   $('.overlay').css( {
      "opacity" : .6
   });

   $('#overlay, #close').click(function() {     
      $('#popup, .overlay').fadeOut(function(){
         $('html').css( {"overflow-x" : 'auto'});
      });
   });
   
   $(window).bind('resize', function(){
      $('.overlay').css("width", $(document).width() + "px");
      centerLightbox('#popup');
   });

   centerLightbox('#popup');
});

function centerLightbox(obj) 
{
   $(obj).css("top", ($(window).height() - $(obj).height()) / 2);
   $(obj).css("left", ($(window).width() - $(obj).width()) / 2);
}

function getCenterWidth(obj) 
{
   return ($(window).width() - $(obj).width()) / 2;
}

function getCenterHeight(obj) 
{
   return ($(window).height() - $(obj).height()) / 2;
}

function setAlert(strMessage, strMessageId, blnRunTestMode)
{
   strAlertMessage = strMessage;
   strAlertMessageId = strMessageId;
   if ( blnRunTestMode !== undefined ) 
   {
      blnTestMode = blnRunTestMode;
   }
}

function setCookie(strCookieName,boolValue,intDaysExpire)
{
   var objExpireDate = new Date();
   objExpireDate.setDate(objExpireDate.getDate()+intDaysExpire);
   document.cookie = strCookieName + "=" + boolValue +
   ((intDaysExpire==null) ? "" : ";expires="+objExpireDate.toUTCString());
}

function getCookie(strCookieName) 
{
   if (document.cookie.length > 0) 
   {
      intCookieStart = document.cookie.indexOf(strCookieName + "=");
      if (intCookieStart != -1) 
      {
         intCookieStart = intCookieStart + strCookieName.length + 1;
         intCookieEnd = document.cookie.indexOf(";", intCookieStart);
         if (intCookieEnd == -1)
         {
            intCookieEnd = document.cookie.length;
         }
         return unescape(document.cookie.substring(intCookieStart, intCookieEnd));
      }
   }
   return false;
}

function deleteCookie()
{
   document.cookie = "hc_alert"+strAlertMessageId+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function checkCookie() 
{
   boolVisited = getCookie('hc_alert'+strAlertMessageId);

   if (!blnTestMode)
   {
         if (boolVisited) 
         {
            return true;
         } 
         else 
         {
            setCookie('hc_alert'+strAlertMessageId, true, 1);
            boolVisited = getCookie('hc_alert'+strAlertMessageId);
            if(!boolVisited)
            {
               $('#contentMessage').html('<p>Please enable cookies to view an important message about the school</p>');
            }
            else
            {
               $('#contentMessage').html(strAlertMessage);
            }
            return false;
         }
   }
   else
   {
      setCookie('hc_alert'+strAlertMessageId, true, 1);
      boolVisited = getCookie('hc_alert'+strAlertMessageId);
      $('#contentMessage').html(strAlertMessage);
      return false;
   }
}
