(function () {
     function toArray(pseudoArray) {
         var result = [];
         for (var i = 0; i < pseudoArray.length; i++)
             result.push(pseudoArray[i]);
         return result;
     }

     Function.prototype.bind = function (object) {
         var method = this;
         var oldArguments = toArray(arguments).slice(1);
         return function () {
             var newArguments = toArray(arguments);
             return method.apply(object, oldArguments.concat(newArguments));
         };
     }

     Function.prototype.bindEventListener = function (object) {
         var method = this;
         var oldArguments = toArray(arguments).slice(1);
         return function (event) {
             return method.apply(object, event || window.event, oldArguments);
         };
     }
})();

function d2(x) {
 if(x<10) { return '0'+x; }
 return x;
}


function FltSearchBox(form_name,parameters) {
  if(document.forms[form_name] == null) {
    this.delayedLoad = true;
    this.delayedParameters = parameters;
    this.delayedFormName = form_name;
  } else {
    this.init(form_name,parameters);
  }
}

FltSearchBox.prototype.formLoad = function() {
  this.request = ajax_obj();
  if(!this.request) { return false; }
  this.request.onreadystatechange = this.formLoaded.bind(this,'_');
  if(this.contentUrl) {
    this.request.open("GET", 'http://'+location.host+this.contentUrl, true);
  } else {
    this.request.open("GET", 'http://'+location.host+'/ajax/sb_generic.php', true);    
  }
  this.request.send(null);
  return false;
}

FltSearchBox.prototype.formLoaded = function() {
  if(this.request.readyState != 4) { return; }
  if(this.request.status != 200 || !this.request.responseText.length) {
    // error - submit anyway
    this.elForm.submit();
    return;
  }
  var res = this.request.responseText;
  var div = document.createElement('div');
  div.innerHTML = res;
  document.body.insertBefore(div,document.body.firstChild);
  this.delayedLoad = false;
  this.init(this.delayedFormName,this.delayedParameters);
  this.delayedPopup();
}

FltSearchBox.prototype.init = function(form_name,parameters) {
  this.maxChildren = 5;
  this.maxNumRooms = 3;
  this.lastSubmitTime = 0;
  this.formName = form_name;
  if(parameters == null) { parameters = []; }
  if(document.forms[form_name]==null) { return ; }
  this.elForm = document.forms[form_name];
  this.elForm.searchBox = this;
  this.elForm.onsubmit = this.preSubmit.bind(this,'_');
  this.firstDate = '';
  this.lastMonth = ''; this.lastYear = '';
  /* dests */
  this.elDest = this.elForm['destination'];
  this.elDest.onchange= this.destChange.bind(this,'_');
  this.elDestHidden = this.elForm['destination_hidden'];
  this.elDestFixed = this.elForm['destination_fixed'];
  this.elSource = this.elForm['source'];
  this.elStars = this.elForm['stars'];
  this.elStarsHidden = this.elForm['stars_hidden'];
  this.elStars.onchange = this.starsChange.bind(this,'_');
  this.elBoard = this.elForm['board'];
  this.elBoardHidden = this.elForm['board_hidden'];
  this.elBoard.onchange = this.boardChange.bind(this,'_');
  if(this.elSource) {
    this.elSource.onchange = this.srcChange.bind(this,'_');
    this.elSourceHidden = this.elForm['source_hidden'];
    this.elSourceFixed = this.elForm['source_fixed'];
  }
  this.contentUrl = parameters['content_url'];
  /* dates */
  this.elNumNights = this.elForm['num_nights'];
  this.elNumNights.onchange= this.slideCalendar.bind(this,'num_nights');
  this.elObMonYear = this.elForm['outbound[monyear]'];
  this.elObMonYear.onchange=this.slideCalendar.bind(this,'outbound');
  this.elObDate = this.elForm['outbound[date]'];
  this.elObDate.onchange = this.slideCalendar.bind(this,'outbound');
  this.elObFull = this.elForm['outbound[full]'];
  this.elObFixed = this.elForm['outbound_fixed'];

  this.elIbDate = this.elForm['inbound[date]'];
  this.elIbDate.onchange = this.slideCalendar.bind(this,'inbound');
  this.elIbMonYear = this.elForm['inbound[monyear]'];
  this.elIbMonYear.onchange= this.slideCalendar.bind(this,'inbound');
  this.elIbFull = this.elForm['inbound[full]'];
  this.elIbFixed = this.elForm['inbound_fixed'];
  this.elIbCalLink = document.getElementById(form_name+'_ib_anchor');
  this.elIbCalLink.onclick = this.showCalIn.bind(this);
  this.elObCalLink = document.getElementById(form_name+'_ob_anchor');
  this.elObCalLink.onclick = this.showCalOut.bind(this);

  this.elNumRooms = this.elForm['num_rooms'];
  this.elNumRooms.onchange = this.numRoomsChange.bind(this,'_');

  for(var i=0;i<this.maxNumRooms;i++) {
    this.elForm['room['+i+'][c]'].onchange = this.showChildren.bind(this,i);
  }
  this.isEurostarDest = 0;
  this.isEurostarSource = 0;
  this.isEurostarEnabled = 0;
  this.elAlternativeRoutes = 0;
  this.display(parameters);
}
FltSearchBox.prototype.setLastMonth = function(y,m) {
  this.lastMonth = m;
  this.lastYear = y;
}
FltSearchBox.prototype.setFirstDate = function(ymd) {
  this.firstDate = ymd;
}
FltSearchBox.prototype.delayedPopup = function() {
  this.display(this.delayedParameters);
  var el = this.elForm.parentNode;
  if(!el.lightbox) {
    new Lightbox(el);
  }
  el.lightbox.show();
}
FltSearchBox.prototype.popup = function(parameters) {
  if(this.delayedLoad) {
    this.delayedParameters = parameters;
    if(parameters && parameters['content_url']) { this.contentUrl = parameters['content_url']; }
    this.formLoad();
    return;
  }
  this.display(parameters);
  var el = this.elForm.parentNode;
  if(!el.lightbox) {
    new Lightbox(el);
  }
  el.lightbox.show();
}

FltSearchBox.prototype.display = function(parameters) {
  if(parameters['loc_type']) {
    this.elForm.className = this.elForm.className.replace(/sb_locations_[^ ]+/,'sb_locations_'+parameters['loc_type']);
  }
//  if(!parameters['board_type']) { parameters['board_type'] = 'hidden'; }
  if(parameters['board_type']) {
    this.elForm.className = this.elForm.className.replace(/sb_board_stars_[^ ]+/,'sb_board_stars_'+parameters['board_type']);
  }
  if(parameters['date_type']) {
    this.elForm.className = this.elForm.className.replace(/sb_dates_[^ ]+/,'sb_dates_'+parameters['date_type']);
  }
  if(parameters['heading']) {
    var el = this.elForm['header_placeholder'];
    el.nextSibling.data = parameters['heading'];
  }
  if(parameters['destination']) {
    this.setSelect(this.elDest,parameters['destination']);
    this.elDestHidden.value = parameters['destination'];
    this.elDestFixed.value = this.slook(this.elDest,parameters['destination']);
  }
  if(parameters['source'] && this.elSource) {
    this.setSelect(this.elSource,parameters['source']);
    this.elSourceHidden.value = parameters['source'];
    this.elSourceFixed.value = this.slook(this.elSource,parameters['source']);
  }
  if(parameters['outbound[full]']) {
    var d = parameters['outbound[full]'].split('-');
    this.setMultipleValuesOutbound(d[0],parseInt(d[1],10),parseInt(d[2],10),1);
  }
  if(parameters['inbound[full]']) {
    var d = parameters['inbound[full]'].split('-');
    this.setMultipleValuesInbound(d[0],parseInt(d[1],10),parseInt(d[2],10),1);
  }
  if(parameters['inbound[full]']||parameters['outbound[full]']) {
    this.slideCalendar('inbound');
  }
  if(parameters['stars']!=undefined) {
    this.setSelect(this.elStars,parameters['stars']);
    this.elForm['stars_hidden'].value = parameters['stars'];
  } else { 
    this.setSelect(this.elStars,'');
    this.elForm['stars_hidden'].value = '';
  }
  if(parameters['board']!=undefined) {
    this.setSelect(this.elBoard,parameters['board']);
    this.elForm['board_hidden'].value = parameters['board'];
  } else {
    this.setSelect(this.elBoard,parameters['board']);
    this.elForm['board_hidden'].value = ''; 
  }
  if(parameters['default_hotel']!=undefined) {
    this.elForm['default_hotel'].value = parameters['default_hotel'];
  } else { this.elForm['default_hotel'].value = ''; }

  if(!parameters['room']) {
    var rooms = [];
    rooms[0] = {'adults':2,'children':0};
  } else {
    var rooms = parameters['room'];
  }
  this.elNumRooms.selectedIndex = rooms.length-1;
  for(var i=0;i<rooms.length;i++) {
    this.elForm['room['+i+'][a]'].selectedIndex = parseInt(rooms[i]['adults'])-1;
    this.elForm['room['+i+'][c]'].selectedIndex = parseInt(rooms[i]['children']);
  }
  this.numRoomsChange();
  this.resetChildren();
  for(var i=0;i<rooms.length;i++) {
    var room = rooms[i];
    if(room['children']>0) {
      for(var j=0;j<room['children'];j++) {
        var age = parameters['children'][i][j];
        if(age>=0) {
          this.elForm['children['+i+']['+j+']'].selectedIndex = 1+parseInt(age);
        }
      }
    }
  }
  this.destChange(); this.srcChange(); // eurostar check
}

FltSearchBox.prototype.showCalIn = function() {
  if(this.calIn == null) {
    var span = document.createElement('span');
    span.style.position = 'absolute';
    span.style.left = '10px';
    span.style.top = '30px';
    this.elIbCalLink.parentNode.appendChild(span);
    this.calIn = new CalendarWidget(span);
    this.calIn.onSelChange = this.setMultipleValuesInbound.bind(this);
  }
  if(this.firstDate) {
    var p = this.firstDate.split('-');
    this.calIn.setFirstDate(p[0],p[1],p[2]);
  }
  if(this.lastYear) { this.calIn.setLastMonth(this.lastYear,this.lastMonth); }
  var p = this.getDate('inbound').split('-');
  this.calIn.selectDate(p[0],p[1],p[2]);
  this.calIn.showMonth();
  return false;
}

FltSearchBox.prototype.showCalOut = function() {
  if(this.calOut == null) {
    var span = document.createElement('span');
    span.style.position = 'absolute';
    span.style.left = '10px';
    span.style.top = '30px';
    this.elObCalLink.parentNode.appendChild(span);
    this.calOut =  new CalendarWidget(span);
    this.calOut.onSelChange = this.setMultipleValuesOutbound.bind(this);
  }
  if(this.firstDate) {
    var p = this.firstDate.split('-');
    this.calOut.setFirstDate(p[0],p[1],p[2]);
  }
  if(this.lastYear) { this.calOut.setLastMonth(this.lastYear,this.lastMonth); }
  var p = this.getDate('outbound').split('-');
  this.calOut.selectDate(p[0],p[1],p[2]);
  this.calOut.showMonth();
  return false;
}

FltSearchBox.prototype.slideCalendar = function(changed) {
  var otime = this.getDateTime('outbound');
  var itime = this.getDateTime('inbound');
  if(changed == 'outbound' || changed == 'num_nights') {
    // slide the inbound date...
    if(changed == 'outbound') {
      this.elObFull.value = this.getDate('outbound');
    }
    var num_days = this.elNumNights.selectedIndex+1;
    itime = otime+(num_days*86400000);
    var d = new Date(itime);
    this.setMultipleValuesInbound(d.getUTCFullYear(),d.getUTCMonth()+1,d.getUTCDate(),true);
  }
  if(changed == 'inbound') {
    // change the number of days...
    this.elIbFull.value = this.getDate('inbound');
    var ndays = (itime-otime)/86400000;
    if(ndays > max_holiday_length || ndays <=0) {
      var num_days = this.elNumNights.selectedIndex+1;
      otime = itime-(num_days*86400000);
      var d = new Date(otime);
      this.setMultipleValuesOutbound(d.getUTCFullYear(),d.getUTCMonth()+1,d.getUTCDate(),true);
    } else {
      this.elNumNights.selectedIndex = ndays-1;
    }
  }
}

/* returns date as string */
FltSearchBox.prototype.getDate = function(name) {
  return this.sval(name+'[monyear]')+'-'+this.sval(name+'[date]');
}

/* returns date as time */
FltSearchBox.prototype.getDateTime = function(dir) {
  var str_date = this.sval(dir+'[monyear]')+'-'+this.sval(dir+'[date]');
  var parts = str_date.split('-');
  return Date.UTC(parts[0],parts[1]-1,parts[2]);
}


FltSearchBox.prototype.sval = function(id) {
  var el = this.elForm[id]
  if(el.value) return el.value;
  return el.options[el.selectedIndex].value;
}
FltSearchBox.prototype.slook = function(el,val) {
  if(el.value) {
    var e = el.selectedIndex;
    el.value = val;
    // IE will pick a 'close match' so beware...
    if(el.value == val) {
      var v = el.options[el.selectedIndex].text;
    } else { var v = ''; }
    el.selectedIndex = e;
    return v;
  }
  for(var i=0;i<el.options.length;i++) {
    if(el.options[i].value == val) return el.options[i].text;
  }
  return '';
}

FltSearchBox.prototype.setMultipleValuesOutbound = function(y,m,d,do_not_cascade) {
  var mon_year = ''+y+'-'+(m<10?'0'+m:m);
  this.setSelect(this.elObMonYear,mon_year);
  this.setSelect(this.elObDate,d2(d));
  this.elObFull.value = mon_year+'-'+d2(d);
  this.elObFixed.value = mon_year+'-'+d2(d);
  if(!do_not_cascade) {
    this.slideCalendar('outbound');
  }
}

FltSearchBox.prototype.setMultipleValuesInbound = function(y,m,d,do_not_cascade) {
  var mon_year = ''+y+'-'+(m<10?'0'+m:m);
  this.setSelect(this.elIbMonYear,mon_year);
  this.setSelect(this.elIbDate,d2(d));
  this.elIbFull.value = mon_year+'-'+d2(d);
  this.elIbFixed.value = mon_year+'-'+d2(d);
  if(!do_not_cascade) {
    this.slideCalendar('inbound');
  }
}

FltSearchBox.prototype.setSelect = function(sel,value) {
  if(sel.value) {
    var ov = sel.selectedIndex;
    sel.value = value;
    if(sel.value != value) { sel.selectedIndex = ov; }
    return;
  }
  var len = sel.options.length;
  for(var i=0;i<len;i++) {
    var el = sel.options[i];
    if(el.value == value) {
      sel.selectedIndex = i;
    }
  }
}

FltSearchBox.prototype.destChange = function() {
  var obd = this.elDest.options[this.elDest.selectedIndex].value;
  switch(obd) {
    case '303':
    case '171':
    case '173':
    case '159':
     this.isEurostarDest = 1;
    break;
    default:
     this.isEurostarDest = 0;
    break;
  }
  this.elDestHidden.value = obd;
  this.checkEurostar();
}

FltSearchBox.prototype.boardChange = function() {
  var val = this.elBoard.options[this.elBoard.selectedIndex].value;
  this.elBoardHidden.value = val;
}

FltSearchBox.prototype.starsChange = function() {
  var val = this.elStars.options[this.elStars.selectedIndex].value;
  this.elStarsHidden.value = val;
}



FltSearchBox.prototype.srcChange = function() {
  if(!this.elSource) { return; }
  var ibd = this.elSource.options[this.elSource.selectedIndex].value;
  switch(ibd) {
    case 'SPX':
    case 'EBF':
    case 'LON':
    case 'WIT':
    case 'ASI':
     this.isEurostarSource = 1;
    break;
    default:
     this.isEurostarSource = 0;
    break;
  }
  this.elSourceHidden.value = ibd;
  this.elSourceFixed.value = ibd;
  this.checkEurostar();
}

FltSearchBox.prototype.checkEurostar = function() {
  if(this.isEurostarDest && this.isEurostarSource) {
    if(!this.isEurostarEnabled) {
      this.enableEurostar(1);
    }
    return;
  }
  if(this.isEurostarEnabled) {
    this.enableEurostar(0);
  }
}

FltSearchBox.prototype.enableEurostar = function(es) {
  var cn = this.elForm;
  if(es) {
    cn.className = cn.className + ' eurostar_enabled';
  } else {
    cn.className = cn.className.replace(/ *eurostar_enabled/g,'');
  }
  this.isEurostarEnabled = es;
}

FltSearchBox.prototype.showChildren = function(index) {
  var num_rooms = this.elNumRooms.selectedIndex+1;
  if(index>=num_rooms) {
    this.setNumChildrenInRoom(index,0,0); return;
  }
  var element = this.elForm['room['+index+'][c]'];
  var adults = parseInt(this.elForm['room['+index+'][a]'].selectedIndex+1);
  var children = parseInt(element.selectedIndex);
  this.setNumChildrenInRoom(index,adults,children);
}

FltSearchBox.prototype.resetChildren = function() {
  for(var i=0;i<this.maxNumRooms;i++) {
    this.showChildren(i);
  }
}

FltSearchBox.prototype.numRoomsChange = function() {
  var num_rooms = this.elNumRooms.selectedIndex+1;
  if(num_rooms < 1) num_rooms = 1; /* fix for webkit/khtml */
  this.setNumRooms(num_rooms);
}

FltSearchBox.prototype.setNumRooms = function(num) {
  for(var i=0;i<this.maxNumRooms;i++) {
    if(i<num) { this.elForm['room_'+i+'_placeholder'].parentNode.parentNode.style.display = 'block'; }
    else {this.elForm['room_'+i+'_placeholder'].parentNode.parentNode.style.display = 'none'; }
  }
  this.resetChildren();
}

FltSearchBox.prototype.setNumChildrenInRoom = function(index,num_adults,num_children) {
  var el = this.elForm['children'+index+'_placeholder'];
  var pn = el.parentNode;
  for(var i=0;i<this.maxChildren;i++) {
    if(i<num_children) {
      var el = this.elForm['children['+index+']['+i+']'];
//      alert('el:'+index+'-'+i+'->'+el);
      if(!el || !el.form) {
        var s = '<select name="children['+index+']['+i+']">';
        s += '<option value="">-</option>';
        s += '<option value="0">0-1</option>';
        
        //var s = document.createElement('select');
        //s.setAttribute('name','children['+index+']['+i+']');
        //s.options[0] = new Option('-','');
        //s.options[1] = new Option('0-1','0');
//        for(var j=1;j<=18;j++) {
//          s.options[j+1] = new Option(j,j);
//        }
        for(var j=1;j<=18;j++) {
          s += '<option value="'+j+'">'+j+'</option>';
        }
        s += '</select>';
//        alert(s);
        var fknode = document.createElement('div');
        fknode.innerHTML = s;
        pn.appendChild(fknode.firstChild);
      }
    } else {
      var el = this.elForm['children['+index+']['+i+']'];
      if(el && el.form) { el.parentNode.removeChild(el); }
    }
  }
  if(!num_children) { 
    pn.parentNode.style.display = 'none';
  } else {
    pn.parentNode.style.display = 'block';
  }
  this.showHideChildren();
}

FltSearchBox.prototype.showHideChildren = function() {
  var num_rooms = this.elNumRooms.selectedIndex+1;
  var cn = this.elForm.className;
  for(var i=0;i<num_rooms;i++) {
    if(this.elForm['room['+i+'][c]'].selectedIndex) {
      if(cn.indexOf('child_enabled')<0) {
        this.elForm.className = cn + ' child_enabled';
      }
      return;
    }
  }
  this.elForm.className = cn.replace(/ *child_enabled/g,'');
}

FltSearchBox.prototype.checkTime = function() {
  if(!this.lastSubmitTime) return true;
  var d = new Date();
  var result = false;
  var t = d.getSeconds();
  if(t > this.lastSubmitTime+3) {
    result = true;
  }
  this.lastSubmitTime = t;
  return false;
}

FltSearchBox.prototype.preSubmit = function() {
  if(!this.checkTime()) return false;
  if(!this.checkPeople()) return false;
  if(!this.checkDates()) return false;
  if(!this.checkDestination()) return false;
  if(!this.checkSourceDest()) return false;
  // do fast ajax check on source->destination
  if(!this.checkTime()) return false;
  return true;
}
FltSearchBox.prototype.checkSourceDest = function() {
  if(!this.elSource) { return true; }
  this.request = ajax_obj();
  if(!this.request) { return false; }
  this.request.onreadystatechange = this.routeCheckComplete.bind(this,'_');
  var src = this.elSourceHidden.value;
  var dest = this.elDestHidden.value;
  this.request.open("GET", 'http://'+location.host+'/ajax/check_route.php?source='+src+'&dest='+dest, true);
  this.request.send(null);
  return false;
}
FltSearchBox.prototype.routeCheckComplete = function() {
  if(this.request.readyState != 4) { return; }
  if(this.request.status != 200 || !this.request.responseText.length) {
    // error - submit anyway
    this.elForm.submit();
    return;
  }
  var res = this.request.responseText.split("\n");
  if(res[0] == '0') { this.errorMessage('The selected route is not available'); return; }
  if(res[0] == '1') { this.elForm.submit(); }
  if(res[0] == '2') { res.shift(); this.alternativeRoutes(res); }
}

FltSearchBox.prototype.addDays = function(date,days) {
  var p = date.split('-');
  var itime = Date.UTC(p[0],p[1]-1,p[2]);
  itime += 86400000*days;
  var d = new Date(itime);
  return d.getUTCFullYear()+'-'+d2(d.getUTCMonth()+1)+'-'+d2(d.getUTCDate())
}
FltSearchBox.prototype.errorMessage = function(msg) {
  alert(msg);
}

FltSearchBox.prototype.selectAlternativeRoute = function(dummy,src) {
  this.setSelect(this.elSource,src);
  this.srcChange();
  this.hideAlternativeRoutes();
  return false;
}

FltSearchBox.prototype.hideAlternativeRoutes = function() {
  this.elForm.className = this.oldClassName;
}

FltSearchBox.prototype.alternativeRoutes = function(res) {
  // note: doesn't work for a permanent widget (yet)
  this.oldClassName = this.elForm.className;
  this.elForm.className = 'alternative_routes_enabled';
  var dest = this.elDest.options[this.elDest.selectedIndex].text;
  var src = this.elSource.options[this.elSource.selectedIndex].text;
  var thead = document.createTextNode("I'm sorry. "+src+' to '+dest+' is not an available route.');
  if(!this.elAlternativeRoutes) {
    var el = this.elForm['alternative_routes_placeholder'];
    var head = document.createElement('h3');
    head.appendChild(thead);
    el.parentNode.appendChild(head);
    this.elAlternativeRoutesHead = head;
    var tcomment = document.createElement('p');
    tcomment.appendChild(document.createTextNode('Please choose one of the alternative(s) below:'));
    el.parentNode.appendChild(tcomment);
    var div = document.createElement('div');
    div.className = 'route_list';
    el.parentNode.appendChild(div);
    this.elAlternativeRoutes = div;
  } else {
    this.elAlternativeRoutesHead.innerHTML = '';
    this.elAlternativeRoutesHead.appendChild(thead);
    this.elAlternativeRoutes.innerHTML = '';
  }
  for(var i=0;i<res.length;i++) {
    if(!res[i].length) continue;
    var p = res[i].split(':');
    var a = document.createElement('a');
    a.href = '';
    a.onclick = this.selectAlternativeRoute.bind(this,'_',p[0]);
    a.appendChild(document.createTextNode(p[1]));
    this.elAlternativeRoutes.appendChild(a);
    this.elAlternativeRoutes.appendChild(document.createElement('br'));
  }
}

FltSearchBox.prototype.checkDates = function() {
  var out_time = this.getDate('outbound');
  var in_time = this.getDate('inbound');
  if(out_time < day_before_outbound) {
    // unfortunate date arithmetic... to get 'day after locked date'
    var date = day_before_outbound;
    // this.addDays(day_before_outbound,1);
    alert("Cannot depart before "+this.prettyDate(date));
    return false;
  }
  if(out_time >= in_time) {
    alert("Return date must be after outbound date.");
    return false;
  }
  return true;
}

FltSearchBox.prototype.prettyDate = function(indate) {
  var d = indate.split('-');
  var months = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Dec'];
  return d[2]+' '+months[parseInt(d[1])];
}

FltSearchBox.prototype.checkDestination = function() {
  if(this.elDestHidden.value == '0') {
    alert("Please select a destination for your holiday");
    return false;
  }
  return true;
}

FltSearchBox.prototype.checkChildren = function(index,num_children) {
  for(var i=0;i<num_children;i++) {
    if(!this.elForm['children['+index+']['+i+']'].selectedIndex) {
      alert('Please select the ages of all children before continuing');
      return false;
    }
  }
  return true;
}

FltSearchBox.prototype.checkPeople = function() {
  var num_people = 0;
  for(var i=0;i<this.maxNumRooms;i++) {
    num_people += this.elForm['room['+i+'][a]'].selectedIndex+1;
    var children = this.elForm['room['+i+'][c]'].selectedIndex;
    if(children) {
      if(!this.checkChildren(i,children)) { return false; }
    }
  }
  if(num_people >9) {
    alert('We accept a maximum of 9 people per booking, you have selected '+num_people);
    return false;
  }
  if(num_people <1) {
    alert("Please select rooms before continuing");
    return false;
  }
  return num_people;
}

function get_num(str) {
  var v = parseInt(str);
  if(isNaN(v)) return 0;
  return v;
}

function d2(x) {
  if(x == 0) return '00';
  if(x<10) return '0'+x;
  return x;
}

function ajax_obj() {
  var req;
  try {
    req = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
      req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(oc) {
      req = null;
    }
  }
  if(!req && typeof XMLHttpRequest != "undefined") {
    req = new XMLHttpRequest();
  }
  return req;
}
