var equipmentText=new Array("Washing&nbsp;Machine","Dish&nbsp;Washer","Microwave","Refrigerator","Freezer","TV","Internet","DVD","CD&nbsp;Player","Smoking","Central&nbsp;Heating","Air&nbsp;Conditioning");

function changeRoom(nv,nr) {
  createCookie("RoomNumber",nr);
  for ( var i=0;i<rooms[nv][0]+1;i++ ) {
    dn="roomtext"+i;
    hideObject(dn);
    if ( nr==i ) showObject(dn); }
  return; }

function changeVillaMenu(mn) {
  mc=villamenu;
  cvm=villa;
  if ( pagename.substr(0,6)!="manage" ) newpagefile=(mn==0)?villas[cvm][1]+".htm":vmenus[mn][1];
  if ( pagename.substr(0,6)=="manage" ) newpagefile=lmenus[mn][1];
  createCookie("VillaMenuNumber",mn);
  if ( newpagefile=="managelogout.php" ) newpagefile=vmenus[mc][1];
  if ( newpagefile!=pagefile ) {
    if ( pageparameter=="preview" ) newpagefile+="?preview";
    windowOpen(root+newpagefile,'_parent'); }
  return; }

function villaHead(villa) {
  if ( pageparameter=="collect" ) return;
  restoreData();
  unpackPrices(villa);
  vt=villas[villa][7];
  rooms[villa]=new Array();
  if ( villas[villa][18]!="" ) rooms[villa]=villas[villa][18].split("/");
  costsroom[villa]=new Array();
  if ( villas[villa][19]!="" ) costsroom[villa]=villas[villa][19].split("/");
  createCookie("VillaName",villas[villa][1]);
  document.write('<div id="content" class="cb">');
  txt='<table border=0 width="100%"><tr><td valign="top">';
  txt+='<h1>';
  if ( villas[villa][7]=="SCA"&&rooms[villa][0]>1 ) txt+='<span class="notranslate">'+rooms[villa][0]+' </span>Apartments at ';
  if ( villas[villa][7]=="SCA"&&rooms[villa][0]==1 ) txt+='Apartment at ';
  if ( villas[villa][7]=="BB"&&rooms[villa][0]>1 ) txt+='<span class="notranslate">'+rooms[villa][0]+' </span>Rooms at ';
  txt+='<span class="notranslate">'+villas[villa][2]+', '+villas[villa][3]+'.</span></h1>';
  if ( rooms[villa].length==0 ) {
    if ( villas[villa][5]=="0" ) txt+='<h2><span class="notranslate">'+villas[villa][4]+' </span>people : '+villas[villa][8]+'.</h2>';
    if ( villas[villa][5]!="0" ) {
      txt+='<h2><span class="notranslate">'+villas[villa][4]+' </span>people<span class="notranslate"> : '+villas[villa][5]+' </span>';
      txt+=(villas[villa][5]==1)?"bedroom.":"bedrooms.";
      txt+='</h2>'; } }
  if ( rooms[villa].length>0 ) {
    if ( rooms[villa][0]==1 ) {
      txt+='<h2><span class="notranslate">'+villas[villa][4]+' </span>people<span class="notranslate"> : '+villas[villa][5]+' </span>';
      txt+=(villas[villa][5]==1)?"bedroom.":"bedrooms."; }
    if ( rooms[villa][0]>1 ) {
      k=0;
      txt+='<table>';
      for ( var j=0;j<rooms[villa][0];j++ ) {
        txt+='<tr><td><h2><span class="notranslate">'+rooms[villa][k+1]+' </span>';
//        if ( villas[villa][7]=="SCA" ) txt+='Apartment';
        txt+='</td><td><h2><span class="notranslate"> : '+rooms[villa][k+3]+' </span>people';
        if ( villas[villa][7]=="SCA" ) {
          txt+=' : <span class="notranslate">'+rooms[villa][k+2]+' </span>';
          txt+=(rooms[villa][k+2]==1)?"bedroom.":"bedrooms."; }
        if ( villas[villa][7]!="SCA" ) txt+='.';
        txt+='</td></tr>';
        k=k+3; }
      txt+='</table>'; } }
  if ( villas[villa][6]!="No"&&villas[villa][6]!="" ) txt+='<h2>'+villas[villa][6]+'.</h2>';
  txt+='<span id="pricerange">';
  txt+=villaPriceRange();
  txt+='</span>';
  if ( villas[villa][17]!="" ) {
    txt+='</td><td align="right" valign="top" width="40%" style="font-style:italic"><h2>';
    if ( villas[villa][17].indexOf('#')<0 ) { txt+=villas[villa][17]; }
    else {
      bits=villas[villa][17].split("#");
      for ( var ib=0;ib<bits.length-1;ib=ib+2 ) txt+=bits[ib]+displayCurrency(bits[ib+1],"EUR","EUR");
      if ( bits.length>0 ) txt+=bits[ib]; }
    txt+='&nbsp;</h2>'; }
  document.write(txt+'</td></tr></table><hr />'); }

function villaRoomHeader(room,action) {
  cr=readCookie("RoomNumber");
  if ( cr==null ) cr=0;
  if ( cr!=room ) document.write('<span id="roomtext'+room+'" style="display:none">');
  if ( cr==room ) document.write('<span id="roomtext'+room+'" style="display:inline">');
  if ( action>0 ) {
    did="description"+room;
    description=getinnerHTML(did);
    document.write(description);
    document.write('</span>');
    return; }
  k=room*3;
  txt='<table border=0 width="100%"><tr><td><h1><span class="notranslate">'+rooms[villa][k+1]+'</span>';
  if ( villas[villa][7]=="SCA" ) txt+=' Apartment';
  txt+=' at <span class="notranslate">'+villas[villa][2]+', '+villas[villa][3]+' </span></h1>';
  txt+='<h2><span class="notranslate">'+rooms[villa][k+3]+' </span>people<span class="notranslate"> : '+rooms[villa][k+2]+' </span>';
  txt+=(rooms[villa][k+2]==1)?"bedroom.":"bedrooms.";
  txt+='</h2></table>';
  ct=pricedata[villa][0];
  cl=1000000;
  ch=0;
  if ( pricedata[villa][8] ) {
    cz=' per week.';
    for ( var ii=0;ii<costsroom[villa].length;ii++ ) {
      if ( costsroom[villa][ii]==room ) {
        np=(ii*13)+2;
        for ( var jj=0;jj<12;jj++ ) {
          if ( perweek[villa][np]!=0&&perweek[villa][np]<cl ) cl=perweek[villa][np];
          if ( perweek[villa][np]>ch ) ch=perweek[villa][np];
          np++; } } } }
  if ( !pricedata[villa][8]&&pricedata[villa][9] ) {
    cl=1000000;
    ch=0;
    cz=" per night.";
    for ( var ii=0;ii<costsroom[villa].length;ii++ ) {
      if ( costsroom[villa][ii]==room ) {
        np=(ii*13)+2;
        for ( var jj=0;jj<12;jj++ ) {
          if ( pernight[villa][np]!=0&&pernight[villa][np]<cl ) cl=pernight[villa][np];
          if ( pernight[villa][np]>ch ) ch=pernight[villa][np];
          np++; } } } }
  txt+='<h2>';
  if ( cl==ch ) txt+=displayCurrency(cl,ct)+cz;
  if ( cl!=ch ) txt+=displayCurrency(cl,ct)+' to '+displayCurrency(ch,ct)+cz;
  document.write(txt+'</h2></td></tr></table>');
  document.write('<hr /><div class="slide" id="slides'+room+'" align="left" style="float:left"></div>');
  did="description"+room;
  description=getinnerHTML(did);
  document.write(description);
  document.write('</span>');
  return; }

function villaPriceRange() {
  vptxt="";
  ct=pricedata[villa][0];
  if ( pricedata[villa][9] ) {
    vptxt+="<h2>";
    cz=" per night";
    cl=pricedata[villa][15]
    ch=pricedata[villa][16];
    if ( villas[villa][7]=="BB" ) cz=' per room per night';
    if ( villas[villa][7]=="SCA" ) cz=' per apartment per night';
    if ( villas[villa][7]=="SCA"&&rooms[villa][0]==1 ) cz=' per night';
    if ( cl==ch ) vptxt+=displayCurrency(cl,ct)+cz;
    if ( cl!=ch ) vptxt+=displayCurrency(cl,ct)+' to '+displayCurrency(ch,ct)+cz;
    vptxt+=".</h2>"; }
  if ( !pricedata[villa][9] ) {
    vptxt+="<h2>";
    cz=' per week';
    cl=pricedata[villa][13]
    ch=pricedata[villa][14];
    if ( villas[villa][7]=="BB" ) cz=' per room per week';
    if ( villas[villa][7]=="SCA" ) cz=' per apartment per week';
    if ( villas[villa][7]=="SCA"&&rooms[villa][0]==1 ) cz=' per week';
    if ( cl==ch ) vptxt+=displayCurrency(cl,ct)+cz;
    if ( cl!=ch ) vptxt+=displayCurrency(cl,ct)+' to '+displayCurrency(ch,ct)+cz;
    vptxt+=".</h2>"; }
  return vptxt; }

function villaEnd(language,answer,slidestimer) {
  if ( villas[villa][1]=="casadasfloresapartments" ) {
    roomButtons();
    villaRoomHeader(0,0);
    villaRoomHeader(1,0);
    villaRoomHeader(2,0);
    villaRoomHeader(3,1);
    slideShowStart("slides0",imagefile0,imagetext0);
    slideShowStart("slides1",imagefile1,imagetext1);
    slideShowStart("slides2",imagefile2,imagetext2); }
  if ( !slidestimer ) slidetimer=3;
  if ( villas[villa][12]!="" ) villaContents();
  slideShowStart("slides",imagefile[villa],imagetext[villa],slidestimer*1000);
  document.write('</div>');
  return; }

function villaContents() {
  var answers=new Array();
  answers=villas[villa][12];
  txt='<hr /><table width="100%" align="centre"><tr>';
  var i=0;
  for ( j=0;j<equipmentText.length;j++ ) {
    i++;
    if ( i==5&&j!=11 ) {
      txt+='</td></tr><tr>';
      i=1; }
    txt+='<td align="right" width="15%">'+equipmentText[j]+':&nbsp</td><td align="left" width="5%">';
    txt+=(answers.substr(j,1)=="Y")?"Yes":"No";
    txt+='</td>'; }
  document.write(txt+'</tr></table>');
  return; }

function villaVideo(language,videoLink) {
  return;
  document.write('<br /><br />Click <a href="youtubeframe.htm?'+videoLink+'">here</a> for a video tour of the villa.');
  return; }

function roomButtons() {
  document.write('<hr /><span class="notranslate">');
  var j=1;
  var k=0;
  var roombuttons=new Array();
  for ( var i=0;i<rooms[villa][0];i++ ) {
    roombuttons[k]=rooms[villa][j];
    k++;
    roombuttons[k]='changeRoom('+villa+','+i+')';
    k++;
    j=j+3; }
  roombuttons[k]='Essential Information';
  k++;
  roombuttons[k]='changeRoom('+villa+',3)';
  document.write(showButtons("topmenu",roombuttons,true,0,5));
  document.write('</span><hr />');
  return; }
