function ShortList(pref)
{
  var slink = document.getElementById('S' + pref);
  var carray = getCookie("EBslist").split('|');
  var prefexists = -1;
  
  var x = 0;
  for (x=0; x < carray.length; x++) 
  { 
    if (carray[x] == pref) { prefexists = x; }
  }
  
  if (prefexists == -1)
  {
    carray[carray.length] = pref;               // property not shortlisted, add it
    slink.innerHTML = "(shortlisted)";  // update the link

    // reset the shortlist cookie string
    var newcookie = ''; newcount = 0;
    for (x = 0; x < carray.length; x++) 
    { 
      //alert(carray[x]);
      if (newcookie.length > 0) { newcookie = newcookie + "|"; }
      if (carray[x] != "0") { newcookie = newcookie + carray[x]; newcount++; }
    }
    
    createCookie("EBslist",newcookie,30) // set the updated cookie
    
    // update the cookie text box
    if (newcount == 0) 
    {
      document.getElementById('slist_cnt').innerHTML = "No property saved";
    } else {
      if (newcount == 1)
      {
        document.getElementById('slist_cnt').innerHTML = "<a href=\"http://www.lanzarotebreaks.com/shortlist.php\" title=\"View your saved properties\">1 property saved</a>";
      } else {
        document.getElementById('slist_cnt').innerHTML = "<a href=\"http://www.lanzarotebreaks.com/shortlist.php\" title=\"View your saved properties\">" + newcount + " properties saved</a>";
      }
    }
    
  }
  
}

function IsListed(pref)
{
  var carray = getCookie("EBslist").split('|');
  var prefexists = -1;
  
  var x = 0;
  for (x=0; x < carray.length; x++) 
  { 
    if (carray[x] == pref) { prefexists = x; }
  }
  
  return (prefexists > -1);
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

