function strstr(haystack,needle,bool) {
    var pos = 0;
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}
function strpos( haystack, needle, offset){
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}

function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}

function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}


function ReloadImage(id,url) {
document.getElementById(id).src = url+"?"+new Date();
}

function ToDecimalAmount(X) { var D, C, T // X >= 0
  with (Math) { D = floor(X) ; C = round(100*(X-D)) ; T = C%10 }
  return D + "." + (C-T)/10 + T }

function showcar(val) {
  var img;
  img="../images/cars/"+val+".jpg";
  document.getElementById('CARPIX').src=img; 
}

function showcarhireform(st)
{
   if (st==0) {
     hideDiv('CARHIRE1');
     showDiv('CARHIRE2');
   }
   else {
     hideDiv('CARHIRE2');
     showDiv('CARHIRE1');
   }

}

function transferform1(st,qty,lang)
{
  switch (lang) {
  case "ES":
     c1="¿Cuántos pasajeros? "; 
     break;
  default:
     c1="How many passengers? ";
  }  

  var html;
  html = "";
  if (st==0) {
     html+= "<input type=\"hidden\" name=\"QT1\" value=\""+qty+"\">";
     }
  if (st==1) {
     html+= "<p>"+c1+"<input type=\"text\" name=\"QT1\" size=\"2\" style=\"font-size: 8pt\" value=\""+qty+"\"></p>";
     }
  document.getElementById("TRANSFORM1").innerHTML = html;
}


function transferform2(st,qty,lang)
{
  switch (lang) {
  case "ES":
     c1="¿Cuántos pasajeros? "; 
     break;
  default:
     c1="How many passengers: ";
  }  

  var html;
  html = "";
  if (st==0) {
     html+= "<input type=\"hidden\" name=\"QT2\" value=\""+qty+"\">";
     }
  if (st==1) {
     html+= "<p>"+c1+"<input type=\"text\" name=\"QT2\" size=\"2\" style=\"font-size: 8pt\" value=\""+qty+"\"></p>";
     }
  document.getElementById("TRANSFORM2").innerHTML = html;
}


function flightform(fl0,fl1,fl2,fl3,fl4,fl5,fl6,lang)
{
  switch (lang) {
  case "ES":
     c1="Le contactaremos por email más cerca de la fecha de su llegada para pedir detalles de sus vuelos.";
     c2="Introduzca los detalles de sus vuelos en los campos abajo.";
     c3="Número del vuelo de llegada: ";
     c4="Número del vuelo de salida: ";
     c5="a las ";
     c6="el "; 
     break;
  default:
     c1="We will contact you by email nearer to your time of arrival to request your flight details.";
     c2="Please enter your flight details in the spaces below.";
     c3="Arriving on flight number: ";
     c4="Leaving on flight number: ";
     c5="at ";
     c6="on "; 
  }  
   

  var html;
  html = "";
  if (fl6==0) {
     html+= "<input type=\"hidden\" name=\"FN1\" value=\"\">";
     html+= "<input type=\"hidden\" name=\"FN2\" value=\"\">";
     html+= "<input type=\"hidden\" name=\"FD1\" value=\""+fl1+"\">";
     html+= "<input type=\"hidden\" name=\"FD2\" value=\""+fl4+"\">";
     html+= "<input type=\"hidden\" name=\"FT1\" value=\"\">";
     html+= "<input type=\"hidden\" name=\"FT2\" value=\"\">";
     }
  if (fl6==1) {
     html+= "<p style=\"margin-top: 15\">"+c1+"</p>";
     html+= "<input type=\"hidden\" name=\"FN1\" value=\"\">";
     html+= "<input type=\"hidden\" name=\"FN2\" value=\"\">";
     html+= "<input type=\"hidden\" name=\"FD1\" value=\""+fl1+"\">";
     html+= "<input type=\"hidden\" name=\"FD2\" value=\""+fl4+"\">";
     html+= "<input type=\"hidden\" name=\"FT1\" value=\"\">";
     html+= "<input type=\"hidden\" name=\"FT2\" value=\"\">";
     }
  if (fl6==2) {
     html+= "<p style=\"margin-top: 15\">"+c2+"\n";
     html+= "<p style=\"margin-top: 5\">"+c3+"<input type=\"text\" name=\"FN1\" size=\"12\" value=\""+fl0+"\"style=\"font-size: 8pt\">\n";
     html+= c5+"<input type=\"text\" name=\"FT1\" maxlength=\"5\" size=\"5\" style=\"font-size: 8pt\" value=\""+fl2+"\"> "+c6;
     html+= "<input type=\"text\" name=\"FD1\" maxlength=\"8\" size=\"8\" style=\"font-size: 8pt\" value=\""+fl1+"\"></p>\n";
     html+= "<p style=\"margin-top: 5\">"+c4+"<input type=\"text\" name=\"FN2\" size=\"12\" value=\""+fl3+"\" style=\"font-size: 8pt\">\n";
     html+= c5+"<input type=\"text\" name=\"FT2\" maxlength=\"5\" size=\"5\" style=\"font-size: 8pt\" value=\""+fl5+"\"> "+c6;
     html+= "<input type=\"text\" name=\"FD2\" maxlength=\"8\" size=\"8\" style=\"font-size: 8pt\" value=\""+fl4+"\"><br><br></p>\n";
     }
  document.getElementById("FLIGHTFORM").innerHTML = html;
}

function provedit(itemno)
{
  document.getElementById('IR1').value=itemno; 
  document.SHOPEDIT.submit();
}
function flightedit(itemno)
{
  document.getElementById('IR2').value=itemno; 
  document.FLIGHTEDIT.submit();
}
function transferedit(itemno)
{
  document.getElementById('IR3').value=itemno; 
  document.TRANSFEREDIT.submit();
}
function carhireedit(itemno)
{
  document.getElementById('IR4').value=itemno; 
  document.CARHIREEDIT.submit();
}
function basketdelete(itemno)
{
  document.getElementById('IT5').value=itemno; 
  document.DELETEBASKET.submit();
}


function basketform(room,datefrom,dateto,noguests,lang)
{
  var html;
  html = "";
  html+= "<form method=\"POST\" name=\"BASKET\" action=\"search.php\">";
  html+= "<input type=\"hidden\" name=\"depDate\" value=\""+datefrom+"\">";
  html+= "<input type=\"hidden\" name=\"retDate\" value=\""+dateto+"\">";
  html+= "<input type=\"hidden\" name=\"noguests\" value=\""+noguests+"\">";
  html+= "<input type=\"hidden\" name=\"RM\" value=\""+room+"\">";
  html+= "<input type=\"hidden\" name=\"MD\" value=\"1\">";
  html+= "</form>";
  document.getElementById("basket").innerHTML = html;
  document.BASKET.submit();
}






function hideDiv(divName) 
{
  document.getElementById(divName).style.visibility="hidden";
}
function showDiv(divName) 
{
  document.getElementById(divName).style.visibility="visible";
}



function showroominfo(evt,roomno,roominfo,lang)
{

  infowindow="";
  infowindow2="";
  infowindow += "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"740\" bgcolor=\"#EAEAFF\">"; 
  infowindow += "<tr><td valign=\"top\">";
  infowindow += "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"740\">"; 
  infowindow += "<tr><td bgcolor=\"#0000CC\"><p><strong><font color=\"#FFFFFF\">"+GetWord_Search(0)+"</font></strong></p></td><td bgcolor=\"#0000CC\" align=\"right\" valign=\"top\"><a href=\"javascript:showroominfo('','','','"+lang+"');\"><img border=\"0\" src=\"/images/closewindow.jpg\" width=\"21\" height=\"21\"></a></td></tr>";
  infowindow += "<tr><td bgcolor=\"#FFFFFF\" colspan=\"2\" valign=\"top\">";
  infowindow2 += "</td></tr>";
  infowindow2 += "</table>";
  infowindow2 += "</td></tr>";
  infowindow2 += "</table>";


  if (roominfo=="" || roominfo=="0") { 
    var xhtml = "<table><tr><td></td></tr></table>"; 
    document.getElementById("ROOMINFO").innerHTML = xhtml;
    document.getElementById("ROOMINFO").style.visibility="hidden";
    return;
  }

  // generate data into array
  var ri=new Array();
  x=0;
  l=0;
  i=0; 
  while (l==0) {
     y=strpos(roominfo,"|",x);
     if (y!=false) {
        ri[i] = roominfo.substring(x,y);
        i=i+1;
        x=y+1;
     }
     else
       l=1;
  }      

  line1=Search_Line1(ri[2],ri[1],ri[14],ri[9],ri[25]);
  line2=Search_Line2(ri[15],ri[16],ri[17],ri[18],ri[4]);
  line3=Search_Line3(ri[5],ri[6],ri[7],ri[29],ri[30],ri[8],ri[24]);              // kitchen
  line4=Search_Line4(ri[10],ri[11],ri[27],ri[28]);                               // laundry
  line6=Search_Line6(ri[12],ri[13],ri[39],ri[40],ri[41],ri[42],ri[43],ri[44]);   // leisure and entertainment

  line5=Search_Line5(ri[1],ri[19],ri[20],ri[21],ri[22]);  // general
  line7=Search_Line7(ri[23],ri[38],ri[45],ri[46],ri[47],ri[48],ri[49],ri[50],ri[32],ri[51],ri[52]); // sports
  line8=Search_Line8(ri[53],ri[54],ri[55],ri[56],ri[57],ri[58],ri[59],ri[60],ri[61]); // baby


  linex="<p>"+line1+line2+line5+line3+line4+line6+line7+line8+"</p>";

  // load piclist
  nopics=0;
  for (i=1;i<=10;i++) 
    if (ri[0].substring(i-1,i)=="1") 
      nopics++;


  piclist="";
  piclist2="";
  if (nopics>0) {
     piclist+="<div align=\"center\">";
     piclist+="<center>";
     piclist+="<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\">";
     piclist+="<tr>";
     piclist+="<td>";
     piclist+="<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
     defpic="";
     var img = new Array();
     cntr=0;
     for (i=1;i<=10;i++) {
         img[i]="";
         if (ri[0].substring(i-1,i)=="1") {
            cntr++;
            if (nopics>7)
               if (cntr==1 || cntr==6) piclist+="<tr>";
            else
               if (cntr==1) piclist+="<tr>";
            piclist+="<td align=\"center\" valign=\"middle\">";
          
            imgfile1="/images/property/" + roomno + "-A" + i + ".jpg";
            imgfile2="/images/property/" + roomno + "-B" + i + ".jpg";
            img[i]=imgfile1;
            if (defpic=="")
                defpic=imgfile2;
            piclist+="<a href=\"javascript:ReloadImage('pxx','"+imgfile2+"');\">";
            piclist+="<img border=\"0\" name=\"pxx"+i+"\" name=\"pxx"+i+"\" src=\""+imgfile1+"\">";
            piclist+="</a>";
            piclist+="</td>";
            if (nopics>7)
               if (cntr==5 || cntr==nopics) piclist+="</tr>";        
            else
               if (cntr==nopics) piclist+="</tr>";  

         }
     } 
     piclist+="</table></td></tr></table></center></div>";
  }

  if (nopics>0) 
    piclist2 += "<img border=\"0\" name=\"pxx\" id=\"pxx\" src=\""+defpic+"\">";
  else
    piclist="";



  if (nopics>0) {
    tab1 = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td height=\"250\" valign=\"top\">";
    tab2 = "</td><td width=\"300\" align=\"center\" valign=\"top\"><h3>"; 
    tab3 = "</h3></td></tr><tr><td bgcolor=\"#EAEAFF\" colspan=\"2\" valign=\"bottom\">"+piclist+"</td></tr></table>"; 
  }
  else {
    tab1 = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td height=\"250\" valign=\"top\">";
    tab2 = "</td>"; 
    tab3 = "</tr></table>"; 
  }
 


  xhtml=infowindow+tab1+linex+tab2+piclist2+tab3+infowindow2;
  var yp1=evt.clientY;  // page position
  var yp2=mouseY(evt) ;
  yp=yp2-yp1+50;
  document.getElementById("ROOMINFO").style.position = "absolute";
  document.getElementById("ROOMINFO").style.left = "120px";
  document.getElementById("ROOMINFO").style.top  = yp+"px";
  document.getElementById("ROOMINFO").innerHTML = xhtml;
  document.getElementById("ROOMINFO").style.visibility="visible";


  if (nopics>0) {
    for (i=1;i<=10;i++) {
      if (img[i]!="") {
        id="pxx"+i;
        ReloadImage(id,img[i]);
      }
    }
  }
}

function roommouseout(roomno,avail)
{
  var id = "r"+roomno;
  var img;
  if (avail==0)
      col="#A9A9A8";
  else
      col="#8CC593";
  document.getElementById(id).style.backgroundColor=col;

}

function roommouseover(roomno,avail)
{
  var id = "r"+roomno;
  var img;
  if (avail==0)
      col="#DEDDDD";
  else
      col="#C6DEC5";
  document.getElementById(id).style.backgroundColor=col;
}


