function listby(){
  if(names!=""){
    var top = names.length;
    var tmpn, tmpv;
    var options = "";
    for(var i=0;i<top;i++){
      tmpn = names[i];
      tmpv = urls[i];
      if(tmpv=="optgroup") 
        if(options!="") options+="</optgroup><optgroup label=\""+tmpn+"\">";
        else  options+="<optgroup label=\""+tmpn+"\">";
      else{
        if(crrntFltr==names[i]) options+="<option value=\""+tmpv+"\" selected=\"selected\">"+tmpn+"</option>";
        else options+="<option value=\""+tmpv+"\">"+tmpn+"</option>";
      }
    }
    if(sbswitchcn=="change"){ 
      document.getElementById("filterSelect").innerHTML="<select name=\"qcksrchslct\" class=\"qcksrchslct\"  onmouseover=\"this.style.backgroundColor='#fff'\">"+options+"</select>";
    }
  }
}


function replaceOptions(str,rplcStr,min,max,select){
  var tmp = "";
  for(var i=min;i<=max;i++){
    if(i==select && i!=0) tmp+="<option selected>"+i+"</option>";
    else tmp+="<option>"+i+"</option>"; 
  }
  return(str.replace(rplcStr,tmp));
}

function runRooms(x,ad,ch,which){
  var i;
  for(i=1;i<=x;i++){ 
    addRoom("false",i,ad[i-1],ch[i-1],which,true);
    addChildAge(i);
  }      
}

function childAges(){
  var top = 18;
  var rtn = "<option>?</option>";
  for(var i=0;i<top;i++){
    if(i==0) rtn+="<option>&lt;1</option>";
    else  rtn+="<option>"+i+"</option>";
  }
  return(rtn);
}

function addChildAge(i){
  var childAges = "", childAgesOuter = "", maxChildPerLine = 0;

  var j, numChildren=0;
  var displayChildren = [];
  //for(i=1;i<=currNumRooms;i++){
  try{numChildren = eval("document.search.rmc_"+(i)+".selectedIndex")}catch(e){;}
  displayChildren.push(numChildren);

    
  //if(numChildren>0) document.getElementById("childselect"+i).className="childselecton";
 // else document.getElementById("childselect"+i).className="childselect";
  for(j=1;j<=numChildren;j++){
    tmp = "<option>-?-</option>";
    for(var k=0;k<18;k++){
      if(k==0) tmp += "<option[%selected%]>&lt;1</option>";
      else tmp += "<option[%selected%]>"+k+"</option>";          
      
      try{if(cages[i-1][j-1]==k)tmp=tmp.replace("[%selected%]"," selected");}catch(e){;}
      //if(eval("document.search.rmage"+i+"_"+j))
      //  if(eval("(document.search.rmage"+i+"_"+j+".selectedIndex)-1")==k){
      //    tmp = tmp.replace("[%selected%]"," selected");          
      //}
      tmp = tmp.replace("[%selected%]","");
    } 
    childAges = "<select name=\"rmage"+i+"_"+j+"\">"+tmp+"</select>";
    document.getElementById("cage"+i+"_"+j).innerHTML=childAges;
    //document.getElementById("cage"+i+"_"+j).className="childselecton";
    display("cage"+j);
  }   
    
    
    
    //no show
    if((3-numChildren)>-1){
      for(j=(numChildren+1);j<=3;j++){
        try{document.getElementById("cage"+i+"_"+j).innerHTML="";}catch(e){;}
        //document.getElementById("cage"+i+"_"+j).className="childselect";
        childAges.replace("[%x%]","");
      }  
    }
      
   // } 
   
  var display1=false, display2=false, display3=false;
  //show header
  for(j=1;j<=currNumRooms;j++){
    if(displayChildren[j-1]>0) display1=true;
    if(displayChildren[j-1]>1) display2=true;
    if(displayChildren[j-1]>2) display3=true;
  }
  if(display1==true) document.getElementById("cage1").innerHTML="&#xa0;<i>Child Ages (0-17)</i>";
  else document.getElementById("cage1").innerHTML="";

}


function addRoom(inc,count,ad,ch,which,runrooms){
  var top;  
  var r1 = [0,0,0,0,0], r2 = [0,0,0,0,0], r3 = [0,0,0,0,0], r4 = [0,0,0,0,0];

  if(currNumRooms>=1){
    try{r1[0]=document.search.rma_1.selectedIndex;}catch(e){;}
    try{r1[1]=document.search.rmc_1.selectedIndex;}catch(e){;}
    try{r1[2]=document.search.rmage1_1.selectedIndex;}catch(e){;}
    try{r1[3]=document.search.rmage1_2.selectedIndex;}catch(e){;}
    try{r1[4]=document.search.rmage1_3.selectedIndex;}catch(e){;}    
  }

  
  if(currNumRooms>=2){
    try{r2[0]=document.search.rma_2.selectedIndex;}catch(e){;}
    try{r2[1]=document.search.rmc_2.selectedIndex;}catch(e){;}
    try{r2[2]=document.search.rmage2_1.selectedIndex;}catch(e){;}
    try{r2[3]=document.search.rmage2_2.selectedIndex;}catch(e){;}
    try{r2[4]=document.search.rmage2_3.selectedIndex;}catch(e){;}
  }
  
  if(currNumRooms>=3){
    try{r3[0]=document.search.rma_3.selectedIndex;}catch(e){;}
    try{r3[1]=document.search.rmc_3.selectedIndex;}catch(e){;}
    try{r3[2]=document.search.rmage3_1.selectedIndex;}catch(e){;}
    try{r3[3]=document.search.rmage3_2.selectedIndex;}catch(e){;}
    try{r3[4]=document.search.rmage3_3.selectedIndex;}catch(e){;}
  }
  
  if(currNumRooms>=4){
    try{r4[0]=document.search.rma_4.selectedIndex;}catch(e){;}
    try{r4[1]=document.search.rmc_4.selectedIndex;}catch(e){;}
    try{r4[2]=document.search.rmage4_1.selectedIndex;}catch(e){;}
    try{r4[3]=document.search.rmage4_2.selectedIndex;}catch(e){;}
    try{r4[4]=document.search.rmage4_3.selectedIndex;}catch(e){;}
  }

  var maxRooms = 4;
  var i, tmp;
  if(inc=="true") i = currNumRooms+1;
  else i = count;

  if(i<=maxRooms){
  
    var template = "<div id=\"rm"+i+"\"><table class=\"rooms\" id=\"rmstbl\">[%header%]<tr><td class=\"srchbxtxt\" width=\"50\">Room&nbsp;"+i+"</td><td class=\"srchbxtxt\"  width=\"45\"><select name=\"rma_"+i+"\">[%adults%]</select></td><td class=\"srchbxtxt\" id=\"childselect[%i%]\" width=\"45\"><select name=\"rmc_"+i+"\" onchange=\"addChildAge([%i%])\">[%children%]</select>&#xa0;&#xa0;</td><td>&#xa0;&#xa0;&#xa0;<span id=\"cage[%i%]_1\" class=\"childselect\"></span>&#xa0;<span id=\"cage[%i%]_2\" class=\"childselect\"></span>&#xa0;<span id=\"cage[%i%]_3\" class=\"childselect\"></span></td></tr></table></div>";
        
    template = replaceOptions(template,"[%adults%]",1, 4,ad);
    template = replaceOptions(template,"[%children%]",0, 3,ch);
        
    //template = template.replace("[%cage%]","<div id=\"cageout_"+i+"\"></div>");
    template = template.replace(/\[%i%]/g,i);

    if(i==1) template = template.replace("[%header%]","<tr><td></td><td>Adults</td><td>Child</td><td id=\"cage1\"></td></tr>");
    else template = template.replace("[%header%]","");

    document.getElementById("roomoptions").innerHTML += template;
    //rndd("div#rm"+i,"all","#e7f1e0","#cfe2cf","smooth border #5A965A");
    if(inc=="true") currNumRooms++;
    
    //alert(currNumRooms);
    if(currNumRooms > 1) display("rembutton");
    else hide("rembutton");
    try{ 
      eval("tmp = document.search.rmc_"+(i)+".selectedIndex");
      if(tmp>0){
        addChildAge(which);
      }
    }catch(e){;}



  if((currNumRooms-1)>=1){
    try{document.search.rma_1.selectedIndex=r1[0];}catch(e){;}
    try{document.search.rmc_1.selectedIndex=r1[1];}catch(e){;}
    try{document.search.rmage1_1.selectedIndex=r1[2];}catch(e){;}
    try{document.search.rmage1_2.selectedIndex=r1[3];}catch(e){;}
    try{document.search.rmage1_3.selectedIndex=r1[4];}catch(e){;}
  }
  
  if((currNumRooms-1)>=2){
    try{document.search.rma_2.selectedIndex=r2[0];}catch(e){;}
    try{document.search.rmc_2.selectedIndex=r2[1];}catch(e){;}
    try{document.search.rmage2_1.selectedIndex=r2[2];}catch(e){;}
    try{document.search.rmage2_2.selectedIndex=r2[3];}catch(e){;}
    try{document.search.rmage2_3.selectedIndex=r2[4];}catch(e){;}
  }
  
  if((currNumRooms-1)>=3){
    try{document.search.rma_3.selectedIndex=r3[0];}catch(e){;}
    try{document.search.rmc_3.selectedIndex=r3[1];}catch(e){;}
    try{document.search.rmage3_1.selectedIndex=r3[2];}catch(e){;}
    try{document.search.rmage3_2.selectedIndex=r3[3];}catch(e){;}
    try{document.search.rmage3_3.selectedIndex=r3[4];}catch(e){;}
  }
  
  if((currNumRooms-1)>=4){
    try{document.search.rma_4.selectedIndex=r4[0];}catch(e){;}
    try{document.search.rmc_4.selectedIndex=r4[1];}catch(e){;}
    try{document.search.rmage4_1.selectedIndex=r4[2];}catch(e){;}
    try{document.search.rmage43_2.selectedIndex=r4[3];}catch(e){;}
    try{document.search.rmage4_3.selectedIndex=r4[4];}catch(e){;}
  }

    
  }else{
    alert("Maximum number of rooms per reservation is "+maxRooms+".");
  }
}

function removeRoom(){     
  var i = currNumRooms;
  var brwsr = navigator.userAgent+"";
  var tmp;
   
  if((brwsr.contains("Mac") && brwsr.contains("MSIE"))){
    document.getElementById("rm"+i).innerHTML = "";
    tmp = document.getElementById("roomoptions").innerHTML;
    tmp = tmp.replace("<DIV id=rm"+i+"></DIV>","");
    document.getElementById("roomoptions").innerHTML = tmp;
  }else{
    document.getElementById("roomoptions").removeChild(document.getElementById("rm"+i));
  }
  currNumRooms--;
  if(currNumRooms==1) hide("rembutton");
  //addChildAge();

}

var NUM_CENTYEAR = 30;var BUL_YEARSCROLL = true;var calendars = [];var RE_NUM = /^\-?\d+$/;function cal(objTarget){this.gen_date = genDate;this.gen_day = genDay;this.gen_time = genTime;this.gen_tsmp = genTsmp;this.prs_date = prsDate;this.prs_time = prsTime;this.prs_tsmp = prsTsmp;this.gen_my = genMy;this.popup = genPop;this.target = objTarget;this.year_scroll = BUL_YEARSCROLL;this.id = calendars.length;calendars[this.id] = this;}

function genPop(str_datetime){

  if (str_datetime) 
    this.dt_current = this.prs_tsmp(str_datetime);
  else {
    switch(this.id){
      case 0:
        this.dt_current = this.prs_tsmp((parseInt(this.target.dayst.selectedIndex,10)+1)+"-"+(this.target.mnthst.value).replace("/","-"));
        break;
      case 1:
        var tmpStMonth = (this.target.mnthst.value).split("/")[0];
        var tmpStYear = (this.target.mnthst.value).split("/")[1];
        var tmpEnMonth = (this.target.mnthen.value).split("/")[0];
        var tmpEnYear = (this.target.mnthen.value).split("/")[1];
        var thisDate = new Date(tmpEnMonth+"/"+(parseInt(this.target.dayen.selectedIndex,10)+1)+"/"+tmpEnYear);
        var startDate = new Date(tmpStMonth+"/"+(parseInt(this.target.dayst.selectedIndex,10)+1)+"/"+tmpStYear);
        if(thisDate<startDate){
          this.dt_current = this.prs_tsmp((parseInt(this.target.dayst.selectedIndex,10)+2)+"-"+(this.target.mnthst.value).replace("/","-"));
        }else{
          this.dt_current = this.prs_tsmp((parseInt(this.target.dayen.selectedIndex,10)+1)+"-"+(this.target.mnthen.value).replace("/","-"));
        }
        break;
      }
      
    this.dt_selected = this.dt_current;
  }
    
  if(!this.dt_current) return;
    
  var base = window.location.href.split('/');
  base = base[0]+"//"+base[2];
  var obj_calwindow = window.open(base+'/cal/cal.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,'Calendar', 'width=200,height=190,status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes');obj_calwindow.opener = window;obj_calwindow.focus();
}


function genTsmp(dt_datetime){return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));}
function genDate(dt_datetime){return ((dt_datetime.getDate() < 10 ? '0' : '')+dt_datetime.getDate()+"-"+(dt_datetime.getMonth() < 9 ? '0' : '')+(dt_datetime.getMonth() + 1) + "-"+dt_datetime.getFullYear());}
function genDay(dt_datetime){return (dt_datetime.getDate());}
function genMy(dt_datetime){return(((dt_datetime.getMonth()+1) < 10 ? '0' : '')+(dt_datetime.getMonth()+1)+"/"+dt_datetime.getFullYear());}
function genTime(dt_datetime) {return((dt_datetime.getHours() < 10 ? '0' : '')+dt_datetime.getHours()+":"+(dt_datetime.getMinutes() < 10 ? '0' : '')+(dt_datetime.getMinutes())+":"+(dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds()));}
function prsTsmp(str_datetime){if(!str_datetime) return (new Date());if(RE_NUM.exec(str_datetime)) return new Date(str_datetime);var arr_datetime = str_datetime.split(' ');return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));}
function prsDate(str_date){var arr_date = str_date.split('-');var dt_date = new Date();dt_date.setDate(1);dt_date.setMonth(arr_date[1]-1);if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);dt_date.setFullYear(arr_date[2]);var dt_numdays = new Date(arr_date[2], arr_date[1], 0);dt_date.setDate(arr_date[0]);return (dt_date);}function prsTime(str_time, dt_date){if (!dt_date) return null; var arr_time = String(str_time ? str_time : '').split(':');if (!arr_time[0]) dt_date.setHours(0); else if (RE_NUM.exec(arr_time[0])) if (arr_time[0] < 24) dt_date.setHours(arr_time[0]); if (!arr_time[1]) dt_date.setMinutes(0); else if (RE_NUM.exec(arr_time[1])) if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]); if (!arr_time[2]) dt_date.setSeconds(0); else if (RE_NUM.exec(arr_time[2])) if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]); dt_date.setMilliseconds(0); return dt_date;}



//var tabDetails = document.getElementById("srchbxtabdetails");
//var tabChange = document.getElementById("srchbxtabchange");
/*
function switchSearchBox(which){
  switch(which){
    case "change": 
      document.getElementById("srchbx").innerHTML = changeSearch;
      document.getElementById("srchbxtabs").innerHTML = tabChange;
      document.getElementById("searchbottom").innerHTML = searchBottom;
      document.getElementById("searchcriteria").innerHTML = "";
      
      if(hasSortby==true) document.getElementById("sortby").innerHTML = "";
      rndd("div#datesbox","all","#30A5BF","#CFE1E6","smooth border #5A965A");
      rndd("div#roomsbox","all","#30A5BF","#CFE1E6","smooth border #5A965A");
      //rndd("div#srchbx","bottom","#fff","#09c","smooth border #09c");
      rndd("div#searchbottom","bottom","#fff","#30A5BF","smooth border #30A5BF");
      rndd("div#srchbx","tr","#fff","#30A5BF","smooth border #30A5BF");
      sbswitchcn="change";
      listby();
      break;
    case "details": 
      if(sbswitchcount==1) document.getElementById("searchcriteria").innerHTML = "";
      document.getElementById("srchbx").innerHTML = ("<div id='searchcriteria'>"+searchDetails+"</div>");
      document.getElementById("srchbxtabs").innerHTML = tabDetails;
      document.getElementById("searchbottom").innerHTML = ""; 
      if(hasSortby==true){
        document.getElementById("sortby").innerHTML = sortbySearch;
        rndd("div#sortby","bottom","#fff","#09c","smooth border #09c");
      }else 
      rndd("div#srchbx","bottom","#fff","#30A5BF","smooth border #30A5BF");  
      rndd("div#srchbx","tr","#fff","#30A5BF","smooth border #30A5BF");
      rndd("div#scinner","all","#adceae","#e7f1e0","smooth border #5A965A");
      sbswitchcn="details";   
      break;
    case "nosrch":
      if(sbswitchcount>1) document.getElementById("srchbx").innerHTML = changeSearch;;
      
      document.getElementById("srchbxtabs").innerHTML = "";
      document.getElementById("searchbottom").innerHTML = searchBottom;
      document.getElementById("searchcriteria").innerHTML = "";
      
      if(hasSortby==true) document.getElementById("sortby").innerHTML = "";
      rndd("div#datesbox","all","#30A5BF","#CFE1E6","smooth border #5A965A");
      rndd("div#roomsbox","all","#30A5BF","#ADCEAE","smooth border #5A965A");
      rndd("div#searchbottom","bottom","#fff","#30A5BF","smooth border #30A5BF");
      //rndd("div#srchbx","top","#fff","#ADCEAE","smooth border #5A965A");
      sbswitchcn="change";
      listby();
      break;    
  }
}*/

function htlSrch(clld){
  var whch = document.search;
  if(whch.qcksrchslct){
    var fltr = whch.qcksrchslct[whch.qcksrchslct.selectedIndex].value;
    if(fltr!="") fltr = "/"+fltr+".html";
    else fltr = fltr+".html";
    if(clld=="cntnnt" || clld=="cntry" || clld=="cntrystt" || clld=="stt" || clld=="cty"){
      if(whch.qcksrchslct.selectedIndex==0){
        alert("Please choose a city");
        whch.qcksrchslct.style.backgroundColor='#b5e36b';
        whch.qcksrchslct.focus();
        return(false);
      }else{
        whch.action = whch.domain.value+whch.thisPage.value.replace("!",fltr);
       
      }

    }else{
      whch.action = whch.domain.value+whch.thisPage.value+fltr;
    }
  }
 
  var numRooms = currNumRooms;
  var numChildren;
  var ok = true;
  for(var i=1;i<=numRooms;i++){
    try{numChildren = eval("document.search.rmc_"+i+".selectedIndex");}catch(e){;}
    for(var j=1;j<=numChildren;j++){
      if(eval("document.search.rmage"+i+"_"+j+".selectedIndex")==0) ok=false; 
    }
  }
  if(ok==false){
    alert("Please select the age of children at time of travel");
    return(false);
  }else return(true);
}


