
/* Layoutanpassung zugeklappte Bestenliste 300 */

$(function() {
	var s = 0;
	for (i=0; i<3; i++) {
		s = s + $('#best table tr:eq(' + i + ')').height();
	}
	$('#best').height(s);
})


/* Layoutanpassung Newsitems */

$(function(){
	$('div.element div.newsitem:last').css('margin-right','0');
})


/* Layoutanpassung Objektivseite */

$(function(){
	$('div.objektiv-info').each(function() {
		$('div.produktsteckbrief-main').css('margin-bottom','0');
	})
})


/* Navigation helper ---------------------------------------- */

/* Ausblenden der breadcrumbs 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 ueber Navi fuer 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 vergroessern ---------------------------------------- */

$(function(){
	
	// Bestenliste vergroessern
	var j=0;
	var h=0;
	var get = new Array();
	var bidarray = new Array();
	
	var hoehe = $('#best table').height();
	
	$('#more').click(function(){
		$('#best').animate({
					height: hoehe
				}, 'slow');	
		$('#more').hide('slow');
		$('#all').show('slow');
	});

	$('.connect_prodiff').bind('click',function(){
		var action = window.location.href;
		
		if($('.paging_prev').attr('href') != undefined){
			var action = $('.paging_prev').attr('href');
		}
		if($('.paging_last').attr('href') != undefined){
			var action = $('.paging_last').attr('href');
		}
		if($('.paging_first').attr('href') != undefined){
			var action = $('.paging_first').attr('href');
		}
		if($('.paging_next').attr('href') != undefined){
			var action = $('.paging_next').attr('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 getlength = get.length;
			var bidlength = post.length;
			var bidarray = "";

			if (getlength > 0){
				bidarray = get;
				$.each(post, function(a, b){
					var v = 0;
				
					$.each(get, function(i, n){
						if (escape(n) == b){
							v = 1;						
						}
					});
					if (v != 1){
						bidarray[getlength] = b;
						getlength = getlength + 1;
					}
				});
			}else{
				bidarray = post;
			}
		}else{
			
			bidarray = get;
		}

		
		var location = '/suche/produktvergleich.html?';
		$.each(bidarray,function(i,n){
			if(i == 0){
				location += n;
			}else{
				location += '&' + n;
			}
		});
		
	
		if ($('#Bestenliste_Testcamera_ID').val() !== 'null' && $('#Bestenliste_Testcamera_ID').val() ==''){
			alert('Bitte wählen Sie zum Vergleichen der Objektive eine Testkamera aus!');
			return false;
		}

		
		if (bidarray.length < 2) {
		
		
			alert('Bitte mindestens 2 Produkte vergleichen!');
			return false;
		}
		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() {
		$("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+" ");
}


/* URLs zusammenbauen und auslesen fuer Paging ---------------------- */

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 != n){
						if (first == 0){
							newaction += "?" + n;
							first = 1;
						}else{
							newaction += "&" + n;
						}
 					}
				}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;
