/*
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Bitflux GmbH                                      |
// +----------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License");      |
// | you may not use this file except in compliance with the License.     |
// | You may obtain a copy of the License at                              |
// | http://www.apache.org/licenses/LICENSE-2.0                           |
// | Unless required by applicable law or agreed to in writing, software  |
// | distributed under the License is distributed on an "AS IS" BASIS,    |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
// | implied. See the License for the specific language governing         |
// | permissions and limitations under the License.                       |
// +----------------------------------------------------------------------+
// | Author: Bitflux GmbH <devel@bitflux.ch>                              |
// +----------------------------------------------------------------------+

*/
var liveSearchReq = false;
var tFromFlight = null;
var tDestinationFlight = null;
var liveSearchLastFromFlight = "";
var liveSearchLastDestinationFlight = "";
var tDestinationHotel = null;
var liveSearchLastDestinationHotel = "";
var tPickupCar = null;
var tReturnCar = null;
var liveSearchLastPickupCar = "";
var liveSearchLastReturnCar = "";
var preventSubmit = false;

function checkIE7() {
  var agent = navigator.userAgent.toLowerCase();
  var ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
  var major = parseInt(navigator.appVersion);
  return (ie && (major == 4) && (agent.indexOf("msie 7.") != -1));
}

var isIE7 = checkIE7();
var isIE = false;
// on !IE we only have to initialize it once
if(window.XMLHttpRequest) {
  liveSearchReq = new XMLHttpRequest();
}

function liveSearchInit() {
  if(navigator.userAgent.indexOf("Safari") > 0) {
    document.getElementById("fromFlight").addEventListener("keydown",liveSearchKeyPressFromFlight,false);
    document.getElementById("destinationFlight").addEventListener("keydown",liveSearchKeyPressDestinationFlight,false);

    document.getElementById("destinationHotel").addEventListener("keydown",liveSearchKeyPressDestinationHotel,false);

    document.getElementById("pickupCar").addEventListener("keydown",liveSearchKeyPressPickupCar,false);
    document.getElementById("returnCar").addEventListener("keydown",liveSearchKeyPressReturnCar,false);
  } else if(navigator.product == "Gecko") {
    document.getElementById("fromFlight").addEventListener("keypress",liveSearchKeyPressFromFlight,false);
    document.getElementById("fromFlight").addEventListener("blur",liveSearchHideDelayedFromFlight,false);
    document.getElementById("destinationFlight").addEventListener("keypress",liveSearchKeyPressDestinationFlight,false);
    document.getElementById("destinationFlight").addEventListener("blur",liveSearchHideDelayedDestinationFlight,false);

    document.getElementById("destinationHotel").addEventListener("keypress",liveSearchKeyPressDestinationHotel,false);
    document.getElementById("destinationHotel").addEventListener("blur",liveSearchHideDelayedDestinationHotel,false);

    document.getElementById("pickupCar").addEventListener("keypress",liveSearchKeyPressPickupCar,false);
    document.getElementById("pickupCar").addEventListener("blur",liveSearchHideDelayedPickupCar,false);
    document.getElementById("returnCar").addEventListener("keypress",liveSearchKeyPressReturnCar,false);
    document.getElementById("returnCar").addEventListener("blur",liveSearchHideDelayedReturnCar,false);
  } else {
    document.getElementById("fromFlight").attachEvent("onkeydown",liveSearchKeyPressFromFlight);
    document.getElementById("destinationFlight").attachEvent("onkeydown",liveSearchKeyPressDestinationFlight);
    document.getElementById("fromFlight").attachEvent("onblur",liveSearchHideDelayedFromFlight);
    document.getElementById("destinationFlight").attachEvent("onblur",liveSearchHideDelayedDestinationFlight);

    document.getElementById("destinationHotel").attachEvent("onkeydown",liveSearchKeyPressDestinationHotel);
    document.getElementById("destinationHotel").attachEvent("onblur",liveSearchHideDestinationHotel);

    document.getElementById("pickupCar").attachEvent("onkeydown",liveSearchKeyPressPickupCar);
    document.getElementById("returnCar").attachEvent("onkeydown",liveSearchKeyPressReturnCar);
    document.getElementById("pickupCar").attachEvent("onblur",liveSearchHideDelayedPickupCar);
    document.getElementById("returnCar").attachEvent("onblur",liveSearchHideDelayedReturnCar);
    isIE = true;
  }
}

// Flight From //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Flight From //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Flight From //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function liveSearchHideDelayedFromFlight() {
  preventSubmit = false;
  window.setTimeout("liveSearchHideFromFlight()",400);
}

function liveSearchHideFromFlight() {
  var res = document.getElementById("shadowboxFromFlight");
  var highlight = document.getElementById("LSHighlightFromFlight");
  if(highlight) {
    highlight.removeAttribute("id");
  }
  if(isIE) {
    var toHide = document.getElementsByTagName("select");
    for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
  }
  res.style.display = "none";
  preventSubmit = false;
}

function liveSearchMouseOverFromFlight(elm) {
  highlight = document.getElementById("LSHighlightFromFlight");
  if(highlight) {
    highlight.removeAttribute('id');
  }
  elm.parentNode.parentNode.setAttribute('id','LSHighlightFromFlight');
}

function liveSearchMouseOutFromFlight(elm) {
  elm.parentNode.parentNode.removeAttribute('id');
}

function liveSearchKeyPressFromFlight(event) {
  preventSubmit = false;
  //reset the hidden country value - in case of name change
  document.getElementById('from_cc_flight').value = "";
  document.getElementById('from_ac_flight').value = "";

  var code;
  if (event.keyCode) code = event.keyCode;
  else if (event.which) code = event.which;

  if(code == 40 )
  //KEY DOWN
  {
    highlight = document.getElementById("LSHighlightFromFlight");
    if(!highlight) {
      if(document.getElementById("LSShadowFromFlight").firstChild != undefined) {
        highlight = document.getElementById("LSShadowFromFlight").firstChild.firstChild.firstChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.nextSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightFromFlight");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //KEY UP
  else if(code == 38) {
    highlight = document.getElementById("LSHighlightFromFlight");
    if(!highlight) {
      if(document.getElementById("LSShadowFromFlight").firstChild != undefined) {
        highlight = document.getElementById("LSShadowFromFlight").firstChild.firstChild.lastChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.previousSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightFromFlight");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //ESC
  else if(code == 27) {
    highlight = document.getElementById("LSHighlightFromFlight");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    document.getElementById("shadowboxFromFlight").style.display = "none";
  }
  // ENTER
  else if(code == 13) {
    highlight = document.getElementById("LSHighlightFromFlight");
    if(highlight) {
      highlight.firstChild.firstChild.click();
      highlight.removeAttribute("id");
      document.getElementById("shadowboxFromFlight").style.display = "none";
      liveSearchLastFromFlight = document.getElementById('fromFlight').value;
      preventSubmit = true;
      return false;
    }
  }
  // BACKSPACE AND DELETE
  else if(code == 8 || code == 46) {
    highlight = document.getElementById("LSHighlightFromFlight");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    liveSearchStartFromFlight();
  }
}

function liveSearchStartFromFlight() {
  if(tFromFlight) {
    window.clearTimeout(tFromFlight);
  }
  tFromFlight = window.setTimeout("liveSearchDoSearchFromFlight()",200);
}

function liveSearchDoSearchFromFlight() {
  if(typeof liveSearchRoot == "undefined") {
    liveSearchRoot = "";
  }
  if(typeof liveSearchRootSubDir == "undefined") {
    liveSearchRootSubDir = "";
  }
  if(typeof liveSearchParams == "undefined") {
    liveSearchParams = "";
  }
  if(liveSearchLastFromFlight != document.getElementById('fromFlight').value) {
    if(liveSearchReq && liveSearchReq.readyState < 4) {
      liveSearchReq.abort();
    }
    if(Trim(document.getElementById('fromFlight').value).length <= 1) {
      liveSearchHideFromFlight();
      return false;
    }
    if(window.XMLHttpRequest) {
      if(isIE7) {
        liveSearchReq = new XMLHttpRequest();
      }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
      liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    liveSearchReq.onreadystatechange= liveSearchProcessReqChangeFromFlight;
    liveSearchReq.open("GET", liveSearchRoot + "/partner/partners/20005/include/livesearch_flight.php?f=from&q=" + encodeURIComponent(document.getElementById('fromFlight').value) + liveSearchParams);
    liveSearchLastFromFlight = document.getElementById('fromFlight').value;
    liveSearchReq.send(null);
  }
}

function liveSearchProcessReqChangeFromFlight() {
  if(liveSearchReq.readyState == 4) {
    if(liveSearchReq.responseText != "") {
      var res = document.getElementById("shadowboxFromFlight");
      res.style.display = "inline";
      var sh = document.getElementById("LSShadowFromFlight");
      sh.innerHTML = liveSearchReq.responseText;
      if(isIE) {
        var toHide = hideCheck(res, document.getElementsByTagName("select"));
        for(var i = toHide.length; i; toHide[--i].style.visibility = "hidden");
      }
    } else {
      var res = document.getElementById("shadowboxFromFlight");
      if(isIE) {
        var toHide = document.getElementsByTagName("select");
        for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
      }
      res.style.display = "none";
    }
  }
}

// Flight Destination //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Flight Destination //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Flight Destination //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function liveSearchHideDelayedDestinationFlight() {
  preventSubmit = false;
  window.setTimeout("liveSearchHideDestinationFlight()",400);
}

function liveSearchHideDestinationFlight() {
  var res = document.getElementById("shadowboxDestinationFlight");
  var highlight = document.getElementById("LSHighlightDestinationFlight");
  if(highlight) {
    highlight.removeAttribute("id");
  }
  if(isIE) {
    var toHide = document.getElementsByTagName("select");
    for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
  }
  res.style.display = "none";
  preventSubmit = false;
}

function liveSearchMouseOverDestinationFlight(elm) {
  highlight = document.getElementById("LSHighlightDestinationFlight");
  if(highlight) {
    highlight.removeAttribute('id');
  }
  elm.parentNode.parentNode.setAttribute('id','LSHighlightDestinationFlight');
}

function liveSearchMouseOutDestinationFlight(elm) {
  elm.parentNode.parentNode.removeAttribute('id');
}

function liveSearchKeyPressDestinationFlight(event) {
  preventSubmit = false;
  //reset the hidden country value - in case of name change
  document.getElementById('destination_cc_flight').value = "";
  document.getElementById('destination_ac_flight').value = "";

  var code;
  if (event.keyCode) code = event.keyCode;
  else if (event.which) code = event.which;

  if(code == 40 )
  //KEY DOWN
  {
    highlight = document.getElementById("LSHighlightDestinationFlight");
    if(!highlight) {
      if(document.getElementById("LSShadowDestinationFlight").firstChild != undefined) {
        highlight = document.getElementById("LSShadowDestinationFlight").firstChild.firstChild.firstChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.nextSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightDestinationFlight");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //KEY UP
  else if(code == 38) {
    highlight = document.getElementById("LSHighlightDestinationFlight");
    if(!highlight) {
      if(document.getElementById("LSShadowDestinationFlight").firstChild != undefined) {
        highlight = document.getElementById("LSShadowDestinationFlight").firstChild.firstChild.lastChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.previousSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightDestinationFlight");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //ESC
  else if(code == 27) {
    highlight = document.getElementById("LSHighlightDestinationFlight");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    document.getElementById("shadowboxDestinationFlight").style.display = "none";
  }
  // ENTER
  else if(code == 13) {
    highlight = document.getElementById("LSHighlightDestinationFlight");
    if(highlight) {
      highlight.firstChild.firstChild.click();
      highlight.removeAttribute("id");
      document.getElementById("shadowboxDestinationFlight").style.display = "none";
      liveSearchLastDestinationFlight = document.getElementById('destinationFlight').value;
      preventSubmit = true;
      return false;
    }
  }
  // BACKSPACE AND DELETE
  else if(code == 8 || code == 46) {
    highlight = document.getElementById("LSHighlightDestinationFlight");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    liveSearchStartDestinationFlight();
  }
}

function liveSearchStartDestinationFlight() {
  if(tDestinationFlight) {
    window.clearTimeout(tDestinationFlight);
  }
  tDestinationFlight = window.setTimeout("liveSearchDoSearchDestinationFlight()",200);
}

function liveSearchDoSearchDestinationFlight() {
  if(typeof liveSearchRoot == "undefined") {
    liveSearchRoot = "";
  }
  if(typeof liveSearchRootSubDir == "undefined") {
    liveSearchRootSubDir = "";
  }
  if(typeof liveSearchParams == "undefined") {
    liveSearchParams = "";
  }
  if(liveSearchLastDestinationFlight != document.getElementById('destinationFlight').value) {
    if(liveSearchReq && liveSearchReq.readyState < 4) {
      liveSearchReq.abort();
    }
    if(Trim(document.getElementById('destinationFlight').value).length <= 1) {
      liveSearchHideDestinationFlight();
      return false;
    }
    if(window.XMLHttpRequest) {
      if(isIE7) {
        liveSearchReq = new XMLHttpRequest();
      }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
      liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    liveSearchReq.onreadystatechange= liveSearchProcessReqChangeDestinationFlight;
    liveSearchReq.open("GET", liveSearchRoot + "/partner/partners/20005/include/livesearch_flight.php?f=destination&q=" + encodeURIComponent(document.getElementById('destinationFlight').value) + liveSearchParams);
    liveSearchLastDestinationFlight = document.getElementById('destinationFlight').value;
    liveSearchReq.send(null);
  }
}

function liveSearchProcessReqChangeDestinationFlight() {
  if(liveSearchReq.readyState == 4) {
    if(liveSearchReq.responseText != "") {
      var res = document.getElementById("shadowboxDestinationFlight");
      res.style.display = "inline";
      var sh = document.getElementById("LSShadowDestinationFlight");
      sh.innerHTML = liveSearchReq.responseText;
      if(isIE) {
        var toHide = hideCheck(res, document.getElementsByTagName("select"));
        for(var i = toHide.length; i; toHide[--i].style.visibility = "hidden");
      }
    } else {
      var res = document.getElementById("shadowboxDestinationFlight");
      if(isIE) {
        var toHide = document.getElementsByTagName("select");
        for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
      }
      res.style.display = "none";
    }
  }
}

// Hotel Destination //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Hotel Destination //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Hotel Destination //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function liveSearchHideDelayedDestinationHotel() {
  preventSubmit = false;
  window.setTimeout("liveSearchHideDestinationHotel()",400);
}

function liveSearchHideDestinationHotel() {
  var res = document.getElementById("shadowboxDestinationHotel");
  var highlight = document.getElementById("LSHighlightDestinationHotel");
  if(highlight) {
    highlight.removeAttribute("id");
  }
  if(isIE) {
    var toHide = document.getElementsByTagName("select");
    for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
  }
  res.style.display = "none";
  preventSubmit = false;
}

function liveSearchMouseOverDestinationHotel(elm) {
  highlight = document.getElementById("LSHighlightDestinationHotel");
  if(highlight) {
    highlight.removeAttribute('id');
  }
  elm.parentNode.parentNode.setAttribute('id','LSHighlightDestinationHotel');
}

function liveSearchMouseOutDestinationHotel(elm) {
  elm.parentNode.parentNode.removeAttribute('id');
}

function liveSearchKeyPressDestinationHotel(event) {
  preventSubmit = false;
  //reset the hidden country value - in case of name change
  document.getElementById('destination_cc_hotel').value = "";
  document.getElementById('destination_ac_hotel').value = "";

  var code;
  if (event.keyCode) code = event.keyCode;
  else if (event.which) code = event.which;

  if(code == 40 )
  //KEY DOWN
  {
    highlight = document.getElementById("LSHighlightDestinationHotel");
    if(!highlight) {
      if(document.getElementById("LSShadowDestinationHotel").firstChild != undefined) {
        highlight = document.getElementById("LSShadowDestinationHotel").firstChild.firstChild.firstChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.nextSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightDestinationHotel");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //KEY UP
  else if(code == 38) {
    highlight = document.getElementById("LSHighlightDestinationHotel");
    if(!highlight) {
      if(document.getElementById("LSShadowDestinationHotel").firstChild != undefined) {
        highlight = document.getElementById("LSShadowDestinationHotel").firstChild.firstChild.lastChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.previousSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightDestinationHotel");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //ESC
  else if(code == 27) {
    highlight = document.getElementById("LSHighlightDestinationHotel");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    document.getElementById("shadowboxDestinationHotel").style.display = "none";
  }
  // ENTER
  else if(code == 13) {
    highlight = document.getElementById("LSHighlightDestinationHotel");
    if(highlight) {
      highlight.firstChild.firstChild.click();
      highlight.removeAttribute("id");
      document.getElementById("shadowboxDestinationHotel").style.display = "none";
      liveSearchLastDestinationHotel = document.getElementById('destinationHotel').value;
      preventSubmit = true;
      return false;
    }
  }
  // BACKSPACE AND DELETE
  else if(code == 8 || code == 46) {
    highlight = document.getElementById("LSHighlightDestinationHotel");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    liveSearchStartDestinationHotel();
  }
}

function liveSearchStartDestinationHotel() {
  if(tDestinationHotel) {
    window.clearTimeout(tDestinationHotel);
  }
  tDestinationHotel = window.setTimeout("liveSearchDoSearchDestinationHotel()",200);
}

function liveSearchDoSearchDestinationHotel() {
  if(typeof liveSearchRoot == "undefined") {
    liveSearchRoot = "";
  }
  if(typeof liveSearchRootSubDir == "undefined") {
    liveSearchRootSubDir = "";
  }
  if(typeof liveSearchParams == "undefined") {
    liveSearchParams = "";
  }
  if(liveSearchLastDestinationHotel != document.getElementById('destinationHotel').value) {
    if(liveSearchReq && liveSearchReq.readyState < 4) {
      liveSearchReq.abort();
    }
    if(Trim(document.getElementById('destinationHotel').value).length <= 1) {
      liveSearchHideDestinationHotel();
      return false;
    }
    if(window.XMLHttpRequest) {
      if(isIE7) {
        liveSearchReq = new XMLHttpRequest();
      }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
      liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    liveSearchReq.onreadystatechange= liveSearchProcessReqChangeDestinationHotel;
    liveSearchReq.open("GET", liveSearchRoot + "/partner/partners/20005/include/livesearch_hotel.php?f=destination&q=" + encodeURIComponent(document.getElementById('destinationHotel').value) + liveSearchParams);
    liveSearchLastDestinationHotel = document.getElementById('destinationHotel').value;
    liveSearchReq.send(null);
  }
}

function liveSearchProcessReqChangeDestinationHotel() {
  if(liveSearchReq.readyState == 4) {
    if(liveSearchReq.responseText != "") {
      var res = document.getElementById("shadowboxDestinationHotel");
      res.style.display = "inline";
      var sh = document.getElementById("LSShadowDestinationHotel");
      sh.innerHTML = liveSearchReq.responseText;
      if(isIE) {
        var toHide = hideCheck(res, document.getElementsByTagName("select"));
        for(var i = toHide.length; i; toHide[--i].style.visibility = "hidden");
      }
    } else {
      var res = document.getElementById("shadowboxDestinationHotel");
      if(isIE) {
        var toHide = document.getElementsByTagName("select");
        for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
      }
      res.style.display = "none";
    }
  }
}

// Car Pickup //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Car Pickup //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Car Pickup //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function liveSearchHideDelayedPickupCar() {
  preventSubmit = false;
  window.setTimeout("liveSearchHidePickupCar()",400);
}

function liveSearchHidePickupCar() {
  var res = document.getElementById("shadowboxPickupCar");
  var highlight = document.getElementById("LSHighlightPickupCar");
  if(highlight) {
    highlight.removeAttribute("id");
  }
  if(isIE) {
    var toHide = document.getElementsByTagName("select");
    for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
  }
  res.style.display = "none";
  preventSubmit = false;
}

function liveSearchMouseOverPickupCar(elm) {
  highlight = document.getElementById("LSHighlightPickupCar");
  if(highlight) {
    highlight.removeAttribute('id');
  }
  elm.parentNode.parentNode.setAttribute('id','LSHighlightPickupCar');
}

function liveSearchMouseOutPickupCar(elm) {
  elm.parentNode.parentNode.removeAttribute('id');
}

function liveSearchKeyPressPickupCar(event) {
  preventSubmit = false;
  //reset the hidden country value - in case of name change
  document.getElementById('pickup_cc_car').value = "";
  document.getElementById('pickup_ac_car').value = "";

  var code;
  if (event.keyCode) code = event.keyCode;
  else if (event.which) code = event.which;

  if(code == 40 )
  //KEY DOWN
  {
    highlight = document.getElementById("LSHighlightPickupCar");
    if(!highlight) {
      if(document.getElementById("LSShadowPickupCar").firstChild != undefined) {
        highlight = document.getElementById("LSShadowPickupCar").firstChild.firstChild.firstChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.nextSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightPickupCar");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //KEY UP
  else if(code == 38) {
    highlight = document.getElementById("LSHighlightPickupCar");
    if(!highlight) {
      if(document.getElementById("LSShadowPickupCar").firstChild != undefined) {
        highlight = document.getElementById("LSShadowPickupCar").firstChild.firstChild.lastChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.previousSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightPickupCar");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //ESC
  else if(code == 27) {
    highlight = document.getElementById("LSHighlightPickupCar");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    document.getElementById("shadowboxPickupCar").style.display = "none";
  }
  // ENTER
  else if(code == 13) {
    highlight = document.getElementById("LSHighlightPickupCar");
    if(highlight) {
      highlight.firstChild.firstChild.click();
      highlight.removeAttribute("id");
      document.getElementById("shadowboxPickupCar").style.display = "none";
      liveSearchLastPickupCar = document.getElementById('pickupCar').value;
      preventSubmit = true;
      return false;
    }
  }
  // BACKSPACE AND DELETE
  else if(code == 8 || code == 46) {
    highlight = document.getElementById("LSHighlightPickupCar");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    liveSearchStartPickupCar();
  }
}

function liveSearchStartPickupCar() {
  if(tPickupCar) {
    window.clearTimeout(tPickupCar);
  }
  tPickupCar = window.setTimeout("liveSearchDoSearchPickup()",200);
}

function liveSearchDoSearchPickup() {
  if(typeof liveSearchRoot == "undefined") {
    liveSearchRoot = "";
  }
  if(typeof liveSearchRootSubDir == "undefined") {
    liveSearchRootSubDir = "";
  }
  if(typeof liveSearchParams == "undefined") {
    liveSearchParams = "";
  }
  if(liveSearchLastPickupCar != document.getElementById('pickupCar').value) {
    if(liveSearchReq && liveSearchReq.readyState < 4) {
      liveSearchReq.abort();
    }
    if(Trim(document.getElementById('pickupCar').value).length <= 1) {
      liveSearchHidePickupCar();
      return false;
    }
    if(window.XMLHttpRequest) {
      if(isIE7) {
        liveSearchReq = new XMLHttpRequest();
      }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
      liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    liveSearchReq.onreadystatechange= liveSearchProcessReqChangePickup;
    liveSearchReq.open("GET", liveSearchRoot + "/partner/partners/20005/include/livesearch_car.php?f=pickup&q=" + encodeURIComponent(document.getElementById('pickupCar').value) + liveSearchParams);
    liveSearchLastPickupCar = document.getElementById('pickupCar').value;
    liveSearchReq.send(null);
  }
}

function liveSearchProcessReqChangePickup() {
  if(liveSearchReq.readyState == 4) {
    if(liveSearchReq.responseText != "") {
      var res = document.getElementById("shadowboxPickupCar");
      res.style.display = "inline";
      var sh = document.getElementById("LSShadowPickupCar");
      sh.innerHTML = liveSearchReq.responseText;
      if(isIE) {
        var toHide = hideCheck(res, document.getElementsByTagName("select"));
        for(var i = toHide.length; i; toHide[--i].style.visibility = "hidden");
      }
    } else {
      var res = document.getElementById("shadowboxPickupCar");
      if(isIE) {
        var toHide = document.getElementsByTagName("select");
        for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
      }
      res.style.display = "none";
    }
  }
}

// Car Return //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Car Return //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Car Return //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function liveSearchHideDelayedReturnCar() {
  preventSubmit = false;
  window.setTimeout("liveSearchHideReturn()",400);
}

function liveSearchHideReturn() {
  var res = document.getElementById("shadowboxReturnCar");
  var highlight = document.getElementById("LSHighlightReturnCar");
  if(highlight) {
    highlight.removeAttribute("id");
  }
  if(isIE) {
    var toHide = document.getElementsByTagName("select");
    for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
  }
  res.style.display = "none";
  preventSubmit = false;
}

function liveSearchMouseOverReturnCar(elm) {
  highlight = document.getElementById("LSHighlightReturnCar");
  if(highlight) {
    highlight.removeAttribute('id');
  }
  elm.parentNode.parentNode.setAttribute('id','LSHighlightReturnCar');
}

function liveSearchMouseOutReturnCar(elm) {
  elm.parentNode.parentNode.removeAttribute('id');
}

function liveSearchKeyPressReturnCar(event) {
  preventSubmit = false;
  //reset the hidden country value - in case of name change
  document.getElementById('return_cc_car').value = "";
  document.getElementById('return_ac_car').value = "";

  var code;
  if (event.keyCode) code = event.keyCode;
  else if (event.which) code = event.which;

  if(code == 40 )
  //KEY DOWN
  {
    highlight = document.getElementById("LSHighlightReturnCar");
    if(!highlight) {
      if(document.getElementById("LSShadowReturnCar").firstChild != undefined) {
        highlight = document.getElementById("LSShadowReturnCar").firstChild.firstChild.firstChild;
      } else {
        highlight = false;
      }
    } else {
      highlight.removeAttribute("id");
      highlight = highlight.nextSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightReturnCar");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //KEY UP
  else if(code == 38) {
    highlight = document.getElementById("LSHighlightReturnCar");
    if(!highlight) {
      if(document.getElementById("LSShadowReturnCar").firstChild != undefined) {
        highlight = document.getElementById("LSShadowReturnCar").firstChild.firstChild.lastChild;
      } else {
        highlight = false;
      }
    }
    else {
      highlight.removeAttribute("id");
      highlight = highlight.previousSibling;
    }
    if(highlight) {
      highlight.setAttribute("id","LSHighlightReturnCar");
    }
    if(!isIE) { event.preventDefault(); }
  }
  //ESC
  else if(code == 27) {
    highlight = document.getElementById("LSHighlightReturnCar");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    document.getElementById("shadowboxReturnCar").style.display = "none";
  }
  // ENTER
  else if(code == 13) {
    highlight = document.getElementById("LSHighlightReturnCar");
    if(highlight) {
      highlight.firstChild.firstChild.click();
      highlight.removeAttribute("id");
      document.getElementById("shadowboxReturnCar").style.display = "none";
      liveSearchLastReturnCar = document.getElementById('returnCar').value;
      preventSubmit = true;
      return false;
    }
  }
  // BACKSPACE AND DELETE
  else if(code == 8 || code == 46) {
    highlight = document.getElementById("LSHighlightReturnCar");
    if(highlight) {
      highlight.removeAttribute("id");
    }
    liveSearchStartReturnCar();
  }
}

function liveSearchStartReturnCar() {
  if(tReturnCar) {
    window.clearTimeout(tReturnCar);
  }
  tReturnCar = window.setTimeout("liveSearchDoSearchReturn()",200);
}

function liveSearchDoSearchReturn() {
  if(typeof liveSearchRoot == "undefined") {
    liveSearchRoot = "";
  }
  if(typeof liveSearchRootSubDir == "undefined") {
    liveSearchRootSubDir = "";
  }
  if(typeof liveSearchParams == "undefined") {
    liveSearchParams = "";
  }
  if(liveSearchLastReturnCar != document.getElementById('returnCar').value) {
    if(liveSearchReq && liveSearchReq.readyState < 4) {
      liveSearchReq.abort();
    }
    if(Trim(document.getElementById('returnCar').value).length <= 1) {
      liveSearchHideReturn();
      return false;
    }
    if(window.XMLHttpRequest) {
      if(isIE7) {
        liveSearchReq = new XMLHttpRequest();
      }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
      liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    liveSearchReq.onreadystatechange= liveSearchProcessReqChangeReturn;
    liveSearchReq.open("GET", liveSearchRoot + "/partner/partners/20005/include/livesearch_car.php?f=return&q=" + encodeURIComponent(document.getElementById('returnCar').value) + liveSearchParams);
    liveSearchLastReturnCar = document.getElementById('returnCar').value;
    liveSearchReq.send(null);
  }
}

function liveSearchProcessReqChangeReturn() {
  if(liveSearchReq.readyState == 4) {
    if(liveSearchReq.responseText != "") {
      var res = document.getElementById("shadowboxReturnCar");
      res.style.display = "inline";
      var sh = document.getElementById("LSShadowReturnCar");
      sh.innerHTML = liveSearchReq.responseText;
      if(isIE) {
        var toHide = hideCheck(res, document.getElementsByTagName("select"));
        for(var i = toHide.length; i; toHide[--i].style.visibility = "hidden");
      }
    } else {
      var res = document.getElementById("shadowboxReturnCar");
      if(isIE) {
        var toHide = document.getElementsByTagName("select");
        for(var i = toHide.length; i; toHide[--i].style.visibility = "visible");
      }
      res.style.display = "none";
    }
  }
}

// Misc

function hideCheck(o, l){
  function getOffset(o){
    for(var r = {l: o.offsetLeft, t: o.offsetTop, r: o.offsetWidth, b: o.offsetHeight}; o = o.offsetParent; r.l += o.offsetLeft, r.t += o.offsetTop);
    return r.r += r.l, r.b += r.t, r;
  }
  for(var b, s, r = [], a = getOffset(o), j = isNaN(l.length), i = (j ? l = [l] : l).length; i; b = getOffset(l[--i]), (a.l == b.l || (a.l > b.l ? a.l <= b.r : b.l <= a.r)) && (a.t == b.t || (a.t > b.t ? a.t <= b.b : b.t <= a.b)) && (r[r.length] = l[i]));
  return j ? !!r.length : r;
}

function Trim(TRIM_VALUE) {
  if(TRIM_VALUE.length < 1) {
    return "";
  }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE == "") {
    return "";
  } else {
    return TRIM_VALUE;
  }
} //End Function

function RTrim(VALUE) {
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0) {
    return "";
  }
  var iTemp = v_length -1;

  while(iTemp > -1) {
    if(VALUE.charAt(iTemp) == w_space) {
    } else {
      strTemp = VALUE.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  } //End While
  return strTemp;
} //End Function

function LTrim(VALUE) {
  var w_space = String.fromCharCode(32);
  if(v_length < 1) {
    return "";
  }
  var v_length = VALUE.length;
  var strTemp = "";
  var iTemp = 0;
  while(iTemp < v_length){
    if(VALUE.charAt(iTemp) == w_space){
    } else {
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  } //End While
  return strTemp;
} //End Function