function isBrowser(sBrowser, sPlatform){
	var b=navigator.appName;
		if(b=='Netscape'){b='ns'}
	var ver=navigator.appVersion;
	var ua=navigator.userAgent.toLowerCase();
	var bResult=false;
	var bBrowser=false;
	var bPlatform=false;
	switch(sBrowser){
		case 'any':
			bBrowser = true;
			break;
		case 'ie3':
			bBrowser = ver.indexOf('MSIE 3')>0;
			break;
		case 'ie4':
			bBrowser = ver.indexOf('MSIE 4')>0;
			break;
		case 'ie45':
			break;
		case 'ie5':
			bBrowser = ver.indexOf('MSIE 5')>0;
			break;
		case 'ie55':
			bBrowser = ver.indexOf('MSIE 5.5')>0;
			break;
		case 'ie6':
			bBrowser = ver.indexOf('MSIE 6')>0;
			break;
		case 'ie':
			bBrowser = ver.indexOf('MSIE')>0;
			break;
		case 'dom':
			bBrowser = (document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
			break;
		case 'ns2':
			bBrowser = ((b=='ns')&&(ver==2));
			break;
		case 'ns3':
			bBrowser = ((b=='ns')&&(ver==3));
			break;
		case 'ns4':
			bBrowser = ((b=='ns')&&(ver.indexOf('4.')>-1));
			break;
		case 'ns6':
			bBrowser = ((b=='ns')&&(ver.indexOf('5.')>-1));
			break;
	}

	switch(sPlatform){
		case 'any' :
			bPlatform = true;
			break;
		case 'win' :
			bPlatform = (ua.indexOf('win')>-1);
			break;
		case 'mac' :
			bPlatform = (ua.indexOf('mac')>-1);
			break
	}
	bResult=(bPlatform && bBrowser);
	return(bResult);
}

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"
		}
	]

};

function PageQuery(q) {
				if(q.length > 1) this.q = q.substring(1, q.length);
				else this.q = null;

				this.keyValuePairs = new Array();
				if(q) {
					for(var i=0; i < this.q.split("&").length; i++) {
						this.keyValuePairs[i] = this.q.split("&")[i];
					}
				}

				this.getKeyValuePairs = function() { return this.keyValuePairs; }
				this.getValue = function(s) {
					for(var j=0; j < this.keyValuePairs.length; j++) {
						if(this.keyValuePairs[j].split("=")[0] == s)
							return this.keyValuePairs[j].split("=")[1];
					}
					return false;
				}
				this.getParameters = function() {
					var a = new Array(this.getLength());
					for(var j=0; j < this.keyValuePairs.length; j++) {
						a[j] = this.keyValuePairs[j].split("=")[0];
					}
					return a;
				}
				this.getLength = function() { return this.keyValuePairs.length; }
			}


function lessThan(val1, val2){
	///alert('lt');
	return(val1 < val2);
}

function greaterThan(val1, val2){
	return(val1 > val2);
}

function GetQueryStringValue(sKey,sDefault){
	var sSearch = window.location.search;
	
	var ret = sDefault;
	
	var re = new RegExp("[\?\&]" + sKey + "=([^\&]+)", "i");
	
	var match = re.exec(sSearch);
	
	if (match)
		ret = match[1];
	
	return(ret);
}

function GotoModuleSummaryPage(page){
	// need to resubmit back to same page but with page setting changed...

	alert('goto page ' + page + ' : ' + window.location);
}


function swapImage(image,name){
		document.images[name].src = image;
}

function findFormElements(sStartingWith){
	oElement = null;
	aResults = new Array();
	
	if(document.all){
		for (var i=0;i<document.all.length;i++){
			oElement = document.all[i];
			
			if(oElement.id.indexOf(sStartingWith) == 0){
				aResults[aResults.length] = oElement.id;
			}
		}
	} else {
		//alert ('genericGetElementByID : elements : ' + sElementName) ;
		for (var j=0;j<document.forms.length;j++){
			for (var k=0;k<document.forms[j].length;k++){
				oTemp = document.forms[j].elements[k];
				if (oTemp.name.indexOf(sStartingWith) == 0){
					aResults[aResults.length] = oTemp.name;
				}
			}
		}
	}
	
	return(aResults);
}

function genericGetElementByID(sElementName){
	var oResult = null;
	var oTemp = null ;

	if(sElementName.indexOf('~') >= 0){
		//alert('DONT get element ' + sElementName);
	} else {
		//alert('get element ' + sElementName);
		
		if(document.all){
			oResult = eval('document.all.' + sElementName);
			//alert ('genericGetElementByID : all : ' + sElementName) ;
		} else {
			//alert ('genericGetElementByID : elements : ' + sElementName) ;
			for (var j=0;j<document.forms.length;j++){
				for (var i=0;i<document.forms[j].length;i++){
					oTemp = document.forms[j].elements[i];
					if (oTemp.name == sElementName){
						oResult = oTemp ;
					}
				}
			}
		}
	}
	//alert('get element ' + sElementName + ' ' + oResult.name);
	return(oResult);
}

function genericGetElementValue(oElement){
	var sValue = '';
	
	var sElementType=String(oElement.type);
	
	if(sElementType=='undefined'){
		//Check if it is a radio button, as the type property is on the array elements
		if(oElement[0]) sElementType=String(oElement[0].type);
	}
	
	//alert(oElement.getAttribute("name") +  " " + oElement + " [" + sElementType + "]");
	
	if(document.all){
		switch (sElementType){
			case 'checkbox'	:
				sValue = String(oElement.checked);
				
				if(sValue != 'true'){
					sValue = '';
				}			
				break;
			case 'radio'	:
				for (i=0;i<oElement.length;i++){
					//alert(oElement.value);
					if (oElement[i].checked){
						sValue = oElement[i].value;
					}
				}			
				break;
			
			case 'select-one'	:

				if(oElement.options.length > 0) {
					sValue = oElement.options[oElement.options.selectedIndex].value;
				}
				
				break;
				
			default	:
				sValue = oElement.value;			
				break;
		}		
	} else {
		// The value is obtained differently depending on the element type
		switch (sElementType){
			case 'text' :
			case 'edit' :
			case 'textarea' :
			case 'hidden' :
				sValue = oElement.value ;
				break ;
				
			case 'select-one':
				if(oElement.options.length > 0) {
					sValue = oElement.options[oElement.selectedIndex].value ;
				}
				break;
				
			case 'radio' :
				/*

				alert(oElement.length);
				for (i=0;i<oElement.length;i++){
					if (oElement[i].checked){
						sValue = oElement[i].value;
					}
				}
				*/
				sValue = "" ;
				
				var idOrName = oElement.getAttribute("name");
				var element = document.getElementById(idOrName);
				var radioGroupName = null;  

				// if null, then the id must be the radio group name

				if (element == null) {
					radioGroupName = idOrName;
				} else {
					radioGroupName = element.name;  
				}

				if (radioGroupName == null)

				return null;    

				var radios = document.getElementsByTagName('input');

				for (var i=0; i<radios.length; i++) {
					var input = radios[ i ]; 
					if (input.type == 'radio' && input.name == radioGroupName && input.checked) {        
						sValue = input.value;
						break;
					}

				}	
				
				break ;
				
			default :
				sValue = oElement.value ;
				break;
		}
		//alert ('genericGetElementValue : ' + oElement.type + ' : ' + oElement.name + ' - ' + sValue) ;
	}
	return(sValue);
}

function openPopup(url){
	w = 800;
	h = 600;
	
	// AA - don't know what document.layers is supposed to be doing, in certain times it's reported undefined.
	try
	{
		if (document.all || document.layers) 
		{
			w = screen.availWidth;
			h = screen.availHeight;
		}
	} catch (e){
	}
	
	try {				
		
	//var leftPos = (popW)/2, topPos = (popH)/2;  // <--- this is for center screen
		var leftPos = 0, topPos = 0;
					
		window.open(url,'popup','width=' + w + ',height=' + h + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=1');
		window.opener = self;
		
		} catch (e){
	}
	
	return false;
}

function openPopupWithFeatures(url, left, top, width, height, resizable, chromeOnOff) {
	
	var popupOptions = '';

	// Add options for left, top, width or height (ignoring any non-numeric and zero values)
	if(!isNaN(left) && left > 0) {
		popupOptions += 'left=' + left;
	}
	
	if(!isNaN(top) && top > 0) {
		if(popupOptions.length > 0) {
			popupOptions += ',';
		}
		popupOptions += 'top=' + top;
	}

	if(!isNaN(width) && width > 0) {
		if(popupOptions.length > 0) {
			popupOptions += ',';
		}
		popupOptions += 'width=' + width;
	}

	if(!isNaN(height) && height > 0) {
		if(popupOptions.length > 0) {
			popupOptions += ',';
		}
		popupOptions += 'height=' + height;
	}

	if(popupOptions.length > 0) {
		popupOptions += ',';
	}

	if(chromeOnOff == 'off') {
		popupOptions += 'titlebar=no,statusbar=no,menubar=no,scrollbars=no';
	} else {
		popupOptions += 'titlebar=yes,statusbar=yes,menubar=yes,scrollbars=yes';
	}

	popupOptions += ',resizable=' + resizable;
	
	try {				
		window.open(url, 'popup', popupOptions);
		window.opener = self;
	} catch (e) {
	}
	
	return false;
}


function selectAll(){
	checkboxes = findFormElements("check");
	alert('select all ' + checkboxes.length + ' found');
	
	for (i=0;i<checkboxes.length;i++){
		alert(checkboxes[i].id + ' ' + checkboxes[i].checked);
		checkboxes[i].checked = true;
	}
}

function unSelectAll(){
	checkboxes = findFormElements("check");
	alert('unselect all ' + checkboxes.length + ' found');	
	
	for (i=0;i<checkboxes.length;i++){
		checkboxes[i].checked = false;
	}
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	var form = document.forms[FormName];
	
	for (var i=0;i < form.length;i++){
		field = form.elements[i];
		
		if(field.type = 'checkbox'){
			field.checked = CheckValue;
		}
	}
}


function popupWindow(link){
	//alert(link.href);
	window.open(link.href)
}

function openWindow(link){
	window.open(link.href);
}



function interrogate(what) {
	var output = '';
	for (var i in what)
		output += i+ '\n';
	alert(output);
}

//alert(openWindow);