/* *****************************************
            STANDARD HELIX JS FILE 
    This file is updated with new releases.
    Avoid editing this file.
   ***************************************** */
// Add the IE6 Menu handler to the onLoad stack
addEvent(window, 'load', ie6menuFix);
// Generic AddEvent Function
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false); 
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	} 
}
/* Progress Bar Functions */
function setupProgBar(id) {
	var bar = document.getElementById(id);
	if (bar) {
		bar.innerHTML = '';
		bar.style.height = '15px';
		bar.style.border = '1px solid red';
		bar.style.padding = '0';
		var meter = document.createElement('div');
		meter.style.height = '100%';
		meter.style.overflow = 'hidden';
		meter.style.backgroundImage = 'url(/images/progBar_bg.gif)';
		meter.style.width = '5%';
		meter.id = id + '_meter';
		bar.appendChild(meter);
		var leftImg = document.createElement('img');
		leftImg.src = '/images/progBar_left.gif';
		leftImg.style.cssFloat = 'left';
		leftImg.style.styleFloat = 'left';
		meter.appendChild(leftImg);
		var rightImg = document.createElement('img');
		rightImg.src = '/images/progBar_right.gif';
		rightImg.style.cssFloat = 'right';
		rightImg.style.styleFloat = 'right';
		meter.appendChild(rightImg);		
		return true;
	} else {
		return false;	
	}	
}
function setProgress(bar, value) {
	var meter = document.getElementById(bar+'_meter');
	if (meter) {
		if (value < 0) value = 0;
		if (value > 100) value = 100;
		meter.style.width = value+'%';
		return true;
	} else {
		return false;	
	}
}
/* Menu fix for IE6 */
function activateMenu(nav) {
	// currentStyle restricts the Javascript to IE only
	var navroot = document.getElementById(nav);  
	if (document.all && navroot && navroot.currentStyle) {          
		// Get all the list items within the menu 
		var lis = navroot.getElementsByTagName("LI");  
		for (i=0; i < lis.length; i++) {		
			// If the LI has another menu level
			if (lis[i].lastChild && (lis[i].lastChild.tagName == "UL")) {
				// assign the function to the LI
				lis[i].onmouseover = function() {					
					this.lastChild.style.display = "block";
				}
				lis[i].onmouseout = function() {                       
					this.lastChild.style.display = "none";
				}
			}
		}	// end for
	}	// end if
}
/* By default, 'dropdownmenu' is a suckerfish menu, needs fixing in IE6 */
function ie6menuFix() {
	// If you want other menus added, add them below or in a seperate JS file add the line
	// addEvent(window, 'load', someFunction);
	// with someFunction being a function like this with a list of menus
    activateMenu('dropdownmenu'); 
}
// Effecient browser detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]
};
BrowserDetect.init();
// Initialises a single thread AJAX object
function initAjax() { 
   var ajax = null;
	if (window.XMLHttpRequest) {
      ajax = new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      ajax = new ActiveXObject("Microsoft.XMLHTTP");
   }
   return ajax;
}
// Make a GET AJAX call. Calling this function again will abort a previous call unless abort is set to false
function ajaxCall(url, callback) {
	//if (typeof(ajax) == "undefined") ajax = initAjax();
	ajax = initAjax();
	if (ajax == null) return;
	
	ajaxCallback = callback;
	ajax.onreadystatechange = callback;
	ajax.open( "GET", url, true );
	ajax.send( null );
}

