var zindex=0;
var ids = new Array("addOns","kontakt","popup");
var change;



function showEvent(e){
	
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.fromElement;
alert (e.fromElement);
}

function containsDOM (container, containee)
{
  var isParent = false;
  do
  {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt)
{
  if (element.contains && evt.fromElement)
    return !element.contains(evt.fromElement);
  else if (evt.relatedTarget)
    return !containsDOM(element, evt.relatedTarget);
}

function checkMouseLeave (element, evt)
{
  if (element.contains && evt.toElement)
    return !element.contains(evt.toElement);
  else if (evt.relatedTarget)
    return !containsDOM(element, evt.relatedTarget);
}




function LinkHome(Ziel) {
 	window.opener.location.href = Ziel;
 	window.close();
}

function LinkHomeNoClose(Ziel) {
 	window.opener.location.href = Ziel;
}

function LinkHomeConfirm(Ziel,Message){
Check = confirm(Message);
if (Check == true){
  window.opener.location.href = Ziel;
  window.close();
}
}


function Confirm(Ziel,Message){
Check = confirm(Message);
if (Check == true){
  window.location.href = Ziel;
}
}


function ConfirmAjax(url,data,typ,urlPara,Message){
	Check = confirm(Message);
	if(Check == true){
	addRequest(url,data,typ,urlPara);
	}
	doOuterQueue('wait');
}



function einausblenden(id){
	
if('none'!=top.document.getElementById(id).style.display){
	top.document.getElementById(id).style.display='none'; 
	}
else{
	top.document.getElementById(id).style.display='block';
	}
	
}

function ausblenden(id){
	
	top.document.getElementById(id).style.display='none'; 
	
}

function einblenden(id){

	top.document.getElementById(id).style.display='block';

	
}

function changeStatusAjax(url,data,typ,urlPara,id){
	
if('none'!=top.document.getElementById(id).style.display){
	top.document.getElementById(id).style.display='none'; 
	}
else{
	top.document.getElementById(id).style.display='block';
	addRequest(url,data,typ,urlPara);
	doOuterQueue('wait');
	}
	
}


function ConfirmAjaxAndChangeStatus(url,data,typ,urlPara,Message,id){
	Check = confirm(Message);
	if(Check == true){
		
		addRequest(url,data,typ,urlPara);
	
		if('none'!=top.document.getElementById(id).style.display) top.document.getElementById(id).style.display='none'; 
		else top.document.getElementById(id).style.display='block';
	
		doOuterQueue('wait');
	}
		
}



function changeStatus(id){
if('none'!=top.document.getElementById(id).style.display)
top.document.getElementById(id).style.display='none'; 
else top.document.getElementById(id).style.display='block';
}



function movepic(img_name,img_src){
		document[img_name].src=img_src;
}






function hide(id){
document.getElementById(id).style.display='none'; 
}

function goOn(id,pageid)
	{
	for(var i=0; i<=2; i++)
		{
		ids[i] == id ? change = "block" : change = "none";
		top.document.getElementById(ids[i]).style.display = change;
		if(id == 'pic') { addRequest('responseBrowser.php',pageid,'browsePics','','status'); doOuterQueue('browsePicsWait'); }
		if(id == 'doc') { addRequest('responseBrowser.php',pageid,'browseDocs','','status'); doOuterQueue('browseDocsWait'); }
		}
	}

	


function insert(status, tagOpen, tagClose){
	changeStatus(status);
	tag(tagOpen, tagClose, '');
}

function tag(tagOpen, tagClose, sampleText) {
	var txtarea;
	if (top.document.editform) {
		txtarea = top.document.editform.wpTextbox1;
	} else {
		// some alternate form? take the first one we can find
		var areas = top.document.getElementsByTagName('textarea');
		txtarea = areas[0];
	}

	// IE
	if (document.selection  && !is_gecko) {
		var theSelection = top.document.selection.createRange().text;
		if (!theSelection) {
			theSelection=sampleText;
		}
		txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			top.document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			top.document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		if (endPos-startPos) {
			replaced = true;
		}
		var scrollTop = txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if (!myText) {
			myText=sampleText;
		}
		var subst;
		if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
			txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		//set new selection
		if (replaced) {
			var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
			txtarea.selectionStart = cPos;
			txtarea.selectionEnd = cPos;
		} else {
			txtarea.selectionStart = startPos+tagOpen.length;
			txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
		}
		txtarea.scrollTop = scrollTop;

	// All other browsers get no toolbar.
	// There was previously support for a crippled "help"
	// bar, but that caused more problems than it solved.
	}
	// reposition cursor if possible
	if (txtarea.createTextRange) {
		txtarea.caretPos = top.document.selection.createRange().duplicate();
	}
}



function checkmail(mail) {
  var reg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(reg);
  return(regex.test(mail));
}





function encode_utf8(rohtext) {
             // dient der Normalisierung des Zeilenumbruchs
             rohtext = rohtext.replace(/\r\n/g,"\n");
             var utftext = "";
             for(var n=0; n<rohtext.length; n++)
                 {
                 // ermitteln des Unicodes des  aktuellen Zeichens
                var c=rohtext.charCodeAt(n);
                // alle Zeichen von 0-127 => 1byte
                 if (c<128)
                     utftext += String.fromCharCode(c);
                 // alle Zeichen von 127 bis 2047 => 2byte
                 else if((c>127) && (c<2048)) {
                     utftext += String.fromCharCode((c>>6)|192);
                     utftext += String.fromCharCode((c&63)|128);}
                 // alle Zeichen von 2048 bis 66536 => 3byte
                 else {
                     utftext += String.fromCharCode((c>>12)|224);
                     utftext += String.fromCharCode(((c>>6)&63)|128);
                     utftext += String.fromCharCode((c&63)|128);}
                 }
             return utftext;
         }




