/*    Caret Functions     */
function getCaretEnd(obj){
	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		var Lp=obj.createTextRange();
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
function getCaretStart(obj){
	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		var Lp=obj.createTextRange();
		Lp.setEndPoint("EndToStart",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}
/* ----------------- */

/*    Escape function   */
String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};


function actb(obj,evt,ca,err){

	if (!err) { err = 'pressSearch';}

	if (is_ie && !is_ie5_5up) { return; }

	/* ---- Variables ---- */
	var actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	var actb_lim = 10;    // Number of elements autocomplete can show (-1: no limit)
	var actb_firstText = true; // should the auto complete be limited to the beginning of keyword?
	var actb_mouse = true; // Enable Mouse Support
	var actb_delimiter = new Array();  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	/* ---- Variables ---- */

	/* --- Styles --- */
	var actb_bgColor = '#fff';
	var actb_textColor = '#0b123f';
	var actb_hColor = '#aaacbc';
	var actb_fFamily = 'Arial, Helvetica, Verdana, sans-serif';
	var actb_fSize = '0.9em';
	var actb_hStyle = 'text-decoration:underline;font-weight="normal"';
	/* --- Styles --- */

	/* ---- Don't touch :P---- */
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_keywords = new Array();
	var actb_display = false;
	var actb_pos = 0;
	var actb_total = 0;
	var actb_curr = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = true;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	/* ---- "Constants" ---- */

	var cdoc = document;

	// --------------------------------------------------
	// Added by MT 26.04.2008: Need to exclude properties
	// of the object's prototype so we don't see all the
	// methods added in by the Prototype library. Added
	// the following line to every for ( ... in ... )
	// block that I could find, this skips any properties
	// of the objects prototype.
	// --------------------------------------------------
	// if (!actb_keywords.hasOwnProperty(key)) continue;
	// --------------------------------------------------

	actb_keywords = ca;
	actb_curr = obj;

	// --------------------------------------------------
	// Added by MT 27.04.2008: Populate ID on form submit
	// --------------------------------------------------
	function actb_populateId() {
		var str = actb_curr.value.toLowerCase();
		for (key in actb_keywords) {
			if (!actb_keywords.hasOwnProperty(key)) continue;
			if (str == key.toLowerCase()) {
				var id = actb_keywords[key];
				break;
			}
		}
		var hidden = $(actb_curr.id + 'Id');
		if (hidden) {
			hidden.value = (id) ? id : 0;
		}
	}

	var f = $(actb_curr.form);
	if (f) {
		var actb_formHandler = function(e){ actb_populateId(); }
		f.observe('submit',actb_formHandler);
	}
	// --------------------------------------------------

	var oldkeydownhandler = document.onkeydown;
	var oldblurhandler = obj.onblur;
	var oldkeypresshandler = obj.onkeypress;

	document.onkeydown = actb_checkkey;
	obj.onblur = actb_clear;
	obj.onkeypress = actb_keypress;

	function actb_clear(evt){
		if (!evt) evt = event;
		document.onkeydown = oldkeydownhandler;
		actb_curr.onblur = oldblurhandler;
		actb_curr.onkeypress = oldkeypresshandler;
		actb_removedisp();
	}
	function actb_parse(n){
		if (actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actb_firstText){
			// Highlight the first occurrence of the search text at the start of a word
			var re = new RegExp("^((.+ )*)" + t, "i");
			var m = n.match(re);
			// The underlined text should start at the character position
			// following the second element of the returned array
			var p = RegExp.$2.length;
		}else{
			// Highlight the first occurrence of the search text
			var re = new RegExp(t, "i");
			var p = n.search(re);
		}

		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<span style='"+(actb_hStyle)+"'>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</span>";
		for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
		return tobuild;
	}
	function curTop(){
		actb_toreturn = 0;
		obj = actb_curr;
		while(obj){
			actb_toreturn += obj.offsetTop;
			obj = obj.offsetParent;
		}
		return actb_toreturn;
	}
	function curLeft(){
		actb_toreturn = 0;
		obj = actb_curr;
		while(obj){
			actb_toreturn += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		return actb_toreturn;
	}
	function actb_generate_iframe(a){
		// Extra iframe underlay added by Matt to fix IE bug
		// with layers drawn over the top of by form elements
		if(a.insertAdjacentHTML) {
			a.insertAdjacentHTML("afterEnd", '<iframe id="tat_iframe" src="/javascript/blank.html" scroll="none"></iframe>');
			b = document.getElementById('tat_iframe');
			b.style.position = a.style.position;
			b.style.top		 = a.style.top;
			b.style.left	 = a.style.left;
			b.style.width	 = a.width;
			b.style.height	 = a.offsetHeight
			b.style.zIndex	 = 100;
			a.style.zIndex	 = 101;
		}
		// also added a "removeChild()" for "tat_iframe"
		// wherever there's one for "tat_table"
	}
	function actb_generate(){
		if (document.getElementById('tat_table'))  { document.body.removeChild(document.getElementById('tat_table')); actb_display = false; }
		if (document.getElementById('tat_iframe')) { document.body.removeChild(document.getElementById('tat_iframe')); }
		if (actb_kwcount == 0){
			//(AJP comment out no ccs element pressSearch) document.getElementById(err).style.visibility="inherit";
			//(AJP comment out no ccs element pressSearch) document.getElementById(err).style.display="";
			actb_display = false;
			return;
		}
		else {
			//(AJP comment out no ccs element pressSearch) document.getElementById(err).style.visibility="hidden";
			//(AJP comment out no ccs element pressSearch) document.getElementById(err).style.display="none";
		}
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='1px';
		a.style.position='absolute';
		a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft() + "px";
		a.style.backgroundColor=actb_bgColor;
		a.id = 'tat_table';
		// Extra attributes added by Dave
		a.width = actb_curr.offsetWidth;
		a.style.borderStyle = "solid";
		a.style.borderWidth = "1px";
		// Extra attributes added by Matt
		a.style.borderColor = "#aaacbc";
		a.style.textAlign	= "left";
		a.style.zIndex	= "300";

		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		var counter = 0;


		//Added by JonC
		r = a.insertRow(-1);
		if (first && !actb_tomake){
			r.style.backgroundColor = actb_hColor;
			first = false;
			actb_pos = 0;
		}else if(actb_pre == i){
			r.style.backgroundColor = actb_hColor;
			first = false;
			actb_pos = 0;
		}else{
			r.style.backgroundColor = actb_bgColor;
		}
		r.id = 'tat_tr'+(0);
		c = r.insertCell(-1);
		c.style.color = actb_textColor;
		c.style.fontFamily = actb_fFamily;
		c.style.fontSize = actb_fSize;
		c.style.cursor = 'default';
		c.innerHTML = '<span style="'+(actb_hStyle)+'">'+actb_curr.value+'</span>';
		c.id = 'tat_td'+(0);
		c.setAttribute('pos',0);
		if (actb_mouse){
			c.onclick = function() {
				actb_insertword(actb_curr.value);
			};
			c.onmouseover = actb_table_highlight;
		}

		for (key in actb_keywords) {
			if (!actb_keywords.hasOwnProperty(key)) continue;
			if (actb_bool[key]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
					r.style.backgroundColor = actb_hColor;
					first = false;
					actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_hColor;
					first = false;
					actb_pos = counter;
				}else{
					r.style.backgroundColor = actb_bgColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.color = actb_textColor;
				c.style.fontFamily = actb_fFamily;
				c.style.fontSize = actb_fSize;
				c.style.cursor = 'default';
				c.innerHTML = actb_parse(key);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_mouse){
					c.onclick=actb_mouseclick;
					c.onmouseover = actb_table_highlight;
				}
				j++;
			}
			if (j - 1 == actb_lim && j < actb_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_bgColor;
				c = r.insertCell(-1);
				c.style.color = actb_textColor;
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actb_fSize;
				c.style.cursor = 'default';
				c.align='center';
				c.innerHTML = '\\/';
				if (actb_mouse){
					c.onclick = actb_mouse_down;
				}
				break;
			}
		}

		actb_generate_iframe(a);

		actb_rangeu = 0;
		actb_ranged = j-1;
		actb_display = true;
		if (actb_pos <= 0) actb_pos = 0;
	}
	function actb_remake(){
		if (document.getElementById('tat_table'))  { document.body.removeChild(document.getElementById('tat_table')); }
		if (document.getElementById('tat_iframe')) { document.body.removeChild(document.getElementById('tat_iframe')); }
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft() + "px";
		a.style.backgroundColor=actb_bgColor;
		a.id = 'tat_table';
		// Extra attributes added by Dave
		a.width = actb_curr.offsetWidth;
		a.style.borderStyle = "solid";
		a.style.borderWidth = "1px";
		// Extra attributes added by Matt
		a.style.borderColor = "#aaacbc";
		a.style.textAlign	= "left";
		a.style.zIndex	= "300";

		if (actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_fSize;
			c.style.cursor = 'default';
			c.align='center';
			c.innerHTML = '/\\';
			if (actb_mouse){
				c.onclick = actb_mouse_up;
			}
		} else {
			//Added by JonC
			r = a.insertRow(-1);
			if (first && !actb_tomake){
				r.style.backgroundColor = actb_hColor;
				first = false;
				actb_pos = 0;
			}else if(actb_pre == i){
				r.style.backgroundColor = actb_hColor;
				first = false;
				actb_pos = 0;
			}else{
				r.style.backgroundColor = actb_bgColor;
			}
			r.id = 'tat_tr'+(0);
			c = r.insertCell(-1);
			c.style.color = actb_textColor;
			c.style.fontFamily = actb_fFamily;
			c.style.fontSize = actb_fSize;
			c.style.cursor = 'default';
			c.innerHTML = '<span style="'+(actb_hStyle)+'">'+actb_curr.value+'</span>';
			c.id = 'tat_td'+(0);
			c.setAttribute('pos',0);
			if (actb_mouse){
				c.onclick = function() {
					actb_insertword(actb_curr.value);
				};
				c.onmouseover = actb_table_highlight;
			}
		}

		for (key in actb_keywords) {
			if (!actb_keywords.hasOwnProperty(key)) continue;
			if (actb_bool[key]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actb_bgColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.color = actb_textColor;
					c.style.fontFamily = actb_fFamily;
					c.style.fontSize = actb_fSize;
					c.style.cursor = 'default';
					c.innerHTML = actb_parse(key);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actb_mouse){
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_fSize;
			c.style.cursor = 'default';
			c.align='center';
			c.innerHTML = '\\/';
			if (actb_mouse){
				c.onclick = actb_mouse_down;
			}
		}

		actb_generate_iframe(a);
	}
	function actb_goup(){
		if (!actb_display) return;
		if (actb_pos == 1) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_timeOut);
	}
	function actb_godown(){
		if (!actb_display) return;
		if (actb_pos == actb_total) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
		actb_pos++;
		if (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_timeOut);
	}
	function actb_movedown(){
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
	}
	function actb_moveup(){
		actb_rangeu--;
		actb_ranged--;
		actb_remake();
	}

	/* Mouse */
	function actb_mouse_down(){
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_timeOut);
	}
	function actb_mouse_up(evt){
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_timeOut);
	}
	function actb_mouseclick(evt){
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
		actb_pos = this.getAttribute('pos');
		actb_penter();
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_timeOut);
	}
	function actb_table_highlight(){
		actb_mouse_on_list = 1;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
		actb_pos = this.getAttribute('pos');
		while (actb_pos < actb_rangeu) actb_moveup();
		while (actb_pos > actb_ranged) actb_mousedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_timeOut);
	}
	/* ---- */

	function actb_insertword(a){
		if (actb_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					str += a;
					l = str.length;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
			actb_curr.value = str;
			setCaret(actb_curr,l);
		}else{
			actb_curr.value = a;
		}
		actb_mouse_on_list = 0;
		actb_removedisp();
	}
	function actb_penter(){

		if (err == 'bookerSearch' || err == 'guestSearch') {
			console.log('testing = '+err);
			if (actb_pos <= 0) {
				actb_pos = 1;
			}
		} else {
			if (actb_pos <= 0) {
				actb_insertword(actb_curr.value);
				return;
			}
		}

		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		for (key in actb_keywords) {
			if (!actb_keywords.hasOwnProperty(key)) continue;
			if (actb_bool[key]) c++;
			if (c == actb_pos){
				word = key;
				break;
			}
		}
		actb_insertword(word);
	}
	function actb_removedisp(){
		if (!actb_mouse_on_list){
			actb_display = false;
			if (document.getElementById('tat_table'))  { document.body.removeChild(document.getElementById('tat_table')); }
			if (document.getElementById('tat_iframe')) { document.body.removeChild(document.getElementById('tat_iframe')); }
			if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(){
		return !actb_caretmove;
	}
	function actb_checkkey(evt){
		if (!evt) evt = event;
		a = evt.keyCode;
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = 0;
		switch (a){
			case 38:
				actb_goup();
				actb_caretmove = 1;
				return false;
				break;
			case 40:
				actb_godown();
				actb_caretmove = 1;
				return false;
				break;
			case 13: case 9:
				actb_penter();
				actb_caretmove = 1;
				return false;
				break;
			default:
				setTimeout(function(){actb_tocomplete(a)},50);
				break;
		}
	}

	function actb_tocomplete(kc){
		if (kc == 38 || kc == 40 || kc == 13) return;
		var i;
		if (actb_display){
			var word = 0;
			var c = 0;
			for (key in actb_keywords) {
				if (!actb_keywords.hasOwnProperty(key)) continue;
				if (actb_bool[key]) c++;
				if (c == actb_pos){
					word = actb_keywords[key];
					break;
				}
			}
			actb_pre = word;
		}
		else {
			actb_pre = -1;
			//(AJP comment out no ccs element pressSearch) document.getElementById(err).style.visibility="hidden"; // Hide the error text
			//(AJP comment out no ccs element pressSearch) document.getElementById(err).style.display="none";
		}

		if (actb_curr.value == ''){
			actb_mouse_on_list = 0;
			actb_removedisp();
			return;
		}
		if (actb_delimiter.length > 0){
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);

			delim_split = '';
			for (i=0;i<actb_delimiter.length;i++){
				delim_split += actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}else{
			var t = actb_curr.value.addslashes();
		}
		if (actb_firstText){
			// Check whether the text entered matches the start of any of the words in the list
			var re = new RegExp("^(.+ )*" + t, "i");
		}else{
			// Check whether the text entered matches the start of any of the words in the list
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
		actb_kwcount = 0;
		for (key in actb_keywords) {
			if (!actb_keywords.hasOwnProperty(key)) continue;
			actb_bool[key] = false;
			if (re.test(key)){
				actb_total++;
				actb_bool[key] = true;
				actb_kwcount++;
				if (actb_pre == actb_keywords[key]) actb_tomake = true;
			}
		}
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_timeOut);
		actb_generate();
	}


}

//<!--
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4,
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater")
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // 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;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 ||
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);
    var is_aix2  = (agt.indexOf("aix 2") !=-1);
    var is_aix3  = (agt.indexOf("aix 3") !=-1);
    var is_aix4  = (agt.indexOf("aix 4") !=-1);
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1);
    var is_mpras    = (agt.indexOf("ncr")!=-1);
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant ||
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

