$().ready(function(){if(has_special){write_specialattrib_options();write_specialattrib_values();$("#cart_quantity select#specialattrib_options").change(write_specialattrib_values);$("div#attribImages_optionsList a").click(onclick_specialattribImages);$("div#attribImages_optionsList a").click(write_specialattrib_values);if(has_exclusions)$("div#attribImages_optionsList a").click(exclusion_attributes);$("div#attribImages_optionsList a").click(change_attribImages_borderColor);$("div#attribImages_optionsList a").click(writePrice);}
write_attribImages();if(has_exclusions)exclusion_attributes();change_attribImages_borderColor();writePrice();if(has_exclusions)$("#cart_quantity select:not(#products_qty)").change(exclusion_attributes);$("#cart_quantity select:not(#products_qty)").change(change_attribImages_borderColor);$("div.attribImages_unSpecialList a").click(onclick_attribImages);if(has_exclusions)$("div.attribImages_unSpecialList a").click(exclusion_attributes);$("div.attribImages_unSpecialList a").click(change_attribImages_borderColor);$("div.attribImages_unSpecialList a").click(writePrice);$("#cart_quantity select").change(writePrice);});function exclusion_attributes(){if($("select.disabled").length>0){$("#cart_quantity select.disabled").each(function(){var org_id=this.id;org_id=org_id.substr(5);var selIndex=$("#cart_quantity select[id="+org_id+"]:not(.disabled) option:selected").val();$("#cart_quantity select[id="+org_id+"]:not(.disabled) option").remove();$(this).copyOptions("#cart_quantity select[id="+org_id+"]","all");$("div.attribImages_unSpecialList td").show();$(this).remove();$("#cart_quantity select[id="+org_id+"]").val(selIndex);});}
$("#cart_quantity select:not(#products_qty, #specialattrib_options, #specialattrib_values, .disabled)").each(function(){var selectbox=this;if($("#cart_quantity select[id="+selectbox.id+"].disabled").length==0){$(selectbox).clone().insertAfter(selectbox).addClass("disabled").attr("id",'copy_'+selectbox.id).attr("name",'copy_'+selectbox.name).attr("disabled",'disabled').hide();}});var selectedoptionSp=$("#cart_quantity #specialattrib_values").val();$("#cart_quantity select:not(#products_qty, #specialattrib_options, #specialattrib_values, .disabled)").each(function(){var selectbox=this;var selectedoption=this.value;$.each(obj_values,function(i,val){if(selectedoption==val.code||selectedoptionSp==val.code){if(val.excl_values!=""&&val.excl_values!=null){var excl_values=val.excl_values;var arr_excl_values=excl_values.split("|");$.each(arr_excl_values,function(i1,row_excl_values){$("div.attribImages_unSpecialList td#td_"+row_excl_values).addClass('invisible').hide();});$("#cart_quantity select:not(#products_qty, #specialattrib_options, #specialattrib_values, .disabled)").removeOption(arr_excl_values);}}});});}
function writePrice(){var obj=obj_values;var selectboxes=document.getElementsByTagName("select");var summe=0;for(var i=0;i<selectboxes.length;i++){for(var x=0;x<obj.length;x++){if(selectboxes[i].options.length<1)
continue;if(selectboxes[i].options[selectboxes[i].selectedIndex].value==obj[x].code&&selectboxes[i].id.indexOf("copy")==-1&&selectboxes[i].id!="specialattrib_options"&&selectboxes[i].id!="products_qty"){if(obj[x].price_prefix=="-"){if(obj[x].price_is_percent=="1"){summe-=parseFloat(getOptionsSumWhithoutPercent()*(obj[x].price_percent_value/100));}else{summe-=parseFloat(obj[x].price);}}else{if(obj[x].price_is_percent=="1"){summe+=parseFloat(getOptionsSumWhithoutPercent()*(obj[x].price_percent_value/100));}else{summe+=parseFloat(obj[x].price);}}}}}
var productsQuantity=document.getElementById("products_qty").selectedIndex;productsQuantity+=1;var summeNormal=summe+parseFloat(products_price_normal);var summeNormalQty=(productsQuantity*summeNormal);var priceNormal=document.getElementById("priceNormal");priceNormal.firstChild.nodeValue=formatcurrency(summeNormalQty);if(document.getElementById("priceRabatt")){var price_scale_discount=0;var summeRabattScale=0;if(products_price_scale_discount_value.length>0){for(var y=0;y<products_price_scale_discount_value.length;y++){if(summeNormalQty>=products_price_scale_discount_value[y]['sum'])
price_scale_discount=products_price_scale_discount_value[y]['discount'];}
if(price_scale_discount>0){summeRabattScale=(summeNormalQty*(price_scale_discount/100));}}
var summeRabattPaymentmethod=(summeNormalQty*0.01);var summeRabattDiscount=0;if(products_price_discount_value>0){summeRabattDiscount=(summeNormalQty*(products_price_discount_value/100));}
var summeRabattQty=(summeNormalQty-summeRabattScale-summeRabattDiscount);var priceRabatt=document.getElementById("priceRabatt");priceRabatt.firstChild.nodeValue=formatcurrency(summeRabattQty);if(document.getElementById("sumPricePayment1")){var sumPricePayment1=document.getElementById("sumPricePayment1");sumPricePayment1.firstChild.nodeValue=formatcurrency(summeRabattQty);}
if(document.getElementById("sumPricePayment2")){var sumPricePayment2=document.getElementById("sumPricePayment2");sumPricePayment2.firstChild.nodeValue=formatcurrency(summeNormalQty-summeRabattScale-summeRabattPaymentmethod);}
if(document.getElementById("sumPricePayment_p_1")){var sumPricePayment_p_1=document.getElementById("sumPricePayment_p_1");sumPricePayment_p_1.firstChild.nodeValue=formatcurrency(summeRabattQty+(summeRabattQty*0.01));}
if(document.getElementById("sumPricePayment_p_2")){var sumPricePayment_p_2=document.getElementById("sumPricePayment_p_2");sumPricePayment_p_2.firstChild.nodeValue=formatcurrency(summeRabattQty+(summeRabattQty*0.02));}
if(document.getElementById("sumPricePaymentDiscountValue")){var sumPricePaymentDiscountValue=document.getElementById("sumPricePaymentDiscountValue");sumPricePaymentDiscountValue.firstChild.nodeValue=price_scale_discount+"%";}}}
function onclick_attribImages(){var elem_id=this.id;var arr_elem_id=elem_id.split("_");$("#cart_quantity select[id=id_"+arr_elem_id[0]+"]:not(.disabled)").val(arr_elem_id[1]);}
function onclick_specialattribImages(){var elem_id=this.id;var arr_elem_id=elem_id.split("_");$("#cart_quantity select[id=specialattrib_options]").val(arr_elem_id[1]);}
function change_attribImages_borderColor(){$(".attribImages_unSpecialList a, #attribImages_optionsList a").removeClass('attribImagesActive');;$("#cart_quantity select:not(#products_qty, #specialattrib_values, .disabled)").each(function(){if(this.id=="specialattrib_options"){$("#attribImages_optionsList #td_"+this.value+" a").addClass('attribImagesActive');}else{$("#attribImages_"+this.id.substr(3)+" #td_"+this.value+" a").addClass('attribImagesActive');}});}
function write_attribImages(){for(var i=0;i<obj_options.length;i++){if(obj_options[i].type=="special")continue;var showImages=false;for(var x=0;x<obj_values.length;x++){if(obj_values[x].code_option==obj_options[i].code&&obj_values[x].image!=""&&obj_values[x].image!="kein_material_a.jpg"){showImages=true;}}
if(showImages==false)continue;var dest=document.getElementById("attribImages_"+obj_options[i].code);write_attribImages_table(obj_options[i].code,obj_values,dest,false);}}
function write_attribImages_table(option_id,obj_values,dest,specialattrib){var table=document.createElement("table");dest.appendChild(table);var tbody=document.createElement("tbody");table.appendChild(tbody);var p=0;for(var x=0;x<obj_values.length;x++){if(!specialattrib){if(option_id!=obj_values[x].code_option)
continue;}
if(obj_values[x].image=="")
continue;if(p==0||p==maxcolsAttribImages){var tr=document.createElement("tr");tbody.appendChild(tr);p=0;}
var td=document.createElement("td");td.setAttribute("id","td_"+obj_values[x].code);tr.appendChild(td);var link_image=document.createElement("a");link_image.setAttribute("href",window.location.href);link_image.onclick=function(){return false;};link_image.setAttribute("id",option_id+"_"+obj_values[x].code);var image=document.createElement("img");image.setAttribute("src","/"+obj_values[x].image);image.setAttribute("alt",obj_values[x].name);td.appendChild(link_image);link_image.appendChild(image);p++;}}
function write_specialattrib_options(){if(document.getElementById("specialattrib_options")){var obj=obj_options;var list=document.getElementById("specialattrib_options");list.options.length=0;for(var i=0;i<obj_options.length;i++){if(obj_options[i].type=="special"){list.options[i]=new Option(obj_options[i].name,obj_options[i].code);}}
var dest=document.getElementById("attribImages_optionsList");write_attribImages_table('void',obj_options,dest,true);}}
function write_specialattrib_values(){var selected_value_text="";if($("#specialattrib_values option:selected").text()!=""){selected_value_text=$("#specialattrib_values option:selected").text();}
$("#specialattrib_values option").remove();var selected_option=$("#specialattrib_options option:selected").val();$("#specialattrib_values").attr('name','id['+selected_option+']');var selected_value="";$.each(obj_values,function(i,value){if(selected_option==value.code_option){$("#specialattrib_values").addOption(value.code,value.text);if(i==0){selected_value=value.code;}else if(delete_price_info(selected_value_text)==delete_price_info(value.text)){selected_value=value.code;}}});$("#specialattrib_values").val(selected_value);}
function delete_price_info(value_text){var suche=value_text.indexOf(" (+");if(suche==-1){var suche=value_text.indexOf(" (-");}
if(suche==-1){var suche=value_text.length;}
return value_text.substr(0,suche);}
function getOptionsSumWhithoutPercent(){var summe=0;$("#cart_quantity select:not(#products_qty, #specialattrib_options, .disabled) option:selected").each(function(){for(var x=0;x<obj_values.length;x++){if(this.value==obj_values[x].code){if(obj_values[x].price_prefix=="-"){if(obj_values[x].price_is_percent!="1")
summe-=parseFloat(obj[x].price);}else{if(obj_values[x].price_is_percent!="1")
summe+=parseFloat(obj_values[x].price);}}}});return(products_price_normal+summe);}
function formatcurrency(strValue){strValue=strValue.toString().replace(/\$|\,/g,'');dblValue=parseFloat(strValue);if(currency=='CHF'){dblValue=Math.round(strValue/0.10)*0.10;}
blnSign=(dblValue==(dblValue=Math.abs(dblValue)));dblValue=Math.floor(dblValue*100+0.50000000001);intCents=dblValue%100;strCents=intCents.toString();dblValue=Math.floor(dblValue/100).toString();if(intCents<10)
strCents="0"+strCents;for(var i=0;i<Math.floor((dblValue.length-(1+i))/3);i++)
dblValue=dblValue.substring(0,dblValue.length-(4*i+3))+'.'+dblValue.substring(dblValue.length-(4*i+3));return(((blnSign)?'':'-')+dblValue+','+strCents+' '+currency);}
function changePBorderImage(imageNumber){arr_divs=document.getElementById('thumbnailList').getElementsByTagName("div");for(var i=0;i<arr_divs.length;i++){arr_divs[i].id="";}
arr_divs[(imageNumber-1)].id="current";}
function changePImage(newimage,sizeFrom,sizeTo,imageNumber){if(document.getElementById){if(document.getElementById('productimage')){changePBorderImage(imageNumber);var isIE=false;var imageSRC=newimage.href;var reGIF=new RegExp("_"+sizeFrom+".gif","g");var reJPG=new RegExp("_"+sizeFrom+".jpg","g");imageSRC=imageSRC.replace(reJPG,"_"+sizeTo+".jpg");imageSRC=imageSRC.replace(reGIF,"_"+sizeTo+".gif");image=document.getElementById('productimage');image.style.backgroundImage="url("+imageSRC+")";var imageLink=document.getElementById('productimage').firstChild.getAttribute("onclick");if(imageLink&&typeof(imageLink)=="function"){imageLink=imageLink.toString();if(imageLink.indexOf("function anonymous")==0){isIE=true;imageLink=imageLink.substring(imageLink.indexOf("{")+2);imageLink=imageLink.substring(0,imageLink.lastIndexOf("}")-1);}}
var imageSearchStart=imageLink.indexOf("imgID");if(imageSearchStart!=-1){imageSeachEnd=imageLink.indexOf("'",imageSearchStart);imageLink=imageLink.substr(0,imageSearchStart)+imageLink.substr(imageSeachEnd);}
imageLink=imageLink.replace(/&'/g,"&imgID="+imageNumber+"'");if(isIE){document.getElementById('productimage').firstChild.setAttribute("onclick",new Function("",imageLink));}else{document.getElementById('productimage').firstChild.setAttribute("onclick",imageLink);}}
return false;}else{return false;}}
