/**
 *
 * kreativrot.de
 *
 */

function reverse(text) {
  text = text.split("");
  reversetext = text.reverse();
  reversetext = reversetext.join("");
  return reversetext;
}

function zeve(uid) {
	if (document.getElementById(uid).style.display == 'none')
	{
		document.getElementById(uid).style.display = 'block';
	}
	else
	{
		document.getElementById(uid).style.display = 'none';
	}
}

function ze(uid) {
	document.getElementById(uid).style.display = 'block';
}
function ve(uid)
{
	document.getElementById(uid).style.display = 'none';
}


/**
 * AUTORESIZE TEXTAREA
 */

function autoresize(txtbox) {
    var cols = txtbox.cols ;
    var content = txtbox.value ;
    var lineCount = 3 ;

    var lastEOL = -1 ;
    do {
        var begin = lastEOL+1 ;
        lastEOL = content.indexOf("\n",lastEOL+1) ;
        var line = "" ;
        if(lastEOL != -1) {
            line = content.substring(begin,lastEOL) ;
        } else {
            line = content.substring(begin,content.length) ;
        }
        var rows_in_line = Math.floor(line.length/cols)+1 ;
        lineCount += rows_in_line
    } while (lastEOL != -1) ;
    txtbox.rows = lineCount ;
}


/**
 * SEARCHHILIGHT
 */

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;
			if (pn.className != "searchword") {
				// 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("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}


function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = window.location.href;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p') { // q= for Google, p= for Yahoo
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	                for (w=0;w<words.length;w++) {
				highlightWord(document.getElementById("content_in"),words[w]);
                	}
	        }
	}
}

function start () 
{
   googleSearchHighlight();
}

window.onload = start;


