var w3c = (document.getElementById) ? true : false;
var ns4 = (document.layers && !w3c) ? true : false;
var ie = (document.all) ? true : false;
var ie4 = (ie && !w3c) ? true : false;
var opera = (window.opera) ? true : false;

function resizePopup(popupWindow, popupWidth, popupHeight) {

   if (popupWidth > screen.width) { popupWidth = screen.width; }
   if (popupHeight > screen.height) { popupHeight = screen.height; }
   var offsetX = Math.round((screen.width - popupWidth) / 2);
   var offsetY = Math.round((screen.height - popupHeight) / 2);
   popupWindow.moveTo(offsetX, offsetY);
   popupWindow.resizeTo(popupWidth, popupHeight);
}

function UBS_refreshImage( id )
{
	if ( id && document[id] ) // ie bug: refresh image
	{
		var image = document[id].src;
		document[id].src = image;
	}
}

function UBS_openWindow( url, name, width, height, toCenter, resizable )
{
	function getCenterPos( type, winSize, scrDefault )
	{
		if (!winSize) return "";
		
		var scrSize = (screen[type]) ? screen[type] : scrDefault;
		var winPos  = (scrSize - winSize)/2;
		
		return (type=="width") ? ",screenX="+winPos+",left="+winPos : ",screenY="+winPos+",top="+winPos;
	}
	
	var pars = "dependent=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes";
	
	if ( resizable ) {
		pars += ",resizable="+resizable;
	} else {
		pars += ",resizable=yes";
	}
	
	if ( width ) pars += ",width="+width;
	if ( height ) pars += ",height="+height;
	
	if ( toCenter )
	{
		pars += getCenterPos("width",width,800);
		pars += getCenterPos("height",height,600);
	}
	
	var w = window.open(url, name, pars);
	w.focus();
}

// keep UBS_open() for compatibility reasons
function UBS_open( url, pars, name )
{
	var w = window.open( url, name, pars );
	w.focus();
}

function UBS_close()
{
	if ( opener ) opener.focus();
	window.close();
}

function UBS_linkToSelected( formname, fieldname )
{
	var form = document.forms[formname];

	if ( form )
	{
		var obj = form[fieldname];
		var url = obj.options[obj.selectedIndex].value;

		if (url!="")
		{
			document.location.href = url;
		}
	}
}

function UBS_search2( formname, fieldname, isSubmit )
{
	var form = document.forms[formname];

	if ( form[fieldname].value != "" && isSubmit )
	{
		var newValue = "";
		if ( form["restrictArea"] )
		{
			newValue = form["restrictArea"].value+":"+form["restrictContent"].value+" || ";
		}
		newValue += form[fieldname].value;
		form["qt"].value = newValue;
		form.submit();
		return true;
	}
	else if ( !isSubmit )
	{
		return form[fieldname].value != "";
	}
}

function UBS_search( formname )
{
	var form = document.forms[formname];
	form.submit();
	return true;
	
}
var UBS_oldImage = "";

function UBS_imageOn( imageId, newImage )
{
	if ( !document.images ) return;
	UBS_oldImage = document.images[ imageId ].src;
	document.images[ imageId ].src = newImage;
}

function UBS_imageOff( imageId )
{
	if ( document.images && UBS_oldImage )
	{
		document.images[ imageId ].src = UBS_oldImage;
		UBS_oldImage = "";
	}
}

function UBS_tweakstatusline(){
	/*
	** IE does not support the default shape of the area element in image maps.
	** By putting the image in a link, the same result can be achieved.   Unfortunately,
	** when the cursor is placed anywhere in the image, IE then displays only the URL
	** of that link in the browser status line.  The following function seems to circum-
	** vent the problem without solving it, wherefore it should be regarded as voodoo.
	*/
	if (ie) {
		status = '';	// Should be set to the URL of the area, but IE wrongly seems to					
					// interpret this as defaultStatus.
		return true;
	}
}

function UBS_displayChart(id, numCharts, activeChart) {
  var maxTabs = numCharts;
  var top;
  if (document.getElementById) {
    for (i = 1; i < maxTabs + 1; i++) {
      top = i * 2;
      if (document.getElementById('chart' + id + '_' + i)) document.getElementById('chart' + id + '_' + i).style.display = 'none';
      if (document.getElementById('tab' + id + '_' + i)) document.getElementById('tab' + id + '_' + i).className = 'tabTitle';
      if (document.getElementById('tablink' + id + '_' + i)) document.getElementById('tablink' + id + '_' + i).className = 'tabTitle';
      if (document.getElementById('tabtop' + id + '_' + (top - 1))) document.getElementById('tabtop' + id + '_' + (top - 1)).className = 'borderTop';
      if (document.getElementById('tabtop' + id + '_' + top)) document.getElementById('tabtop' + id + '_' + top).className = 'borderTop';
      if (document.getElementById('tabtop' + id + '_' + (top + 1))) document.getElementById('tabtop' + id + '_' + (top + 1)).className = 'borderTop';
    }
    top = activeChart * 2;
    if (document.getElementById('chart' + id + '_' + activeChart)) document.getElementById('chart' + id + '_' + activeChart).style.display = 'block';
    if (document.getElementById('tab' + id + '_' + activeChart)) document.getElementById('tab' + id + '_' + activeChart).className = 'tabTitleActive';
    if (document.getElementById('tablink' + id + '_' + activeChart)) document.getElementById('tablink' + id + '_' + activeChart).className = 'tabTitleActive';
    if (document.getElementById('tabtop' + id + '_' + (top - 1))) document.getElementById('tabtop' + id + '_' + (top - 1)).className = 'border';
    if (document.getElementById('tabtop' + id + '_' + top)) document.getElementById('tabtop' + id + '_' + top).className = 'border';
    if (document.getElementById('tabtop' + id + '_' + (top + 1))) document.getElementById('tabtop' + id + '_' + (top + 1)).className = 'border';
  }
}

function redirectToPage(selection) {
   var index = selection.selectedIndex
   var value = selection.options[index].value;
   if (value != "") {
      location.href = value;
   }
}

function UBS_hasFeatureArea() {
	alert(document.getElementsByTagName('DIV')[0]);
	arrayOfDivs = document.getElementsByTagName('div');
	alert(arrayOfDivs.length);
	if (typeof(arrayOfDivs.length) != "undefined") {
		for (var i = 0; i < arrayOfDivs.length; i++) {
			alert (arrayOfDivs[i].getAttribute("class"));
			if (arrayOfDivs[i].getAttribute("class") == "featureArea") {
				alert ("This page has a feature area");
				return true;
			}
		}
	}
	alert ("This page has no feature area");
	return false;
}
