// JavaScript Document $(function(){ /****************** VARIABLES ******************/ var costMultiplier = 2.1; // Price multiplier. var vatMultiplier = 1.19; // VAT multiplier. var extPrintCost = 119.0; // Printing cost for 1 meter. var extLEDCost = 357.0; // LED cost for 1 meter. var extColorCost = 23.8; // Coloring cost for 1 meter. var stepSize = 5; // Step size while moving slider bar. // All the remaining data is determined at here. // ONE SIDED CASE // // TWO SIDED CASE // var dimensionsMatrix = { "W" : Array(400 ,500 ,600 ,700 ,800 ,900 ,1000), // Available widths. "H" : Array(400,500,600,700,800,900,1000,1100,1300,1400,1600,1700,1800,1900,2000,2500,3000) // Available heights. } var costMatrix = { // 17 x 11 "0" : Array(119,123,138,145,149,167,175,180,186,192,195), "1" : Array(123,150,159,168,186,195,206,209,215,221,227), "2" : Array(138,159,167,175,197,210,221,229,233,238,241), "3" : Array(145,168,175,190,204,214,227,231,236,241,245), "4" : Array(149,186,197,204,241,249,262,271,276,282,291), "5" : Array(167,195,210,214,249,276,282,284,287,291,296), "6" : Array(175,206,221,227,262,282,296,303,308,313,318), "7" : Array(180,209,229,231,271,284,303,311,330,348,358), "8" : Array(189,218,236,239,279,289,310,338,356,366,373), "9" : Array(192,221,238,241,282,291,313,348,366,400,433), "10" : Array(204,235,252,277,303,317,341,381,420,449,478), "11" : Array(236,269,296,310,322,337,347,390,432,463,493), "12" : Array(254,280,304,336,368,384,401,437,474,504,534), "13" : Array(265,289,314,353,392,408,426,462,497,531,565), "14" : Array(279,298,327,372,416,424,441,470,506,548,589), "15" : Array(350,369,415,456,497,528,559,615,671,735,799), "16" : Array(434,445,527,577,620,635,665,728,773,841,906) } // ----------------- // /****************** CORE FUNCTIONALITY ******************/ var extColor = extPrint = extLED = false; var Dim = { "W" : { "min" : dimensionsMatrix.W[0], "max" : dimensionsMatrix.W[dimensionsMatrix.W.length-1] }, "H" : { "min" : dimensionsMatrix.H[0], "max" : dimensionsMatrix.H[dimensionsMatrix.H.length-1] } } var widthSlider = $('#width-slider').slider({ range:"min", step:stepSize, min: dimensionsMatrix.W[0], max: dimensionsMatrix.W[dimensionsMatrix.W.length-1], value : $(".width-value").val(), slide: function( event, ui ) { $(".width-value").val(ui.value); doCalc();} }); var heightSlider = $('#height-slider').slider({ range:"min", step:stepSize, min: dimensionsMatrix.H[0], max: dimensionsMatrix.H[dimensionsMatrix.H.length-1], value : $(".height-value").val(), slide: function( event, ui ) { $(".height-value").val(ui.value); doCalc();} }); $(".width-value").change(function() { checkValues("W",this); doCalc(); }); $(".height-value").change(function() { checkValues("H",this); doCalc(); }); function calculateCost(w,h) { var costLoc = Array(0,0); var gotW = false; var gotH = false; var fW = 0; var fH = 0; if(w > dimensionsMatrix.W[dimensionsMatrix.W.length-1]) { costLoc[0] = dimensionsMatrix.W.length-1; } else { for(i=0;i= w && gotW == false) { fW = dimensionsMatrix.W[i]; costLoc[0] = i; gotW = true; } } } if(h > dimensionsMatrix.H[dimensionsMatrix.H.length-1]) { costLoc[1] = dimensionsMatrix.H.length-1; } else { for(j=0;j= h && gotH == false) { fH = dimensionsMatrix.H[j]; costLoc[1] = j; gotH = true; } } } $.each(costMatrix,function(a,d) { if(a == costLoc[1]) { totalCost = d[costLoc[0]]; } }); totalDim = (fW/1000) * (fH/1000); totalUmfang = (fW/1000 + fW/1000 + fH/1000 + fH/1000); //var numOfCopies = parseInt($(".product-count").val()); var numOfCopies = parseInt(1); //totalDim = ((fW * 2) + (fH * 2)) / 1000; //var numOfCopies = parseInt($(".product-count").val()); // // // // // // // // // // // //totalCost = (totalCost * costMultiplier).toFixed(2); //if(extPrint) { totalCost = parseFloat(totalCost) + parseFloat((totalDim * extPrintCost)); } //if(extLED) { totalCost = parseFloat(totalCost) + parseFloat((totalDim * extLEDCost)); } //if(extColor) { totalCost = parseFloat(totalCost) + parseFloat((totalDim * extColorCost)); } // // // // // // // // // // // totalCost = (totalCost * costMultiplier).toFixed(2); if(totalDim<1){ //if(extPrint) { totalCost = parseFloat(totalCost) + parseFloat((1 * extPrintCost)); } if(extPrint) { totalCost = parseFloat(totalCost) + parseFloat(1 * extPrintCost); } }else{ //if(extPrint) { totalCost = parseFloat(totalCost) + parseFloat((totalDim * extPrintCost)); } if(extPrint) { totalCost = parseFloat(totalCost) + parseFloat((((w * h) / 1000000) * extPrintCost)); } } //if(extLED) { totalCost = parseFloat(totalCost) + parseFloat((totalDim * extLEDCost)); } if(extLED) { totalCost = parseFloat(totalCost) + parseFloat((((w * h) / 1000000) * extLEDCost)); } if(extColor) { totalCost = parseFloat(totalCost) + parseFloat((totalUmfang * extColorCost)); } totalCost = parseFloat(totalCost).toFixed(2); totalCost = (totalCost * numOfCopies).toFixed(2); vatCost = (totalCost * vatMultiplier).toFixed(2); /* **************************************************************************************** */ $("span.t-cost").html(totalCost); $("span.t-v-cost").html(vatCost); document.getElementById("price_prd").value=totalCost; return totalCost; } function doCalc() { calculateCost($(".width-value").val(),$(".height-value").val()); } function checkValues(type,object) { Val = $(object).val(); if(type == "W") { if(Val < Dim.W.min) { Val = Dim.W.min; } if(Val > Dim.W.max) { Val = Dim.W.max; } widthSlider.slider("value",Val); } if(type == "H") { if(Val < Dim.H.min) { Val = Dim.H.min; } if(Val > Dim.H.max) { Val = Dim.H.max; } heightSlider.slider("value",Val); } $(object).val(Val); doCalc(); } checkValues("W",".width-value"); checkValues("H",".height-value"); /* $(".cost-calculator input, .cost-calculator select").change(function() { doCalc(); }); */ ////////////////////////////////////////////////////////////////////////////////////////////// $(".color-select").change(function() { $(".selected-color").css("background",$(":selected",this).attr("hex")); }); $(".ext-color").change(function() { if($(this).attr("checked")) { $(".prod-ext-color").animate({ "opacity":1, "height":"120px" }); extColor = true; } else { $(".prod-ext-color").animate({ "opacity":0, "height":"0px" }); extColor = false; } doCalc(); }); $(".ext-image").change(function() { if($(this).attr("checked")) { $(".ext-image-tr").removeClass("display-n"); $(".prod-ext-image").animate({ "opacity":1, "height":"23px" }); extPrint = true; } else { $(".prod-ext-image").animate({ "opacity":0, "height":"0px" },function() { $(".ext-image-tr").addClass("display-n"); }); extPrint = false; } doCalc(); }); $(".ext-led").change(function() { if($(this).attr("checked")) { extLED = true; } else { extLED = false; } doCalc(); }); //$(".product-count").change(function() { // if($(this).val() < 1 || isNaN($(this).val())) { // $(this).val(1); // } // doCalc(); //}); });