
/* Navigation helper ---------------------------------------- */
/* Ausblenden der breadcrumps bei Mousover auf Pulldownnavi */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) { 
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover"; 
			$(".flashcontainer").css("left", -1000);
			$(".navbar").css({ display: "none" });
			$(".select").css({ visibility: "hidden" });
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			$(".flashcontainer").css("left", 0);
			$(".navbar").css({ display: "block" });
			$(".select").css({ visibility: "visible" });
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//** Flashfinderanimation ausblenden wenn mousover �ber navi f�r die mozillaengine
flashHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			$(".flashcontainer").css("left", -1000);
		}
		sfEls[i].onmouseout=function() {
			$(".flashcontainer").css("left", 0);
		}
	}
}
if (window.addEventListener) window.addEventListener("load", flashHover, false);



/* Bestenliste 300 vergrossern ---------------------------------------- */

$(function(){
	
	// Bestenliste vergr��ern
	var j=0;
	var h=0;
	var get = new Array();
	var bidarray = new Array();
	
	$('#more').click(function(){
		$('#best').animate({
					height: 630
				}, 'slow');
		// $('#die_tolle_slideshow').animate({
		//			height: 746
		//		}, 'slow');					
		$('#more').hide('slow');
		$('#all').show('slow');
	});

	$('.connect_prodiff').bind('click',function(){
		var action = window.location.href;
		var actarray = action.split(/[?&]/ig);
		
		
		$.each(actarray, function(i, n){
			if (n.match(/bid\[\]/)){
				get[j] = n;
				j = j+1;
			}
		})

		
		if($('.product_checkbox[@checked]').serialize() != ""){
			var checkbox = $('.product_checkbox[@checked]').serialize(); 
			var post = checkbox.split(/[&]/)
			
			var bidlength = post.length;

			bidarray = post;
			
			$.each(get, function(i, n){
				var v = 0;

				$.each(post, function(a, b){
					if (escape(n) == b && v == 0){
					 v = 1;
					}
				});
				if (v != 1){
					n = n.replace(/\[/, '%5B');
					n = n.replace(/\]/, '%5D');
					bidarray[bidlength] = n;			
				}
			});
		}else{

			bidarray = get;
		}
		
		if (bidarray.length < 2) {
			alert('Bitte mindestens 2 Produkte vergleichen!');
			return false;
		}
		
		var location = '/suche/produktvergleich.html?';
		$.each(bidarray,function(i,n){
			if(i == 0){
				location += n;
			}else{
				location += '&' + n;
			}
		})
		document.location.href = location;
	});
	
	$('.connect_mark').bind('click',function(){
		document.location.href = '/user/user.html?wx_command=Note&wx_action=add&'+
								 $('.product_checkbox[@checked]').serialize();
	});

	// "merkliste" und "meine produkte":
	// alle auswaehlen
	$("a.usercard_list_check_all").bind("click", function() {
		
		var category = $(this).attr('id');
		
		
		
		$("."+category+" input.product_checkbox").attr("checked", true);
	});
	
	// auswahl aufheben
	$("a.usercard_list_uncheck_all").bind("click", function() {
		$("input.product_checkbox").attr("checked", false);
	});
});

/* Newsletter ---------------------------------------- */

function chkFormular(){
	 if(document.newsletterform.name.value == "") {
		 alert("Bitte geben Sie Ihren Namen an!");
		 return false;
	 }
	 else if(document.newsletterform.vorname.value == "") {
		 alert('Bitte geben Sie Ihren Vornamen an!');
		 return false;
	 }
	 else if(document.newsletterform.email.value != "") {
		var str = document.newsletterform.email.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str)== false){
			 alert("Die eingegebene E-Mail-Adresse ist nicht korrekt!");
			 return false;
		}
		else {
	   		document.newsletterform.submit();
			window.location.href ="/newsletter/abo.html?td=snd";
		}
	 }
	 else {
  		alert('Bitte geben Sie Ihre E-Mailadresse an!');
		return false;
	 }
}



/* Suchfeld leeren  ---------------------------------- */
function leeren() {
    if(document.suchform.term.value=="Volltextsuche") {
        document.suchform.term.value="";
    }
}



/* aktuelles Datum ausgeben  ---------------------------------- */
function datum() {
   var Datum = new (Date);
    var Tag = Datum.getDate();
    var Wochentag = Datum.getDay();
    var Monat = Datum.getMonth()+1;
    if(Monat<10) Monat = "0"+Monat;
    var Jahr = Datum.getFullYear();
    var Tagname = new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
    document.write(Tagname[Wochentag]+", "+Tag+"."+Monat+"."+Jahr+" ");
}








jQuery.actionGet ={

	addActionGet : function(param, wert){
		return this.each(function(){
			var el = jQuery(this);
			var id = el.attr('id');
			var klasse = el.attr('class');
			if (el.attr('action') == undefined){
				var action = el.attr('href');
				var attribut = 'href';
			}else{
				var action = el.attr('action');
				var attribut = 'action'
			}
			
			var test = action.split(/[?&]/ig);

			var i = 0;
			var laenge = test.length;
			
			for (j=0; j <= laenge-1; j++){
				if (test[j] == param + "=" + wert){
					i=1;
				}
			}
			
			var matching = action.match(/\?/);
			if (i == 0){
				if (matching){
					action += "&" + param + "=" + wert;
				}else{
					action += "?" + param + "=" + wert;
				}
			}
			if (typeof id == 'undefined' || id == ''){
				$("." + klasse).attr(attribut, action);
			}else{
				$("#" + id).attr(attribut, action);
			}
		})
	},

	delActionGet : function(param){
		return this.each(function(){
			var el = jQuery(this);
			var id = el.attr('id');
			var klasse = el.attr('class');
			var first = 0;
			var newaction = "";

			if (el.attr('action') == undefined){
				var action = el.attr('href');
				var attribut = 'href';
			}else{
				var action = el.attr('action');
				var attribut = 'action'
			}

			var actionarr = action.split(/[?&]/ig);

			$.each( actionarr, function(i, n){
				var matching = n.match(/\=/);
				if (matching){
					var get = n.split("=");
 					if(param != get[0]){
						if (first == 0){
							newaction += "?" + get[0] + "=" + get[1];
							first = 1;
						}else{
							newaction += "&" + get[0] + "=" + get[1];
						}
 					}
				}else{
					newaction += n;
				}	 
			});
			if (id == undefined){
				$("." + klasse).attr(attribut, newaction);
			}else{
				$("#" + id).attr(attribut, newaction);
			}
		})
	}

}

jQuery.fn.addActionGet = jQuery.actionGet.addActionGet;
jQuery.fn.delActionGet = jQuery.actionGet.delActionGet;

