function detectBrows(e){
   if (!e){e = window.event;}
   return e;
}

addLoadEvent(initialiseEvents);
addLoadEvent(enableSelects);

//this function is a hack for a bug where ajax disable states remain after a
//search when back from the browser is selected
function enableSelects(){
  $("scuAirportSelect").disabled = false;
  $("scuDurationSelect").disabled = false;
}

//when order of js includes can be changed this function needs to be moved to interstitialDisplay.js
function initialiseInterstitial(){
  if(!document.body) return false;
  var docBody = document.body;
  var backgroundImage = '/images/body/backgrounds/background.jpg';
  var mainPhotoPath = '/images/interstitual/bg-interstitualContainer-03.png';
  var mainPhotoPathIE = '/images/interstitual/bg-interstitualContainerIE-03.gif';

  var interstitialHtml = '<img style="display:none" src="' + backgroundImage +'" alt="" />' +
      '<h1>Searching for your dream holiday</h1>';
  var bgClassName = '';

  //IE6 does not handle form submit and animated gif's well hence script based animation for IE.
  if(!browser.isIE){
    bgClassName = 'bg01';
    interstitialHtml = interstitialHtml + '<img class="progressBar" src="/images/interstitual/progress-bar.gif" alt="" />' +
       '<br />' +
       '<img src="' + mainPhotoPath + '" class="intImg" alt="">';
  }else{
    interstitialHtml = interstitialHtml + '<img class="progressBar" id="progressBar0" src="/images/interstitual/progressBar0.gif" alt="" />' +
        '<img class="progressBar" id="progressBar1" src="/images/interstitual/progressBar1.gif" alt="" />' +
        '<img class="progressBar" id="progressBar2" src="/images/interstitual/progressBar2.gif" alt="" />' +
        '<img class="progressBar" id="progressBar3" src="/images/interstitual/progressBar3.gif" alt="" />' +
        '<img class="progressBar" id="progressBar4" src="/images/interstitual/progressBar4.gif" alt="" />' +
        '<img class="progressBar" id="progressBar5" src="/images/interstitual/progressBar5.gif" alt="" />' +
        '<img class="progressBar" id="progressBar6" src="/images/interstitual/progressBar6.gif" alt="" />' +
        '<img class="progressBar" id="progressBar7" src="/images/interstitual/progressBar7.gif" alt="" />' +
        '<img class="progressBar" id="progressBar8" src="/images/interstitual/progressBar8.gif" alt="" />' +
        '<img class="progressBar" id="progressBar9" src="/images/interstitual/progressBar9.gif" alt="" />' +
        '<img class="progressBar" id="progressBar10" src="/images/interstitual/progressBar10.gif" alt="" />' +
        '<img class="progressBar" id="progressBar11" src="/images/interstitual/progressBar11.gif" alt="" />' +
        '<img class="progressBar" id="progressBar12" src="/images/interstitual/progressBar12.gif" alt="" />' +
        '<img class="progressBar" id="progressBar13" src="/images/interstitual/progressBar13.gif" alt="" />' +
        '<br />' +
        '<img src="' + mainPhotoPathIE + '" id="progressBar14" class="intImgIE" alt="">';
  }
  interstitialHtml = interstitialHtml + '<p>Lowest prices guaranteed and low deposits. Book online today!</p><img src="/images/interstitual/thats-why-were-FC.gif" alt="That\'s why we\'re First Choice" />';
  var interstitialDiv = document.createElement("div");
  interstitialDiv.setAttribute("id","interstitialContainerEmbedded");
  interstitialDiv.setAttribute("class",bgClassName);
  interstitialDiv.innerHTML = interstitialHtml;
  docBody.appendChild(interstitialDiv);

}

function initialiseEvents(){

  initialiseInterstitial();

 var scuAirportSelect         = $( 'scuAirportSelect' );
 var selectedDepartureAirport = $( 'selectedDepartureAirport' );
 if ( selectedDepartureAirport.value != scuAirportSelect.value )
 {
   selectOption( scuAirportSelect, selectedDepartureAirport.value );
 }
 scuDa = $("scuDate");
 scuDSel = $("scuDaySelect");
 scuMYSel = $("scuMonthYearSelect");
 scuAport = $("scuAirport");
 scuAportSel = $("scuAirportSelect");
 scuDur = $("scuDuration");
 scuDurSel = $("scuDurationSelect");
 scuWh = $("scuWho");
 var scuWhTASel = new Array(5);
 var scuWhSenSel = new Array(5);
 var scuWhChSel = new Array(5);
 var scuWhInSel = new Array(5);
 for(i=1;i<=5;i++)
 {
  scuWhTASel[i] = $("scuWhoAdultsSelect"+i);
  scuWhSenSel[i] = $("scuWhoSeniorsSelect"+i);
  scuWhChSel[i] = $("scuWhoChildrenSelect"+i);
  scuWhInSel[i] = $("scuWhoInfantsSelect"+i);
 }
 scuWhCl = $("scuWhoClose");
 numberOfRooms = $("numberOfRooms");

 var y = 'yes';
 var h = 'hide';
 updateDayOfWeek();
 updateRoom();
 configureIsuFeatures(false);

 numberOfRooms.onchange = function(e){
 updateRoom();
 }
 scuDa.onclick = function(){
  functionsPanelOverlay(scuDa,y, false);
 }
 scuDSel.onclick = function(){
  functionsPanelOverlay(scuDa,y, false);
 }
 scuMYSel.onclick = function(){
  functionsPanelOverlay(scuDa,y, false);
 }
 scuDSel.onmousedown = function(){
  functionsPanelOverlay(scuDa,y, false);
 }
 scuDSel.onchange = function(){
 updateRoom();
 updateDayOfWeek()
 updateRefinedSearchPanel('IsuSelectDate');
}
 scuMYSel.onmousedown = function(){
  functionsPanelOverlay(scuDa,y, false);
 }
 scuMYSel.onchange = function(){
  updateRoom();
  updateDayOfWeek()
  updateRefinedSearchPanel('IsuSelectDate');
 }
 scuDur.onclick = function(){
  functionsPanelOverlay(scuDur,y, false);
 }
 scuDurSel.onclick = function(){
  functionsPanelOverlay(scuDur,y, false);
 }
 scuDurSel.onmousedown = function(){
  functionsPanelOverlay(scuDur,y, false);
 }
 scuDurSel.onchange = function(){
  clearMessage();
  updateRefinedDurationSelection();
  functionsPanelOverlay(scuDur,h, false);
 }
 scuAport.onclick = function(){
  functionsPanelOverlay(scuAport,y, false);
 }
 scuAportSel.onclick = function(){
  functionsPanelOverlay(scuAport,y, false);
 }
 scuAportSel.onmousedown = function(){
  functionsPanelOverlay(scuAport,y, false);
 }
 scuAportSel.onchange = function(){
  updateDepartureAirportSelection();
  functionsPanelOverlay(scuAport,h, false);
 }
 scuWh.onclick = function(){
  functionsPanelOverlay(scuWh,y, false);
 }
 for (i=1;i<=5;i++)
 {
  scuWhTASel[i].onmousedown = function(){
  functionsPanelOverlay(scuWh,y, false);
 }
  scuWhTASel[i].onchange = function(){
  functionsPanelOverlay(scuWh,h, false);
 }
  scuWhSenSel[i].onmousedown = function(){
  functionsPanelOverlay(scuWh,y, false);;
 }
  scuWhSenSel[i].onchange = function(){
  functionsPanelOverlay(scuWh,h, false);
 }
  scuWhChSel[i].onmousedown = function(){
  functionsPanelOverlay(scuWh,y, false);
 }
  scuWhChSel[i].onchange = function(){
  configChildAgesForRooms(this.id);
   functionsPanelOverlay(scuWh,h, false);
 }
  scuWhInSel[i].onmousedown = function(){
  functionsPanelOverlay(scuWh,y, false);
 }
  scuWhInSel[i].onchange = function(){
  functionsPanelOverlay(scuWh,h, false);
 }
 }
}