/* $Id: carconfigurator.js 11749 2011-02-03 15:27:44Z mhammel $ */
(function(e,d,b){var c,a;c={sent:{},send:{},lastPrice:0,bFirstFeatureClick:true,addEvent:function(h,g,f){if(!(h in this.send)){this.send[h]={}}if(!(f in this.send[h])){this.send[h][f]=[]}if(!(h in this.sent)){this.sent[h]={}}if(!(f in this.sent[h])){this.sent[h][f]=[]}e.merge(this.send[h][f],g.replace(/[ ]*,[ ]*/g,",").split(","))},eventAlreadySent:function(h,f,g){g=g||"events";return e.inArray(f,this.sent[h][g])>-1},call:function(f){e("<img>").attr("src",f)},omniture:(function(){var f="omniture";return{eventAlreadySent:function(g,h){h=h||"events";return e.inArray(g,c.sent[f][h])>-1},addEvent:function(h,g){g=g||"events";c.addEvent(f,h,g)},track:function(g){g=g||"tl";var h;if(typeof s==="object"&&e.isFunction(s[g])){for(h in c.send[f]){if(c.send[f].hasOwnProperty(h)){s[h]=c.send[f][h].join(",");e.unique(e.merge(c.sent[f][h],c.send[f][h]))}}s[g]();for(h in c.send[f]){if(c.send[f].hasOwnProperty(h)){s[h]="";c.send[f][h]=[]}}}}}})(),trackPriceChange:function(f){var g=this.lastPrice;this.lastPrice=f;return g!==f},isConfigured:function(f){if(typeof this.oConfig!=="object"){this.oConfig=typeof oCarConfiguratorTrackingConfig==="function"?oCarConfiguratorTrackingConfig(this):{}}return f in this.oConfig&&e.isFunction(this.oConfig[f])},trackSectionClicks:function(f){if(this.isConfigured("sectionClicked")){this.oConfig.sectionClicked(f)}},trackFeatureClicks:function(){if(this.isConfigured("featureClicked")){var f=e("#configSections").data("aTotalSum")[0];this.oConfig.featureClicked(this.bFirstFeatureClick,f,this.trackPriceChange(f))}if(this.bFirstFeatureClick){this.bFirstFeatureClick=false}},trackConfiguratorStart:function(){if(this.isConfigured("configuratorStart")){this.oConfig.configuratorStart(e("#configSections").data("aTotalSum")[0])}}};String.prototype.firstToUpperCase=function(f){return(f||"")+this.charAt(0).toUpperCase()+this.substr(1)};Array.prototype.addArray=function(f,g){g=g||2;if(Object.prototype.toString.call(f)!=="[object Array]"){f=[f]}for(var h=0;h<this.length;h+=1){this[h]=!isNaN(this[h])?this[h]*1:0;f[h]=!isNaN(f[h])?f[h]*1:0;this[h]+=f[h];this[h]=Math.round(this[h]*Math.pow(10,g))/Math.pow(10,g)}return this};Array.prototype.sumInitialize=function(f){for(var g=0;g<f.length;g+=1){this[g]=0}return this};jQuery.fn.extend({check:function(){return this.each(function(){this.checked=!this.disabled})},uncheck:function(){return this.each(function(){this.checked=false})},checkToggle:function(f){if(typeof f==="boolean"&&f===false){return this}return this.each(function(){if(!this.disabled){this.checked=this.type!=="radio"?!this.checked:true}})},setDisabled:function(){return this.each(function(){e(this).addClass("disabled").find("input").get(0).disabled=true})},setEnabled:function(){return this.each(function(){e(this).removeClass("disabled").find("input").get(0).disabled=false})},clickable:function(){return this.each(function(){e(this).andSelf().css({visibility:"visible",cursor:"pointer"})})}});a=(function(){var h,f,k,i,g=e("#accessories > div.sectionContent > h3"),j=", ";i={priceBuildHTML:function(n,o){o=o||"";for(var m=0,l="";m<n.length;m+=1){l+=m===0?"<span>"+n[m]+"</span>\t\n":'<span class="xPrice">('+o+n[m]+")</span>\t\n"}return l},priceFormat:function(n){for(var m=0,l=[];m<n.length;m+=1){l[m]=(b.currencySymbols&&e.isArray(b.currencySymbols)&&b.currencySymbols.length>=n.length?b.currencySymbols[m]:b.currencies[m])+" "+n[m].toFixed(2)}return l},writeSectionSum:function(n,m){var l=this.priceBuildHTML(m);e("h1.sectionHead",n).find("span:not(.info, .sectionName)").remove().end().find("span.sectionName").after(l)},writeSubSectionSum:function(n,m){var l=this.priceBuildHTML(m);e("h3.sectionHead[id="+n+"]").find("span:not(.info, .sectionName)").remove();e("h3.sectionHead[id="+n+"]").find("span.sectionName").after(l)},writeTotalSum:function(m){var l=this.priceBuildHTML(m);e("#topSum, #bottomSum").find("span.price").each(function(){e(this).html(l)})},fullPriceUpdate:function(){var m,p,n=[].sumInitialize(b.currencies),l={country:b.priceFormatter.country},o={currencies:b.currencies,formatterName:b.priceFormatter.name,prices:{}};f.each(function(){var q=e(this).data("aSectionSum");o.prices[this.id]=q;n.addArray(q);if(this.id==="accessories"){g=e("#accessories > div.sectionContent > h3");g.each(function(){var r=e(this).data("aSubSectionSum");o.prices[this.id]=r})}});o.prices.sum=n;e("#configSections").data("aTotalSum",n);l.priceData=JSON.stringify(o);m={data:l,url:b.priceFormatter.uri,timeout:b.priceFormatter.timeout,success:function(r){var q;if(r.error){return this.error()}if(r.prices){r=r.prices}for(q in r){if(q in r){if((q==="1EXTERIOR")|(q==="2INTERIOR")|(q==="3TRANSPORTATION")|(q==="4SAFETY")|(q==="5INFOTAINMENT")){i.writeSubSectionSum(q,r[q])}else{if(q!="sum"){i.writeSectionSum(e("#"+q),r[q])}else{i.writeTotalSum(r[q])}}}}},error:function(){var q;for(q in o.prices){if(o.prices.hasOwnProperty(q)){if(q!=="sum"){i.writeSectionSum(e("#"+q),i.priceFormat(o.prices[q]))}else{i.writeTotalSum(i.priceFormat(o.prices[q]))}}}}};if(b.priceFormatter.useCrossSiteJSONP){p="jsonp";m.url+="?jsonpCallback=?"}else{p="ajax";m.dataType="json"}e[p](m)},updateColors:function(m){var o="",l,n=e("input",m).val();e("#carNavigation > .carNav").show();for(l in b.model.perspectiveNameParts){if(b.model.perspectiveNameParts.hasOwnProperty(l)){o=b.oImagePath.cars+b.model.perspectiveNameParts[l].prefix+b.model.prefix+b.model.name+"_"+n+b.model.perspectiveNameParts[l].postfix+".png";e("#"+l+"View").attr("src",o);e("#carNavigation .show > #"+l+"Wrp").show()}}},updateRims:function(l){var n="",m=e("input",l).val();n=b.oImagePath.rims+b.model.name+"/"+m+"_"+b.model.name+".gif";e("#rimLayer").attr("src",n)},variantSetFeatures:function(l){f.each(function(){var n,m=e(this);e("ul.features",m).each(function(){var p=[],o=e(this);e("li:not(.group, .conflict li)",o).each(function(){if(!(this.id in d)){p.push(this);e(this).setDisabled()}else{if(e.isArray(d[this.id].excludingVariants)&&e.inArray(l,d[this.id].excludingVariants)>-1){p.push(this);e(this).setDisabled()}else{e(this).setEnabled()}}});n=e("input:checked",p).uncheck();if(n.is(":radio")){if(o.children("li:not(.group, .disabled, .conflict li):eq(0)").find("input:radio[name="+n.attr("name")+"]").check().length===0){o.siblings("ul.features").add(o.parent(".third, .twothird").siblings(".third, .twothird").children("ul.features")).children("li:not(.group, .disabled, .conflict li):eq(0)").find("input:radio[name="+n.attr("name")+"]").check()}}})})},sectionSelectionUpdates:function(o,n){var l=[],p=[].sumInitialize(b.currencies);e.each(o,function(){var r=e(this),q=r.attr("id");l.push(i.getFeatureName(r));if(q in d&&"price" in d[q]){p.addArray(d[q].price)}});if(f.index(n)===0){l=e.merge([n.data("sSelectedVariantName")],l);p.addArray(n.data("sSelectedVariantPrice"))}if(n.attr("id")==="accessories"){var m=e("#accessories > div.sectionContent > h3");m.each(function(){var x=e(this),t=[],u=[].sumInitialize(b.currencies);var w=this.id;var v=e(this).next(".sectionContent");var r=e(this).next("div.sectionContent").children().children().children("li.selected");r.each(function(){var z=e(this),y=z.attr("id");t.push(i.getFeatureName(z));u.addArray(d[y].price)});e("h3.sectionHead[id="+w+"] span.info",n).text(t.join(j));x.data("aSubSectionSum",u);var q})}e("h1.sectionHead span.info",n).text(l.join(j));n.data("aSectionSum",p)},getFeatureName:function(l){return e("label strong",l).text()},checkForConflicts:function(m){var l=this;f.find("ul.features li.conflict").removeClass("conflict").removeData("aConflictSources").find(".message").remove();e(".mail").bind("click",displaySendLayer);e(".service").removeClass("sendInactive");f.find("ul.features li.selected").each(function(){var o=this.id,n=[];if(!"excludes" in d[o]||!e.isArray(d[o].excludes)||d[o].excludes.length===0){return}e.each(d[o].excludes,function(){if(e("#"+this).hasClass("selected")){n.push(this)}});if(n.length>0){l.setConflict(o,n);e(".mail").unbind("click");e(".service").addClass("sendInactive")}})},setConflict:function(m,p){var l=[],o,n=e("#"+m);if(!e.isArray(p)){p=[p]}e.each(p,function(){var r=e("#"+this),q=r.closest("li.section");l.push({name:i.getFeatureName(r),sectionId:q.attr("id")});if(q.hasClass("closed")){q.find("h1.sectionHead").click()}});o='<ul class="conflictSources">';e.each(l,function(){o+="<li>"+b.conflictMsg.details.replace("%FEATURE%",'<span class="conflictSource">'+this.name+"</span>").replace("%SECTION%",'<a href="#'+this.sectionId+'">'+e("#"+this.sectionId).data("sSectionName")+"</a>")+"</li>"});o+="</ul>";n.addClass("conflict").append('<div class="message">'+b.conflictMsg.intro+o+"</div>")}};return{init:function(l){h=this;f=l;f.each(function(){e(this).data("sSectionName",e("h1.sectionHead .sectionName",this).text())});h.handleEngineTypes()},handleSelectedFeatures:function(l,m){l=l||f;m=g;m.each(function(){var o=e(this),n=o.attr("id")});l.each(function(){var p=e(this),n=p.attr("id"),o=[];e("ul.features li:not(.group)",p).removeClass("selected");e("ul.features li:not(.group) input:checked",p).each(function(){o.push(e(this).closest("li").addClass("selected").get(0))}).siblings().removeClass("selected");i.sectionSelectionUpdates(o,p);if(n.firstToUpperCase("update") in i){i[n.firstToUpperCase("update")](e("ul.features li.selected",p))}});i.fullPriceUpdate();i.checkForConflicts()},handleEngineTypes:function(m){var o,q=f.slice(0,1),l,n,p="false";if(typeof(hideLpgIcon)!="undefined"){if(hideLpgIcon==="true"){p="true"}}q.find("tr.selected").removeClass("selected");if(m instanceof jQuery&&m.length===1){m.addClass("selected")}else{m=q.find("td:first-child input:checked").closest("tr").addClass("selected")}l=q.find("tr:not(:first-child)").index(m);n=q.find("table tr.selected + tr").hasClass("lpgFeature");$rowsBefore=q.find("table tr:lt("+(l+1)+")");rowsBeforeLpgCount=$rowsBefore.filter("tr.lpgFeature").length;if(n){q.find("table tr.selected + tr").addClass("selected")}l+=1-rowsBeforeLpgCount;q.data("sSelectedVariantName",q.find("table tr.selected td:nth-child(2) label").text());if(b.variants[l].price){o=b.variants[l].price}else{o=[0]}if(n&&!(p==="true")){if(e("#lpgIcon").length!==1){e("#carPicWrp").append("<img id='lpgIcon' src='/assets/images/global/carconfigurator-lpg.png' style='position:absolute;left:35px;top:270px;'/>")}}else{e("#lpgIcon").remove()}q.data("sSelectedVariantPrice",b.variants[l].price);e("#topSum, #bottomSum").each(function(){e(this).find("h1 span.modelName em").text(b.variants[l].name)});i.variantSetFeatures(l);h.handleSelectedFeatures()}}})();e(document).ready(function(){e("body").addClass("jsReady");if(oCtaHelper){oCtaHelper.refreshGroup(e("#carPicWrp a.button"));oCtaHelper.refreshGroup(e("#carConfFooter a.button"))}var f=e("#configSections > li.section");var g=e("#accessories > div.sectionContent > h3");f.addClass("closed").children(".sectionContent").hide().slice(0,1).slideDown("slow",function(){e(this).closest("li").removeClass("closed")});f.find("h1.sectionHead").clickable().click(function(i){var h=e(this).closest("li");c.trackSectionClicks(h.hasClass(".closed"));e(this).next(".sectionContent").slideToggle("slow");h.toggleClass("closed")});e(".toggleListView span.utilityLink","#carConfigurator").clickable().click(function(h){if(e(this).closest("li.collapse").length){f.addClass("closed").find(".sectionContent").slideUp("slow");g.addClass("closed")}else{f.removeClass("closed").find(".sectionContent").slideDown("slow");g.removeClass("closed");c.trackSectionClicks(true)}});f.find("h3.sectionHead").clickable().click(function(i){var h=e(this).closest("li");e(this).next(".sectionContent").slideToggle("slow");e(this).toggleClass("closed")});e("#engine tr:not(':first-child', '.lpgFeature')").clickable().click(function(i){var h=e(this).closest("tr").find("td:first-child input").is("tr.selected input:radio:checked, :disabled");if(e(i.target).is("label, label *")){i.preventDefault()}if(!h){if(e(i.target).is(":not(input)")){e(this).find("td:first-child input").check()}a.handleEngineTypes(e(this));c.trackFeatureClicks()}});e("#configSections ul.features li:not(.group)").clickable().click(function(j){var h=e(j.target),k,i=e(this).closest("li").find("input").is("li.selected>input:radio:checked, :disabled");if(!e(this).closest("li").hasClass("conflict")||!h.is(".message a")){if(h.is("label, label *")){j.preventDefault()}if(!i){if(h.is(":not(input)")){e("input:radio, input:checkbox",this).checkToggle()}a.handleSelectedFeatures(e(this).closest(".section"));c.trackFeatureClicks()}}else{k=e(h.attr("href").match(/(#.*)$/i)[0]);if(k.hasClass("closed")){k.find("h1.sectionHead").click()}}});e("#carNavigation>.carNav").clickable().click(function(j){var i,h=e(this);if(!h.hasClass("active")){e("#carNavigation .carNav").removeClass("active");h.addClass("active");i=e("#carPicWrp #"+h.attr("id").match(/(.*)ViewBtn/)[1]+"Wrp").show();if(e.support.opacity){i.find("img").fadeIn("slow").parent("div").addClass("show").siblings(".show").removeClass("show").find(".car, #rimLayer").fadeOut("slow")}else{i.addClass("show").siblings(".show").removeClass("show")}}});a.init(f);c.trackConfiguratorStart();oCustomToolTip.setContentGetter(function(h){return e("#Content"+h).html()});oCustomToolTip.setTriggerClass("tooltip");oCustomToolTip.setAlignment("top","right");oCustomToolTip.init("15px","-42px")})})(jQuery,oCarConfiguratorFeatureData,oCarConfiguratorGlobalSettings);jQuery(document).ready(function(){jQuery("#cc").live("click",function(){if(jQuery("#emailcc").parent().parent().find(".sendPdfLabel").html().charAt(0)!="*"){var b=jQuery("#emailcc").parent().parent().find(".sendPdfLabel").html();var a="*"+b;jQuery("#emailcc").parent().parent().find(".sendPdfLabel").html(a)}else{var b=jQuery("#emailcc").parent().parent().find(".sendPdfLabel").html();var c=b.substring(1);jQuery("#emailcc").parent().parent().find(".sendPdfLabel").html(c)}});jQuery("#return").live("click",function(a){a.preventDefault();jQuery("#inlineWindow_sendToFriend #closer_sendToFriend").click()});jQuery("#returnConfirm").live("click",function(a){a.preventDefault();jQuery("#inlineWindow_sendToFriend #closer_sendToFriend").click()});jQuery("#submit").live("click",function(r){r.preventDefault();var v=jQuery("#configSections #engine :checked").val(),p=jQuery("#configSections #colors :checked").attr("id").replace("input",""),f=jQuery("#configSections #seatCover :checked").attr("id").replace("input",""),q=jQuery("#configSections #rims :checked").attr("id").replace("input",""),t=jQuery("#configSections #optionalEquipment :checked").val(),o=jQuery("#configSections #accessories :checked").val(),u=[],x,g=[],k,c=jQuery("#configSections #warranties :checked").val(),w;jQuery("#configSections #optionalEquipment :checked").each(function(){u.push('"'+jQuery(this).attr("id").replace("input","")+'"')});jQuery("#configSections #accessories :checked").each(function(){g.push('"'+jQuery(this).val()+'"')});if(t){x=',"optional":['+u+"]"}else{x=""}if(o){k=',"accessories":['+g+"]"}else{k=""}if(c&&(c!="")&&(c!=null)){warrantyID=jQuery("#configSections #warranties :checked").attr("id").replace("input","");w=',"warranties":["'+warrantyID+'"]'}else{w=""}var m=jQuery("#sendconfiguration #email").val(),n=jQuery("#sendconfiguration #emailcc").val(),j=jQuery("#sendconfiguration #cc").val(),h=jQuery("#sendconfiguration #message").val().replace(/\015\012|\015|\012/ig,"##").replace(/\"/ig,"''").replace(/\\/ig,"&#92;");if(j==="on"){j="true"}else{j="false"}var l=',"mailData": {"to": "'+m+'","cc":"'+n+'","confirm": "'+j+'","message":"'+h+'"}';categoryArray='"categories": {"engine": "'+v+'","color":"'+p+'","seatCover": "'+f+'","rims":"'+q+'"'+x+w+k+"}";var d='{"site":"'+siteName+'","xmlReference":"'+dataXmlName+'",'+categoryArray+l+"}";var e="";if(jQuery("#cc").attr("checked")){e="true"}else{e="false"}if(h===""){jQuery("#sendconfiguration span#errorMessage").css("display","block")}if(h!==""){jQuery("#sendconfiguration span#errorMessage").css("display","none")}var a="";if(m!=""&&isValidEmailAddress(m)){a="true"}var i="";if(n!=""&&isValidEmailAddress(n)){i="true"}if(a!=="true"){jQuery("#sendconfiguration span#errorMail").css("display","block")}if(a==="true"){jQuery("#sendconfiguration span#errorMail").css("display","none")}if(i!=="true"&&e==="true"){jQuery("#sendconfiguration span#errorMailcc").css("display","block")}if((i!=="true"&&e!=="true")|(i==="true"&&e==="true")){jQuery("#sendconfiguration span#errorMailcc").css("display","none")}if(a==="true"&&h!=""&&(i==="true"|(e!="true"))){var b=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");b.open("POST",pdfServiceUrl,true);b.setRequestHeader("Content-Type","application/json; charset=utf-8");b.send(d);h=jQuery("div#sendToFriend-confirm").html();h+='<script type="text/javascript">s.events="event26";var s_code=s.t();if(s_code)document.write(s_code);<\/script>';jQuery("#inlineWindow_sendToFriend div.contentArea div.contentText").html(h)}})});function isValidEmailAddress(b){var a=new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);return a.test(b)}function displaySendLayer(b){b.preventDefault();var g=jQuery("div#carConfigurator div#topSum span.modelName").html().replace(/(<.*?>)|\015\012|\015|\012|\s{2,}/ig,""),j=jQuery("div#carConfigurator li#engineTypes h1.sectionHead span.info").html().replace(/(<.*?>)|\015\012|\015|\012|\s{2,}/ig,""),k=jQuery("#colors li.selected label span strong").html(),d=jQuery("#seatCover li.selected label span strong").html(),c=jQuery("#rims li.selected label span strong").html(),e=jQuery("div#carConfigurator li#optionalEquipment h1.sectionHead span.info").html(),f=jQuery("div#carConfigurator li#accessories h1.sectionHead span.info").html(),i=jQuery("div#carConfigurator li#warranties h1.sectionHead span.info").html(),m=jQuery("div#carConfigurator li#warranties h1.sectionHead span.sectionName").html(),h=jQuery("#configSections #warranties :checked").val();if(e){e=", "+e}if(e===null){e=""}if(f!=""&&f!=null){f=", "+f}else{f=""}if(h&&(h!="")&&(h!=null)){warrantyString=", "+m+": "+i}else{warrantyString=""}var l=jQuery.trim(g)+", "+jQuery.trim(j)+", "+k+", "+d+", "+c+e+f+warrantyString,a=jQuery("div#sendToFriend-start").html();jQuery("#inlineWindow_sendToFriend div.contentArea div.contentText").html(a);message=jQuery("#sendconfiguration textarea#message").val().replace("@@configurationString",l);jQuery("#inlineWindow_sendToFriend div.contentArea div.contentText div#configurationString").html(l);jQuery("#inlineWindow_sendToFriend div.contentArea div.contentText textarea#message").val(message);jQuery("#sendconfiguration span#errorMail").css("display","none");jQuery("#sendconfiguration span#errorMailcc").css("display","none");jQuery("#sendconfiguration span#errorMessage").css("display","none");activateInlineWindow("inlineWindow_sendToFriend","test")};
