var slideSpeed=1000;var dropdownSettings=new Object({minRows:1,maxRows:100,targetColumnSize:2,openFx:"fadeIn",openSpeed:300,closeFx:"fadeOut",closeSpeed:300,valueAttr:"value"});var checkboxSettings=new Object({empty:"/images/contact/empty.png"});var productGroupList;var dealerList;var productList;var productPreview;var productDropdown;var categoryDropdown;var subcategoryDropdown;var submitbutton_clicked=false;var pID;function isProductRequest(){if($("#check_subject_product").attr("checked")||$("#check_subject_product_group").attr("checked")){return true}else{return false}}function checkIfProductRequest(){if(isProductRequest()){$("#plzsearch").slideDown(slideSpeed);$("#check_subject_question").attr("disabled",true);$(".comment span.required").hide()}else{if(!($("#check_subject_product").attr("checked"))&&!($("#check_subject_product_group").attr("checked"))){$("#plzsearch").slideUp(slideSpeed);$("#check_subject_question").attr("disabled",false);$(".comment span.required").show()}else{$(".comment span.required").show()}}}function ProductGroupList(){var a=this;this.jQuery_element=$("#subject_product_group");this.getSelectedProductGroups=function(){var b=new Array();a.jQuery_element.find("input:checkbox:checked[name=product_groups]").each(function(){b.push($(this).attr("value"))});return b};this.subjectSelected=function(){return $("#check_subject_product_group:checked").length};this.entrySelected=function(){return a.jQuery_element.find("input:checkbox:checked[name=product_groups]").length};this.anotherSubjectSelected=function(){return $("#subject_list > li > :checkbox:checked:not(#check_subject_product_group)").length}}function Product(e,b,d,c){var a=this;this.id==e;this.name=b;this.image_url=d;this.description=c;this.equals=function(f){if(a.id==f.id&&a.name==f.name&&a.image_url==f.image_url&&a.description==f.description){return true}return false}}function ProductList(b){var a=this;this.jQuery_element=$('<table id="product_list"></table>').appendTo(b);this.displayed_products=new Array();this.selectSubject=function(){$("#subject_product div.subject_content").show();$("#plzsearch").show();$("#check_subject_product").attr("checked",true)};this.subjectSelected=function(){return $("#check_subject_product:checked").length};this.entrySelected=function(){return a.displayed_products.length};this.anotherSubjectSelected=function(){return $("#subject_list > li > :checkbox:checked:not(#check_subject_product)").length};this.getSelectedProducts=function(){return a.displayed_products};this.addProduct=function(f){var g=false;for(var e=0;e<a.displayed_products.length;e++){if(f.equals(a.displayed_products[e])){g=true}}if(!g){a.displayed_products.push(f);var d=$("<tr></tr>").appendTo(a.jQuery_element);var c='<td class="image"></td><td class="name"><b>'+f.name+"</b><p>"+f.description+'</p></td><td class="description"><a class="iconlink show_details" href="#" title="'+f.name+'">Produktdetails anzeigen</a></td><td class="remove_link"><a class="iconlink remove" href="#">Löschen</a></td>';$(c).appendTo(d);if(f.image_url){d.find("td.image").append('<img class="product_image" src="'+f.image_url+'" title="'+f.description+'" alt="'+f.name+'" />')}d.find("td.description a.show_details").click(function(){var h=new ProductDetails(f.details);return false});d.find("td.remove_link a.remove").bind("click",function(){a.removeProduct(d,f);return false});if(b.css("display")=="none"){b.show()}}};this.addProductByID=function(c){if(!c){return false}$.getJSON("/cgi/ajax/api_single_product.cgi",{product:c},function(e){if(e.result&&!e.error){var d=ajax_product_request_handler(e.result.products.product);a.addProduct(d);a.selectSubject()}})};this.removeProduct=function(e,d){for(var c=0;c<a.displayed_products.length;c++){if(d.equals(a.displayed_products[c])){a.displayed_products.splice(c,1)}}e.remove();if(!a.jQuery_element.find("tr").length){b.hide()}}}function CategoryDropdown(){var a=this;this.dropdown;this.addCategories=function(b){$("#menu_category").children().remove();a.removeSelection();$.each(b.categories.category,function(c,d){$('<li class="mc_root" value="'+d.$id+'">'+d.$name+"</li>").appendTo("#menu_category").bind("click",d,function(f){if(typeof d.category=="undefined"){subcategoryDropdown.removeSelection();subcategoryDropdown.disable(true);productDropdown.loadProducts(f.data.$id)}else{subcategoryDropdown.addCategories(d.category);subcategoryDropdown.disable(false)}})});a.dropdown=$("#selectbox_category").mcDropdown("#menu_category",dropdownSettings);$("#menu_category").width("340px");$("#selectbox_category").siblings("a").width("289px")};this.removeSelection=function(){if(a.dropdown){a.dropdown.html("")}subcategoryDropdown.disable(true)}}function SubcategoryDropdown(){var a=this;this.dropdown;this.addCategories=function(b){$("#menu_subcategory").children().remove();a.removeSelection();if(b.length){$.each(b,function(d,e){$('<li class="mc_root" value="'+e.$id+'">'+e.$name+"</li>").appendTo("#menu_subcategory").bind("click",e.$id,function(f){productDropdown.loadProducts(f.data)})})}else{var c=b;$('<li class="mc_root" value="'+c.$id+'">'+c.$name+"</li>").appendTo("#menu_subcategory").bind("click",c.$id,function(d){productDropdown.loadProducts(d.data)})}a.dropdown=$("#selectbox_subcategory").mcDropdown("#menu_subcategory",dropdownSettings);$("#menu_subcategory").width("340px");$("#selectbox_subcategory").siblings("a").width("289px")};this.removeSelection=function(){if(a.dropdown){$("#selectbox_subcategory").siblings("div").html("Unterkategorie auswählen")}};this.disable=function(b){if(a.dropdown){a.dropdown.disable(b)}}}function ProductDropdown(b){var a=this;this.dropdown;this.addProducts=function(e){$("#menu_product").children().remove();a.removeSelection();for(var c=0;c<e.length;c++){var d=e[c];$('<li class="mc_root" value="'+c+1+'">'+d.name+"</li>").appendTo("#menu_product").bind("click",d,function(f){b.addProduct(f.data)})}$("#selectbox_product").mcDropdown("#menu_product",dropdownSettings);$("#menu_product").width("600px");$("#selectbox_product").mcDropdown().disable(false);$("#selectbox_product").siblings("a").width("289px");a.dropdown=$("#selectbox_product").siblings("div")};this.loadProducts=function(d){var c=new Array();$.getJSON("/cgi/ajax/api_products.cgi",{category:d},function(f){if(f.result&&!f.error){if(f.result.products.product.$id){var e=ajax_product_request_handler(f.result.products.product);e.description=f.result.products.product.description.$t;c.push(e)}else{$.each(f.result.products.product,function(g,h){var j=ajax_product_request_handler(h);j.description=h.description.$t;c.push(j)})}productDropdown.addProducts(c)}})};this.removeSelection=function(){if(a.dropdown){a.dropdown.html("Modell auswählen")}}}function ProductPreview(){var a=this;this.show=function(){$("#product_preview").css("visibility","visible")};this.hide=function(){$("#product_preview").css("visibility","hidden")};this.addProduct=function(b){a.product=b;if(b.image_url){$("#product_preview img").attr("src",b.image_url).css("display","block")}else{$("#product_preview img").css("display","none")}$("#product_preview div strong").text(b.name);$("#product_preview div p").text(b.description);a.show();$("#link_add_product a.add_product").unbind("click").bind("click",b,function(c){productList.addProduct(c.data);a.hide();a.removeProduct();productDropdown.removeSelection();return false})};this.removeProduct=function(){a.product=null;$("#link_add_product a.add_product").unbind("click")}}function ProductDetails(b){var a=this;this.addDetail=function(f,g,d){if(f.indexOf("Feature")>-1){a.addFeature(g)}else{var e='<tr class="data"><td class="description">'+f+'</td><td class="value">'+g+"</td></tr>";if(d){$(e).appendTo(a.jQuery_element.find("table.technical_data"))}else{$(e).appendTo(a.jQuery_element.find("table.all_technical_data"))}}};this.addFeature=function(e){var d="<li><span>"+e+"</span></li>";$(d).appendTo(a.jQuery_element.find("div.features ul"))};$("#product_details").remove();a.jQuery_element=$('<div id="product_details"></div>').appendTo("body");$('<div id="product_description"><div class="text"><h2>'+b.brand.$t+" - "+b.name.$t+'</h2><p class="description">'+b.long_description.$t+'</p></div><div class="image"></div><div class="clear"></div></div><div id="product_data_headlines"><h3>Technische Daten</h3><h3>Features</h3></div><div id="product_data"><div class="inner_content"><div class="technical_data"><table class="technical_data" cellspacing="0" cellpadding="0" border="0"></table><div class="switch"><a class="iconlink show_details" href="#" title="» alle technischen Daten anzeigen">alle technischen Daten anzeigen</a></div><div class="all_technical_data"><table class="all_technical_data" cellspacing="0" cellpadding="0"></table></div></div><div class="features"><ul></ul></div><div class="clear"></div></div></div><p class="legend"><span>j</span> = im Lieferumfang, <span>o</span> = optional, <span>n</span> = nicht verfügbar</p>').appendTo(this.jQuery_element);if(b.images.image){var c;if(b.images.image.length){$.each(b.images.image,function(d,e){if(e.$position=="0"){c=e.variants.normal.$t}})}else{c=b.images.image.variants.normal.$t}a.jQuery_element.find("div.image").append('<img src="'+c+'"/><p>Abbildung ähnlich.</p>')}a.jQuery_element.find(".tabs > span a").click(function(){a.showTab(a.jQuery_element.find(".tabs > span a").index($(this)));return false});a.jQuery_element.find("div.switch a.show_details").click(function(){if(a.jQuery_element.find("div.all_technical_data").is(":visible")){a.jQuery_element.find("div.all_technical_data").hide();a.jQuery_element.find("table.all_technical_data").hide();$(this).text("alle technischen Daten anzeigen").attr("title","» alle technischen Daten anzeigen").removeClass("hide_details").addClass("show_details")}else{a.jQuery_element.find("div.all_technical_data").show();a.jQuery_element.find("table.all_technical_data").show();$(this).text("alle technischen Daten ausblenden").attr("title","» alle technischen Daten ausblenden").removeClass("show_details").addClass("hide_details")}return false});$.each(b.additional,function(d,e){a.addDetail(e.description.$t,e.value.$t,e.$important)});$("#colorbox").removeClass("premium");$.fn.colorbox({width:"830px",height:"85%",inline:true,opacity:2/3,href:"#product_details",open:true})}function Dealer(g,c,f,d,b,e,a){this.id=g;this.name=c;this.street=f;this.city=d;this.range=b;this.distance=e;this.premium=a;this.selected}function DealerList(b){var a=this;this.parent_element=b;this.displayed_dealer=new Array();this.getSelected=function(){var c=new Array();$.each(a.displayed_dealer,function(d){if(a.displayed_dealer[d].selected){c.push(this)}});return c};this.entrySelected=function(){var c=false;$.each(a.displayed_dealer,function(d){if(a.displayed_dealer[d].selected){c=true}});return c};this.setSelected=function(d,c){$.each(a.displayed_dealer,function(e){if(this.id==d){a.displayed_dealer[e].selected=c}})};this.addDealer=function(d){a.displayed_dealer.push(d);var c;if(d.premium){c='<div class="dealer_entry premium"></div>'}else{c='<div class="dealer_entry"></div>'}var e=$(c).appendTo(b);$('<input name="check_dealer" id="check_dealer_'+d.id+'" type="checkbox" value="'+d.id+'" /><a class="iconlink show_details" href="#" title="» Händlerdetails anzeigen">Händlerdetails anzeigen</a><div class="dealer_details"><address><strong>'+d.name+"</strong>"+d.street+"<br />"+d.city+'</address><span class="product_range_label">Sortiment:</span><span class="product_range">'+d.range+'</span><br /><span class="product_distance_label">Entfernung:</span><span class="product_distance">'+d.distance+" km</span></div>").appendTo(e);e.children("a.show_details").attr("href","/cgi/dealer_search.cgi?action=dealer_details&id="+d.id).attr("title",d.name).click(function(){if(d.premium){$("#colorbox").addClass("premium")}else{$("#colorbox").removeClass("premium")}$.fn.colorbox({height:"490px",width:"850px",opacity:2/3,title:d.name,href:"/cgi/dealer_search.cgi?action=dealer_details&id="+d.id,iframe:true,open:true});return false});if(d.premium){e.append('<img class="premium_logo" src="/images/contact/premium.gif" title="Premium Händler" alt="Premium Händler" />')}if(b.css("display")=="none"){b.slideDown(slideSpeed)}e.find("input[type=checkbox]").checkbox(checkboxSettings).bind("check",d.id,function(f){$(this).parent().addClass("active");a.setSelected(f.data,true)}).bind("uncheck",d.id,function(f){$(this).parent().removeClass("active");a.setSelected(f.data,false)})};this.removeAllDealers=function(){while(a.displayed_dealer.length){a.displayed_dealer.pop()}b.children("div.dealer_entry").remove()};this.setError=function(c){a.html("Fehler: "+c)}}function getURLParam(e){var d="";var c=window.location.href;if(c.indexOf("?")>-1){var b=c.substr(c.indexOf("?"));var f=b.split("&");for(var a=0;a<f.length;a++){if(f[a].indexOf(e+"=")>-1){var g=f[a].split("=");d=g[1];break}}}return d}function ajax_product_request_handler(a){var b=new Product();b.id=a.$id;b.name=a.name.$t;b.details=a;b.description=a.description.$t;if(a.images.image){if(a.images.image.length){$.each(a.images.image,function(c,d){if(d.$position=="0"){b.image_url=d.variants.small.$t}})}else{b.image_url=a.images.image.variants.small.$t}}return b}$(document).ready(function(){productList=new ProductList($("#request_products"));productPreview=new ProductPreview();productDropdown=new ProductDropdown(productPreview);categoryDropdown=new CategoryDropdown();subcategoryDropdown=new SubcategoryDropdown();productGroupList=new ProductGroupList();$("body").append('<ul id="menu_category" class="mcdropdown_menu"></ul><ul id="menu_subcategory" class="mcdropdown_menu"></ul><ul id="menu_product" class="mcdropdown_menu"></ul>');dealerList=new DealerList($("#dealer_area"));pID=getURLParam("pID");if(pID){$.getJSON("/cgi/ajax/api_single_product.cgi",{product:pID},function(data){if(data.result&&!data.error){var product=ajax_product_request_handler(data.result.products.product);productPreview.addProduct(product);productList.addProduct(product);productList.selectSubject();$.scrollTo($("#plzsearch"),2000,{offset:-10});$("#search_plz").focus()}})}$("input[type=checkbox]").checkbox(checkboxSettings).bind("disable",function(){this.checked=false});$("#check_subject_product_group").bind("check",function(){checkIfProductRequest();$("#check_subject_question").attr("disabled",true);$(this).siblings("div.subject_content").slideDown(slideSpeed)}).bind("uncheck",function(){checkIfProductRequest();$(this).siblings("div.subject_content").slideUp(slideSpeed)}).bind("disable",function(){$("#subject_product_group").addClass("disabled")}).bind("enable",function(){$("#subject_product_group").removeClass("disabled")});$("#check_subject_product").bind("check",function(){checkIfProductRequest();$("#check_subject_question").attr("disabled",true);$(this).siblings("div.subject_content").slideDown(slideSpeed)}).bind("uncheck",function(){checkIfProductRequest();$(this).siblings("div.subject_content").slideUp(slideSpeed)}).bind("disable",function(){$("#subject_product").addClass("disabled")}).bind("enable",function(){$("#subject_product").removeClass("disabled")});$("#check_subject_question").bind("check",function(){$("#check_subject_product").attr("disabled",true);$("#check_subject_product_group").attr("disabled",true);$(this).siblings("div.subject_content").slideDown(slideSpeed)}).bind("uncheck",function(){$("#check_subject_product").attr("disabled",false);$("#check_subject_product_group").attr("disabled",false);$(this).siblings("div.subject_content").slideUp(slideSpeed)}).bind("disable",function(){$("#subject_question").addClass("disabled")}).bind("enable",function(){$("#subject_question").removeClass("disabled")});$("#testrun").bind("check",function(){$("div.telephone span.required").show()}).bind("uncheck",function(){$("div.telephone span.required").hide()});categoryDropdown.addCategories(categories);$("#selectbox_subcategory").mcDropdown("#menu_subcategory",dropdownSettings);$("#selectbox_product").mcDropdown("#menu_product",dropdownSettings);$("#selectbox_subcategory").mcDropdown().disable(true);$("#selectbox_product").mcDropdown().disable(true);$("#plzsearch_button").click(function(){$("#search_plz").focus();if($("#plzsearch #search_plz").valid()){dealerList.removeAllDealers();var zip=$("input#search_plz").val();$.getJSON("/cgi/ajax/search_retailer.cgi",{plz:zip,product_groups:[productGroupList.getSelectedProductGroups()]},function(data){if(data.result&&!data.error){$.each(data.result,function(i,item){var dealer=new Dealer(item.ID,item.name,item.address,item.zip+" "+item.place,item.all_product_groups,item.dist,item.premium);dealerList.addDealer(dealer);if(i==3){return false}})}})}return false});$("#search_plz").keydown(function(e){if(e.keyCode==13){$("a#plzsearch_button").trigger("click")}}).mask("99999",{placeholder:""});$("#postal-or-zip-code").mask("99999",{placeholder:""});jQuery.validator.addMethod("dealerSelected",function(value,element){return dealerList.entrySelected()});jQuery.validator.addMethod("productSelected",function(value,element){return productList.displayed_products.length});jQuery.validator.addMethod("productGroupSelected",function(value,element){return productGroupList.entrySelected()});$("#contact_form").validate({errorClass:"errorfield",submitHandler:function(form){$("#contact_form").append('<div id="product_request_loading_overlay"></div><div id="product_request_loading_animation"></div><div id="product_request_loading_messages"></div>');$("#contact_form div#product_request_loading_overlay").css({opacity:0.6});if(!productGroupList.subjectSelected()&&!productList.subjectSelected()){$("#your_subject input#check_subject_question").attr("checked",true)}var selected_products="";if(productList.subjectSelected()&&productList.entrySelected()){$.each(productList.getSelectedProducts(),function(i){selected_products+="&product="+this.id})}$.ajax({type:"post",url:"/cgi/contact.cgi",data:"action=exec&"+$("#contact_form").serialize()+selected_products,success:function(json){data=eval("("+json+")");$("#product_request_loading_animation").remove();if(data.Error){$("#product_request_loading_messages").html(data.Error.join("<br />"))}else{$.scrollTo($("body"),1000);$("#contact_form").before('<div id="success_message"><p>'+data.success+'</p><p><a class="more" href="/" title="zurück zur Startseite">zurück zur Startseite</a><br /><a class="more" href="/produktsortiment" title="zu unserem Online-Shop">zu unserem Online-Shop</a></p></div>').remove()}$("#product_request_loading_messages").animate({opacity:1},3000,function(){$("#product_request_loading_messages").fadeOut(function(){$(this).remove()});$("#product_request_loading_overlay").fadeOut(function(){$(this).remove()})})}})},errorElement:"span",errorPlacement:function(error,element){if(element.parent().parent()[0]==$("ul#subject_list")[0]){error.prependTo(element.siblings("div.subject_content").children("div.inner_content")).hide().css("height","auto").slideDown()}else{error.appendTo(element.parent()).hide().css("height","auto").slideDown()}},invalidHandler:function(){$("#contact_form").trigger("label_errorfield_created").unbind("label_errorfield_created")},showErrors:function(errorMap,errorList){if(submitbutton_clicked){submitbutton_clicked=false;$("#contact_form").unbind("label_errorfield_created").bind("label_errorfield_created",function(){$.scrollTo($("div.errorfield:eq(0)").parent(),1000)});this.defaultShowErrors()}},rules:{check_subject_product:{productSelected:{depends:function(element){return $("#check_subject_product").attr("checked")&&(!productGroupList.subjectSelected()||(productGroupList.subjectSelected()&&!productGroupList.entrySelected()))}}},check_subject_product_group:{productGroupSelected:{depends:function(element){return $("#check_subject_product_group").attr("checked")&&(!productList.subjectSelected()||(productList.subjectSelected()&&!productList.entrySelected()))}}},comment:{required:function(){return !(isProductRequest())}},phone:{required:"#testrun:checked"}},messages:{person:"Bitte geben Sie einen Ansprechpartner ein.",email:{required:"Bitte geben Sie Ihre E-Mail-Adresse ein.",email:"Bitte geben Sie eine gültige E-Mail-Adresse ein."},phone:"Bitte geben Sie Ihre Telefonnummer an.",comment:"Bitte geben Sie eine kurze Nachricht ein, damit wir Ihr Anliegen besser verstehen.",check_subject_product:{productSelected:'Bitte wählen Sie mindestens ein Produkt aus. Bestätigen Sie Ihre Auswahl bitte über den Link "Produkt auswählen".'},check_subject_product_group:{productGroupSelected:"Bitte wählen Sie mindestens eine Produktgruppe aus."}}});$("a.form_submit").click(function(){submitbutton_clicked=true;$("#contact_form").submit();return false})});