// JavaScript Document $(function(){ /****************** VARIABLES ******************/ var costMultiplier = 2.1; // Price multiplier. var vatMultiplier = 1.19; // VAT multiplier. var extPrintCost = 59.5; // Printing cost for 1 meter. var extLEDCost = 166.6; // 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 // var dimensionsMatrix = { "W" : Array(500 ,600 ,700 ,800 ,900 ,1000,1250,1550,2000,2500,3000,3500,4000,4500,5000,5500,6000), // Available widths. "H" : Array(400 ,500 ,600 ,700 ,800 ,900 ,1000,1100,1300) // Available heights. } var costMatrix = { // 17 x 11 "0" : Array(81 ,89,91,105,117,124,131,141,179,207,237,275,305,340,381,408,439), "1" : Array(102 ,125,113,136,155,159,166,170,227,256,293,340,378,422,481,511,548), "2" : Array(125 ,142,120,146,163,169,175,182,245,274,313,364,404,451,514,546,587), "3" : Array(113 ,120,127,150,161,178,186,194,256,291,334,387,431,480,546,582,625), "4" : Array(136 ,146,150,181,189,196,210,224,303,340,389,454,503,563,646,685,733), "5" : Array(155 ,163,161,189,216,223,231,236,317,358,428,477,530,592,678,720,772), "6" : Array(159 ,169,178,196,223,228,233,247,333,375,431,501,556,622,711,755,810), "7" : Array(161 ,171,180,198,227,231,235,277,360,425,487,567,629,704,811,857,919), "8" : Array(167 ,176,188,212,233,235,255,319,379,462,543,629,711,794,877,959,1042), "9" : Array(169 ,179,190,214,237,243,280,331,456,512,583,681,755,845,976,1030,1105), "10" : Array(173 ,189,197,229,240,252,315,372,468,548,642,742,841,939,1037,1136,1234), "11" : Array(202 ,219,234,237,248,261,325,384,534,597,680,794,880,986,1141,1204,1291), "12" : Array(208 ,226,242,277,291,304,349,414,581,646,736,860,953,1069,1241,1307,1399), "13" : Array(221 ,239,248,295,309,323,360,426,596,664,757,885,979,1098,1273,1342,1437), "14" : Array(227 ,245,256,303,317,333,370,437,610,682,777,908,1006,1127,1306,1376,1475) } // ----------------- // /****************** 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(); //}); });