for (var customMessageId in customMessage) {  
   if(customMessage[customMessageId].message != undefined) {
    if(customMessage[customMessageId].homeOnly == undefined) customMessage[customMessageId].homeOnly = true;
    if (unescape(location.href).indexOf("/home/")!=-1||!customMessage[customMessageId].homeOnly) {// Check home only option
     document.write('<div id="habCustomMessagePopupBox_' + customMessageId + '" style="position:absolute; width: 300px; left: 0; top: -400px; border: ' + popupCustomMessageBorder + '; background-color: ' + popupCustomMessageBGColor + '; padding: 4px; z-index: 3000; visibility:hidden;filter:progid:DXImageTransform.Microsoft.RandomDissolve(duration=1) progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135); -moz-opacity:0;"></div>');
    }
   }
} //END LOOP


//== STICKY NOTE SCRIPT FROM DYNAMIC DRIVE  =============================================
/***********************************************
* Sticky Note script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Go to http://www.dynamicdrive.com/ for full source code
***********************************************/

var customMessageDisplayMode="always"

var customMessageFadeEnabled="yes"       //("yes" to enable fade in effect, "no" to disable)
var customMessageAutoHideBox=["no", 5]  //Automatically hide box after x seconds? [yes/no, if_yes_hide_after_seconds]
var customMessageShowOnScroll="yes"      //Should box remain visible even when user scrolls page? ("yes"/"no)
var customMessageFadeLengthIE=1          //fade in duration for IE, in seconds
var customMessageFadeDegreeMoz=0.05      //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)
var customMessageShowOnScrollVar = new Array();
var objref = new Array();

////////No need to edit beyond here///////////

if (parseInt(customMessageDisplayMode)!=NaN)
var customMessageRandomNum=Math.floor(Math.random()*customMessageDisplayMode)

function displayCustomMessagePopupBox(thisMessage){
  var ie=document.all && !window.opera
  var dom=document.getElementById
  iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
  objref[thisMessage]=(dom)? document.getElementById("habCustomMessagePopupBox_" + thisMessage) : document.all.habCustomMessagePopupBox
  var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
  var docwidth=(ie)? iebody.clientWidth : window.innerWidth
  docheight=(ie)? iebody.clientHeight: window.innerHeight
  var objwidth=objref[thisMessage].offsetWidth
  objheight=objref[thisMessage].offsetHeight

  try {
   switch(customMessage[thisMessage].positioning) {
     case 0: { objref[thisMessage].style.left=docwidth/2-objwidth/2+"px"; objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"; break; } 
     case 1: { objref[thisMessage].style.left="1px"; objref[thisMessage].style.top="1px"; break; }
     case 2: { objref[thisMessage].style.left="1px"; objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"; break; }
     case 3: { objref[thisMessage].style.left="1px"; objref[thisMessage].style.top=scroll_top+docheight-objheight+"px"; break; }
     case 4: { objref[thisMessage].style.left=docwidth/2-objwidth/2+"px"; objref[thisMessage].style.top="1px"; break; } 
     case 5: { objref[thisMessage].style.left=docwidth/2-objwidth/2+"px"; objref[thisMessage].style.top=scroll_top+docheight-objheight+"px"; break; } 
     case 6: { objref[thisMessage].style.left=docwidth-objwidth+"px"; objref[thisMessage].style.top="1px"; break; } 
     case 7: { objref[thisMessage].style.left=docwidth-objwidth+"px"; objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"; break; } 
     case 8: { objref[thisMessage].style.left=docwidth-objwidth+"px"; objref[thisMessage].style.top=scroll_top+docheight-objheight+"px"; break; } 
     default: { objref[thisMessage].style.left=docwidth/2-objwidth/2+"px"; objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"; } 
   }
  } catch(er) {
   objref[thisMessage].style.left=docwidth/2-objwidth/2+"px"
   objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"
  }

  if (customMessageShowOnScroll=="yes") customMessageShowOnScrollVar[thisMessage]=setInterval("customMessageStaticFadeBox('"+thisMessage+"')", 50)

  if (customMessageFadeEnabled=="yes" && objref[thisMessage].filters) {
   objref[thisMessage].filters[0].duration=customMessageFadeLengthIE
   objref[thisMessage].filters[0].Apply()
   objref[thisMessage].filters[0].Play()
  }
  objref[thisMessage].style.visibility="visible"
  if (objref[thisMessage].style.MozOpacity){
   if (customMessageFadeEnabled=="yes")
    mozfadevar=setInterval("customMessageFadeFxMoz('"+thisMessage+"')", 90)
   else {
    objref[thisMessage].style.MozOpacity=1
    controlledCustomMessageHideBox(thisMessage)
   }
  } else
     controlledCustomMessageHideBox(thisMessage)
}

function customMessageFadeFxMoz(thisMessage){
  if (parseFloat(objref[thisMessage].style.MozOpacity)<1)
   objref[thisMessage].style.MozOpacity=parseFloat(objref[thisMessage].style.MozOpacity)+customMessageFadeDegreeMoz
  else {
   clearInterval(mozfadevar)
   controlledCustomMessageHideBox(thisMessage)
  }
}

function customMessageStaticFadeBox(thisMessage){
  var ie=document.all && !window.opera
  var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
  try {
   switch(customMessage[thisMessage].positioning) {
     case 1: { objref[thisMessage].style.top=scroll_top; break;}
     case 4: { objref[thisMessage].style.top=scroll_top; break;}
     case 6: { objref[thisMessage].style.top=scroll_top; break;}
     case 3: { objref[thisMessage].style.top=scroll_top+docheight-objheight+"px"; break; }
     case 5: { objref[thisMessage].style.top=scroll_top+docheight-objheight+"px"; break; }
     case 8: { objref[thisMessage].style.top=scroll_top+docheight-objheight+"px"; break; }
     default: { objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"; }
   }
  } catch(er) {
   objref[thisMessage].style.top=scroll_top+docheight/2-objheight/2+"px"
  }
}

function hideCustomMessageFadeBox(thisMessage){
  objref[thisMessage].style.visibility="hidden"
  if (typeof customMessageShowOnScrollVar[thisMessage]!="undefined")
  clearInterval(customMessageShowOnScrollVar[thisMessage])
}

function controlledCustomMessageHideBox(thisMessage){
  if (customMessageAutoHideBox[0]=="yes"){
   var delayvar=(customMessageFadeEnabled=="yes" && objref[thisMessage].filters)? (customMessageAutoHideBox[1]+objref[thisMessage].filters[0].duration)*1000 : customMessageAutoHideBox[1]*1000
   setTimeout("hideCustomMessageFadeBox("+thisMessage+")", delayvar)
  }
}

//== END DYNAMIC DRIVE SCRIPT=====================


function getHabCustomMessageCookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}


function getHabCustomMessagePopupCookie(which,lid,fid) {
  var cookieName = 'habCustomMessagePopup_' + which + '_' + lid + '_' + fid;
  var cookieExists = getHabCustomMessageCookie(cookieName);
  if(cookieExists=="") return false; else return true;
}

function setHabCustomMessagePopupCookie(which,lid,fid,frequency) {
  var cookieName = 'habCustomMessagePopup_' + which + '_' + lid + '_' + fid;

  var today = new Date();
  var expire = new Date();

  switch (frequency) {
   case 0: { document.cookie=cookieName+"=;";                      // clear cookie
                   break; }
   case 1: { document.cookie=cookieName+"=session;";               // expire on window close
                   break; }
   case 2: { expire.setTime(today.getTime() + 1000*60*60*24);      // expire in one day
                   document.cookie=cookieName+"=24;expires="+expire.toGMTString();
                   break; }
   case 3: { expire.setTime(today.getTime() + 1000*60*60*24*7);    // expire in one week
                   document.cookie=cookieName+"=week;expires="+expire.toGMTString();
                   break; }
   case 4: { expire.setTime(today.getTime() + 1000*60*60*24*365);  // expire in one year
                   document.cookie=cookieName+"=week;expires="+expire.toGMTString();
                   break; }
  }
}

function setRemindMeLater(which) { // Sets session cookie and closes window
  setHabCustomMessagePopupCookie(which,league_id,franchise_id,1);
  hideCustomMessageFadeBox(which);
}

function setNeverRemindMe(which) { // Sets session cookie and closes window
  setHabCustomMessagePopupCookie(which,league_id,franchise_id,4);
  hideCustomMessageFadeBox(which);
}

for (var customMessageId in customMessage) {
 if(customMessage[customMessageId].message != undefined) {
  if (unescape(location.href).indexOf("/home/")!=-1||!customMessage[customMessageId].homeOnly) {// Check home only option
   try {
    var tempHTML = "";
 
    if(franchise_id==undefined) {
     var franchise_id;
     var thisCustomMessageFranchise = "guest";
    } else {
     var thisCustomMessageFranchise = franchise_id;
    }

    if(customMessage[customMessageId].active==undefined) customMessage[customMessageId].active = true;
 
    if(customMessage[customMessageId].franchises==undefined) 
     var doThisFranchise = true;
    else if (customMessage[customMessageId].franchises.indexOf(thisCustomMessageFranchise) >= 0)
           var doThisFranchise = true;
         else
           var doThisFranchise = false;
    
    if(customMessage[customMessageId].remindOption==undefined||customMessage[customMessageId].remindOption==false||customMessage[customMessageId].frequency==0)
     var remindOption = "";
    else 
     var remindOption = '[ <a href="#1" onClick="setRemindMeLater(\''+customMessageId+'\'); return false">Remind me later</a> ][ <a href="#1" onClick="setNeverRemindMe(\''+customMessageId+'\'); return false">Never remind me</a> ]'
 
    if(doThisFranchise&&customMessage[customMessageId].active) {
     if(customMessage[customMessageId].frequency==0) {  //Show each visit so clear all cookies
       setHabCustomMessagePopupCookie(customMessageId,league_id,franchise_id,0);
     }
 
     if(!getHabCustomMessagePopupCookie(customMessageId,league_id,franchise_id)) {
      tempHTML += customMessage[customMessageId].message;
      setHabCustomMessagePopupCookie(customMessageId,league_id,franchise_id,customMessage[customMessageId].frequency);
     }

     if(tempHTML!="") {
      var tableHTML = '<br /><table align="center" cellspacing="1" class="homepagemodule report" id="customMessages"><caption><span>'+customMessage[customMessageId].caption+'</span></caption><tbody><tr><th>'+customMessage[customMessageId].header+'</th></tr>';
      tableHTML += '<tr class="oddtablerow"><td style="padding: 10px;">' + tempHTML + '</td></tr>';
      tableHTML += '<tr class="eventablerow"><td style="text-align: center; padding: 10px;">'+remindOption+'[ <a href="#1" onClick="hideCustomMessageFadeBox(\''+customMessageId+'\'); return false">Close</a> ]</td></tr>';
      tableHTML += '</table>';
      document.getElementById('habCustomMessagePopupBox_' + customMessageId).innerHTML = tableHTML;
      displayCustomMessagePopupBox(customMessageId);
     }
    } // END IF DO THIS FRANCHISE
 
   } catch(er) {
    //Do Nothing
   }
  } // END IF HOME ONLY OPTION
 }  // END IF MESSAGE IS NOT UNDEFINED
}  // END FOR LOOP

