/**
 * Name: toggle_product_info
 * Beschreibung: Ziehharmonika-Funktion fuer Produktinformationen
 *
 * Parameter:
 * item : das Item, in dem der Inhalt zu toggeln is
 * path : Pfad zu den Bildern, um ihn systemunabhaengig zu halten
 */
function toggle_product_info(item, path) {
  //aktueller Zustand
  var visibility = $(item).parent().children('.falk_description_content').css("display");

  //wenn das aktuell offene Item geklickt wird nur zuklappen
  if("block" == visibility) {
    $(item).parent().children('.falk_description_content').slideUp('fast');
    $(item).children('.falk_icon').attr('src', path+'toggle_plus_icon.gif');
  }
  else {
    //das aktuell offene Item zuklappen
    $("#falk_act_item").slideUp('150');
    $("#falk_act_item").parent().children('div').children('.falk_icon').attr('src', path+'toggle_plus_icon.gif');
    $("#falk_act_item").attr('id', '');

    //dem geklickten Element das Flag mitgeben
    $(item).parent().children('.falk_description_content').attr('id', 'falk_act_item');

    //das geklickte Element ausklappen
    setTimeout('$("#falk_act_item").slideDown("100")', 130);
    $("#falk_act_item").parent().children('div').children('.falk_icon').attr('src', path+'toggle_minus_icon.gif');
  }
}


/**
 * Name: toggle_help
 * Beschreibung: Ziehharmonika-Funktion fuer Help Box
 *
 * Parameter:
 * item : das Item, in dem der Inhalt zu toggeln is
 * path : Pfad zu den Bildern, um ihn systemunabhaengig zu halten
 */
 
function toggle_help(item, path) {
  //aktueller Zustand
  var visibility = $(item).children('#toggle_help').css("display");
	var arrow_img_path = $(item).parent().children('.falk_help_box_inner').children('.falk_chapter_headline').children('div').children('.falk_icon').attr('src', path+'toggle_plus_icon.gif');
	
  //wenn das aktuell offene Item geklickt wird nur zuklappen
  if("block" == visibility) {
    $(item).children('#toggle_help').slideUp('fast');
    $('#falk_help_box_inner').children('.falk_chapter_headline').children('div').children('.falk_icon').attr('src', path+'toggle_plus_icon.gif');
  }
  else {
    //das geklickte Element ausklappen
    setTimeout('$("#toggle_help").slideDown("100")', 130);
		$('#falk_help_box_inner').children('.falk_chapter_headline').children('div').children('img.falk_icon').attr('src', path+'toggle_minus_icon.gif');
  }
}


/**
 * Name: -
 * Beschreibung: wird ausgefuehrt, sobald das Dokement fertig geladen ist
 *              - Einblenden und Ausblenden der zweiten Navigatiobsebene
 *              - Mouse-Over fuer die Produkt-Icons
 */
$(document).ready(
  function(){

    /* 
    //Einblenden der zweiten Navigatiobsebene
    $('#falk_main_nav ul li a').hover(
      function() {
        //Mouse-Over fuer die Hauptnavigation
        $(this).parent().children('ul').css("display", "block");
        $(this).parent().children('.falk_main_nav_a').css("background-position", "left -35px");

        //Mouse-Over fuer die Kind-Elemente des Listen-Elements aus der Hauptnavigation (.falk_main_nav_li)
        // => dafuer sorgend, dass nicht gleich wieder alles ausgbledet wird weges des Mouse-Outs am Ende dieses Blocks
        $(this).parent().children().hover(
          function() {
            $(this).css("display", "block");
            $(this).parent().children('.falk_main_nav_a').css("background-position", "left -35px");
          },
          function() {}
        );

        //Mouse-Out fuer die Subnavigationsliste
        $(this).parent().children('.falk_sub_nav').hover(
          function(){},
          function(){
            $(this).hide();
            $(this).parent().children('.falk_main_nav_a').css("background-position", "left top");
          }
        );
      },
      function() {
        //Mouse-Out fuer das Listen-Element aus der Hauptnavigation
        $(this).parent().children('ul').css("display", "none");
        $(this).parent().children('.falk_main_nav_a').css("background-position", "left top");
      }
    );
    */

    $(".falk_sub_nav > li:first-child > div > a").css("border-top-width", "0");
    $(".falk_sub_nav > li:last-child > div > a").css("border-bottom-width", "0");

    $(".falk_sub_nav > li > div > a").prepend('<span style="color: #e31921">&raquo;</span> ');

    $(".falk_sub_nav li:first-child").css("border-top", "1px solid #666");
    $(".falk_sub_nav li:last-child").css("margin-bottom", "8px");

    //Ausblenden der zweiten Navigationsebene
    $(".falk_sub_nav").hide();
 
    //Einblenden der zweiten Navigationsebene
    $("#falk_main_nav_ul > li").hover(
      function() {
        $(this).css("background", "#1A1A1A");
        $(this).css("border-color", "#666");
        $(this).find("> a").css("color", "#fff");
        $(this).find("ul").show();
      },
      function() {
        $(this).css("background", "transparent");
        $(this).css("border-color", "transparent");
        $(this).find("> a").css("color", "#ccc");
        $(this).find("ul").hide();
      }
    );
 
    $(".falk_sub_nav > li").hover(
      function() {
        $(this).find("> div > a").css("color", "#fff");
      },
      function() {
        $(this).find("> div > a").css("color", "#ccc");
      }
    );

    $(".falk_with_arrow, .falk_next a").append('&nbsp;<span style="color: #e31921">&raquo;</span>');
    $(".falk_back_link a, .falk_prev a").prepend('<span style="color: #e31921">&laquo;</span>&nbsp;');

    //Mouse-Over fuer die Produkt-Icons
    $(".falk_product_thumbs .falk_thumb img").hover(
      function() {
        $(this).css("border", "1px solid #333333");
      },
      function() {
        if($(this).attr("class").indexOf("act") < 0)
          $(this).css("border", "1px solid #ffffff");
      }
    );


    //Anpassen der Abmessungen des Overlays
    $("#falk_overlay").css("height", ($("#falk_wrapper").height() + 60)+"px");
    $("#falk_overlay").css("width", $('body').width());
		
  }
);



/**
 * Name: change_product_detail
 * Beschreibung: Ziehharmonika-Funktion fuer Produktinformationen
 *
 * Parameter:
 * src : URL des Icons, dessen zugehoeriges Bild als Detailbild dargestellt werden soll
 * img_nr : key des Bildes, das ausgetauscht werden soll
 */
function change_product_detail(src, img_nr) {
  //Bild austauschen
  var file_path = src.substr(0, src.indexOf('_ico'));
  var file_ending = src.substr(src.indexOf('_ico'));
  file_ending = file_ending.substr(file_ending.indexOf('.'));
  var new_src = file_path+file_ending;
  $("#product_img").attr("src", new_src);

  //Rahmen um das Thumb handeln
  $(".falk_product_thumbs .falk_thumb .falk_thumb_act").css("border", "1px solid #ffffff");
  $(".falk_product_thumbs .falk_thumb .falk_thumb_act").attr("class", "");
  $(".falk_product_thumbs .falk_thumb:eq("+(img_nr-1)+") img").attr("class", "falk_thumb_act");
}



/**
 * Name: remove_basket_item
 * Beschreibung: ein Element aus dem Warenkorb entfernen und diesen aktualisieren
 *
 * Parameter:
 * el : der geklickte Link
 * form_name : Name des abzuschickenden Formulars
 * btn_value : value des Buttons, der eigentlich zum Loeschen geklickt wird
 */
function remove_basket_item(el_name, form_name, btn_val) {
  //die versteckte Checkbox auch checked setzen
  $("#"+el_name).prev().attr("checked", "checked");

  //das zum loeschen fehlende Flag einhaengen
  $("#"+el_name).after('<input name="removeBtn" type="hidden" value="'+btn_val+'">');

  //das Formular abschicken
  document.getElementsByName(form_name)[0].submit();
}



/**
 * Name: serial_to_product
 * Beschreibung: Liefert zu einer Seriennummer das passende Produkt
 *
 * Parameter:
 * seriel: Die Seriennummer
 */
function serial_to_product(serial) {
  $("#falk_serial_content").html('');

  var errormsg = new Array();

  if($("#field_serial").val()=="") {
    errormsg.push('Bitte geben Sie eine Seriennummer ein.');
  }
  if($("#field_date_year").val()=="" || $("#field_date_month").val()=="" || $("#field_date_day").val()=="") {
    errormsg.push('Bitte geben Sie ein korrektes Datum ein.');
  }
  if($("#field_purchase_store").val()=="") {
    errormsg.push('Bitte wählen Sie einen Händler aus.');
  }
  else if($("#field_purchase_store").val() == 'Sonstige' && $("#field_further_purchase_store").val() == '') {
    errormsg.push('Bitte geben Sie einen Händler ein.');
  }

  if (0 < errormsg.length) {
    var html = '<div class="errorbox" style="padding: 15px 0; fonz-size: 1.0em;"><p>';
    for (var i = 0; i < errormsg.length; i++) {
      html += errormsg[i]+'<br />';
    }
    html += '</p></div>';
    $("#falk_serial_content").html(html);
  }
  else {
    $.get('/_scripts/ajax_broker.php', { 'snum': serial, 'action': 'get_serial' }, function(retval) {
      var product = eval('('+retval+')');
      if ('[]' != retval) {
        var product = eval('('+retval+')');

        $("#falk_serial_content").html('<div class="falk_under_chapter_text"><p class="falk_annotation">Sie haben ein: <strong>'+product.Produkt+'</strong></p></div>');
        $("#falk_navi_version").val(retval);
        $("#falk_purchase_date").val($("#field_date_year").val()+'-'+$("#field_date_month").val()+'-'+$("#field_date_day").val());
        if ($("#field_purchase_store").val() != 'Sonstige') {
          $("#falk_purchase_store").val($("#field_purchase_store").val());
        }
        else {
          $("#falk_purchase_store").val($("#field_further_purchase_store").val());
        }
        $("#falk_serial_note").hide();
        $("#falk_tobasket_button").show();
        $("#falk_serial_get_product").hide();
        $("#falk_serial_tobasket").show();

        //eventuell von der Artikelnummershop anhaengigen Text einblenden
        var show_artnumshop = ""+product.Artikelnummershop+"";
        if(show_artnumshop != "") {
          if(show_artnumshop.indexOf('140000') >= 0) {
            $("#falk_140000_content").show();
          }
          else if(show_artnumshop.indexOf('140001') >= 0) {
            $("#falk_140001_content").show();
          }
          else if(show_artnumshop.indexOf('140002') >= 0) {
            $("#falk_140002_content").show();
          }
          else if(show_artnumshop.indexOf('140003') >= 0) {
            $("#falk_140003_content").show();
          }

	}

        //eventuell Hinweis ueber Ungueltigkeit des Gutscheins ausgeben (wenn das Navi vor mehr als 30 Tagen gekauft wurde)
        var check_year = $("#field_date_year").val();
        var check_month = $("#field_date_month").val();
        var check_day = $("#field_date_day").val();
        toggle_voucher_hint(check_year, check_month, check_day);
      }
      else {
        $("#falk_serial_content").html('<div class="errorbox" style="padding: 15px 0; fonz-size: 1.0em;"><p>Es konnte kein Produkt für die eingegebene Seriennummer ermittelt werden.</p></div>');
      }
    });
  }

}



/**
 * Name: toggle_voucher_hint
 * Beschreibung: zeigt einen Hinweis an, wenn das Produkt vor mehr als zehn Tagen gekauft wurde
 *
 * Parameter:
 * year: Jahr als int
 * month: Monat als int
 * day: Tag als int
 */
function toggle_voucher_hint(year, month, day) {
  $("#falk_serial_voucher_date_content").hide();
  
  $.get('/_scripts/ajax_broker.php', { 'date': year+'-'+month+'-'+day, 'action': 'check_days' }, function(retval) {
    if ('false' == retval)
      $("#falk_serial_voucher_date_content").show();
  });
}


/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
* jira 143
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
	}
	else{
	var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
	}
	return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("hintbox")){
		dropmenuobj=document.getElementById("hintbox")
		dropmenuobj.innerHTML=menucontents
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		if (tipwidth!=""){
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
		}
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
		dropmenuobj.style.visibility="visible"
		obj.onmouseout=hidetip
	}
}

function hidetip(e){
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="-500px"
}

function createhintbox(){
	var divblock=document.createElement("div")
	divblock.setAttribute("id", "hintbox")
	document.body.appendChild(divblock)
}

if (window.addEventListener)
	window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
	window.attachEvent("onload", createhintbox)
else if (document.getElementById)
	window.onload=createhintbox
;


/**
 * Name: formlenght_feedback
 * Beschreibung: Feedback an nutzer bei längerer Eingabe in Formularfeld als 35 Zeichen
 *
 * Parameter:
 * formElement : das Element, welches auf Länge geprüft wird
 * Date :   08.02.11
 */
 	// Wenn es sich um Eingabeformular für Nutzerdaten handelt, 
	// maximallänge der Eingabe von 35 Zeichen für Adressfelder als Feedback asugeben
$(function(){
//		$(':input[title]').tooltip({ position: "top center", opacity: 0.95});					 
			 

	// Formular zur Adresseingabe?
	if ( $('.falk_use_account').length || $('.falk_recommend_form').length ) {
		$('.check_length').focus(function(){			//Feld welches geprüft werden soll
			// Nach jeder Tasteneingabe prüfen auf Länge
			$('input.check_length').keydown(function() {
				// Länge ermitteln
				var getLength = $(this).val().length;
				// Wenn länger als 35 Zeichen, letztes löschen und Info Layer einblenden
				if (getLength >= 35) {
					var eingabe = $(this).val();
					var maxInput = eingabe.substring(0, eingabe.length - 1);
					$(this).val(maxInput);
					$(this).tooltip({ position: "top center", opacity: 0.95}).show();
				}
			});
		});
	}  // Ende if
});



