//<!-- provides Functionality needed for opening a Popup-Window -->
function openGroupComposition() {
	window.open("","groupComposition","width=500,height=340,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,hscroll=no, resizable=no,copyhistory=no");
}

function openShowMeteringCode() {
	window.open("","showMeteringCode","width=500,height=180,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,hscroll=no, resizable=no,copyhistory=no");
}

/* enlarge/reduce font sizes. Sebastian Lisken. Tested for IE and gecko. */

function changeFontSizeById (targetID, increment)
{
  if (! document.getElementById) return;
  var rootNode = document.getElementById(targetID);
  if (rootNode != null) {
    changeFontSize(rootNode, increment);
  }
}

function changeFontSizesByTagName (tagName, increment)
{
  if (! document.getElementById) return;
  var rootNodes = document.getElementsByTagName(tagName);
  if (rootNodes != null) {
    for (var i = 0; i < rootNodes.length; ++i) {
      changeFontSize(rootNodes[i], increment);
    }
  }
}

function changeDocumentFontSize (increment)
{
  changeFontSize(document.getElementsByTagName('body')[0], increment);
}

function changeFontSize (element, increment)
{
  var factor = Math.pow(2, increment);
  var oldSize = getFontSize(element), newSize;
  if (oldSize == null) {
    newSize = round(factor * 100, 0.01) + "%";
  } else {
    newSize = round(oldSize.value * factor, 0.01) + '' + oldSize.unit;
  }
  element.style.fontSize = newSize;
}

function getStyle (element, cssProperty)
{
  var value;
  if (document.defaultView && document.defaultView.getComputedStyle) {
    cssProperty = cssProperty.replace(/[A-Z]/g, function (match) 
      { 
        return "-" + match.toLowerCase(); 
      } 
    );
    value = document.defaultView.getComputedStyle(element, '').getPropertyValue(cssProperty);
  } else if (element.currentStyle) {
    value = element.currentStyle[cssProperty];
  } else {
    value = null;
  }
  return value;
}

/*
  named font sizes and their approximate translation into percentages.
  http://www.w3.org/TR/REC-CSS2/fonts.html#font-size-props
*/
var absoluteSizeNames = new Array('xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large');
var relativeSizeNames = new Array('smaller', 'larger');
var namedSizes = { };
var normalSize = "100%", normalSizeIndex = 3, sizeFactor = 1.2;
for (i in absoluteSizeNames)
{
  namedSizes[absoluteSizeNames[i]] = Math.pow(sizeFactor, i - normalSizeIndex) * 100 + "%";
}
namedSizes[relativeSizeNames[0]] = 1 / sizeFactor;
namedSizes[relativeSizeNames[1]] = sizeFactor;
namedSizes[undefined] = namedSizes[null] = namedSizes[''] = normalSize;

function getFontSize (element)
{
  var fontSize = getStyle(element, "fontSize");
  if (fontSize in namedSizes) {
    fontSize = namedSizes[fontSize];
  }
  var tailIndex = fontSize.match(/[^0-9]*$/).index;
  var number = parseFloat(fontSize.substring(0, tailIndex));
  if (isNaN(number)) {
    return null;
  } else {
    return { unit: fontSize.substring(tailIndex), value: number };
  }
}

function round (number, granularity)
{
  return Math.round(number / granularity) * granularity;
}

function MM_jumpMenu(targ,selObj,restore,alertText)
{	
	var targetLink=selObj.options[selObj.selectedIndex].value;
	if (alertText=="undefined" || alertText=="" || alertText=="noAlert") alertText = false;
	if ( targetLink.length > 4) {
		if ( targetLink.substring(0,4) == "http") {
	  		if (!alertText || confirm(alertText) ) {
	    		eval("newWin =window.open('"+targetLink+"', '_new')");
					selObj.options[0].selected=true;
			}
		} else {
			eval("location.href='"+targetLink+"'");
			selObj.options[0].selected=true;
		}
  }
  selObj.selectedIndex=0;
}

function openPictureWindow_Fever(imageName,imageWidth,imageHeight,title,alt) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight);
	newWindow.document.open();
	newWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	newWindow.document.write('<html><title>'+title+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\" title=\"'+alt+'\">');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}


function AutoTrimmer (form) {
	Event.observe($(form), 'submit', function() {
		AutoTrimmer.execute(form);
	});
}

AutoTrimmer.execute = function (form) {
	var trimInput = function (input) {
		input.value = input.value.strip();
	};
	form = $(form);
	form.getInputs('text').each(trimInput);
	form.select('textarea').each(trimInput);
	return true;
}
