$(function() { var color_koef = 3; // коэффициент количества цветов $("#note").html(); var KOEFF_1 = 150; // редактируемые параметры var KOEFF_2 = 55; UpdateResults(); /* WIDTH */ $("#slider_width").slider( { min:0, max:350, value:50, stop: function(event, ui) { var curVal = DetectPosition(ui.value, 50); //$("#slider_width").slider({value:curVal*50}); GetWidthPocket(curVal*50); UpdateResults(); $("#checkit").html(curVal*50); }, slide: function (event, ui) { var curVal = DetectPosition(ui.value, 50); //$("#slider_width").slider({value:curVal*50}); GetWidthPocket(curVal*50); UpdateResults(); $("#checkit").html(curVal*50); } } ); function DetectPosition(val, decim) { var val = Math.round(val/decim); return val; } function GetWidthPocket(val) { var res; var fal; //фальцы if(val == 0){res = 22; fal = '6';} else if(val == 50) {res = 24; fal = '7';} else if(val == 100) {res = 28; fal = '8';} else if(val == 150) {res = 32; fal = '8,5';} else if(val == 200) {res = 34; fal = '9';} else if(val == 250) {res = 36; fal = '9';} else if(val == 300) {res = 40; fal = '10';} else if(val == 350) {res = 42; fal = '11';} $("#width_value").html(res); $("#fal_val").html(fal); // значение для фальцев $("#fal_val2").html(fal); // значение для фальцев } /*Checkbox*/ function IsColorPrint() { if($("#color_print").is(":checked")) { return true; } else { return false; } } $("#color_print").click(UpdateResults); /* HEIGHT */ $("#slider_height").slider( { min:0, max:350, value:140, orientation:'vertical', stop: function(event, ui) { var curVal = DetectPosition(ui.value, 70); //$("#slider_height").slider({value:curVal*70}); GetHeightPocket(curVal*70); UpdateResults(); }, slide: function (event, ui) { var curVal = DetectPosition(ui.value, 70); //$("#slider_height").slider({value:curVal*70}); GetHeightPocket(curVal*70); UpdateResults(); } } ); function GetHeightPocket(val) { var res; if(val == 0) {res=30;} else if(val == 70) {res=40;} else if(val == 140) {res=50;} else if(val == 210) {res=55;} else if(val == 280) {res=60;} else if(val == 350) {res=67;} $("#height_value").html(res); } $(".pocket_height_div").click( function() { $("#height_value").html($(this).html()); $("#slider_height").slider({value:parseInt($(this).css("left"))}); UpdateResults(); } ); /* PUBLISH */ $("#slider_publish").slider( { min:0, max:400, value:250, stop: function(event, ui) { var curVal = DetectPosition(ui.value, 50); //$("#slider_publish").slider({value:curVal*50}); GetPublishPocket(curVal*50); UpdateResults(); }, slide: function (event, ui) { var curVal = DetectPosition(ui.value, 50); //$("#slider_publish").slider({value:curVal*50}); GetPublishPocket(curVal*50); UpdateResults(); } } ); function GetPublishPocket(val) { var res; if(val==0) {res = 5;} else if(val == 50) {res = 10;} else if(val == 100) {res = 20;} else if(val == 150) {res = 30;} else if(val == 200) {res = 40;} else if(val == 250) {res = 50;} else if(val == 300) {res = 60;} else if(val == 350) {res = 100;} else if(val == 400) {res = 500;} $("#publish_value").html(res); } $(".pocket_publish_div").click( function() { //$("#publish_value").html($(this).html()); $("#slider_publish").slider({value:parseInt($(this).css("left"))}); GetPublishPocket(parseInt($(this).css("left"))); UpdateResults(); } ); /* FAT */ $("#slider_fat").slider( { min:10, max:30, value:14, slide:function(event, ui) { $("#fat_value").html(ui.value); UpdateResults(); }, stop:function (event, ui) { $("#fat_value").html(ui.value); UpdateResults(); } } ); /* COLORS */ $("#add_color_front").click( function() { var total = TotalColors(); if(total < 4) { IncreaseColors('front'); } else { ReduceColors('back'); IncreaseColors('front'); } UpdateColorNumber(); UpdateResults(); } ); $("#add_color_back").click( function() { var total = TotalColors(); if(total < 4) { IncreaseColors('back'); } else { ReduceColors('front'); IncreaseColors('back'); } UpdateColorNumber(); UpdateResults(); } ); $("#remove_color_front").click( function() { ReduceColors('front'); UpdateColorNumber(); UpdateResults(); } ); $("#remove_color_back").click( function() { ReduceColors('back'); UpdateColorNumber(); UpdateResults(); } ); function IncreaseColors(side) { var on_count = GetOnCount(side); if(on_count < 4) { on_count++; var off_divs_count = 4 - on_count; var off_divs = AddOffDivs(side, off_divs_count); var on_divs = AddOnDivs(side, on_count); var html = on_divs + off_divs; $("#"+side+"_colors_number").html(html); } } function ReduceColors(side) { var on_count = parseInt(GetOnCount(side)); if(on_count > 0) { on_count--; var off_divs_count = 4 - on_count; var off_divs = AddOffDivs(side, off_divs_count); var on_divs = AddOnDivs(side, on_count); var html = on_divs + off_divs; $("#"+side+"_colors_number").html(html); } } function AddOnDivs(side, count) // side = front || back { var str = ""; for(var i = 0; i < count; i++) { str += "
\r\n"; } return str; } function AddOffDivs(side, count) // side = front || back { var str = ""; for(var i = 0; i < count; i++) { str += "
\r\n"; } return str; } function GetOnCount(side) { var number = 0; $(".on_div_"+side).each( function() { number++; } ); return number; } function TotalColors() { var front = GetOnCount('front'); var back = GetOnCount('back'); return front+back; } function UpdateColorNumber() { $("#back_value").html(GetOnCount('back')); $("#front_value").html(GetOnCount('front')); } /* CALCULATES */ function getWeightForOnePocket() // определяем массу одного пакета { var Z = parseInt($("#width_value").html()); // ширина пакета var F = parseFloat(str_replace(',', '.', $("#fal_val").html())); // фальцы var h = parseInt($("#height_value").html()); // высота var thick = parseInt($("#fat_value").html()); // толщина var weight = (Z+F*2)*h*thick*2*0.95/10000; return weight; } function getWeightForAllPockets(weight_for_one) // определяем массу всего тиража { var publish = parseInt($("#publish_value").html()); // тираж var weightAll = publish*(weight_for_one - (weight_for_one/100*9)); return weightAll; } function getVolumeForAll(weightAll) { var volume = weightAll/13*0.05; return volume; } function GetColorK() { var total = TotalColors(); var k; if(total == 0) {k = 3;} else if(total == 1) {k = 9;} else if(total == 2) {k = 15;} else if(total == 3) {k = 23;} else if(total == 4) {k = 30;} return k; } function roundTo(val) { var res = Math.round(val*100)/100; return res; } $("#go").click( function() { UpdateResults(); } ); function getMargin() { var val = parseFloat($("#publish_value").html()); var MARGIN; if(val==5) {MARGIN = '2.4';} else if(val == 10) {MARGIN = '1.4';} else if(val == 20) {MARGIN = '1.29';} else if(val == 30) {MARGIN = '1.2';} else if(val == 40) {MARGIN = '1.15';} else if(val == 50) {MARGIN = '1.09';} else if(val == 60) {MARGIN = '1.08';} else if(val == 100) {MARGIN = '1.01';} else if(val == 500) {MARGIN = '0.94';} return MARGIN; } function UpdateResults() { var publish = parseInt($("#publish_value").html()); // тираж var front = parseInt($("#front_value").html()); var back = parseInt($("#back_value").html()); var weight = getWeightForOnePocket(); var weightAll = getWeightForAllPockets(weight); var volume = getVolumeForAll(weightAll); var ColorK = GetColorK(); var additional_price = ((ColorK+KOEFF_1+KOEFF_2)*weight)/1000; //var price_for_one = MARGIN*additional_price; var price_for_one; var MARGIN = getMargin(); // дополнительная наценка if(IsColorPrint()) { price_for_one = roundTo(MARGIN*additional_price*1.1); } else { price_for_one = roundTo(MARGIN*additional_price); } $("#note").html(""); $("#weight_value").html(ReplaceDot(roundTo(weight))); $("#weight_value_all").html(ReplaceDot(roundTo(weightAll))); $("#volume_value").html(ReplaceDot(roundTo(volume))); if(weight < 4 && weightAll < 30) { price_for_one = roundTo(1.25*price_for_one); } else if(weight < 4) { price_for_one = roundTo(1.1*price_for_one); } else if(weightAll<30) { price_for_one = roundTo(1.1*price_for_one); } var price_for_all = price_for_one*publish*1000; $("#price_value").html(ReplaceDot(price_for_one)); $("#price_all_value").html(FloatToMoney(roundTo(price_for_all))); $("#send_div").html("Отправить этот заказ менеджеру"); $("#order_form").css("height", "0px"); } function FloatToMoney(floatNumb) { var arr_float = floatNumb.toString().split("."); var ceil = arr_float[0]; var res =''; var cur_res = ''; var thumb = arr_float[1]; if(typeof(thumb) != 'undefined') { thumb = ',' + arr_float[1]; } else thumb = ''; if(ceil.length > 3) { while(ceil.length > 3) { cur_res = ' '+ceil.substr(ceil.length - 3, 3); ceil = ceil.slice(0, ceil.length - 3); res = cur_res + res; } res = ceil + res + thumb; } else { res = ceil + thuumb; } return res; } function ReplaceDot(floatNumb) { var res = str_replace('.', ',', floatNumb.toString()); return res; } function str_replace ( search, replace, subject ) { if(!(replace instanceof Array)){ replace=new Array(replace); if(search instanceof Array){//If search is an array and replace is a string, then this replacement string is used for every value of search while(search.length>replace.length){ replace[replace.length]=replace[0]; } } } if(!(search instanceof Array))search=new Array(search); while(search.length>replace.length){//If replace has fewer values than search , then an empty string is used for the rest of replacement values replace[replace.length]=''; } if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well. for(k in subject){ subject[k]=str_replace(search,replace,subject[k]); } return subject; } for(var k=0; k-1){ subject = subject.replace(search[k], replace[k]); i = subject.indexOf(search[k],i); } } return subject; } /* ORDER */ $("#order_a").live('click', function() { $("#send_div").html(""); $("#order_form").animate( { "height":"350px", }, 1000 ); } ); function GetAllOrder() { var pocket_width = $("#width_value").html(); var pocket_height = $("#height_value").html(); var pocket_publish = $("#publish_value").html(); var pocket_fat = $("#fat_value").html(); var front = $("#front_value").html(); var back = $("#back_value").html(); var isColor = IsColorPrint(); var falci = $("#fal_val").html(); var weight_one = $("#weight_value").html(); var weight_all = $("#weight_value_all").html(); var volume = $("#volume_value").html(); var price = $("#price_value").html(); var price_all = $("#price_all_value").html(); var msg = "Ширина пакета - "+pocket_width+" (см)\r\n"; msg += "Фальцы - два по "+falci+" (см)\r\n"; msg += "Высота пакета - "+pocket_height+" (см)\r\n"; msg += "Толщина пакета - "+pocket_fat+" (мкм)\r\n"; msg +="Тираж - "+pocket_publish+" (тыс)\r\n\r\n"; if(isColor) {msg +="Использовать цветной полиэтилен\r\n";} msg += "Цветность - "+front+"+"+back+"\r\n\r\n"; msg += "Масса одного пакета - "+weight_one+" (г)\r\n"; msg += "Масса всего тиража - "+weight_all+" (кг)\r\n"; msg += "Объем тиража - "+volume+" (м3)\r\n\r\n"; var email = $("#email").val(); var name = $("#name").val(); var org = $("#org").val(); var text = $("#text").val(); var phone = $("#phone").val(); msg += "Цена одного пакета - "+price+" (руб.)\r\n"; msg += "Стоимость всего тиража - "+price_all+" (руб)\r\n"; msg += "\r\nПользователь указал следующие данные:\r\n"; msg += "Имя - "+name+"\r\n"; msg += "Телефон - "+phone+"\r\n"; msg += "Email - "+email+"\r\n"; msg += "организация - "+org+"\r\n\r\n"; msg += "Примечание\r\n"; msg += text+"\r\n\r\n"; $.ajax( { url:"/price/config/send.php", type:"POST", data: "msg="+encodeURIComponent(msg), success:function(data) { alert("Ваше сообщение отправлено"); ClearForm(); $("#order_form").animate( { "height":"0", }, 1000 ); }, error: function(xhr, status) { alert(status); } } ); } function ClearForm() { $("#email").val(""); $("#name").val(""); $("#org").val(""); $("#text").val(""); $("#phone").val(""); } $("#send_it").click(GetAllOrder); function isValidEmail(email) { re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i; return re.test(email); } function isValidName(name) { re = /^[а-яА-Я\s\-]+$/; return re.test(name); } });