// ================== // ==== function ==== // ================== // =============== // ==== ÎÁÙÅÅ ==== // =============== function getUrlVars (name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } function RemoveDiv(div) { if(typeof div== 'string') div=document.getElementById(div); if(div && div.parentNode)div.parentNode.removeChild(div); SumPerRow(); return false; } function notify(url) { if (confirm("Âûñëàòü óâåäîìëåíèå?")) { document.location = url; return true; } return false; } function empty (mixed_var) { if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || typeof mixed_var === 'undefined') { return true; } } function isset(id) { if((document) && (document.getElementById(id))) { return true; } else { return false; } } // =============== // ==== ÇÀÊÀÇ ==== // =============== var c = 0; var CleanRow = ''; var StartCount = 0; jQuery(document).ready(function() { if ($('#lines').length > 0) { StartCount = $('#lines').children().last().attr('id'); if (empty(StartCount)) { StartCount='line1'; } c = StartCount.substr(4); CopyCleanRow(); SumPerRow(); } }); function CopyCleanRow () { // ==== Êîïèðóåì ÷èñòóþ ñòðîêó ==== CleanRow = document.getElementById('line0').innerHTML; } function AddRow () { // ==== Äîáàâëåì ñòðîêó è ìåíÿåì èíäåêñ ==== c++; // ñîçäàåì div var div = document.createElement ('div'); div.setAttribute('id', 'line'+c); // çàìåíÿåì àðãóìåíò ôóíêöèè RemoveDiv(0) íà íîìåð íîâîé ñòðîêè RemoveDiv(1) divContent= CleanRow.replace(/(\()(\d+\))/gi,'$1'+c+')'); // èùåì ðîäèòåëñêèé êîíòåéíåð parent = document.getElementById ('line'+(c-1)).parentNode; var parent = document.getElementById ('line'+(0)).parentNode; // äîáàâëÿåì íàø
parent.appendChild (div); // çàïîëíÿåì åãî ñêîïèðîâàíûéì div document.getElementById('line'+c).innerHTML=divContent; // äîáàâëÿåì ðÿä íîìåð ñ document.getElementById('id('+c+')').innerHTML=c; } function RemoveDivLine(num) { div='line'+num; RemoveDiv(div); // åñëè óäàëèëè âñå ñòðîêè äîáàâëÿåì íîâóþ var StartCount= $('#lines').children().last().attr('id'); if (empty(StartCount)) { c=0; AddRow(); } // ñóììèðóåì SumPerRow(); return false; } function DDivLine(num) { div='line'+num; // document.getElementById('priceValue('+num+')').value = 0; document.getElementById('quantValue('+num+')').value = 0; document.getElementById(div).style.background="#ffc5c5"; //RemoveDiv(div); // åñëè óäàëèëè âñå ñòðîêè äîáàâëÿåì íîâóþ var StartCount= $('#lines').children().last().attr('id'); if (empty(StartCount)) { c=0; AddRow(); } // ñóììèðóåì SumPerRow(); return false; } function flyFind(value, number) { // ==== flyFind ==== $.post("/ajax/flySearch.php", { load:'search',what: ""+value+"", row_number: number}, function(data,textStatus) { if (data!=0) { window.document.getElementById('livesearch'+number).innerHTML=data; // Ïîêàçûâàåì îêíî document.getElementById('livesearch'+number).style.display='block'; } }); return false; } function displaySearch(id){ document.getElementById(id).style.display = ('' == document.getElementById(id).style.display)? '' : 'none'; } function selectFirst(key) { // ==== Ñòðåëêà âíèç ïåðâûé åëåìåíò èç ñïèñêà ==== // Mozilla if(key == 40) { window.document.getElementById('searchSelect('+c+')').focus(); window.document.getElementById('searchSelect('+c+')').selectedIndex=0; } return false; } function SubmitForm(key) { // ==== ENTER - âñòàâêà âûáðàíîãî ïóíêòà ìåíþ ==== //Mozilla if (key==13) { showSelected(); } return false; } function showSelected(c){ // ==== Âûáîðêà è çàïîëíåíèå ==== // Ïîëó÷àåì çíà÷åíèå var _obj = document.getElementById('searchSelect('+c+')'); _value=document.getElementById('code('+c+')'); // Âûáèðàåì ÷òî íóæíî var selIndex = _obj.selectedIndex; _value.value = _obj.options[selIndex].value; _value.text =_obj.options[selIndex].text; // Ðàçáèâàåì íà çíà÷åíèÿ var iArray = _value.value.split("|"); var iArrayTitle = _value.text.split("|"); // Çàïîëíÿåì // code, mod_id, product_id, brend_id, brend, price â êà÷åñòâå option document.getElementById('code('+c+')').value = iArray[0]; // document.getElementById('mod_id('+c+')').innerHTML = iArray[1]; document.getElementById('mod_idValue('+c+')').value = iArray[1]; // document.getElementById('product_id('+c+')').innerHTML = iArray[2]; document.getElementById('product_idValue('+c+')').value = iArray[2]; document.getElementById('brand('+c+')').innerHTML = iArray[4]; document.getElementById('brand_idValue('+c+')').value = iArray[3]; document.getElementById('price('+c+')').innerHTML = iArray[5]+' ãðí.'; document.getElementById('priceValue('+c+')').value = iArray[5]; document.getElementById('total('+c+')').innerHTML = iArray[5]+' ãðí.'; document.getElementById('totalValue('+c+')').value = iArray[5]; document.getElementById('color('+c+')').innerHTML = iArray[7]; document.getElementById('size('+c+')').innerHTML = iArray[8]; document.getElementById('title('+c+')').innerHTML = iArrayTitle[0]; document.getElementById('onstock('+c+')').innerHTML = iArrayTitle[1]; // Ñêðûâàåì îêíî document.getElementById('livesearch('+c+')').style.display='none'; // ==== Ïåðåñ÷åò çàêàçà ==== SumPerRow(); } function SumPerRow(){ // ==== Ïåðåñ÷åò çàêàçà ==== var Summary=0; var TotalQuantity=0; for(i=0; i<=c; i++) { price=document.getElementById('priceValue('+i+')'); if(!empty(price)) { price=parseFloat(document.getElementById('priceValue('+i+')').value); quant=parseFloat(document.getElementById('quantValue('+i+')').value); TotalPerRow=quant * price; Quantity=quant; document.getElementById('totalValue('+i+')').value = TotalPerRow; document.getElementById('total('+i+')').innerHTML = TotalPerRow +' ãðí.'; Summary+=TotalPerRow; TotalQuantity+=Quantity; } } document.getElementById('quantity').innerHTML = TotalQuantity-1; document.getElementById('summary').innerHTML = Summary; document.getElementById('summaryValue').value = Summary; } // ============== // === Email ==== // ============== function livesearchEmail(value) { // ==== livesearchEmail ==== $.post("/ajax/flySearch.php", {load:'searchEmail',what: ""+value+""}, function(data,textStatus){ if (data!=0) { window.document.getElementById('livesearch-email-list').innerHTML=data; // Ïîêàçûâàåì îêíî document.getElementById('livesearch-email-list').style.display='block'; } }); return false; } function SelectEmail(){ // ==== Âûáîðêà è çàïîëíåíèå ==== // Ïîëó÷àåì çíà÷åíèå var _obj = document.getElementById('choose-email'); _value=document.getElementById('emailValue'); // Âûáèðàåì ÷òî íóæíî var selIndex = _obj.selectedIndex; _value.value = _obj.options[selIndex].value; // Ðàçáèâàåì íà çíà÷åíèÿ var iArray = _value.value.split("|"); // Çàïîëíÿåì // id,username,email,tel,tel2,city,adress â êà÷åñòâå option document.getElementById('usernameValue').value = iArray[1]; document.getElementById('emailValue').value = iArray[2]; document.getElementById('telValue').value = iArray[3]; document.getElementById('tel2Value').value = iArray[4]; document.getElementById('cityValue').value = iArray[5]; document.getElementById('addressValue').value = iArray[6]; if(isset('usergroup')) { document.getElementById('usergroup').value = iArray[7]; } if(isset('user_id')) { document.getElementById('user_id').value = iArray[0];} // Ñêðûâàåì îêíî document.getElementById('livesearch-email-list').style.display='none'; } function SelectEmailFirst(key) { // ==== Ñòðåëêà âíèç ïåðâûé åëåìåíò èç ñïèñêà ==== // Mozilla if(key==40) { window.document.getElementById('livesearch-email-list').focus(); window.document.getElementById('livesearch-email-list').selectedIndex=0; } return false; } function SelectEmailSubmit(key) { // ==== ENTER - âñòàâêà âûáðàíîãî ïóíêòà ìåíþ ==== //Mozilla if (key==13) { SelectEmail(); } return false; } // ============== // ==== Tel ===== // ============== function livesearchTel(value) { $.post("/ajax/flySearch.php", {load:'searchTel',what: ""+value+""}, function(data,textStatus) { if (data!=0) { window.document.getElementById('livesearch-tel-list').innerHTML=data; // Ïîêàçûâàåì îêíî document.getElementById('livesearch-tel-list').style.display='block'; } }); return false; } function SelectTel() { // Ïîëó÷àåì çíà÷åíèå var _obj = document.getElementById('choose-tel'); _value=document.getElementById('telValue'); // Âûáèðàåì ÷òî íóæíî var selIndex = _obj.selectedIndex; _value.value = _obj.options[selIndex].value; // Ðàçáèâàåì íà çíà÷åíèÿ var iArray = _value.value.split("|"); // Çàïîëíÿåì // id,username,email,tel,tel2,city,adress â êà÷åñòâå option document.getElementById('usernameValue').value = iArray[1]; document.getElementById('emailValue').value = iArray[2]; document.getElementById('telValue').value = iArray[3]; document.getElementById('telValue').focus(); document.getElementById('tel2Value').value = iArray[4]; document.getElementById('cityValue').value = iArray[5]; document.getElementById('addressValue').value = iArray[6]; if(isset('usergroup')) { document.getElementById('usergroup').value = iArray[7]; } if(isset('user_id')) { document.getElementById('user_id').value = iArray[0];} // Ñêðûâàåì îêíî document.getElementById('livesearch-tel-list').style.display='none'; } function SelectTelFirst(key) { // Mozilla if (key == 40) { window.document.getElementById('livesearch-tel-list').focus(); window.document.getElementById('livesearch-tel-list').selectedIndex=0; } return false; } function SelectTelSubmit(key) { // ENTER - âñòàâêà âûáðàíîãî ïóíêòà ìåíþ // Mozilla if (key == 13) { SelectTel(); } return false; } function telAction ($array) { $.ajax({ type: 'GET', url: '/ajax/OrderContol.php', dataType: 'json', data: $.param ($array['json']), success: function (response) { switch ($array['json']['jaction']) { case 'tel-save': modalBoxLoad (response.html, { autoClose: 800, }); break; } }, error: function() { modalBoxLoad ('×òî-òî ïîøëî íå òàê...'); } }); /* $.post({ url: '/js/OrderContol.php?jaction=' + $array['json']['jaction'], queryString: 1, }) .done(function (response) { modalBoxLoad (response.html, { autoClose: 600, }); }) .fail (function() { modalBoxLoad ('×òî-òî ïîøëî íå òàê...'); }); */ } // ===================== // ==== unknownUser ==== // ===================== function newUnknownUser() { if(document.getElementById('default').checked) { var currentTime = new Date(); var month = currentTime.getMonth() + 1; var day = currentTime.getDate(); var year = currentTime.getFullYear(); var hour = currentTime.getHours(); var min = currentTime.getMinutes(); var sec = currentTime.getSeconds(); var currentDate = month + "/" + day + "/" + year + "/" + hour + "." + min + "." + sec; var currentTel = '+380000000000'; document.getElementById('emailValue').value = currentDate +'@user.com'; document.getElementById('telValue').value =currentTel; document.getElementById('usergroup').value = 1; document.getElementById('user_id').value = '0'; document.getElementById('usernameValue').value = 'êëèåíò'; } } // ======================= // ==== userCheckData ==== // ======================= function userCheckData(value,fields) { // ==== livesearchEmail ==== $.post("/ajax/flySearch.php", {load:'userCheckData',what: ""+value+"", field:fields}, function(data,textStatus){ if (data!=0) { window.document.getElementById('result-'+fields+'').innerHTML=data; // Ïîêàçûâàåì îêíî document.getElementById('result-'+fields+'').style.display='block'; } }); return false; } // =================== // ==== LISTENERS ==== // =================== jQuery(document).ready(function() { $(".input_status").click(function() { $( "#status_box_"+$(this).attr("data-id") ).show(); }) $( ".status_box ul li.name_city" ).click(function() { $("#input_status_"+$(this).attr("data-id")).val($(this).text()); $( ".status_box" ).hide(); }); $( ".status_box ul li.other" ).click(function() { $("#input_status_"+$(this).attr("data-id")).val(""); $( ".status_box" ).hide(); $("#input_status_"+$(this).attr("data-id")).focus(); }); $(".need-confirm").click(function(e) { e.preventDefault(); if (confirm ("Âû äåéñòâèòåëüíî æåëàåòå óäàëèòü?") == true) { window.location = $(this).attr("href"); return true; } return false; }); $("#sms_tpl").change(function() { $.get("/ajax/sms_tpl.php", { tplID: this.value },function(data) { $("#sms_msg").val(data); $("#sms_c").html($("#sms_msg").val().length); }); }); $("#sms_send").click(function() { if($("#sms_tel1").attr("checked") || $("#sms_tel2").attr("checked")) { return true; }else{ alert("Íå óêàçàí íîìåð òåëåôîíà!"); return false; } }); w=120; $("input[name=\'sms_type\']").click(function() { i = $("#sms_msg").val().length; if(this.value=="l"){w=120;if(i>w){$("#sms_c").css( "color","red" );}else{$("#sms_c").css( "color","black" );}} else{w=70;if(i>w){$("#sms_c").css( "color","red" );}else{$("#sms_c").css( "color","black" );}} $("#sms_c_sum").html(w); }); $("#sms_c_sum").html(w); $("#sms_msg").keyup(function() { i = this.value.length; if(i>w){$("#sms_c").css( "color","red" );} else{$("#sms_c").css( "color","black" );} $("#sms_c").html(i); }); // âàëèäàöèÿ ôîðìû // $("#add-item").validationEngine(); // Òåëåôîí $('.info.tel input[type=text]').on('change', function() { telAction({ 'json': { 'jaction': 'tel-save', 'field': $(this).attr('name'), 'value': $(this).val(), 'order_id': getUrlVars('order_ID'), } }); }); });