discount=20;
language=readCookie("Language");
dc=readCookie("Currency");
if ( dc==null ) dc="EUR";
loggedin=readCookie("OwnerCheck");
if ( loggedin!=null ) {

// Management: check for owner check. if set, defines list of villas which will be accessible.
//             if only one villa in list, set VillaNumber and VillaName cookies and jump straight to manageavailability.php
//             select lowest numbered villa for owner as default.
//             set villa order to include all villas from 1 to maximum.

  createCookie("Accommodation",0);
  createCookie("Guests",0);
  createCookie("Bedrooms",0);
  ownercheck=unescape(readCookie("OwnerCheck"));
  order=new Array("");
  j=0;
  for ( i in villas ) {
    check=hex_md5(owner[i][1])+hex_md5(owner[i][2])
    if ( i>0&&check==ownercheck ) {
      order[j]=i;
      j++ } }
  orders="";
  for ( i=0;i<j;i++ ) { orders=orders.concat(order[i]+"," ); }
  createCookie("VillaOrder",orders);
  if ( j==1 ) {
    createCookie("VillaNumber",order[0]);
    createCookie("VillaName",villas[order[0]][1]);
    window.open("manageavailability.php","_parent"); } }

var old=0;
orders=readCookie("VillaOrder");
order=new Array("");
if ( orders!=null ) {
  old=1;
  orders=unescape(orders);
  order=orders.split(","); }
else {
  var j=0;
  var more=villas.length-1;
  done=new Array();
  for ( var i=0;i<villas.length;i++) { done[i]=0; }
  for ( var i=0;i<villas.length;i++) { if ( villas[i][0]!="live" ) { done[i]=i; more=more-1; } }
  while ( more>0 ) {
    i=(old==0)?Math.floor(Math.random()*villas.length):order[j];
    if ( i>0&&i<=villas.length&&done[i]==0 ) {
      order[j]=i;
      j++;
      done[i]=i;
      more=villas.length-1;
      for ( var i=1;i<villas.length;i++) { if ( done[i]!=0 ) more=more-1; } } }
  if ( old==0 ) {
    orders="";
    for ( i=0;i<j;i++ ) { orders=orders.concat(order[i]+"," ); }
    createCookie("VillaOrder",orders); } }
order=new Array("");
old=1;
order=orders.split(",");
iv=order.length-1;
numberofguests=readCookie("Guests");
if ( numberofguests==null ) numberofguests=0;
numberofbedrooms=readCookie("Bedrooms");
if ( numberofbedrooms==null ) numberofbedrooms=0;
accommodationtype=readCookie("Accommodation");
if ( accommodationtype==null ) accommodationtype=0;

document.write('<div class="cb">');
if ( loggedin==null ) {
document.write('<table style="cursor:pointer;display:inline;float:left;padding:5px;margin-bottom:10px" width="285">');
document.write('<tr><td style="font-weight: bold;" colspan="2" align="center">Use the selection boxes below to refine the accommodation list<br />&nbsp;</td></tr>');

document.write('<tr><td>Accommodation</td>');
document.write('<td align="right"><select class="input" id="FieldData10" name="FieldData10" width="4" onchange="villaList(1)">');
zngtext='<option value="0"';
if ( accommodationtype=="" ) zngtext+=' selected="selected"';
zngtext+='>Any&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
document.write(zngtext);
document.write('<option value=4');
if ( accommodationtype==4 ) document.write(' selected="selected"');
document.write('>Self Catering</option>');
document.write('<option value=1');
if ( accommodationtype==1 ) document.write(' selected="selected"');
document.write('>Self Catering Villas</option>');
document.write('<option value=2');
if ( accommodationtype==2 ) document.write(' selected="selected"');
document.write('>Self Catering Apartments</option>');
document.write('<option value=3');
if ( accommodationtype==3 ) document.write(' selected="selected"');
document.write('>Bed and Breakfast</option>');
document.write('</select></td></tr>');

document.write('<tr><td>Guests</td>');
document.write('<td align="right"><select class="input" id="FieldData11" name="FieldData11" width="4" onchange="villaList(1)">');
zngtext='<option value="0"';
if ( numberofguests==0 ) zngtext+=' selected="selected"';
zngtext+='>Any&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
document.write(zngtext);
for ( var iii=1;iii<13;iii++ ) {
  document.write('<option value="'+iii+'"');
  if ( iii==numberofguests ) document.write(' selected="selected"');
  document.write('>'+iii+' +</option>'); }
document.write('</select></td></tr>');
document.write('<tr><td>Bedrooms</td>');
document.write('<td align="right"><select class="input" id="FieldData12" name="FieldData12" width="4" onchange="villaList(2)">');
zngtext='<option value="0"';
if ( numberofbedrooms==0 ) zngtext+=' selected="selected"';
zngtext+='>Any&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
document.write(zngtext);
for ( var iii=1;iii<6;iii++ ) {
  document.write('<option value="'+iii+'"');
  if ( iii==numberofbedrooms ) document.write(' selected="selected"');
  document.write('>'+iii+' +</option>'); }
document.write('</select></td></tr></table>'); }

document.write('<div id="villalist"></div></div>');
villaList(0);

function villaList(zzz) {
data=new Array();
jj=0;
zat=accommodationtype;
zng=numberofguests;
znb=numberofbedrooms;
if ( zzz>0 ) {
  zat=Number(getObject("FieldData10").value);
  createCookie("Accommodation",zat);
  zng=Number(getObject("FieldData11").value);
  createCookie("Guests",zng);
  znb=Number(getObject("FieldData12").value);
  createCookie("Bedrooms",znb); }
for ( var ii=0;ii<order.length-1;ii++) {
  var iii=order[ii];
  include=false;
  if ( pagename=="default"||pagename=="testdivs"||pagename=="manage"||pagename=="flyer"||pagename=="accommodation" ) include=true;
  if ( loggedin==null&&villas[iii][0]!="live" ) include=false;
  if ( zat==1&&villas[iii][7]!="SC" ) include=false;
  if ( zat==2&&villas[iii][7]!="SCA" ) include=false;
  if ( zat==3&&villas[iii][7]!="BB" ) include=false;
  if ( zat==4&&villas[iii][7]=="BB" ) include=false;
  if ( Number(villas[iii][4])<zng ) include=false;
  if ( Number(villas[iii][5])<znb ) include=false;
  if ( include ) {
    data[jj]=iii;
    jj++; } }
currentvilla=readCookie("VillaNumber");
vtxt='';
for ( var jj=0;jj<data.length;jj++) {
  var ii=data[jj];
  fc="vd";
  if ( specials[ii]!="" ) fc="vds";
  vtxt+='<table class="'+fc+'" onclick="changeVilla('+ii+')" width="285">';
  tov="Villa";
  if ( villas[ii][7]=="SC"&&villas[ii][5]==0 ) tov="Studio";
  if ( villas[ii][7]=="BB" ) tov="Bed and Breakfast";
  if ( villas[ii][7]=="SCA"&&rooms[ii][0]>1 ) tov=rooms[ii][0]+" Apartments"
  if ( villas[ii][7]=="SCA"&&rooms[ii][0]==1 ) tov="1 Apartment"
  vtxt+='<tr><td valign="top" style="text-align:center"><img class="link" src="' + imageroot + 'images/small_'+villas[ii][1]+'.jpg" width="135" height="100" title="Click for more information" /><br /><strong><em>'+tov+'<br />&nbsp;<br />&nbsp;</em></strong></td><td valign="top" style="text-align:center">';
  vtxt+='<strong><span class="notranslate">'+villas[ii][2]+'<br />'+villas[ii][3]+'</span></strong><br />';
  sd='<span class="notranslate">'+villas[ii][5]+' </span>';
  sd+=(villas[ii][5]=="1")?"bedroom":"bedrooms";
  if ( villas[ii][5]=="0" ) sd=villas[ii][8];
  vtxt+='<span class="notranslate">'+villas[ii][4]+' </span>people,<br />'+sd+'.<br />';
  if ( villas[ii][6]!="No" ) vtxt+=villas[ii][6]+'.<br />';
  ct=pricedata[ii][0];
  cl=1000000;
  ch=0;
  if ( perweek[ii] ) {
    cz=' per week';
    if ( villas[ii][7]=="BB"&&villas[ii][5]!=1 ) cz=' per room per week';
    if ( villas[ii][7]=="SCA" ) cz=' per apartment per week';
    if ( villas[ii][7]=="SCA"&&rooms[ii][0]==1 ) cz=' per week';
    nr=perweek[ii][0];
    np=2;
    for ( var iii=0;iii<nr;iii++ ) {
      for ( var jjjj=0;jjjj<12;jjjj++ ) {
        if ( perweek[ii][np]!=0&&perweek[ii][np]<cl ) cl=perweek[ii][np];
        if ( perweek[ii][np]>ch ) ch=perweek[ii][np];
        np++; }
      np++; } }
  if ( (cl==1000000&&pernight[ii])||villas[ii][7]=="BB" ) {
    cl=1000000;
    ch=0;
    cz=' per night';
    if ( villas[ii][7]=="BB"&&villas[ii][5]!=1 ) cz=' per room per night';
    if ( villas[ii][7]=="SCA" ) cz=' per apartment per night';
    if ( villas[ii][7]=="SCA"&&rooms[ii][0]==1 ) cz=' per night';
    nr=pernight[ii][0];
    np=2;
    for ( var iii=0;iii<nr;iii++ ) {
      for ( var jjjj=0;jjjj<12;jjjj++ ) {
        if ( pernight[ii][np]!=0&&pernight[ii][np]<cl ) cl=pernight[ii][np];
        if ( pernight[ii][np]>ch ) ch=pernight[ii][np];
        np++; }
      np++; } }
  vtxt+='<strong>'+displayCurrency(cl,ct);
  if ( cl!=ch ) vtxt+=' to '+displayCurrency(ch,ct);
  vtxt+='</strong><br />'+cz;
  vtxt+='</td></tr></table>'; }
is=0;
for ( var ii=0;ii<order.length-1;ii++ ) {
  iii=order[ii];
  include=false;
  if ( pagename=="default"||pagename=="manage"||pagename=="flyer"||pagename=="accommodation" ) include=true;
  if ( loggedin==null&&villas[iii][0]!="live" ) include=false;
  if ( zat==1&&villas[iii][7]!="SC" ) include=false;
  if ( zat==2&&villas[iii][7]!="SCA" ) include=false;
  if ( zat==3&&villas[iii][7]!="BB" ) include=false;
  if ( Number(villas[iii][4])<zng ) include=false;
  if ( Number(villas[iii][5])<znb ) include=false;
  if ( include&&specials[iii]!="" ) is++; }
if ( is>0 ) {
  vtxt+='<table border="5" style="border:2px solid red;border-radius:10px;clear:both;margin-bottom:10px;border-collapse:separate" cellpadding="5"><tr><td class="tdr" rowspan="'+is+'"><h1 align="center">Special Offers</h1></td>';
  ft="";
  for ( var ii=0;ii<order.length-1;ii++ ) {
    iii=order[ii];
    include=false;
    if ( pagename=="default"||pagename=="manage"||pagename=="flyer"||pagename=="accommodation" ) include=true;
    if ( loggedin==null&&villas[iii][0]!="live" ) include=false;
    if ( zat==1&&villas[iii][7]!="SC" ) include=false;
    if ( zat==2&&villas[iii][7]!="SCA" ) include=false;
    if ( zat==3&&villas[iii][7]!="BB" ) include=false;
    if ( Number(villas[iii][4])<zng ) include=false;
    if ( Number(villas[iii][5])<znb ) include=false;
    if ( include&&specials[order[ii]]!="" ) {
      fs="";
      if ( specials[iii].indexOf('#')<0 ) { fs+=specials[iii]; }
      else {
        bits=specials[iii].split("#");
        for ( var ib=0;ib<bits.length-1;ib=ib+2 ) fs+=bits[ib]+displayCurrency(bits[ib+1],"EUR","EUR");
        if ( bits.length>0 ) fs+=bits[ib]; }
      vtxt+=ft+'<td class="tdrh" onclick="changeVilla('+order[ii]+')"><strong><span class="notranslate">'+villas[order[ii]][2]+'</span></strong></td><td class="tdr" style="text-align:left">'+fs+'</td></tr>';
      ft='<tr>'; } }
  vtxt+='</table>'; }
vtxt+='<hr style="clear:both;background-color:transparent;border:0px solid transparent;margin-bottom:-20px" />';
getObject("villalist").innerHTML=vtxt;
setCurrency(""); }

