window.onload = init;
function init() {
	if (top.location != self.location) {top.location = self.location.href;}
//	if (ie && document.getElementById('oben'))		menu();
	if (document.getElementById('news'))	newsScrollInit();
	if (document.getElementById('popup')) {
		var images = document.getElementById('popup').getElementsByTagName("img");
		for ( var i=0; i<images.length; i++ ) {
			if (images[i].parentNode.nodeName != "A") {
				images[i].onclick = function () {showimg(this.src,this.alt)};
				images[i].style.cursor="pointer";
}	}	}	}
lstart=800	//The pixel value of where you want the layer to start
loop=true 	//Set this to false if you just want it to go one time
speed=30	//Set the speed, lower value gives more speed
pr_step=1	//Set this to how many pixels you want it to go for each step, this also changes the speed.    

//Makes the object
function newsScrollInit(){
//	lstart=document.getElementById('container').style.width; //The pixel value of where you want the layer to start
	document.getElementById('news').style.width=document.getElementById('news').innerHTML.replace(/(<([^>]+)>)/ig,"").length*8+'px';
	oNewsScroll=new makeObj('news');
	oNewsScroll.moveIt(lstart,0);
	document.getElementById('news').style.visibility='visible';
	oNewsScroll.newsScroll(speed);
}
//Makes the object scroll up
function newsScroll(speed){
	if(this.x>-this.scrollWidth){
		this.moveIt(this.x-pr_step,0)
		setTimeout(this.obj+".newsScroll("+speed+")",speed)
	}else if(loop) {
		this.moveIt(lstart,0)
		eval(this.obj+".newsScroll("+speed+")")
}	}
//Object constructor
function makeObj(obj){
	this.el=document.getElementById(obj);
  	this.css=this.el.style;
	this.scrollHeight=this.el.offsetHeight;
	this.scrollWidth=this.el.offsetWidth;
	this.newsScroll=newsScroll;
	this.moveIt=b_moveIt; this.x; this.y;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}
function b_moveIt(x,y){
	this.x=x;this.y=y
	this.css.left=this.x +'px';
	this.css.top=this.y +'px';
}
function menu(){
	var menu = document.getElementById('oben').getElementsByTagName('LI');
	for (i=0;i<menu.length;i++) {
		if (menu[i].lastChild.nodeName == "UL") {
			menu[i].onmouseover = function () {
				this.lastChild.style.display = "block";
			}
			menu[i].onmouseout = function () {
				this.lastChild.style.display = "none";
}	}	}	}
function showorhide(id) {
	if (id != "serie" && document.getElementById("serie")) {
		document.getElementById("serie").className = "hideit";
		document.getElementById("link_serie").style.color = "#736d6a";
	}
	if (id != "tipp" && document.getElementById("tipp")) {
		document.getElementById("tipp").className = "hideit";
		document.getElementById("link_tipp").style.color = "#736d6a";
	}
	if (id != "inci" && document.getElementById("inci")) {
		document.getElementById("inci").className = "hideit";
		document.getElementById("link_inci").style.color = "#736d6a";
	}
	if (id != "probe" && document.getElementById("probe")) {
		document.getElementById("probe").className = "hideit";
		document.getElementById("link_probe").style.color = "#736d6a";
	}
	if (id != "inhaltsstoffe" && document.getElementById("inhaltsstoffe")) {
		document.getElementById("inhaltsstoffe").className = "hideit";
		document.getElementById("link_inhaltsstoffe").style.color = "#736d6a";
	}
	if (document.getElementById(id).className == "hideit") {
		document.getElementById(id).className = "showit";
		document.getElementById("link_"+id).style.color = "#871113";
	}
	else {
		document.getElementById(id).className = "hideit";
		document.getElementById("link_"+id).style.color = "#736d6a";
}	}
function search_reset() {
	if (document.getElementById('hersteller')) {
		var size = document.getElementById('hersteller').getAttribute('size');
		var sel_h_ids = document.getElementById('hersteller').options;
		for (i = 0; i < sel_h_ids.length; i ++) {	sel_h_ids[i].selected = false;	}
	}
	if (document.getElementById('produktgruppen')) {
		var sel_pg_ids = document.getElementById('produktgruppen').options;
		for (i = 0; i < sel_pg_ids.length; i ++) {	sel_pg_ids[i].selected = false;	}
	}
	if (document.getElementById('untergruppen')) {
		var sel_ug_ids = document.getElementById('untergruppen').options;
		for (i = 0; i < sel_ug_ids.length; i ++) {	sel_ug_ids[i].selected = false;	}
	}
	if (document.getElementById('subgruppen')) {
		var sel_sg_ids = document.getElementById('subgruppen').options;
		for (i = 0; i < sel_sg_ids.length; i ++) {	sel_sg_ids[i].selected = false;	}
	}
	if (document.getElementById('suche')) {
		document.getElementById('suche').value = '';
	}
	$.ajax({
	  url: "/get_suche.php?h_ids=,&pg_ids=,&ug_ids=,&sg_ids=,",
	  cache: false,
	  success: function(html){
		var teile = html.split('::');
		document.getElementById('pg').innerHTML = '<select id="produktgruppen" name="such[produktgruppe_id][]" onchange="get_suche();return true;" multiple="1" size="'+size+'">'	+'<option value="">'+document.getElementById('pg').firstChild.options[0].text+"</option>"+teile[0]+'</select>';
		document.getElementById('ug').innerHTML = '<select id="untergruppen" name="such[untergruppe_id][]" onchange="get_suche();return true;" multiple="1" size="'+size+'">'		+'<option value="">'+document.getElementById('ug').firstChild.options[0].text+"</option>"+teile[1]+'</select>';
		document.getElementById('sg').innerHTML = '<select id="subgruppen" name="such[subgruppe_id][]" multiple="1" size="'+size+'">'												+'<option value="">'+document.getElementById('sg').firstChild.options[0].text+"</option>"+teile[2]+'</select>';
	  }
	});
}
function get_suche() {
	var h_ids = '';
	var pg_ids = '';
	var ug_ids = '';
	var sg_ids = '';
	if (document.getElementById('hersteller')) {
		var size = document.getElementById('hersteller').getAttribute('size');
		var sel_h_ids = document.getElementById('hersteller').options;
		for (i = 0; i < sel_h_ids.length; i ++) {	if (sel_h_ids[i].selected) {h_ids += sel_h_ids[i].value + ',';		}	}
	}
	if (document.getElementById('produktgruppen')) {
		var sel_pg_ids = document.getElementById('produktgruppen').options;
		for (i = 0; i < sel_pg_ids.length; i ++) {	if (sel_pg_ids[i].selected) {pg_ids += sel_pg_ids[i].value + ',';	}	}
	}
	if (document.getElementById('untergruppen')) {
		var sel_ug_ids = document.getElementById('untergruppen').options;
		for (i = 0; i < sel_ug_ids.length; i ++) {	if (sel_ug_ids[i].selected) {ug_ids += sel_ug_ids[i].value + ',';	}	}
	}
	if (document.getElementById('subgruppen')) {
		var sel_sg_ids = document.getElementById('subgruppen').options;
		for (i = 0; i < sel_sg_ids.length; i ++) {	if (sel_sg_ids[i].selected) {sg_ids += sel_sg_ids[i].value + ',';	}	}
	}
	$.ajax({
	  url: "/get_suche.php?h_ids="+h_ids+"&pg_ids="+pg_ids+"&ug_ids="+ug_ids+"&sg_ids="+sg_ids,
	  cache: false,
	  success: function(html){
		var teile = html.split('::');
		if (document.getElementById('pg'))	document.getElementById('pg').innerHTML = '<select id="produktgruppen" name="such[produktgruppe_id][]" onchange="get_suche();return true;" multiple="1" size="'+size+'">'	+'<option value="">'+document.getElementById('pg').firstChild.options[0].text+"</option>"+teile[0]+'</select>';
		if (document.getElementById('ug'))	document.getElementById('ug').innerHTML = '<select id="untergruppen" name="such[untergruppe_id][]" onchange="get_suche();return true;" multiple="1" size="'+size+'">'		+'<option value="">'+document.getElementById('ug').firstChild.options[0].text+"</option>"+teile[1]+'</select>';
		if (document.getElementById('sg'))	document.getElementById('sg').innerHTML = '<select id="subgruppen" name="such[subgruppe_id][]" multiple="1" size="'+size+'">'												+'<option value="">'+document.getElementById('sg').firstChild.options[0].text+"</option>"+teile[2]+'</select>';
	  }
	});
}
function searchSuggest(id) {
	var str = escape(document.getElementById(id).value);
	if (str.length > 1) {
		$.ajax({
		  url: "/get_suche.php?str="+str,
		  cache: false,
		  success: function(html){
				var ss = document.getElementById('suggest_'+id);
				ss.innerHTML = '';
				var str = html.split(";");
				if (str.length>0 && str[0]!='') {
					if (id == 'suche')	var suggest = '<select onchange="setSearch(\''+id+'\');" size="5" id="suggestions_'+id+'">';
					else				var suggest = '<select onchange="setSearch(\''+id+'\');" size="5" id="suggestions_'+id+'" style="position:absolute;top:20px;left:0px;">';
					for(i=0; i < str.length; i++) {
						//Build our element string.  This is cleaner using the DOM, but
						//IE doesn't support dynamically added attributes.
						suggest += '<option value="' + str[i] + '">' + str[i] + '</option>';
					}
					ss.innerHTML = suggest+'</select>';
				}
				else ss.innerHTML = '';
		  }
		});
}	}
//Click function
function setSearch(id) {
	if (document.getElementById('suggestions_'+id).value != '') {
		document.getElementById(id).value = document.getElementById('suggestions_'+id).value;
		if (id == 'suche2')	document.getElementById('suggest_'+id).innerHTML = '';
	}
	//document.getElementById('search_suggest').innerHTML = '';
}
function bildwechsel(id) {
	document.getElementById('big').src = document.getElementById(id).src;
}
function showimg(src,alt) {
	var bild_window = window.open("","Bild","toolbar=no,width=700,height=500,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	bild_window.document.writeln('<html><head>');
	bild_window.document.writeln('<title>'+alt+'</title>');
	bild_window.document.writeln('</head><body onblur="self.close()" style="height:90%;background: url('+src.replace('thumbs/','')+') no-repeat center">');
	bild_window.document.writeln('<div style="position:absolute;right:3px;bottom:3px;"><a href="javascript:" onclick="self.close()">Schließen</a></div>');
	bild_window.document.writeln('</body></html>');
	bild_window.document.close();
	bild_window.focus();
}
function addSmiley(id) {
	if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = document.selection.createRange().text + "["+id+"]";
	}
	else {
		document.getElementsByTagName('textarea')[0].value += "["+id+"]";
		document.getElementsByTagName('textarea')[0].focus();
}	}
function header(id)		{edit("[h]","[/h]","header",id);}
function fett(id)		{edit("[b]","[/b]","fett",id);}
function italic(id)		{edit("[i]","[/i]","italic",id);}
function uline(id) 		{edit("[u]","[/u]","uline",id);}
function url(id) {
	url = prompt("Bitte geben Sie die gewünschte URL ein:", "http://");
	edit("[url="+url+"]","[/url]","url",id);
}
function edit(start,end,id) {
	var textfield = document.getElementsByTagName('textarea')[0];
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();
		var startPos = textfield.selectionStart;
		var endPos = textfield.selectionEnd;
		strSelection = start + textfield.value.substring(startPos, endPos)+ end;
		textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
	}
	else if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = start + document.selection.createRange().text + end;
	}
	else {
		if (document.getElementById(id).style.color=="#aaa") {
			textfield.value += end;
			document.getElementById(id).style.color="blue";
		}
		else {
			textfield.value += start;
			document.getElementById(id).style.color="#aaa";
}	}	}
function vorschau() {
	var textarea = document.getElementsByTagName('textarea')[0].value.split('[');
	vorschautext = textarea[0];
	for (var i=0; i<textarea.length; i++) {
		bracket = textarea[i].split(']')[0];
		if (bracket == 'b')		vorschautext += '<span style="font-weight: bolder;">' + textarea[i].split('b]')[1].split('/b]')[0];
		if (bracket == 'i')		vorschautext += '<span style="font-style: italic;">' + textarea[i].split('i]')[1].split('/i]')[0];
		if (bracket == 'u')		vorschautext += '<span style="text-decoration: underline;">' + textarea[i].split('u]')[1].split('/u]')[0];
		if (bracket == '/b' || bracket == '/i' || bracket == '/u') 	vorschautext += '</span>' + textarea[i].split(']')[1];
		else {
			if (document.getElementById(bracket) && bracket != '') {
				vorschautext +=  '<img src="'+document.getElementById(bracket).src+'">'+textarea[i].split(']')[1];
	}	}	}
	vorschau_window = window.open('',"Vorschau","toolbar=no,width=500,height=200,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.document.open();
	vorschau_window.document.writeln('<html><head><link rel="stylesheet" href="css/3000.css" type="text/css">');
	vorschau_window.document.writeln('<title>Vorschau</title>');
	vorschau_window.document.writeln('</head><body onblur="self.close()">');
	vorschau_window.document.writeln('<pre>'+vorschautext+'</pre>');
	vorschau_window.document.writeln('<div style="position:absolute;right:3px;bottom:3px;"><a href="javascript:" onclick="self.close()">Schließen</a></div>');
	vorschau_window.document.writeln('</body></html>');
	vorschau_window.document.close();
	vorschau_window.focus();
}