//POPUP Emailheader:
var bbcodeswindow_x = 340;
var bbcodeswindow_y = 340;

function fillfield() {
    document.theform.betreff.value = document.theform.schnellbetreff.value;
}

// ToolTip JavaScript Code
function TX_getScrollPos() {
   if (document.body.scrollTop != undefined && navigator.appName.indexOf("Explorer") != -1 ) {
      var res = (document.compatMode != "CSS1Compat") ? document.body : document.documentElement;
      return {x : res.scrollLeft, y : res.scrollTop};
   }
   else {
      return {x : window.pageXOffset, y : window.pageYOffset};
   }

}


//Zeige Bild:
function zeigeBild(sel,alt) {
	document.minibild.src = "" + sel.options[sel.selectedIndex].value;
	document.minibild.alt = "" + sel.options[sel.selectedIndex].value;
}


function TX_showToolTip(e, text) {
	var scr = TX_getScrollPos();
	var cordX = e.clientX + scr.x;
	var cordY = e.clientY + scr.y;
	var correctorY = e.clientY + document.getElementById("tooltip").offsetHeight + 20 - window.innerHeight;

	document.getElementById("tooltip").style.visibility = "hidden";
	document.getElementById("tooltip").innerHTML = text;
	document.getElementById("tooltip").style.position = "absolute";
	document.getElementById("tooltip").style.left = ( cordX + 10 ) + "px";

	if ( correctorY > 0 ) {
		document.getElementById("tooltip").style.top = ( cordY - correctorY ) + "px";
	} else {
		document.getElementById("tooltip").style.top = ( cordY + 10 ) + "px";
	}

	document.getElementById("tooltip").style.visibility = "visible";
}

function TX_hideToolTip() {
	document.getElementById("tooltip").style.visibility = "hidden";
	document.getElementById("tooltip").innerHTML = "false";	
}

function selectAll() {
	theForm = document.getElementById("deleteForm")
	for (i = 0; i < theForm.elements.length; i++) {
		theForm.elements[i].checked = checkAll
	}
	checkAll = (checkAll) ? false : true
}

function checkAll() {
for (var j = 1; j <= 14; j++) {
box = eval("document.checkboxform.delmsg[]"); 
if (box.checked == false) box.checked = true;
   }
}

function uncheckAll() {
for (var j = 1; j <= 14; j++) {
box = eval("document.checkboxform.delmsg[]"); 
if (box.checked == true) box.checked = false;
   }
}

function copykundenummer(wert)
{
	getActiveText();
	var Addwert = ""+wert+"";
	theform.textout.value = wert;
	//AddText(wert);
}

function copyticketnr(wert)
{
	getActiveText();
	var Addwert = ""+wert+"";
	theformticket.ticketid.value = wert;
	//AddText(wert);
}

//NICHTS &Auml;NDERN AB HIER!
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_regexp = (window.RegExp) ? true : false;


function getActiveText(){
	setfocus();
	if ((is_ie && !document.selection) || !document.selection)
	{
		return false;
	}

	var sel = document.selection;
	var rng = sel.createRange();

	if (rng != null && (sel.type == "Text" || sel.type == "None"))
	{
		text = rng.text;
	}
	if (rng != null && theform.textout.createTextRange)
	{
		theform.textout.caretPos = rng.duplicate();
	}
	return true;
}


function AddText(NewCode) {
	if (typeof(theform.textout.createTextRange) != "undefined" && theform.textout.caretPos)
	{
		var caretPos = theform.textout.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ''? NewCode +'' : NewCode;
		caretPos.select();
	}
	else if (theform.textout.selectionStart || theform.textout.selectionStart == '0')
	{ // its mozilla and we'll need to re-write entire text
		delete textout;
		var start_selection = theform.textout.selectionStart;
		var end_selection = theform.textout.selectionEnd;

		// fetch everything from start of text area to selection start
		var start = (theform.textout.value).substring(0, start_selection);
		// fetch everything from start of selection to end of selection
		var middle = NewCode;
		// fetch everything from end of selection to end of text area
		var end = (theform.textout.value).substring(end_selection, theform.textout.textLength);
		
		theform.textout.value = middle;
		setfocus();
		theform.textout.selectionStart = end_selection + middle.length;
		theform.textout.selectionEnd = start_selection + middle.length;
		getActiveText();
		AddTxt = "";
		return;
	}
	else
	{
		theform.textout.value = NewCode;
	}
	setfocus();
	getActiveText();
	AddTxt = "";
}


function setfocus()
{
	theform.textout.focus();
}


function alter_box_height(boxid, pixelvalue)
{
	var box = fetch_object(boxid);
	var boxheight = parseInt(box.style.height);
	var newheight = boxheight + pixelvalue;
	if (newheight > 0)
	{
		box.style.height = newheight + "px";
	}
	return false;
}




//TextCounter Textarea
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}

//Smilie POPUP START:
var gibmemysmiliewindow_x = 320;
var gibmemysmiliewindow_y = 280;

function open_gibmemysmilie_window(x_width, y_width, wysiwyg, forumid)
{
		window.open("user-pn_smilie_show.php", "smilies", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + x_width + ",height=" + y_width);
}
//Smilie POPUP END:


//BBCodes POPUP START:
var bbcodeswindow_x = 340;
var bbcodeswindow_y = 340;

function open_bbcodes_window(x_width, y_width, wysiwyg, forumid)
{
		window.open("user-pn_bbcodes_show.php", "BBCodes", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + x_width + ",height=" + y_width);
}
//BBCodes POPUP END:





function gibmemysmilie(thesmilie)
{
	getActiveText2();
	var AddSmilie = " " + thesmilie + " ";
	AddText2(AddSmilie);
}




function alter_box_height(boxid, pixelvalue)
{
	var box = fetch_object(boxid);
	var boxheight = parseInt(box.style.height);
	var newheight = boxheight + pixelvalue;
	if (newheight > 0)
	{
		box.style.height = newheight + "px";
	}
	return false;
}


function fillfield() {
document.theform.touser.value = document.theform.adressen.value;
}


function waitclose(sek){
				setTimeout('parent.window.close();',sek*1000);
}

function emoticon(smiliecode)
{
document.messageform.message.value += smiliecode;
}

function checkAll() {
for (var j = 1; j <= 14; j++) {
box = eval("document.checkboxform.delmsg[]"); 
if (box.checked == false) box.checked = true;
   }
}

function uncheckAll() {
for (var j = 1; j <= 14; j++) {
box = eval("document.checkboxform.delmsg[]"); 
if (box.checked == true) box.checked = false;
   }
}


function getActiveText2()
{
	setfocus();
	if ((is_ie && !document.selection) || !document.selection)
	{
		return false;
	}

	var sel = document.selection;
	var rng = sel.createRange();

	if (rng != null && (sel.type == "Text" || sel.type == "None"))
	{
		text = rng.text;
	}
	if (rng != null && theform.textout.createTextRange)
	{
		theform.textout.caretPos = rng.duplicate();
	}
	return true;
}


function AddText2(NewCode)
{
	if (typeof(theform.textout.createTextRange) != "undefined" && theform.textout.caretPos)
	{
		var caretPos = theform.textout.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
		caretPos.select();
	}
	else if (theform.textout.selectionStart || theform.textout.selectionStart == '0')
	{ // its mozilla and we'll need to re-write entire text
		var start_selection = theform.textout.selectionStart;
		var end_selection = theform.textout.selectionEnd;

		// fetch everything from start of text area to selection start
		var start = (theform.textout.value).substring(0, start_selection);
		// fetch everything from start of selection to end of selection
		var middle = NewCode;
		// fetch everything from end of selection to end of text area
		var end = (theform.textout.value).substring(end_selection, theform.textout.textLength);

		theform.textout.value = start + middle + end;
		setfocus();
		theform.textout.selectionStart = end_selection + middle.length;
		theform.textout.selectionEnd = start_selection + middle.length;
		getActiveText();
		AddTxt = "";
		return;
	}
	else
	{
		theform.textout.value += NewCode;
	}
	setfocus();
	getActiveText2();
	AddTxt = "";
}




var xmlHttpObject = false;

if (typeof XMLHttpRequest != 'undefined') 
{
    xmlHttpObject = new XMLHttpRequest();
}
if (!xmlHttpObject) 
{
    try 
    {
        xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) 
    {
        try 
        {
            xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) 
        {
            xmlHttpObject = null;
        }
    }
}


function submitForm()
{ 
	var wert1 = document.theform.touser.value;	
	Write(wert1);
}

function Write(wert1)	// url is the script and data is a string of parameters
{ 
	var wert4 = 'checkuser';
	xmlHttpObject.open("POST", "user-pn-helper.php", true);
	xmlHttpObject.onreadystatechange = function() { loadContenttime(wert4); };
	xmlHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttpObject.send('show=checkuser&why='+wert1+'&wert4='+wert4); 
} 

function loadContenttime(wert4)
{	
	document.getElementById('box'+wert4).innerHTML = '<br>&Uuml;berpr&uuml;fe ob User vorhanden ist<br>';
	
	setTimeout(function () { handleContentPOST(wert4); }, 1000);
}



function showdetails(wert1)
{
    xmlHttpObject.open('get','user-pn-helper.php?show=show_NLPunkteLetter&art='+wert1+'',true);
    xmlHttpObject.onreadystatechange = function() { handleContentPOST(wert1); };
    xmlHttpObject.send(null);
    return false;
}


function show_NLPunkteLetter(wert4)
{
	xmlHttpObject.open("POST", "user-pn-helper.php", true);
	xmlHttpObject.onreadystatechange = function() { handleContentPOST(wert4); };
	xmlHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttpObject.send('show=&&id='+wert4); 
}



function submitFormTrans(an,von)
{ 
	var wert = document.theform.wert.value;
	var betreff = document.theform.betreff.value;
	
	WriteTrans(wert,betreff,an,von);
}

function WriteTrans(wert,betreff,an,von)	// url is the script and data is a string of parameters
{ 	
	var wert4 = an;
	xmlHttpObject.open("POST", "user-pn-helper.php", true);
	xmlHttpObject.onreadystatechange = function() { handleContentPOST(wert4); };
	xmlHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttpObject.send('show=trans&wert='+wert+'&betreff='+betreff+'&an='+an+'&von='+von); 
} 

function handleContentPOST(wert4)
{

	
	if (xmlHttpObject.readyState == 3)
	{ 
		document.getElementById('box'+wert4).innerHTML = '<br>&Uuml;berpr&uuml;fe ob User vorhanden ist...<br>';;
	} 
	
    if (xmlHttpObject.readyState == 4)
    {
		
        document.getElementById('box'+wert4).innerHTML = xmlHttpObject.responseText;
    }
}