function insert(aTag, eTag, formName, elementName) {
  var input = document.forms[formName].elements[elementName];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

function getFormElementValue(formname, elementname) {
		var value = document.getElementsByName(elementname)[0].value;
	return value;		
}

function checkBrowser ()
{
	if (navigator.userAgent.indexOf("Opera")!=-1
    && document.getElementById) type="OP";

	if (document.all) type="IE";	

	if (document.layers) type="NN";
	
	if (!document.all && document.getElementById) type="MO";
	
	return type;
}

function getPageCoords (element) {
     /*var element;
     if (document.all)
       element = document.all[elementId];
     else if (document.getElementById)
       element = document.getElementById(elementId);
     */
	 if (element) {
       var coords = {x: 0, y: 0};
       do {
		if(element.currentStyle)
		{
			if(element.currentStyle.position!='relative')
			{
				coords.x += element.offsetLeft;
				coords.y += element.offsetTop;
			}
		}
		else
		{
			coords.x += element.offsetLeft;
			coords.y += element.offsetTop;
		}

         element = element.offsetParent;
       }
       while (element)
       return coords;
     }
     else
       return null;
    }

function showImagePopup (icon, popupId)
{
	if (checkBrowser() == "IE")
	{
		var coords = getPageCoords(icon);
    	if (coords)
      	{
			posx = parseInt(coords.x) + 16;
			posy = parseInt(coords.y) - parseInt(document.getElementById(popupId).offsetHeight) - 3;
		}
		document.getElementById(popupId).style.posLeft = posx;
		document.getElementById(popupId).style.posTop = posy;
		document.getElementById(popupId).style.visibility = "visible";
	}
	if (checkBrowser() == "MO")
	{
		posx = icon.x;
		posy = icon.y;
		document.getElementById(popupId).style.left = (posx + 16) + "px";
		document.getElementById(popupId).style.top = (posy - document.getElementById(popupId).offsetHeight - 3) + "px";
		document.getElementById(popupId).style.visibility = "visible";
	}
}


function hideImagePopup (id)
{
	document.getElementById(id).style.visibility = "hidden";
}

function showMenuPage (step, pageCount)
{
	document.getElementById("menu_page_" + currentPage).style.display = "none";
	nextPage = currentPage + step;
	if (nextPage < currentPage && nextPage < 1)
	{
		nextPage = 1;
	}
	if (nextPage > currentPage && nextPage > pageCount)
	{
		nextPage = pageCount;
	}
	
	currentPage = nextPage;
	document.getElementById("menu_page_" + currentPage).style.display = "block";
	document.getElementById("menuPageInfo").firstChild.nodeValue = currentPage;
}

