﻿// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                      (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);


var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
// or if this is the first browser window opened.  Thus the
// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
var is_aol   = (agt.indexOf("aol") != -1);
var is_aol3  = (is_aol && is_ie3);
var is_aol4  = (is_aol && is_ie4);
var is_aol5  = (agt.indexOf("aol 5") != -1);
var is_aol6  = (agt.indexOf("aol 6") != -1);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

var is_webtv = (agt.indexOf("webtv") != -1);

var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
var is_AOLTV = is_TVNavigator;

var is_hotjava = (agt.indexOf("hotjava") != -1);
var is_hotjava3 = (is_hotjava && (is_major == 3));
var is_hotjava3up = (is_hotjava && (is_major >= 3));

// *** JAVASCRIPT VERSION CHECK ***
var is_js;
if (is_nav2 || is_ie3) is_js = 1.0;
else if (is_nav3) is_js = 1.1;
else if (is_opera5up) is_js = 1.3;
else if (is_opera) is_js = 1.1;
else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
else if (is_hotjava3up) is_js = 1.4;
else if (is_nav6 || is_gecko) is_js = 1.5;
// NOTE: In the future, update this code when newer versions of JS
// are released. For now, we try to provide some upward compatibility
// so that future versions of Nav and IE will show they are at
// *least* JS 1.x capable. Always check for JS version compatibility
// with > or >=.
else if (is_nav6up) is_js = 1.5;
// NOTE: ie5up on mac is 1.4
else if (is_ie5up) is_js = 1.3

// HACK: no idea for other browsers; always check for JS version with > or >=
else is_js = 0.0;

// Preload the button images
var imageSearchOn = new Image();
imageSearchOn.src = 'img/btn_search_small-over.gif';
var imageSearchOff = new Image();
imageSearchOff.src = 'img/btn_search_small.gif';
// note shorter name to reduce filesize of large search results
var imgD1 = new Image();
imgD1.src = 'img/btn_details-over.gif';
var imgD0 = new Image();
imgD0.src = 'img/btn_details.gif';

var imageRefineOn = new Image();
imageRefineOn.src = 'img/btn_refine-over.gif';
var imageRefineOff = new Image();
imageRefineOff.src = 'img/btn_refine.gif';
var imageNewSearchOn = new Image();
imageNewSearchOn.src = 'img/btn_new-over.gif';
var imageNewSearchOff = new Image();
imageNewSearchOff.src = 'img/btn_new.gif';
var imageNextRoomOn = new Image();
imageNextRoomOn.src = 'img/btn_next-over.gif';
var imageNextRoomOff = new Image();
imageNextRoomOff.src = 'img/btn_next.gif';
var imagePreviousRoomOn = new Image();
imagePreviousRoomOn.src = 'img/btn_previous-over.gif';
var imagePreviousRoomOff = new Image();
imagePreviousRoomOff.src = 'img/btn_previous.gif';

// Load blanks for pre IE4 and NS6
var imagePrintOn = new Image();
var imagePrintOff = new Image();
if (is_ie5up || is_nav6up){
  imagePrintOn.src = 'img/btn_print-over.gif';
  imagePrintOff.src = 'img/btn_print.gif';
} else {
  imagePrintOn.src = 'img/space.gif';
  imagePrintOff.src = 'img/space.gif';
}
function printWindow(){
  if (is_ie5up || is_nav6up){
    window.print();
  }
}

// clears a logical group of CBs from 1 to nocbs
function clearAllCBs(formname, cbname, nocbs){
  var gohigh = false;
  // Set/clear them all
  for (n=1; n<=nocbs; n++){
    if (document.forms[formname][cbname+"_"+n].checked ^ gohigh){
      document.forms[formname][cbname+"_"+n].click();
    }
  }
}
function setAllCBs(formname, cbname, nocbs){
  _setAllCBs(formname, cbname, nocbs, true);
}
function toggleAllCBs(formname, cbname, nocbs){
  // #0 is the all-state
  var gohigh = document.forms[formname][cbname+"_0"].checked;
  _setAllCBs(formname, cbname, nocbs, gohigh);
}
function _setAllCBs(formname, cbname, nocbs, gohigh){
  var n;
  // Set/clear them all
  for (n=1; n<=nocbs; n++){
    if (document.forms[formname][cbname+"_"+n].checked ^ gohigh){
      document.forms[formname][cbname+"_"+n].click();
    }
  }
}

// Div display functions
function showDiv(id){
  oDiv = getElementById_Compat(id);
  oDiv.style.display = "block";
}
function hideDiv(id){
  oDiv = getElementById_Compat(id);
  oDiv.style.display = "none";
}
function toggleDiv(id){
  oDiv = getElementById_Compat(id);
  if(oDiv.style.display != "block"){
    oDiv.style.display = "block";
  } else {
    oDiv.style.display = "none";
  }
}

// cross-browser compatible get element
function getElementById_Compat(id){
  var el;
  if (document.getElementById){
    // DOM
    el = document.getElementById(id);
  } else if (document.all){
    // msie
    el = document.all[id];
  } else if (document.layers){
    // nn4
    el = document.layers[id].style;
  }
  return el;
}

function submitForm(formName){
  document.forms[formName].submit();
}

// This is used to make the form common to all details buttons
function submitDetailsForm(id, index){
  // Note the form name is set here to reduce the file size of large search results
  // Set the id of the room button clicked
  // and the index in the previous/next id list
  document.forms.roomForm.index.value = index;
  document.forms.roomForm.id.value = id;
  document.forms.roomForm.submit();
}
