// JavaScript Document
$(document).ready(function() {
	$("form #suchen, form #header_suchen").focus(function() {
		val = $(this).attr("value").replace (/^\s+/,'').replace (/\s+$/,'');
		if(val=="Suchbegriff eingeben") {
			$(this).attr("value","");
		}
	});
	$("form #suchen, form #header_suchen").blur(function() {
		val = $(this).attr("value").replace (/^\s+/,'').replace (/\s+$/,'');
		if(val=="") {
			$(this).attr("value","Suchbegriff eingeben");
		}
	});
	$("#formsubmit").css('display','none');
	$("input[@type='text'].cart_quantity").change( function() { startsearch(this); });
	$(".lieferadresse a").click(function () {
		if($("#address_fa:visible").length!=0) $("#address_fa").slideUp();
		$("#address").slideToggle("slow");
		return false;
	});
	$(".fa_adresse a").click(function () {
		if($("#address:visible").length!=0) $("#address").slideUp();
		$("#address_fa").slideToggle("slow");
		return false;
	});
	$("#hersteller").click(function () {
		url = $(this).attr('href');
		if(url.indexOf('?')==-1) {
			url = url.concat('?KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
		} else {
			url = url.concat('&amp;KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
		}
		tb_show("",url,false);
		return false;
	});
	$("#designer").click(function () {
		url = $(this).attr('href');
		if(url.indexOf('?')==-1) {
			url = url.concat('?KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
		} else {
			url = url.concat('&amp;KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
		}
		tb_show("",url,false);
		return false;
	});
	if($("#bestellen").length!=0) {
		srcvar = $("#bestellen").attr('src').replace(/\.png/g,"_gesperrt.png");
		$("#bestellen").attr('src',srcvar);
		$("#bestellen").click(function () {
			if($("#accept_agb").attr('checked')!=true) {
				alert('Bitte lesen Sie zuerst die AGB und bestätigen Sie diese!');
				return false;
			}
		});
		$("#accept_agb").click(function() {
			srcvar = $("#bestellen").attr('src').replace(/_gesperrt\.png/g,".png");
			if($("#accept_agb").attr('checked')==true) {
				$("#bestellen").attr('src',srcvar);
			} else {
				$("#bestellen").attr('src',srcvar.replace(/\.png/g,"_gesperrt.png"));	
			}
		});
	}
	$("#nur_aktionen").click(function() { startsearch(this); });
});

function showhint(link_to_cart) {
	$("body").append('<div id="TB_overlay" class="TB_overlayBG"></div><div id="hint"><a href="'+window.location.href+'" class="hint_close" title="Hinweis schlie&szlig;en"><img src="images/btn_close_cart.png" alt="Hinweis schlie&szlig;en" /></a><h2>Artikel in den Warenkorb gelegt</h2><a href="'+window.location.href+'" class="hint_shopping" title="weitershoppen"><span>weitershoppen</span></a> <a href="'+link_to_cart+'" class="hint_register" title="zum Warenkorb"><span>zum Warenkorb</span></a></div>');
	$(".hint_close").click( function() {
		anihint();
		return false;
	});
	$(".hint_shopping").click( function() {
		anihint();
		return false;
	});	
	$(".hint_register").click( function() {
		$('#TB_overlay').remove();
		$('#hint').remove();
		window.parent.location.href = this.href;
		return false;
	});
}
function anihint() {
	$("#hint").animate({opacity:0.4, top:"100px", left:"489px"},"slow",
	function() { 
		$("#hint").fadeOut("slow", function() {
			$("#TB_overlay").fadeOut("slow", function() {
				$('#TB_overlay').remove();
				$('#hint').remove();
			});
		});
	});
}

function startsearch(elem) {
	while(elem.tagName.toLowerCase()!='form') {
		elem = elem.parentNode;
	}
	elem.submit();
}

function quantity(elem,type) {
	p = elem.parentNode;
	while(p.tagName.toLowerCase()!='td') {
		p = p.parentNode;
	}
	childs = p.childNodes;
	cc = childs.length;
	if(cc!=0) {
		for(i=0; i<cc; i++) {
			if(childs[i].tagName.toLowerCase()=='input') {
				input = childs[i];
				break;
			}
		}
		if(input) {
			akt = input.value;
			test = akt.match(/\d+/);
			if(test) {
				if(type=='plus') {
					input.value = parseInt(akt)+1;
					startsearch(p);
				} else if(type='minus') {
					if(1<parseInt(akt)) {
						input.value = parseInt(akt)-1;
						startsearch(p);
					}
					else input.value = 1;
				}
			} else {
				input.value = 1;	
			}
		}
	}
	return false;
}

function switchimg(rp) {
	$(".small").hover(
		function() {
			$(".big > img").css('display','none');
			newbig = $(this).children("img")[0].src;
			newbig = newbig.substring(newbig.indexOf("_")+1);
			$(".big").css("backgroundImage","url("+rp + "visioncontent/bilderdatenbank/S2_" + newbig+")");
		},
		function() {
			$(".big > img").css('display','block');
			$(".big").css("backgroundImage","url("+ rp +"images/blank.gif)");
		}
	);
	$(".small").click(function() { return false; });	
}
$(document).ready(function(){
	if($.browser.msie && /MSIE/.test(navigator.userAgent)) {
		$(":input[name*='such_']").focus(function(e) {
			window.scrollTo(0,0);
			$("#test").remove();
			name = $(this).attr('name');
			o = $(this).find("option");
			sel_key = $(this).find("option:selected").attr('value');
			sel_val = $(this).find("option:selected").text();
			val = new Array(); key = new Array();
			for(j=0; j<o.length; j++) {
				key[j] = o.eq(j).attr('value');
				val[j] = o.eq(j).text();
			}
			if($(this).attr("name")=='such_familie') ptop = 371;
			else if($(this).attr("name")=='such_hersteller') ptop = 225;
			else if($(this).attr("name")=='such_designer') ptop = 253;
			else ptop = 281;
			$(this).replaceWith('<div id="testplace">' + sel_val + '</div>');
			$('select').css("visibility","hidden");
			if(19<val.length) {
				$('body').append('<div id="test" style="top:'+ptop+'px; height:320px; overflow-y:scroll; padding-right:20px;"></div>');
			} else {
				$('body').append('<div id="test" style="top:'+ptop+'px;"></div>');
			}
			for(j=0; j<key.length; j++) {
				$("#test").append('<span id="'+key[j]+'">'+val[j]+'</span><br />');
			}
			$("#test span").hover(
				function() {
					$(this).css("background-color","#F2F2F2");

				},
				function() {
					$(this).css("background-color","#FFF");
				}
			);
			$("#test > span").click(function() {
				$('select').css("visibility","visible");
				$("#testplace").replaceWith('<select name="'+name+'" id="'+name+'"></select>');
				$('#'+name+' ~ select').show();
				sel = 0;
				for(i=0; i<key.length; i++) {
					if(key[i]==$(this).attr('id')) {
						sel = i;
						$('#'+name).append("<option value=\""+key[i]+"\" selected=\"selected\">"+val[i]+"</option>");
					} else {
						$('#'+name).append("<option value=\""+key[i]+"\">"+val[i]+"</option>");
					}
				}
				$("#test").remove();
				if(name=='such_familie') {
					if(1<sel) $("#artikelsuche").submit();
					else if(sel==1) {
						url = key[sel];
						if(url.indexOf('?')==-1) {
							url = url.concat('?KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
						} else {
							url = url.concat('&amp;KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
						}
						tb_show("",url,false);
						return false;	
					}
				} else {
					$("#artikelsuche").submit();
				}
			});
			$("#test").focus();
			$("body").click(function() {
				window.location.href = window.location.href;					 
				//$("#artikelsuche").submit();
				/*
				$("#contentbox_unten").css("display","block");
				$('select').css("visibility","visible");
				$("#testplace").replaceWith('<select name="'+name+'" id="'+name+'"></select>');
				for(i=0; i<key.length; i++) {
					if(key[i]==sel_key) {
						$('#'+name).append("<option value=\""+key[i]+"\" selected=\"selected\">"+val[i]+"</option>");
					} else {
						$('#'+name).append("<option value=\""+key[i]+"\">"+val[i]+"</option>");
					}
				}
				$("#"+name).change(function() { startsearch(this); });
				$("#test").remove();
				*/
			});
		});			
	}
});

function family(elem) {
	sel = elem.selectedIndex;
	url = elem.options[sel].value;
	if(1<sel) {
		while(elem.tagName.toLowerCase()!='form') {
			elem = elem.parentNode;
		}
		if(url!='') elem.action = url;
		elem.submit();
	} else if(sel==1) {
		if(url.indexOf('?')==-1) {
			url = url.concat('?KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
		} else {
			url = url.concat('&amp;KeepThis=true&amp;modal=true&amp;TB_iframe=true&amp;height=560&amp;width=715');	
		}
		tb_show("",url,false);
		return false;
	}
}
function alert_land(e) {
	if(e.selectedIndex == e.length-1) {
		alert("Bitte senden Sie uns eine Anfrage, damit wir Ihnen ein Angebot unterbreiten können.");	
	}
}