if (typeof(js_shorlist_defined) == 'undefined') {

var js_shorlist_defined = 1;

var nbisl = 0;

function msl_redirect() {
      document.getElementById('popupconfbut').innerHTML="<p class='instructions' style='text-align:center; padding-bottom:10px;'>Connection to your shortlist, please wait...</p>";
      top.location.href='/search/shortlist.php?id='+$.cookie("mslid");
}

function close_mslw(gosl) {
  if (nbisl == 1) {
    if (gosl)
      naction = "msl_redirect();";
    else
      naction = "cs_mbox_close();";
    cs_mbox_content("<table class='lay-mbox'><tr><td class='lay-mbox-title'>My Shortlist</td></tr><tr><td class='lay-mbox-text'>You can access you shortlist of establishments at any time in the menu on the left. You can access this shortlist to compare your selection, save it or receive it by email.</td></tr><tr><td class='lay-mbox-text' style='text-align:center;'><div id='popupconfbut'><button onclick=\""+naction+" return false;\"  style='margin-top:5px; margin-bottom:10px;'>OK</button></div></td></tr></table>");
  }
  else {
    if (gosl)
      msl_redirect();
    else
      cs_mbox_close();
  }
}

function add_my_shortlist(iid, type) {
  var req = null; 
  if(window.XMLHttpRequest)
    req = new XMLHttpRequest(); 
  else if (window.ActiveXObject)
    req = new ActiveXObject('Microsoft.XMLHTTP'); 
  req.onreadystatechange = function() { 
    if(req.readyState == 4) {
      if(req.status == 200) {
        if (req.responseText == '#ERR_MAX_COUNT#')
          text_msg = "<td class='lay-mbox-error'>Your shortlist has already reached the maximum number of establishments.";
        else if (req.responseText == '#ERR_BAD_ID#')
          text_msg = "<td class='lay-mbox-error'>An error has occurred and this establishment could not be added to your shortlist.";
        else if (req.responseText == '#ERR_ALREADY_IN#')
          text_msg = "<td class='lay-mbox-error'>This establishment is already in your shortlist.";
        else {
          nbisl = req.responseText;
          if (document.getElementById('mslrmdisp')) {
            if (nbisl > 1)
              document.getElementById('mslrmdisp').innerHTML = nbisl+" establishments";
            else
              document.getElementById('mslrmdisp').innerHTML = nbisl+" establishment";
          }
          else if (document.getElementById('mslrmempty'))
            document.getElementById('mslrmempty').innerHTML="<div class='lay-lp-boxmain' onclick=\"top.location.href='/search/shortlist.php?id="+$.cookie("mslid")+"';\"><div class='lay-lp-boxtitle' style='margin-top:25px;'><img src='/visuals/recherche/shortlist.gif'>My Shortlist</div><div class='lay-lp-boxcontent' style='background-position:center right; padding-bottom:5px;'><div id='mslrmdisp'>1 establishment</div></div><div class='lay-lp-boxtitle' style='background-position:bottom right; font-size:10px;'>Details - Compare</div></div>";
          text_msg = "<td class='lay-mbox-text'>Your shortlist has been updated and now contains <b>"+nbisl+"</b> establishment";
            if (req.responseText > 1)
              text_msg = text_msg+"s";
        }
      }
      else
        text_msg = "<td class='lay-mbox-error'>An error has occurred during connection and this establishment could not be added to your shortlist.";
      cs_mbox_content("<table class='lay-mbox'><tr><td class='lay-mbox-title'>My Shortlist</td></tr><tr>"+text_msg+"</tr><tr><td class='lay-mbox-text'><div id='popupconfbut'><table class='tdf'><tr><td class='lay-mbox-text'><button onclick=\"close_mslw(true); return false;\" style='margin-top:5px; margin-bottom:10px;'>View&nbsp;my&nbsp;shortlist</button></td><td class='lay-mbox-text' style='text-align:right;'><button onclick=\"close_mslw(false); return false;\"  style='margin-top:5px; margin-bottom:10px;'>Continue</button></td></tr></table></div></td></tr></table>");
    } 
  }
  cs_mbox_open("<table class='lay-mbox'><tr><td class='lay-mbox-title'>My Shortlist</td></tr><tr><td class='lay-mbox-text'><p class='instructions' style='text-align:center;'><br>Connection to your shortlist, please wait...<br><img src='/visuals/common/loader.gif'><br><br></p></td></tr></table>");
  req.open('POST', '/search/shortlist.php', true); 
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'); 
  req.send('operation=add&type='+type+'&iid='+iid);
}

}
