function insert(aTag, eTag, element)
{
	if(element == null)
	{
		element = "bbedit";
	}
	var input = document.getElementById(element);
  	input.focus();
  	/* f&uuml;r Internet Explorer */
  	if(typeof document.selection != 'undefined')
  	{
    		/* Einf&uuml;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&uuml;r neuere auf Gecko basierende Browser */
  	else if(typeof input.selectionStart != 'undefined')
  	{
    		/* Einf&uuml;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&uuml;r die &uuml;brigen Browser */
  	else
  	{
    		/* Abfrage der Einf&uuml;geposition */
    		var pos;
    		var re = new RegExp('^[0-9]{0,3}$');
    		while(!re.test(pos))
    		{
      			pos = prompt("Einf&uuml;gen an Position (0.." + input.value.length + "):", "0");
    		}
    		if(pos > input.value.length)
    		{
	      		pos = input.value.length;
    		}
    		/* Einf&uuml;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);
  	}

  	/* Palette wieder ausblenden */
  	var dialog = document.getElementById('palette');
  	if(dialog.style.visibility == "visible")
    	{
	    	dialog.style.visibility = "hidden";
	}
}

function showDialog(e, name)
{
	var x = e.pageX || window.event.x;
	var y = e.pageY || window.event.y;

    	var dialog = document.getElementById(name);
    	dialog.style.left = x;
    	dialog.style.top = y;

    	if(dialog.style.visibility == "visible")
    	{
    		dialog.style.visibility = "hidden";
    	}
    	else
    	{
    		dialog.style.visibility = "visible";
    	}
}

function showPreview()
{
	var input = document.getElementById("bbedit");
        window.open("parts/editor/vorschau.php?txt="+encodeURIComponent(input.value), "Vorschau","width=800,height=600,scrollbars=yes");
}



/***************************************************************/
/***************************************************************/
/***************************************************************/
/***************************************************************/

function getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight)
	{ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight)
	{ // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function getScrollPosition()
{
	if(window.pageYOffset)
	{
		return window.pageYOffset;
	}
	else if(document.body.scrollTop)
	{
		return document.body.scrollTop;
	}
	else
	{
		return 0;
	}
}


function showPhoto(pfad, comment, j)
{

	document.getElementById("innerbigphoto").innerHTML = "<table class=\"lightboxnavi\"><tr><td align=\"left\"><a href=\"javascript:prevPhoto("+j+")\"><img src=\"img/prev.png\"></a></td><td align=\"center\"><a href=\"javascript:closePhoto()\"><img src=\"img/close.png\"></a></td><td align=\"right\"><a href=\"javascript:nextPhoto("+j+")\"><img src=\"img/next.png\"></a></td></tr></table><br><img src=\""+pfad+"\" class=\"foto\"><br><br>"+comment;

	document.getElementById("bigphoto").style.display = "block";
	document.getElementById("bigphoto").style.top = getScrollPosition();

	document.getElementById("overlay").style.display = "block";
	document.getElementById("innerbigphoto").style.display = "block";

	document.getElementById("j").value = j;
}

function closePhoto()
{
	document.getElementById("innerbigphoto").innerHTML = "";
	document.getElementById("bigphoto").style.display = "none";
	document.getElementById("overlay").style.display = "none";
	document.getElementById("innerbigphoto").style.display = "none";
}


function nextPhoto(j)
{
	var pfad = "";
	var comment = "";
	j += 1;
	if(j > image_count-1)
	{
		j = 0;
	}
	document.getElementById("j").value = j;

	var pfad = image_array[j];
	var comment = text_array[j];

	document.getElementById("innerbigphoto").innerHTML = "<table class=\"lightboxnavi\"><tr><td align=\"left\"><a href=\"javascript:prevPhoto("+j+")\"><img src=\"img/prev.png\"></a></td><td align=\"center\"><a href=\"javascript:closePhoto()\"><img src=\"img/close.png\"></a></td><td align=\"right\"><a href=\"javascript:nextPhoto("+j+")\"><img src=\"img/next.png\"></a></td></tr></table><br><img src=\""+pfad+"\" class=\"foto\"><br><br>"+comment;
}

function prevPhoto(j)
{
	var pfad = "";
	var comment = "";
	j -= 1;
	if(j < 0)
	{
		j = image_count-1;
	}
	document.getElementById("j").value = j;

	var pfad = image_array[j];
	var comment = text_array[j];

	document.getElementById("innerbigphoto").innerHTML = "<table class=\"lightboxnavi\"><tr><td align=\"left\"><a href=\"javascript:prevPhoto("+j+")\"><img src=\"img/prev.png\"></a></td><td align=\"center\"><a href=\"javascript:closePhoto()\"><img src=\"img/close.png\"></a></td><td align=\"right\"><a href=\"javascript:nextPhoto("+j+")\"><img src=\"img/next.png\"></a></td></tr></table><br><img src=\""+pfad+"\" class=\"foto\"><br><br>"+comment;
}
