/* Preload Images */
function preload() {
	if(document.images)
	{
		picture2 = new Image();
		picture2.src = "include/loading.png";
	}
}

/* Loginpanel */
function showPanel(e) {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	id ='login-panel';
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.left = (e.clientX-400+scrOfX) + "px";
      obj.style.top = (e.clientY+10+scrOfY) + "px";
      obj.style.display = "block";
	id ='name';
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.focus();
	return false;
}

function hidePanel(e) {
	id ='login-panel';
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.display = 'none';
}

/* Loading */
function showLoading() {
	id="loadingbox"; 
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.display = 'block';
	window.scrollTo(0,0);
}

function hideLoading() {
	id="loadingbox"; 
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.display = 'none';
}

/* Show and hide Objects */
function showObj(id) {
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.display = 'block';
}

function hideObj(id) {
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.display = 'none';
}

function showhideObj(id) {
	obj = (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null))); 
	obj.style.display = (obj.style.display == 'block'?'none':'block');
}

/* http://www.kryogenix.org/code/browser/searchhi/ */
function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			klasse = "searchword"+w; // different colors for differnt searchterms

			if (pn.className != klasse) {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("em"); // modified from span to em
				hiword.className = klasse;
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function Highlight(wordstring) {
	var words = wordstring.split(" ");
	for (w=0;w<words.length;w++) {
		if (words[w].length >= 3) {
		    highlightWord(document.getElementsByTagName("body")[0],words[w]);
		}
      }
}

/* post.php */
function add(zeichen)
{
	var area = document.getElementById('text');
	area.focus();
	if (document.selection) 
	{
		sel = document.selection.createRange();
		sel.text = zeichen;
		sel.select(); 
	}
	else if (area.selectionStart || area.selectionStart == '0') 
	{
		var pos = area.selectionStart + zeichen.length;
		area.value = area.value.substring(0, area.selectionStart) + zeichen + area.value.substring(area.selectionEnd, area.value.length);
		area.selectionStart = pos;
		area.selectionEnd = pos; 
	}
	else 
	{
		area.value += zeichen;
	}
	showChars();
}

function addsel(text1, text2)
{
	var area = document.getElementById('text');
	area.focus();
	if (document.selection) 
	{
		var sel = document.selection.createRange();
		var insText = sel.text;
		sel.text = text1 + sel.text + text2;
		if (insText.length == 0) 
		{
			sel.move('character', -text2.length); 
		} 
		else if (false)
		{ 
			sel.moveStart('character', text1.length + insText.length + text2.length); 
		} 
		sel.select(); 
	}
	else if (area.selectionStart || area.selectionStart == '0') 
	{
		var start = area.selectionStart; 
		var end = area.selectionEnd; 
		var insText = area.value.substring(start, end); 
		area.value = area.value.substr(0, start) + text1 + insText + text2 + area.value.substr(end); 
		var pos; 
		if (insText.length == 0) 
		{
			pos = start + text1.length; 
		} 
		else 
		{ 
			pos = start + text1.length + insText.length + text2.length; 
		} 
		area.selectionStart = pos; 
		area.selectionEnd = pos; 
	}
	else 
	{
		area.value = area.value + text1 + text2;
	}
	area.focus();
	showChars();
}

function showChars() 
{
	var form = document.forms["post"];
	var content = form.text.value;
	var chars = max_chars - content.length;
	if (chars < 0) 
	{
		form.text.value = content.substring(0, max_chars);
		chars = 0;
	}
	form.viewer.value = chars;
}

function popimg(url,title,width,height)
{
	F = open('',"popimg","width=" + width + " ,height=" + height + " ,screenX=0,screenY=0,scrollbars=1");
	F.resizeTo(width,height);
	F.document.open();
	F.document.writeln('<html><head><title>'+title+'</title></head><body bgcolor=#FFFFFF style="margin:0px;"><center><img src="'+url+'" border="0" /></center></html>');
	F.document.close();
	F.focus();
}
