/*<![CDATA[*/
/**
 * functions.js - JavaScript Funktionen für Weigel & Schwarz Präsisionstechnik GmbH
 *
 * Copyright (c) 2006    web4media
 *                       Hendrik Adam und Manuel Busse GbR
 *                       Am Streitacker 15
 *                       D-35586 Wetzlar
 *                       Germany
 *
 *                       Fon: +49 (0)64 41 / 30 97 89 - 1
 *                       Fax: +49 (0)64 41 / 30 97 89 - 6
 *                       Web: www.web4media.com
 *
 * Alle Rechte vorbehalten. Unberechtigte Kopie und Weiter-
 * verwendung nicht gestattet.
 *
 */


function w4m_start()
{
	searchHighlight();
}

function ansicht(typ)
{
	switch (typ)
	{
		case 'druck':	setActiveStyleSheet('Druckversion');
						setTimeout('print()', 1000);
						break;
		case 'screen':
		default:		setActiveStyleSheet('Bildschirm');
	}
}

function w4m_popup(url,name,breite,hoehe,features,posx,posy)
{
	var win;
	win=window.open(url,name,"width=" + breite + ",height=" + hoehe + "," + features + "");
	if(!posx)
		x=(screen.width-breite)/2;
	else
		x = posx;
	if(!posy)
		y=(screen.height-hoehe)/2;
	else
		y = posy;
	win.moveTo(x,y);
	win.focus();
}

function w4m_resetfontsizeimg()
{
	imgname = 'schrift_klein';
	imgpath = '/web4media/website/images/functionarea-font-small.gif';
	document.getElementById(imgname).src = imgpath;

	imgname = 'schrift_mittel';
	imgpath = '/web4media/website/images/functionarea-font-middle.gif';
	document.getElementById(imgname).src = imgpath;

	imgname = 'schrift_gross';
	imgpath = '/web4media/website/images/functionarea-font-large.gif';
	document.getElementById(imgname).src = imgpath;
}

function w4m_setfontsizeimg(size)
{
	w4m_resetfontsizeimg();

	var imgname = '';
	var imgpath = '';

	if(!size)
	{
		var size = efa_fontSize.getPref();

		if(size < 99)
		{
			size = 'small';
		}
		else if(size > 101)
		{
			size = 'large';
		}
		else
		{
			size = 'normal';
		}
	}

	switch(size)
	{
		case 'small':	imgname = 'schrift_klein';
						imgpath = '/web4media/website/images/functionarea-font-small-aktive.gif';
						break;
		case 'normal':	imgname = 'schrift_mittel';
						imgpath = '/web4media/website/images/functionarea-font-middle-aktive.gif';
						break;
		case 'large':	imgname = 'schrift_gross';
						imgpath = '/web4media/website/images/functionarea-font-large-aktive.gif';
						break;
	}

	document.getElementById(imgname).src = imgpath;
}

function highlightText(node,text)
{
	if (node.hasChildNodes)
	{
		var hi_cn;
		
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++)
		{
			highlightText(node.childNodes[hi_cn],text);
		}
	}

	if (node.nodeType == 3) // text node
	{ 
		tempNodeVal = node.nodeValue.toLowerCase();
		
		tempWordVal = text.toLowerCase();
		
		if (tempNodeVal.indexOf(tempWordVal) != -1)
		{
			pn = node.parentNode;
			
			if (pn.className != "searchword")
			{
				nv = node.nodeValue;
				
				ni = tempNodeVal.indexOf(tempWordVal);
				
				before = document.createTextNode(nv.substr(0,ni));
				
				docWordVal = nv.substr(ni,text.length);
				
				after = document.createTextNode(nv.substr(ni+text.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 searchHighlight()
{
	if (!document.createElement) return;
	
	ref = window.location+''; // convert to string
	
	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')
        {
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
			
	        for (w=0;w<words.length;w++)
	        {
				//highlightText(document.getElementsByTagName("body")[0],words[w]);
				highlightText(document.getElementById("content"),words[w]);
				
            }
	    }
	}
}

//window.onload = googleSearchHighlight;



/*]]>*/
