1/* 2* 2011-2019 3* 4* @author Jorge Donet Alberola <[email protected]> 5* V17.0.* 6*/ 7if(typeof baseDir==="undefined" && typeof prestashop!=="undefined") 8 baseDir = prestashop.urls.base_url; 9 10var MegaProduct = jQuery.Class({ 11 init: function() 12 { 13 this.quantityInput = $('#quantity_wanted'); 14 this.backupInput = $("input[type='hidden'][name='submitCustomizedDatas']"); 15 this.quantityCont = $('#quantity_wanted_p'); 16 this.attributesCont = $('#attributes'); 17 this.customizationCont = $('.customization_block'); 18 this.addCartCont = $('.add .add-to-cart'); 19 20 21 this.addCartBtn = $('#add_to_cart input'); 22 this.addBtn = $('#btnAddProduct'); 23 this.saveCustoBtn = $('#customizedDatas .button'); 24 this.pageInfoCont = $('#buy_block > p'); 25 this.MPInitialized = false; 26 this.id_product = 0; 27 this.custom_id = 0; 28 this.productType = 'S'; 29 this.price_text = ''; 30 this.stock = ''; 31 this.modal_info = 0; 32 this.ajax_price = 0; 33 this.eval_math = 0; 34 this.days = 1; 35 this.time = 0; 36 this.date_start = new Date(); 37 this.date_end = new Date(); 38 this.attrPrices = new Array(); 39 this.attrDefaultDates = new Array(); 40 this.group_counter = 0; 41 this.attr_counter = 0; 42 43 this.before_price = ''; 44 this.after_price = ''; 45 this.attrIds = ''; 46 this.calendar_start = 0; 47 this.calendar_end = 0; 48 this.selectDate = 0; 49 this.end_date = 1; 50 this.quantityGroups = 0; 51 this.lastPersonalization = 0; 52 this.actionAvailability = 0; 53 this.multiAvailability = new Array(); 54 this.sendEvent = 0; 55 56 this.quantityend = 0; 57 58 this.serviceSelect = new Array(); 59 this.validation = 0; 60 this.diffCalendar = 0; 61 this.urls = 0; 62 this.arrayCustom = new Array(); 63 this.seasons = new Array(); 64 }, 65 addAttrDefaultDate : function(attributes,date_start,date_end){ 66 var valueToPush = new Array(); 67 valueToPush['attributes'] = attributes; 68 valueToPush['date_start'] = date_start; 69 valueToPush['date_end'] = date_end; 70 /*if(days!='') 71 { 72 valueToPush['days'] = days.split('-') 73 } 74 else 75 valueToPush['days'] = new Array();*/ 76 this.attrDefaultDates.push(valueToPush); 77 }, 78 addAttrPrice : function(id,price,pricebeforedisc,attributes,date_start,date_end,days){ 79 var valueToPush = new Array(); 80 valueToPush['id'] = id; 81 valueToPush['price'] = price; 82 valueToPush['pricebeforedisc'] = pricebeforedisc; 83 valueToPush['attributes'] = attributes; 84 valueToPush['date_start'] = date_start; 85 valueToPush['date_end'] = date_end; 86 if(days!='') 87 { 88 valueToPush['days'] = days.split('-') 89 } 90 else 91 valueToPush['days'] = new Array(); 92 this.attrPrices.push(valueToPush); 93 }, 94 setProductType : function(type){ 95 this.productType = type; 96 this.MPInitialized = true; 97 98 }, 99 setIdProduct : function(idProduct){ 100 this.id_product = idProduct; 101 }, 102 setURLS : function(value){ 103 this.urls = value; 104 }, 105 setCustomId : function(value){ 106 this.custom_id = value; 107 }, 108 setMeasure : function(value){ 109 this.measure = value; 110 }, 111 setServiceSelect : function(value){ 112 this.service_select = value; 113 this.serviceSelect = value.split('-'); 114 }, 115 setBeforePrice : function(value){ 116 this.before_price = value; 117 }, 118 setPriceText : function(value){ 119 this.price_text = value; 120 }, 121 setQuantityEnd : function(value){ 122 this.quantityend = value; 123 }, 124 setStock : function(value){ 125 this.stock = value; 126 }, 127 setModalInfo : function(value){ 128 this.modal_info = value; 129 }, 130 setAjaxPrice : function(value){ 131 this.ajax_price = value; 132 }, 133 134 setAfterPrice : function(value){ 135 this.after_price = value; 136 }, 137 setCalendarStart : function(value){ 138 this.calendar_start = value; 139 }, 140 setCalendarEnd : function(value){ 141 this.calendar_end = value; 142 }, 143 setEndDate : function(value){ 144 this.end_date = value; 145 }, 146 setTime : function(value){ 147 this.time = value; 148 }, 149 setActionAvailability : function(actionAvailability){ 150 this.actionAvailability = actionAvailability; 151 }, 152 setValidation : function(validation){ 153 this.validation = validation; 154 }, 155 setDiffCalendar : function(diff){ 156 this.diffCalendar = diff; 157 }, 158 hideContainers : function(){ 159 160 161 $('.add .add-to-cart').addClass('mpHide'); 162 //this.addCartCont.addClass('mpHide'); 163 //this.pageInfoCont.hide(); 164 $('#availability_label').hide(); 165 $('#pQuantityAvailable').hide(); 166 $('#availability_value').hide(); 167 //$('.product-add-to-cart').hide(); 168 169 170 171 $('#quantity_wanted_p').show(); 172 this.changePrice(); 173 if(!$('#megagroups').length && !$('.divmegapos').length) 174 showStepResult(); 175 176 if($('#megagroups').length >= 1){ 177 $('.col-add-qty').addClass('mpHide'); 178 $('.max_quantity').addClass('mpHide'); 179 180 } 181 182 }, 183 184 185 displayPrice : function(price,widthCurrency){ 186 var priceshow = parseFloat(price).toFixed(2); 187 188 if(widthCurrency) 189 priceshow = priceshow.replace(/\./g,",")+' ' +prestashop.currency.sign; 190 //priceshow = formatCurrency(priceshow, currencyFormat, currencySign, currencyBlank); 191 192 return priceshow; 193 }, 194 getAttrPrice : function(disc){ 195 var price = 0; 196 var arrayPrices = this.attrPrices; 197 if(this.attrPrices.length>0) 198 { 199 var ids = new Array(); 200 201 $('#attributes select, #attributes input[type=hidden], #attributes input[type=radio]:checked').each(function(){ 202 ids.push($(this).val()); 203 }); 204 $.each(ids, function(index, value) { 205 var id = parseInt(value); 206 for (var i=0;i<arrayPrices.length;i++) 207 { 208 if(arrayPrices[i]['id']==id) 209 { 210 var applyPrice = true; 211 var attributes = arrayPrices[i]['attributes']; 212 if(attributes!='') 213 { 214 arrayAttributesAttr = attributes.split(',');
215 for(var j =0;j<arrayAttributesAttr.length;j++) 216 { 217 if(!in_array(arrayAttributesAttr[j], ids)) 218 applyPrice = false; 219 } 220 } 221 222 if(applyPrice) 223 { 224 if(disc) 225 price += arrayPrices[i]['price']; 226 else 227 price += arrayPrices[i]['pricebeforedisc']; 228 } 229 } 230 } 231 232 }); 233 } 234 return price; 235 }, 236 changePrice : function(){ 237 if(this.ajax_price!=1) 238 { 239 //var price = this.priceAsFloat($('#our_price_display').html()); 240 var price = $('#mppricedisc').val(); 241 var newprice = parseFloat($('#mpprice').val()); 242 var attrPrice = this.getAttrPrice(true); 243 var pricebase = newprice+attrPrice; 244 if(pricebase==0) 245 { 246 $('.our_price_display').hide(); 247 return; 248 } 249 else 250 { 251 $('.our_price_display').show(); 252 } 253 if($('#pretaxe_price_display').length>0) 254 { 255 var pricewt = pricebase/(1+(taxRate/100)); 256 $('#pretaxe_price_display').html(_MP.displayPrice(pricewt,true)); 257 } 258 259 var labelshowprice = this.displayPrice(pricebase,true)+this.after_price; 260 if(this.before_price!='') 261 labelshowprice = this.before_price+ ' '+ labelshowprice; 262 $('#our_price_display').html(labelshowprice); 263 if($('.mp_total_price').length) 264 $('.mp_total_price').html($('#our_price_display').html()); 265 266 if($('#old_price_display').length>0) 267 { 268 var pricedisc = this.priceAsFloat($('#old_price_display').html()); 269 var newpricedisc = parseFloat($('#mppricedisc').val()); 270 var pricebasedisc = newpricedisc+this.getAttrPrice(false); 271 272 var labelshowprice = this.displayPrice(pricebasedisc,true)+this.after_price; 273 $('#old_price_display').html(labelshowprice); 274 275 } 276 } 277 }, 278 priceAsFloat : function (price){ 279 var arr = price.split(' '); 280 if(arr.length>0) 281 return parseFloat(arr[0].replace(/\./g, '').replace(/,/g,'.').replace(/[^\d\.]/g,''), 10); 282 return 0; 283 }, 284 285 extractPrice : function(price){ 286 var value = price.replace(prestashop.currency.sign,''); 287 }, 288 getTotalMeasure : function() 289 { 290 291 var width = 1; 292 var height = 1; 293 var long = 1; 294 295 var total = width*height*long; 296 return total; 297 }, 298 299 300}); 301 302$(window).load(function(){ 303 applySearchDate(); 304 305 if(typeof _MP!='undefined' && _MP.ajax_price==1) 306 { 307 // SELECT ID GROUPS BY URL 308 if(urlcodeparams!='') 309 { 310 resetGroupsByUrl(urlcodeparams); 311 if($.uniform) $.uniform.update(); 312 changeFilterMPUrlStatus(); 313 showStepResult(); 314 } 315 showprice( getIdProduct(), getIdCombination(), true, null, $('#quantity_wanted').val(), null); 316 } 317 318 /*var urlcodeparams = getParameterByName('mpurl'); 319 320 if(urlcodeparams!='') 321 { 322 resetGroupsByUrl(urlcodeparams); 323 }*/ 324}); 325 326var urlcodeparams = getParameterByName('mpurl'); 327function reloadMegaproduct(){ 328 if(typeof hideMPElements!='undefined'){ 329 $(hideMPElements).addClass('mpHide'); //mpinstall 330 } 331 if($('#megaproduct').length && typeof _MP!='undefined'){ 332 _MP.hideContainers(); 333 } 334 if(typeof hideMegaAttributeGroups!='undefined'){ 335 //mpOnlaunch = 0; 336 loadMegaproduct(); 337 if( typeof setSeats!='undefined') 338 setSeats(); 339 340 hideMegaAttributeGroups(); 341 $('#mp-ul-tabs').show(); 342 if($('#mp-ul-tabs li').length>1){ 343 $('#mp-ul-tabs').show(); 344 $('#mp-ul-tabs li.mp-tab:first').click(); 345 } 346 } 347 348} 349 350$(document).ready(function(){ 351 loadMegaproduct(); 352 353 /* LABEL_ADD. JJMARTIN Añadimos esto para recargar al actualizar producto */ 354 prestashop.on('updatedProduct', function (event) { 355 reloadMegaproduct(); 356 }); 357 /*****/ 358 359}); 360function loadMegaproduct(){ 361 if(typeof loadMPDataCountdown!='undefined') 362 loadMPDataCountdown(); 363 364 if($('#mp-quantity-limits').length){ 365 prestashop.on('updateCart', function (event) {checkLimitCartQuantities(); }); 366 } 367 $(document).on('click', '.ajax_cart_block_remove_link', function(){ 368 setTimeout( function(){window.location.reload();}, 1000); 369 }); 370 371 372 373 if(typeof(_MP)!="undefined") 374 { 375 moveContainerGroups(); 376 377 // If exist partial payment and groups 378 if($('#partial-payment').length && $('#megagroups').length) 379 $('#megagroups').append($('#partial-payment')); 380 var startdays = 0; 381 if(_MP.calendar_start!=0) 382 { 383 startdays = parseInt(parseInt(_MP.calendar_start)/24); 384 } 385 386 if(startdays>0){ 387 startdaysstr = "+"+startdays+"D"; 388 }else{ 389 startdaysstr = startdays+"D"; 390 } 391 // Custum nominative personalization 392 if (typeof applyMPCustomPersonalization === "function") 393 applyMPCustomPersonalization(); 394 395 if($('#id_step_quantity').length){ 396 $('#id_step_quantity').val($('#quantity_wanted').val()); 397 $('.megaproduct_quantity_up, .megaproduct_quantity_down').click(function(e){ 398 var qty = parseInt($('#id_step_quantity').val()); 399 400 if ($(e.delegateTarget).hasClass('megaproduct_quantity_up') && qty >= parseInt(_MP.quantityend)){ 401 return; 402 } 403 if($(this).hasClass('megaproduct_quantity_up')){ 404 qty++; 405 $('.product_quantity_up').click(); 406 } 407 408 if($(this).hasClass('megaproduct_quantity_down') && qty>1){ 409 qty--; 410 $('.product_quantity_down').click(); 411 } 412 413 $('#id_step_quantity').val(qty); 414 $('#id_step_quantity').focus(); 415 showStepResult(); 416 if (typeof applyMPCustomPersonalization === "function") 417 applyMPCustomPersonalization(); 418 419 $('#id_step_quantity').trigger('blur'); 420 421 }); 422 } 423 424 $('.mp-custom-calendar').datepicker({dateFormat: "dd-mm-yy"}); 425 if($("#id_date_start").length){ 426 $("#id_date_start").datepicker({ minDate: startdaysstr, 427 showOtherMonths: true, 428 selectOtherMonths: true, 429 dateFormat: "dd-mm-yy", 430 defaultDate: get_next_month_with_event(), 431 onSelect: function(selectedDate, inst) 432 { 433 434 var selectedday = $("#id_date_start").datepicker("getDate"); 435 var day = $("#id_date_start").datepicker("getDate"); 436 if(_MP.end_date==1){ 437 day.setDate(day.getDate()+1); 438 } 439 if(typeof _MP !='undefined' && _MP.diffCalendar!='0') 440 { 441 $("#id_date_end").datepicker("refresh"); 442 } 443 444 if(serviceselect==1) 445 { 446 startWeekDate = new Date(day.getFullYear(), day.getMonth(), day.getDate() - day.getDay()); 447 selectCurrentWeek(); 448 $('#id_date_end').datepicker('option', 'minDate', startWeekDate); 449 } 450 else 451 { 452 if($('#id_date_end').length) 453 { 454 $('#id_date_end').datepicker('option', 'minDate', day); 455 var selectedday1 = $("#id_date_end").datepicker("getDate"); 456 _MP.date_end = selectedday1; 457 } 458 } 459 _MP.selectDate = 1; 460 _MP.date_start = selectedday; 461 showStepResult(); 462 463 } , 464 beforeShowDay: isAvailable, 465 }); 466 $("#id_date_start").datepicker( "setDate" , get_next_month_with_event() ); 467 //$("#id_date_start").val(get_next_month_with_event()); 468 } 469 470 471 if(typeof _MP.calendar_end!='undefined' && _MP.calendar_end!=0) 472 { 473 var enddays = parseInt(parseInt(_MP.calendar_end)/24); 474 if(enddays>0){ 475 enddays = "+"+enddays+"D"; 476 }else{ 477 enddays = enddays+"D"; 478 } 479 var dtFechaActual = new Date(); 480 dtFechaActual.setDate(dtFechaActual.getDate() + enddays); 481 482 $("#id_date_start").datepicker( "option", "maxDate",enddays); 483 } 484 485 $("#id_date_end").datepicker({ 486 dateFormat: "dd-mm-yy", 487 showOtherMonths: true, 488
489 selectOtherMonths: true, 490 onSelect: function(selectedDate) { 491 if(serviceselect==1) 492 selectCurrentWeek(); 493 //else 494 //$( "#id_date_start" ).datepicker( "option", "maxDate", selectedDate); 495 496 if(typeof(_MP)!="undefined") 497 { 498 var selectedday = $("#id_date_end").datepicker("getDate"); 499 _MP.date_end = selectedday; 500 showStepResult(); 501 } 502 }, 503 beforeShowDay: isEndAvailable, 504 }); 505 506 507 addMPEventProduct(); 508 509 $('#btnCalculeService,#btnStepCalculeService').click(function(){ 510 if($('#id_step_quantity').length>0) 511 $('#quantity_wanted').val($('#id_step_quantity').val()); 512 $('#calculePrice').remove(); 513 $('#megaproducterror').hide(); 514 calculeservice(getIdProduct(), getIdCombination(), true, null, $('#quantity_wanted').val(), null); 515 }); 516 517 if($('#btnDirectOrder').length) 518 { 519 $(document).on("click","#btnDirectOrder",function(e) { 520 e.preventDefault(); 521 if($('#id_step_quantity').length>0) 522 $('#quantity_wanted').val($('#id_step_quantity').val()); 523 var addedFromProductPage = true; 524 if($('#btnAddCalculeService').parents('body').hasClass('content_only')) 525 addedFromProductPage = false; 526 527 addMegaProduct( getIdProduct(), getIdCombination(), addedFromProductPage, null, $('#quantity_wanted').val(), null,true); 528 }); 529 } 530 $(".mp-onlychars").on('keyup', function(e) { 531 var val = $(this).val(); 532 if (val.match(/[^a-zA-Z]/g)) { 533 $(this).val(val.replace(/[^a-zA-Z]/g, '')); 534 } 535 }); 536 537 538 if(typeof _MP!='undefined' && !$('#megagroups').length) 539 { 540 /*$(document).on('click', '#addListSeat', function(e){ 541 alert('l'); 542 });*/ 543 $('#attributes .attribute_select').unbind(); 544 $(document).on('change', '.attribute_select', function(e){ 545 e.preventDefault(); 546 findCombination(); 547 getProductAttribute(); 548 showStepResult(); 549 original_url = window.location; 550 }); 551 $(document).on('click', '.attribute_radio:radio', function(e){ 552 e.preventDefault(); 553 findCombination(); 554 getProductAttribute(); 555 showStepResult(); 556 original_url = window.location; 557 }); 558 } 559 560 $('#color_to_pick_list a').bind('click', function(event) { 561 if(typeof(_MP)!="undefined") 562 _MP.hideContainers(); 563 }); 564 565 } 566 $('#id_step_quantity,#quantity_wanted,#qty,#quantity_wanted_p a').blur(function() { 567 if($('#id_step_quantity').length) 568 $('#quantity_wanted').val($('#id_step_quantity').val()); 569 570 setTimeout(() => { 571 showStepResult(); 572 }, "200"); 573 574 575 576 //if(typeof rulesArray!='undefined' && rulesArray.length==0) 577 showMultiPersonalization(); 578 579 580 }); 581 $('[name=id_drop_date]').change(function(){ 582 showStepResult(); 583 }); 584 585 $('#quantity_wanted_p a').click(function() { 586 if($('#id_step_quantity').length) 587 $('#quantity_wanted').val($('#id_step_quantity').val()); 588 showStepResult(); 589 }); 590 // Solve plusand minus buttons templates 591 $("#quantity_wanted_p a.btn").bind('click',function(e){ 592 setTimeout(showStepResult,50); 593 }); 594 595 $('#megaproduct input[type=text]').change(function(){$('#calculePrice').hide();}); 596 597 $('#mpranges').css('width','300px'); 598 599 $('#btnOrderCalendar').click(function(){ 600 $('#availability').toggle(); 601 $('.fc-today-button').click(); 602 showMPInfo('#availability','',''); 603 604 }); 605 $('#availability').hide(); 606 $('#btnAvailability,#btnAvailability2').click(function(){ 607 608 showMPInfo('#availability','','openMPAvailability'); 609 610 }); 611 if($('#attributes').length>0) 612 { 613 $('#attributes').append($('#megaattributes').html()); 614 $('#megaattributes').html(''); 615 } 616 else 617 { 618 $('#megaattributes').hide(); 619 } 620 $('#id_time_slots,#id_days').change(function(){ 621 622 showStepResult(); 623 }); 624 $('.mp-times-combo').change(function(){ 625 var start = $('#starttime').val(); 626 var end = $('#endtime').val(); 627 $('#id_time_slots').val(start+'-'+end); 628 $('#id_time_start').val(start); 629 $('#id_time_end').val(end); 630 showStepResult(); 631 }); 632 $('.mp-personalization input,.mp-personalization textarea,.mp-personalization select').blur(function(){ 633 showStepResult(); 634 }); 635 $('.mp-personalization select').change(function(){ 636 showStepResult(); 637 }); 638 /*$('.mega-qty-list').blur(function(){ 639 showStepResult(); 640 });*/ 641 $(".mega-qty-list").bind('keyup mouseup', function () { 642 showStepResult(); 643 }); 644 $('.mpcheckbox').change(function() { 645 var fieldvalue = $(this).val(); 646 var id = $(this).attr('name'); 647 var field = '#megafield_'+ fieldvalue; 648 var arraySelect = fieldvalue.split('_'); 649 var arrayIds = id.split('_'); 650 651 mpgroup = null; 652 653 654 id_group = arrayIds[1]; 655 mpgroup = getMPGroupById(id_group); 656 657 field = '#megafield_'+id_group+'_'+ fieldvalue; 658 659 660 661 if($(this).is(":checked")) 662 { 663 $(field).addClass('selectAttr'); 664 665 if(arraySelect.length==2) 666 addMultiselectValues(arraySelect[0],arraySelect[1]); 667 //$(field).click(); 668 } 669 else 670 { 671 $(field).removeClass('selectAttr'); 672 if(arraySelect.length==2) 673 deleteMultiselectValues(arraySelect[0],arraySelect[1]); 674 } 675 var attributes = getMultiSelectGroup(id_group); 676 changeTitleSelected(mpgroup,id_group,attributes); 677 showStepResult(); 678 679 }); 680 if(typeof servicedefaultdate!='undefined' && servicedefaultdate!='') 681 { 682 if($('#id_date_start').length) 683 { 684 $('#id_date_start').val(servicedefaultdate); 685 _MP.date_start = $('#id_date_start').datepicker("getDate"); 686 } 687 else 688 { 689 //arrayDate = servicedefaultdate.split('-'); 690 _MP.date_start = new Date(servicedefaultdate); 691 //_MP.date_start.setUTCFullYear(arrayDate[0]); 692 //_MP.date_start.setUTCMonth(arrayDate[1]);
693 //_MP.date_start.setUTCDate(arrayDate[2]); 694 695 } 696 _MP.selectDate = 1; 697 } 698 699 if(!$('#megagroups').length && checkTimeSlot()) 700 loadTimeSlots(); 701 if($('.mptimes').length) 702 { 703 $('.mptimes').timepicker(); 704 $('.mptimes').blur(function() 705 { 706 showStepResult(); 707 }); 708 } 709 710 $(".resultFloat").draggable({ 711 cursor: 'move', 712 713 }); 714 if($('.mp-accept-terms').length) 715 { 716 $('.mp-accept-terms a.iframe').fancybox({ 717 'type' : 'iframe', 718 'width':600, 719 'height':600 720 }); 721 } 722 addFileUpload('.fileupload'); 723 724 if($('#id_date_select').length) 725 { 726 addMonthYear(); 727 selectionMPDate(); 728 $('#id_date_select').change(function(){ 729 selectionMPDate(); 730 }); 731 $('#id_month_select').change(function(){ 732 selectMPMonth(); 733 }); 734 if($('#id_week_select').length){ 735 loadMPWeeks(); 736 $('#id_week_select').change(function(){ 737 selectMPWeek(); 738 }); 739 } 740 741 } 742 743 744} 745function moveContainerGroups(){ 746 if($('.mpmovecontainer').length){ 747 $('.mpmovecontainer').each(function(){ 748 var id_group = $(this).data('container'); 749 $(this).appendTo($('#mpcontainer'+id_group)); 750 }); 751 } 752 if($('#show-result-container.resultFloat').length) 753 { 754 $('#show-result-container.resultFloat').append($('#megaproducterror')); 755 } 756 else if($('#mpimages').length) 757 { 758 $('#mpimages').append($('#megaproducterror')); 759 } 760 if($('#mpQtySlider').length) 761 { 762 $('#quantity_wanted_p').addClass('mpHide'); 763 $('#quantity_wanted_p').parent().append($('#mpQtySlider')); 764 765 } 766 767} 768 769function openMPAvailability() 770{ 771 $('#availability').show(); 772 $('#productcalendar').fullCalendar('destroy'); 773 if(typeof loadFullCalendar!='undefined'){ 774 loadFullCalendar(); 775 // _MP.multiAvailability = new Array(); 776 } 777 778 779} 780function applySearchDate() 781{ 782 if(typeof searchdate!='undefined' && searchdate!='') 783 { 784 if($('#id_date_start').length) 785 { 786 $('#id_date_start').datepicker("setDate", parseMPDate(searchdate, 'yyyy-mm-dd')); 787 788 _MP.date_start = $('#id_date_start').datepicker("getDate"); 789 } 790 else 791 { 792 _MP.date_start = new Date(searchdate); 793 } 794 _MP.days = 1; 795 _MP.selectDate = 1; 796 loadTimeSlots(); 797 798 } 799 if(typeof searchdays!='undefined') 800 { 801 searchdays = parseInt(searchdays); 802 if(searchdays>0) 803 { 804 if($('#id_date_end').length) 805 { 806 var day = $("#id_date_start").datepicker("getDate"); 807 day.setDate(day.getDate()+searchdays); 808 _MP.date_end = day; 809 810 $('#id_date_end').datepicker("setDate", new Date(day)); 811 } 812 if($('#id_days').length) 813 { 814 $('#id_days').val(searchdays); 815 } 816 _MP.days = searchdays; 817 } 818 } 819 820 821 822 if(typeof searchtimestart!='undefined' && searchtimestart!='') 823 { 824 var idstart = searchtimeslot+'-'+searchtimestart; 825 $('#starttime').val(idstart).change(); 826 } 827 if(typeof searchtimeend!='undefined' && searchtimeend!='') 828 { 829 var idend = searchtimeslot+'-'+searchtimeend; 830 $('#endtime').val(idend).change(); 831 } 832 applysearch = true; 833} 834function addFileUpload(id) 835{ 836 // File Upload 837 838 if($(id).length==0) 839 return; 840 var urlfileupload = baseDir + 'modules/megaproduct/upload/'; 841 $(id).fileupload({ 842 url: urlfileupload, 843 acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 844 dataType: 'json', 845 /*add: function (e, data) { 846 var ext = data.files[0]['name'].split('.').pop().toLowerCase(); 847 if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) { 848 alert('invalid extension!'); 849 } 850 },*/ 851 done: function (e, data) { 852 var group = $(this).attr('data-group'); 853 $('#megafield_'+group).html(''); 854 $.each(data.result.files, function (index, file) { 855 $('#megafieldfiles_'+group).html(''); 856 if(file['error']!='') 857 { 858 $('<p/>').text(file['error']).appendTo('#megafieldfiles_'+group); 859 } 860 if(file['type'].indexOf("image") > -1) 861 { 862 var img = $('<img>'); //Equivalent: $(document.createElement('img')) 863 img.attr('src', baseDir + 'modules/megaproduct/upload/files/thumbnail/'+file.name); 864 img.appendTo('#megafieldfiles_'+group); 865 $('<p/>').text(file.name).appendTo('#megafieldfiles_'+group); 866 } 867 $('#megafield_'+group).val(file.name); 868 showStepResult(); 869 }); 870 }, 871 progressall: function (e, data) { 872 var progress = parseInt(data.loaded / data.total * 100, 10); 873 var group = $(this).attr('data-group');
874 $('#progress'+group+' .progress-bar').css( 875 'width', 876 progress + '%' 877 ); 878 } 879 }).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled'); 880} 881function getSendGroups(quantity) 882{ 883 var sendgroups = ''; 884 885 886 var resultAttrs = listAttrIds(); 887 888 if(resultAttrs[0]==1) 889 { 890 addInputValidation(resultAttrs); 891 return false; 892 } 893 else 894 { 895 sendgroups +=resultAttrs[1]; 896 } 897 898 var resultProducts = listProductIds(quantity); 899 900 if(resultProducts[0]==1) 901 { 902 addInputValidation(resultProducts); 903 return false; 904 } 905 else 906 { 907 sendgroups +=resultProducts[1]; 908 } 909 910 var resultQuantities = listQuantityIds(); 911 if(resultQuantities[0]==1) 912 { 913 addInputValidation(resultQuantities); 914 return false; 915 } 916 else 917 { 918 sendgroups +=resultQuantities[1]; 919 } 920 sendgroups += listPersonalization(); 921 922 /*if(typeof mpLastStep!='undefined') 923 if($('.step'+mpLastStep+'').find('#id_time_slots').length) 924 { 925 if(_MP.time==2 || _MP.time==3 || _MP.time==6) 926 { 927 if(!checkMegaTimes(true)) 928 { 929 return false; 930 } 931 var loadtimes = loadTimeSlots(); 932 if(!loadtimes) 933 { 934 return false; 935 } 936 } 937 if(checkTimeSlot() && ($('#id_time_slots').val()==0 || $('#id_time_slots').val()==null)) 938 { 939 showErrorAlert(errorInfoSelectTime); 940 return false; 941 } 942 }*/ 943 944 return sendgroups; 945} 946function calculeservice(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist) 947{ 948 if(typeof mpOnlaunch!='undefined') 949 mpOnlaunch = 1; 950 951 952 if(_MP.time==2 || _MP.time==3 || _MP.time==6) 953 { 954 if(!checkMegaTimes(true)) 955 { 956 return false; 957 } 958 var loadtimes = loadTimeSlots(); 959 if(!loadtimes) 960 { 961 return false; 962 } 963 } 964 if(checkTimeSlot() && ($('#id_time_slots').val()==0 || $('#id_time_slots').val()==null)) 965 { 966 showErrorAlert(errorInfoSelectTime); 967 return false; 968 } 969 970 971 var sendgroups = getSendGroups(); 972 if(sendgroups===false) 973 return false; 974 var dataoptions = getDataServices(); 975 976 $.ajax({ 977 type: 'POST', 978 url: baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxservices', 979 async: false, 980 cache: false, 981 dataType : "html", 982 data: '&1'+dataoptions+sendgroups+'&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''), 983 success: function(jsonData,textStatus,jqXHR) 984 { 985 if(jsonData) 986 { 987 if(jsonData.indexOf("megaerror")>0){ 988 $('#calculePrice').remove(); 989 if($('#mpimages').length) 990 $('#mpimages').append(jsonData); 991 else if($('.primary_block').length) 992 $('.primary_block').append(jsonData); 993 else 994 $('#main').append(jsonData); 995 $('#calculePrice').hide(); 996 997 showMPInfo('#calculePriceData','',''); 998 999 } 1000 else if(_MP.modal_info==1) 1001 { 1002 if($('.primary_block').length) 1003 $('.primary_block').append(jsonData); 1004 else if($('#primary_block').length) 1005 $('#primary_block').append(jsonData); 1006 else if($('#mph-home-container'+idProduct).length) 1007 $('#mph-home-container'+idProduct).append(jsonData); 1008 else 1009 $('#megaproduct').append(jsonData); 1010 if($('#extraInfoProducts').length>0) 1011 { 1012 $('#extraInfoProducts').append(getInfoExtraProduct()); 1013 } 1014 $('#our_price_display').html($('#mp-total').html()); 1015 $('.our_price_display').show(); 1016 if($('#mp-total-price').length) 1017 { 1018 var price = parseFloat($('#mp-total-price').val()); 1019 if($('#old_price_display').length>0 && $('#reduction_percent_display').lenght>0) 1020 { 1021 var discount = $('#reduction_percent_display').html(); 1022 discount = discount.replace("%", ""); 1023 discount = discount.replace("-", ""); 1024 discount = _MP.priceAsFloat(discount)/100; 1025 var pricedisc = price/(1-discount); 1026 $('#old_price_display').html(_MP.displayPrice(pricedisc,true)); 1027 if($('#price_reduction_display').length) 1028 $('#price_reduction_display').html(_MP.displayPrice(price-pricedisc,true)); 1029 } 1030 if($('#pretaxe_price_display').length>0) 1031 { 1032 var pricewt = price/(1+(taxRate/100)); 1033 $('#pretaxe_price_display').html(_MP.displayPrice(pricewt,true)); 1034 } 1035 } 1036 1037 $('#calculePrice').hide(); 1038 1039 1040 showMPInfo('#calculePriceData','',''); 1041 1042 } 1043 else 1044 { 1045 if($('#mpimages').length) 1046 $('#mpimages').append(jsonData).fadeIn(2000); 1047 else if($('.primary_block').length) 1048 $('.primary_block').append(jsonData).fadeIn(2000); 1049 else 1050 $('#primary_block').append(jsonData).fadeIn(2000); 1051 goToByScroll('calculePrice'); 1052 } 1053 } 1054 addMPEventProduct(); 1055 } 1056 }); 1057} 1058function addMPEventProduct() 1059{ 1060 $('#btnAddCalculeService').unbind('click').click(function(e) { 1061 e.preventDefault(); 1062 if($('#id_step_quantity').length>0) 1063 $('#quantity_wanted').val($('#id_step_quantity').val()); 1064 var addedFromProductPage = true; 1065 if($('#btnAddCalculeService').parents('body').hasClass('content_only')) 1066 addedFromProductPage = false;
1067 1068 addMegaProduct( getIdProduct(), getIdCombination(), addedFromProductPage, null, $('#quantity_wanted').val(), null,false); 1069 }); 1070} 1071function closeMPInfo(id, closefunction) 1072{ 1073 if ($(id).length && $(id).hasClass('ui-dialog-content') && $(id).dialog("isOpen")) { 1074 $(id).dialog('close'); 1075 } 1076 if (!!$.prototype.fancybox){ 1077 if ($('div.fancybox-opened').length) 1078 parent.$.fancybox.close(); 1079 } 1080 1081 1082} 1083function showMPInfo(id,title,openfunction) 1084{ 1085 if(openfunction!='') 1086 window[openfunction](); 1087 1088 if (!!$.prototype.fancybox){ 1089 $.fancybox.open([ 1090 { 1091 type: 'inline', 1092 autoScale: true, 1093 minHeight: 30, 1094 content: $(id) 1095 } 1096 ], { 1097 padding: 5 1098 }); 1099 } 1100 else 1101 { 1102 $(id).dialog({ 1103 autoOpen: true, 1104 modal: true, 1105 width:'auto'}); 1106 if(title!='') 1107 $(id).dialog('option', 'title', title); 1108 } 1109} 1110// Funcion open dialog or fancybox to show messages 1111function showErrorAlert(alerta) 1112{ 1113 1114 if($('.mp-result-error').length) 1115 $('.mp-result-error').html(alerta); 1116 else if (!!$.prototype.fancybox){ 1117 $.fancybox.open([ 1118 { 1119 type: 'inline', 1120 autoScale: true, 1121 minHeight: 30, 1122 content: '<div class="alert alert-danger">'+alerta+'</div>' 1123 } 1124 ], { 1125 padding: 5 1126 }); 1127 } 1128 else 1129 alert(alerta); 1130} 1131function showprice(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist){ 1132 1133 1134 1135 var sendgroups = getSendGroups(); 1136 if(sendgroups===false) 1137 return false; 1138 if(typeof _MP.multiAvailability && _MP.multiAvailability.length>1) 1139 quantity = _MP.multiAvailability.length; 1140 1141 dataoptions = getDataServices(); 1142 $.ajax({ 1143 type: 'POST', 1144 url: baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxservices', 1145 async: true, 1146 cache: false, 1147 dataType : "json", 1148 data: 'type=showprice'+sendgroups+dataoptions+'&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''), 1149 success: function(jsonData,textStatus,jqXHR) 1150 { 1151 if(jsonData) 1152 { 1153 var price = jsonData['price']; 1154 $('.our_price_display').show(); 1155 1156 if(typeof jsonData['comission'] && jsonData['comission']!=''){ 1157 /*var $pricecomission = '<b>(' + jsonData['aftercomission']+' entrada + '+jsonData['comission'] + ' gastos de gestión)</b>';*/ 1158 /*$('#our_price_display').html(pricecomission); 1159 $('.current-price span:first').html(pricecomission); 1160 $('.product-prices .product-price').html(pricecomission);*/ 1161 1162 1163 // es megaseat 1164 if($("#btnSelectSeats").length){ 1165 var $gestion = '<b>(+ gastos de gestión )</b>'; 1166 if($('.product-prices .product-price b').length == 0){ 1167 $('.product-prices .product-price').append($gestion); 1168 } 1169 1170 }else{ 1171 var pricecomission = price + ' <b>(' + jsonData['aftercomission']+' entrada + '+jsonData['comission'] + ' gastos de gestión)</b>'; 1172 $('.product-prices .product-price').html(pricecomission); 1173 $('.product-quantity .col-add-qty').show(); 1174 } 1175 1176 1177 1178 } else { 1179 /*$('#our_price_display').html(price); 1180 $('.current-price span:first').html(price); 1181 $('.product-prices .product-price').html(price);*/ 1182 } 1183 1184 if($('.mp_total_price').length) 1185 $('.mp_total_price').html(price); 1186 if(typeof jsonData['pricewtr']!='undefined') 1187 $('#old_price_display').html(jsonData['pricewtr']); 1188 if(typeof jsonData['discount']!='undefined') 1189 $('#reduction_amount_display').html(jsonData['discount']); 1190 } 1191 } 1192 }); 1193 return true; 1194 1195}; 1196 1197 1198function goToByScroll(id){ 1199 1200 // Scroll 1201 if($("#"+id).length) 1202 $('html,body').animate({ 1203 scrollTop: $("#"+id).offset().top}, 1204 'slow'); 1205}; 1206function valueInArray(arrayValues,item) 1207{ 1208 for (i = 0; i < arrayValues.length; i++) 1209 { 1210 if(arrayValues[i]==item) 1211 return true; 1212 } 1213 1214 return false; 1215}; 1216 1217function listAttrIds() 1218{ 1219 var sendgroups = ''; 1220 var resultgroups= new Array(); 1221 resultgroups[0]=0; 1222 resultgroups[1]=''; 1223 resultgroups[2]= new Array(); 1224 var totalselect = 0; 1225 if(typeof megaGroups!='undefined' && megaGroups.length>0) 1226 { 1227 var ids = 0; 1228 for (i=0; i<megaGroups.length; i++) 1229 { 1230 var totalselect = 0; 1231 if(typeof megaGroups[i]!='undefined' && applyStepValidation(megaGroups[i])) 1232 { 1233 var id_group = megaGroups[i]['id_addgroup']; 1234 var mpgroup = megaGroups[i]; 1235 1236 if(mpgroup['type']=='0' && mpgroup['show']!='3' && !$('#megagroup'+mpgroup['id_addgroup']).hasClass('hideMegaField')) 1237 { 1238 if(mpgroup['multiselect']!=0) 1239 { 1240 mpgroup['selections'] = getMultiSelectGroup(id_group); 1241 totalselect = mpgroup['selections'].length; 1242 1243 for (var j = 0; j < mpgroup['selections'].length; j++) 1244 { 1245 if(sendgroups=='') 1246 sendgroups+='&attrIds='; 1247 if(ids>0) 1248 sendgroups+='-'; 1249 1250 sendgroups+=mpgroup['selections'][j]; 1251 resultgroups[2].push(mpgroup['selections'][j]); 1252 1253 ids++; 1254 } 1255 } 1256 else if(mpgroup['selected']!=0) 1257 { 1258 if($('#megagroup'+megaGroups[i]['id_addgroup']).length && !$('#megagroup'+megaGroups[i]['id_addgroup']).hasClass('hideMegaField') && mpgroup['action']!=1) 1259 { 1260 if(typeof mpgroup['selected']!='undefined' && mpgroup['selected']!='') 1261 { 1262 totalselect = 1; 1263 if(mpgroup['dep']=='1') 1264 { 1265 if(sendgroups=='') 1266 sendgroups+='&attrIds='; 1267 if(ids>0) 1268 sendgroups+='-'; 1269 1270 sendgroups+=mpgroup['selected']; 1271 resultgroups[2].push(mpgroup['selected']); 1272 ids++; 1273 } 1274 } 1275 } 1276 } 1277 if(mpgroup['multiselectmin']!=0 && totalselect<mpgroup['multiselectmin'] && mpOnlaunch==1 && !$('#megagroup'+megaGroups[i]['id_addgroup']).hasClass('hideMegaField')) 1278 { 1279 resultgroups[0]=1; 1280 resultgroups[1]= minselectiontext + ' ' +$('#megalabel_'+id_group+' .mega_title').html()+' '+mpgroup['multiselectmin']; 1281 resultgroups[3] = '#megalabel_'+id_group; 1282 resultgroups[4] = 'minqty'; 1283 return resultgroups; 1284 } 1285 if(mpgroup['multiselectmax']!=0 && totalselect>mpgroup['multiselectmax'] && mpOnlaunch==1 && !$('#megagroup'+megaGroups[i]['id_addgroup']).hasClass('hideMegaField')) 1286 { 1287 resultgroups[0]=1; 1288 resultgroups[1]= maxselectiontext + ' ' +$('#megalabel_'+id_group+' .mega_title').html()+' '+mpgroup['multiselectmax']; 1289 resultgroups[3] = '#megalabel_'+id_group; 1290 resultgroups[4] = 'maxqty'; 1291 return resultgroups; 1292 } 1293 1294 } 1295 if(mpgroup['type']=='3' && mpgroup['required']==1 && mpOnlaunch==1 && !$('#megagroup'+megaGroups[i]['id_addgroup']).hasClass('hideMegaField')) 1296 { 1297 if(mpgroup['customquantity']==0 && $('#megafield_'+megaGroups[i]['id_addgroup']).val()=='') 1298 { 1299 resultgroups[0]=1; 1300 resultgroups[1]= requiredfieldtext + ' ' +$('#megalabel_'+id_group+' .mega_title').html(); 1301 resultgroups[3] = '#megafield_'+megaGroups[i]['id_addgroup']; 1302 resultgroups[4] = 'required'; 1303 return resultgroups; 1304 } 1305 else if(mpgroup['customquantity']==1 || _MP.quantityGroups!=0) 1306 { 1307 var qty = parseInt($('#id_step_quantity').val()); 1308 if(_MP.quantityGroups!=0) 1309 qty = _MP.quantityGroups; 1310 1311 for(k=0;k<qty;k++) 1312 { 1313 if($('#megafield_'+megaGroups[i]['id_addgroup']+'_'+k).val()=='') 1314 { 1315 1316 $('#mpTab'+k).click(); 1317 $('#megafield_'+megaGroups[i]['id_addgroup']+'_'+k).focus(); 1318 var x = k+1; 1319 resultgroups[0]=1; 1320 resultgroups[1]= requiredfieldtext + ' ' + $('#megagroup'+id_group+' .custom_title').html()+ ' (' + x +')'; 1321 return resultgroups; 1322 } 1323 } 1324 } 1325 1326 } 1327 } 1328 } 1329 1330 } 1331 resultgroups[1] = sendgroups; 1332 return resultgroups; 1333}; 1334function getAttrSelectedId(id_group) 1335{ 1336 if($('#group_'+id_group).length>0) 1337 { 1338 return $('#group_'+id_group).val(); 1339 } 1340 else if($('#color_pick_hidden[name="group_'+id_group+'"]').length>0) 1341 { 1342 return $('#color_pick_hidden[name="group_'+id_group+'"]').val(); 1343 } 1344 else if($('.color_pick_hidden[name="group_'+id_group+'"]').length>0) 1345 { 1346 return $('.color_pick_hidden[name="group_'+id_group+'"]').val(); 1347 } 1348 1349 return 0; 1350}; 1351function getFisrtAttrSelectedId(id_group) 1352{ 1353 var idAttr = 0; 1354 if($('#megagroup'+id_group+' li:first').length>0) 1355 { 1356 idAttr = $('#megagroup'+id_group+' li:first').attr('alt'); 1357 } 1358 else if($('#megafield_'+id_group+' option:not([disabled])').length>0) 1359 { 1360 idAttr = $('#megafield_'+id_group+' option:not([disabled])').first().attr('value'); 1361 } 1362 else if($('#megafield_'+id_group).length>0) 1363 { 1364 idAttr = $('#megafield_'+id_group).val(); 1365 } 1366 1367 return idAttr; 1368} 1369function listQuantityIds() 1370{ 1371 var sendgroups=''; 1372 var resultgroups= new Array(); 1373 var separateIds = ''; 1374 resultgroups[0]=0; 1375 resultgroups[1]=''; 1376 resultgroups[2]= new Array(); 1377 if(typeof megaGroups!='undefined' && megaGroups.length>0) 1378 { 1379 var ids = 0; 1380 var idsep = 0; 1381 var separateIds = ''; 1382 var activeMulti = false;
1383 var totalGroups = 0; 1384 var totalOtherGroups = 0; 1385 var maxlimit = 0; 1386 var minlimit = 0; 1387 var minOtherGroups = 0; 1388 var minOtherGroupId = 0; 1389 var minOtherTitleGroup = ''; 1390 var minOtherIdsGroup = ''; 1391 var arrayMinOthers = new Array(); 1392 var arrayQtyGroups = new Array(); 1393 for (i=0; i<megaGroups.length; i++) 1394 { 1395 var id_group = megaGroups[i]['id_addgroup']; 1396 var mpgroup = megaGroups[i]; 1397 if(mpgroup!=null) 1398 { 1399 if(applyStepValidation(megaGroups[i]) && mpgroup['type']=='0' && mpgroup['show']==3 && !$('#megagroup'+mpgroup['id_addgroup']).hasClass('hideMegaField')) 1400 { 1401 var totalqty = 0; 1402 $('#megagroup'+mpgroup['id_addgroup']+' .mega-qty-list').each(function(){ 1403 var id = $(this).attr('data-attr'); 1404 var qty = $(this).val(); 1405 if(qty!=0) 1406 { 1407 totalqty += parseInt(qty); 1408 if(mpgroup['limit']==1) 1409 { 1410 if($('#qty-label-'+id).length>0 && mpgroup['multiselectmin']!=0 && qty<mpgroup['multiselectmin'] && mpOnlaunch==1) 1411 { 1412 resultgroups[0]=1; 1413 resultgroups[1]= minselectiontext + ' ' +$('#qty-label-'+id).html()+' '+mpgroup['multiselectmin']; 1414 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1415 resultgroups[4] = 'limitqty'; 1416 } 1417 if($('#qty-label-'+id).length>0 && mpgroup['multiselectmax']!=0 && qty>mpgroup['multiselectmax'] && mpOnlaunch==1) 1418 { 1419 resultgroups[0]=1; 1420 resultgroups[1]= maxselectiontext + ' ' +$('#qty-label-'+id).html()+' '+mpgroup['multiselectmax']; 1421 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1422 resultgroups[4] = 'limitqty'; 1423 } 1424 } 1425 if(mpgroup['action']==4) 1426 { 1427 if(separateIds=='') 1428 separateIds+='&separateIds='; 1429 if(idsep>0) 1430 separateIds+='-'; 1431 separateIds+=id+'|'+qty; 1432 idsep++; 1433 } 1434 else 1435 { 1436 if(ids==0 && sendgroups=='') 1437 sendgroups+='&quantityIds='; 1438 1439 if(ids>0) 1440 sendgroups+='-'; 1441 sendgroups+=id+'|'+qty+'|'+mpgroup['id_addgroup']+'|'+mpgroup['grouplimitattr']+'|'+mpgroup['action']; 1442 ids++; 1443 } 1444 } 1445 1446 1447 }); 1448 if(mpgroup['action']==3 && mpOnlaunch==1) 1449 { 1450 var qtycart = parseInt($('#quantity_wanted').val()); 1451 if(totalqty!=qtycart) 1452 { 1453 resultgroups[0]=1; 1454 resultgroups[1]= samequantitytext + ' ' +$('#megalabel_'+id_group+' .mega_title').html(); 1455 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1456 resultgroups[4] = 'limitqty'; 1457 } 1458 } 1459 if(mpgroup['limit']==0) 1460 { 1461 if($('#megagroup'+mpgroup['id_addgroup']+' .mega_title').length>0 && mpgroup['multiselectmin']!=0 && totalqty<mpgroup['multiselectmin'] && mpOnlaunch==1) 1462 { 1463 resultgroups[0]=1; 1464 resultgroups[1]= minselectiontext + ' ' +$('#megagroup'+mpgroup['id_addgroup']+' .mega_title').html()+' '+mpgroup['multiselectmin']; 1465 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1466 resultgroups[4] = 'limitqty'; 1467 1468 } 1469 if($('#megagroup'+mpgroup['id_addgroup']+' .mega_title').length>0 && mpgroup['multiselectmax']!=0 && totalqty>mpgroup['multiselectmax'] && mpOnlaunch==1) 1470 { 1471 resultgroups[0]=1; 1472 resultgroups[1]= maxselectiontext + ' ' +$('#megagroup'+mpgroup['id_addgroup']+' .mega_title').html()+' '+mpgroup['multiselectmax']; 1473 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1474 resultgroups[4] = 'limitqty'; 1475 } 1476 } 1477 if(mpgroup['limit']==2) 1478 { 1479 totalGroups += totalqty; 1480 1481 activeMulti = true; 1482 maxlimit = mpgroup['multiselectmax']; 1483 minlimit = mpgroup['multiselectmin']; 1484 } 1485 if(mpgroup['limit']!=3) 1486 { 1487 if(typeof arrayQtyGroups[mpgroup['id_addgroup']]=='undefined') 1488 arrayQtyGroups[mpgroup['id_addgroup']] = 0; 1489 arrayQtyGroups[mpgroup['id_addgroup']] += totalqty; 1490 totalOtherGroups += totalqty; 1491 1492 } 1493 if(mpgroup['limit']==3) 1494 { 1495 minOtherGroups += totalqty; 1496 arrayMinOthers.push({id_addgroup: mpgroup['id_addgroup'],qty: totalqty, ids: mpgroup['grouplimitids'], title: $('#megagroup'+mpgroup['id_addgroup']+' .mega_title').html()}); 1497 1498 } 1499 } 1500 } 1501 } 1502 if(activeMulti) 1503 { 1504 if(minlimit!=0 && totalGroups<minlimit && mpOnlaunch==1) 1505 { 1506 resultgroups[0]=1; 1507 resultgroups[1]= minselectiontext + ' '+minlimit; 1508 } 1509 if(maxlimit!=0 && totalGroups>maxlimit && mpOnlaunch==1) 1510 { 1511 resultgroups[0]=1; 1512 resultgroups[1]= maxselectiontext +' '+maxlimit; 1513 } 1514 } 1515 if(arrayMinOthers.length!=0 && mpOnlaunch==1) 1516 { 1517 for(var n=0;n<arrayMinOthers.length;n++) 1518 { 1519 minOtherIdsGroup=arrayMinOthers[n]['ids']; 1520 //minOtherGroups = arrayMinOthers[n]['qty']; 1521 minOtherGroupId = arrayMinOthers[n]['id_addgroup']; 1522 minOtherTitleGroup = arrayMinOthers[n]['title']; 1523 1524 if(minOtherIdsGroup!='') 1525 { 1526 totalOtherGroups = 0; 1527 1528 var arrayIds = minOtherIdsGroup.split(','); 1529 for(var k=0;k<arrayIds.length;k++) 1530 { 1531 var id = parseInt(arrayIds[k]); 1532 if(typeof arrayQtyGroups[id]!='undefined') 1533 totalOtherGroups += parseInt(arrayQtyGroups[id]); 1534 } 1535 } 1536 if(minOtherGroups>totalOtherGroups) 1537 { 1538 1539 resultgroups[0]=1; 1540 if($('#megadescriptionlong_'+minOtherGroupId).length && $('#megadescriptionlong_'+minOtherGroupId).html()!=''){ 1541 resultgroups[1]= $('#megadescriptionlong_'+minOtherGroupId).html(); 1542 } else { 1543 resultgroups[1]= minOtherTitleGroup+' => '+ maxquantitytext +' :'+minOtherGroups; 1544 } 1545 mpOnlaunch = 0; 1546 break; 1547 } 1548 1549 } 1550 1551 1552 } 1553 } 1554 if(resultgroups[1]=='') 1555 resultgroups[1] = sendgroups+separateIds; 1556 return resultgroups; 1557}; 1558function listCombinationIds() 1559{ 1560 var sendgroups=''; 1561 if(typeof megaGroups!='undefined' && megaGroups.length>0) 1562 { 1563 var ids = 0; 1564 for (i=0; i<megaGroups.length; i++) 1565 { 1566 var id_group = megaGroups[i]['id_group']; 1567 var mpgroup = megaGroups[i]; 1568 if(mpgroup!=null) 1569 { 1570 if(mpgroup['type']=='0' && mpgroup['show']==3) 1571 { 1572 $('#mp-attrqty-'+id_group+' input').each(function(){ 1573 var id = $(this).attr('id').substring(7); 1574 var choice = new Array(); 1575 if($(this).val()!=0) 1576 { 1577 1578 for (j=0; j<megaGroups.length; j++) 1579 { 1580 var idGroup = megaGroups[j]['id_group']; 1581 if(idGroup!=id_group) 1582 choice.push(getAttrSelectedId(idGroup)); 1583 else 1584 choice.push(id); 1585 } 1586 var idCombination = findMPCombination(choice,$(this).val()); 1587 if(idCombination!=0) 1588 { 1589 if(ids==0 && sendgroups=='') 1590 sendgroups+='&combinationIds='; 1591 1592 if(ids>0) 1593 sendgroups+='-'; 1594 sendgroups+=idCombination+'|'+$(this).val(); 1595 ids++; 1596 } 1597 } 1598 }); 1599 } 1600 } 1601 } 1602 } 1603 return sendgroups; 1604}; 1605function findMPCombination(choice,quantity) 1606{ 1607 1608 1609 //testing every combination to find the conbination's attributes' case of the user 1610 for (var combination = 0; combination < combinations.length; ++combination) 1611 { 1612 //verify if this combinaison is the same that the user's choice 1613 var combinationMatchForm = true; 1614 $.each(combinations[combination]['idsAttributes'], function(key, value) 1615 { 1616 if (!in_array(value, choice)) 1617 { 1618 combinationMatchForm = false;
1619 } 1620 }); 1621 if (combinationMatchForm) 1622 { 1623 1624 var idCombinationQty = combinations[combination]['quantity']; 1625 if(idCombinationQty>quantity) 1626 return combinations[combination]['idCombination']; 1627 1628 // var idCustomization = combinations[combination]['idCombination']; 1629 //get the data of product with these attributes 1630 1631 } 1632 } 1633 return 0; 1634} 1635function getInfoExtraProduct() 1636{ 1637 var textInfo=''; 1638 if(typeof megaGroups!='undefined' && megaGroups.length>0) 1639 { 1640 var ids = 0; 1641 for (i=0; i<megaGroups.length; i++) 1642 { 1643 1644 var id_group = megaGroups[i]['id_addgroup']; 1645 var mpgroup = megaGroups[i]; 1646 if(mpgroup!=null) 1647 { 1648 if(mpgroup['type']=='1') 1649 { 1650 var html =$('#megalabel_'+id_group).html(); 1651 //$html.remove(".divmegazoom"); 1652 textInfo += html +'<br/>'; 1653 } 1654 } 1655 } 1656 } 1657 return textInfo; 1658} 1659function listPersonalization() 1660{ 1661 var sendgroups = ''; 1662 var customgroups= new Array(); 1663 1664 if(typeof megaGroups!='undefined' && megaGroups.length>0) 1665 { 1666 for (i=0; i<megaGroups.length; i++) 1667 { 1668 var id_group = megaGroups[i]['id_addgroup']; 1669 var mpgroup = megaGroups[i]; 1670 if(mpgroup!=null) 1671 { 1672 if(applyStepValidation(megaGroups[i]) && mpgroup['type']=='3' && !$('#megagroup'+id_group).hasClass('hideMegaField')) 1673 { 1674 customgroups.push(mpgroup['id_addgroup']); 1675 if(mpgroup['customquantity']==0 || _MP.quantityGroups==0) 1676 { 1677 if(mpgroup['id_group']=='3') 1678 { 1679 customgroups.push(parseFloat($('#megafield_'+mpgroup['id_addgroup']).val())); 1680 } 1681 else 1682 customgroups.push($('#megafield_'+mpgroup['id_addgroup']).val()); 1683 } 1684 else 1685 { 1686 var qty = parseInt($('#id_step_quantity').val()); 1687 if(_MP.quantityGroups!=0) 1688 qty = _MP.quantityGroups; 1689 var multicustom = ''; 1690 for(var k=0;k<qty;k++) 1691 { 1692 if(multicustom!='') 1693 multicustom+='|'; 1694 multicustom += $('#megafield_'+mpgroup['id_addgroup']+'_'+k).val(); 1695 } 1696 customgroups.push(multicustom); 1697 } 1698 } 1699 } 1700 } 1701 } 1702 if(customgroups.length) 1703 { 1704 return '&personalization='+encodeURIComponent(JSON.stringify(customgroups)); 1705 } 1706 return ''; 1707}; 1708function listProductIds(quantity) 1709{ 1710 var sendgroups = ''; 1711 var resultgroups= new Array(); 1712 resultgroups[0]=0; 1713 if(typeof megaGroups!='undefined' && megaGroups.length>0) 1714 { 1715 var ids = 0; 1716 for (i=0; i<megaGroups.length; i++) 1717 { 1718 1719 var id_group = megaGroups[i]['id_addgroup']; 1720 var mpgroup = megaGroups[i]; 1721 if(mpgroup!=null) 1722 { 1723 if(mpgroup['type']=='1') 1724 { 1725 if(sendgroups=='') 1726 sendgroups+='&productIds='; 1727 1728 if(mpgroup['show']!=3) 1729 { 1730 var totalselect = 0; 1731 if(typeof mpgroup['selected']!='undefined' && mpgroup['selected']!=0 && mpgroup['selected']!='' && mpgroup['multiselect']==0) 1732 { 1733 if(ids>0) 1734 sendgroups+='-'; 1735 1736 sendgroups+=mpgroup['selected']+'|1'; 1737 ids++; 1738 totalselect = 1; 1739 } 1740 if(mpgroup['multiselect']!=0) 1741 { 1742 mpgroup['selections'] = getMultiSelectGroup(id_group); 1743 totalselect = mpgroup['selections'].length; 1744 1745 for (var j = 0; j < mpgroup['selections'].length; j++) 1746 { 1747 if(ids>0) 1748 sendgroups+='-'; 1749 1750 sendgroups+=mpgroup['selections'][j]+'|1'; 1751 ids++; 1752 } 1753 } 1754 if(mpgroup['multiselectmin']!=0 && totalselect<mpgroup['multiselectmin'] && mpOnlaunch==1) 1755 { 1756 resultgroups[0]=1; 1757 resultgroups[1]= minselectiontext + ' ' +$('#megalabel_'+id_group+' .mega_title').html()+' '+mpgroup['multiselectmin']; 1758 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1759 resultgroups[4] = 'limitqty'; 1760 return resultgroups; 1761 } 1762 if(mpgroup['multiselectmax']!=0 && totalselect>mpgroup['multiselectmax'] && mpOnlaunch==1) 1763 { 1764 resultgroups[0]=1; 1765 resultgroups[1]= maxselectiontext + ' ' +$('#megalabel_'+id_group+' .mega_title').html()+' '+mpgroup['multiselectmax']; 1766 resultgroups[3] = '#megagroup'+mpgroup['id_addgroup']; 1767 resultgroups[4] = 'limitqty'; 1768 return resultgroups; 1769 } 1770 } 1771 else 1772 { 1773 $('#megafield_'+mpgroup['id_addgroup']+' input').each(function(){ 1774 var id = $(this).attr('id').substring(12); 1775 if($(this).val()!=0) 1776 { 1777 if(ids>0) 1778 sendgroups+='-'; 1779 sendgroups+=id+'|'+$(this).val(); 1780 ids++; 1781 } 1782 }); 1783 1784 } 1785 1786 1787 } 1788 } 1789 } 1790 1791 } 1792 resultgroups[1] = sendgroups; 1793 return resultgroups; 1794}; 1795function showMegaHelp(id_group, type) 1796{ 1797 if(type==0) 1798 { 1799 1800 $('#megadescriptionlong_'+id_group).animate(0, 1000, function() { 1801 $(this).toggle(); 1802 }); 1803 } 1804 else 1805 { 1806 var contentHelp = ''; 1807 var title = ''; 1808 1809 if($('#megadescriptionlong_'+id_group).length) 1810 contentHelp += $('#megadescriptionlong_'+id_group).html()+'<br/>'; 1811 1812 $('#helpmegaproduct').html(contentHelp); 1813 $('#helpmegaproduct').attr('title',title); 1814 if(contentHelp!='') 1815 { 1816 showMPInfo('#helpmegaproduct',title,''); 1817 } 1818 1819 } 1820 1821 return false;
1822 1823}; 1824function showMegaAttrHelp(id_addattr,id_addgroup) 1825{ 1826 1827 var contentHelp = ''; 1828 var title = ''; 1829 if($('#megadescattr_'+id_addattr).length) 1830 { 1831 contentHelp += $('#megadescattr_'+id_addattr).html()+'<br/>'; 1832 title = $('#megadescattr_'+id_addattr).attr('title'); 1833 } 1834 1835 var id = '#megaattrhelp_'+id_addattr; 1836 if(id_addgroup!=0) 1837 { 1838 id = '#megaattrhelp_'+id_addgroup; 1839 } 1840 if(contentHelp=='') 1841 return false; 1842 1843 $('#helpmegaproduct').html(contentHelp); 1844 $('#helpmegaproduct').attr('title',title); 1845 if(contentHelp!='') 1846 { 1847 showMPInfo('#helpmegaproduct',title,''); 1848 1849 1850 } 1851 1852 1853 1854 return false; 1855 1856}; 1857function zoomMegaImage(id_group) 1858{ 1859 var id = '#megaImageList_'+id_group+' .selectAttr'; 1860 $('#megazoom_'+id_group).attr('href',$(id).attr('alt')); 1861 1862 $('#megazoom_'+id_group).fancybox({ 1863 'autoSize' : false, 1864 'width' : 600, 1865 'height' : 'auto', 1866 'hideOnContentClick': true 1867 }); 1868 $('#megazoom_'+id_group).trigger('click'); 1869 return false; 1870 1871} 1872 1873function updateMegaProduct(id_group,id_product) 1874{ 1875 mpgroup = getMegaGroupById(id_group); 1876 if(mpgroup!=null) 1877 { 1878 var megafield = getMegaField(mpgroup,id_group,id_product); 1879 1880 1881 if(mpgroup['selected']==id_product) 1882 { 1883 removeMegaSelect(mpgroup,id_product); 1884 showStepResult(); 1885 return true; 1886 } 1887 1888 changeOptionSelected(megafield); 1889 var arrayAttr = new Array(); 1890 if($.isArray(id_product)) 1891 { 1892 arrayAttr = id_product; 1893 } 1894 else 1895 { 1896 arrayAttr[0]=id_product; 1897 } 1898 1899 changeTitleSelected(mpgroup,id_group,arrayAttr); 1900 changeImageSelected(mpgroup,id_group,id_product); 1901 mpgroup['selected']=id_product; 1902 1903 } 1904 showStepResult(); 1905} 1906function updateMegaProductSelect(id_group) 1907{ 1908 mpgroup = getMegaGroupById(id_group); 1909 if(mpgroup!=null) 1910 { 1911 var id_attribute = $('#megafield_'+id_group).val(); 1912 if(id_attribute.length>1) 1913 { 1914 mpgroup['selections']=id_attribute; 1915 //$('#megaName_'+id_group).html(''); 1916 $('#imageDivGroup_'+id_group).hide(); 1917 //return; 1918 } 1919 1920 if(mpgroup['show']=='4') 1921 { 1922 id_attribute = $('#megagroups input:radio[name=megafield_'+id_group+']:checked').val(); 1923 } 1924 var arrayAttr = new Array(); 1925 if($.isArray(id_attribute)) 1926 { 1927 arrayAttr = id_attribute; 1928 } 1929 else 1930 { 1931 arrayAttr[0]=id_attribute; 1932 } 1933 changeTitleSelected(mpgroup,id_group,arrayAttr); 1934 changeImageSelected(mpgroup,id_group,id_attribute); 1935 1936 1937 mpgroup['selected']=id_attribute; 1938 1939 } 1940 showStepResult(); 1941} 1942function getMegaField(mpgroup,id_group,id_attribute) 1943{ 1944 var megafield = null; 1945 if(mpgroup['show']=='0') 1946 { 1947 megafield = $('#megafield_'+id_group+' option:selected'); 1948 } 1949 /*else if(mpgroup['show']=='4') 1950 { 1951 megafield = $('#megagroups input:radio[name=megafield_'+id_group+']'); 1952 }*/ 1953 else 1954 { 1955 megafield = $('#megagroups #megafield_'+id_group+'_'+id_attribute); 1956 } 1957 if(mpgroup['multiselect']=='1' && $('[name=mpcheckbox_'+id_group+'_'+id_attribute+']').length){ 1958 megafield = $('[name=mpcheckbox_'+id_group+'_'+id_attribute+']'); 1959 } 1960 return megafield; 1961} 1962function changeImageSelected(mpgroup,id_group, id_attribute) 1963{ 1964 if(id_attribute!=null && id_attribute.length>1) 1965 { 1966 $('#imageDivGroup_'+id_group).hide(); 1967 return; 1968 } 1969 1970 $('#imageDivGroup_'+id_group).show(); 1971 var megafield = getMegaField(mpgroup,id_group,id_attribute); 1972 if(mpgroup['show']=='0') 1973 { 1974 if($('#megafield_'+id_group+' option:selected').length>0 && $('#imageGroup_'+id_group).length>0) 1975 { 1976 $('#imageGroup_'+id_group).attr('src',$(megafield).attr('alt')); 1977 $('#imageGroupLink_'+id_group).attr('href',$(megafield).attr('alt')); 1978 } 1979 } 1980 else 1981 { 1982 if($('#imageGroup_'+id_group).length>0) 1983 { 1984 $('#imageGroup_'+id_group).attr('src',$(megafield).attr('alt')); 1985 $('#imageGroupLink_'+id_group).attr('href',$(megafield).attr('alt')); 1986 } 1987 } 1988 if(id_attribute==0) 1989 { 1990 $('#imageDivGroup_'+id_group).hide(); 1991 } 1992} 1993function changeOptionSelected(megafield) 1994{ 1995 $(megafield).parents('ul:first').find('a').each(function(){ 1996 $(this).removeClass('selectAttr'); 1997 }); 1998 $(megafield).addClass('selectAttr'); 1999} 2000function changeTitleSelected(mpgroup,id_group,attributes) 2001{ 2002 if(mpgroup['type']=='7') 2003 return false; 2004 var megatitle = ''; 2005 2006 var megaweight = 0; 2007 2008 if(attributes==null) 2009 return; 2010 2011 for(var k=0;k<attributes.length;k++) 2012 { 2013 if(megatitle!='') 2014 megatitle += ' - '; 2015 2016 if(mpgroup['show']=='0') 2017 { 2018 megatitle += $('#megagroups #megafield_'+id_group+' option[value="' + attributes[k] + '"]').html(); 2019 } 2020 else if(mpgroup['show']=='4' && mpgroup['multiselect']=='0') 2021 { 2022 megatitle += $('#megagroups input:radio[name=megafield_'+id_group+']:checked').attr('title'); 2023 2024 } 2025 else if(mpgroup['show']=='4' && mpgroup['multiselect']=='1') 2026 { 2027 megatitle += $('[for=mpcheckbox_'+id_group+'_'+attributes[k]+']').text(); 2028 2029 } 2030 else 2031 { 2032 var megafield = getMegaField(mpgroup,id_group,attributes[k]); 2033 megatitle += $(megafield).attr('title'); 2034 } 2035 } 2036 $('#megaName_'+id_group).html(megatitle); 2037 if(typeof megatitle!='undefined') 2038 mpgroup['selectedname'] = megatitle; 2039 else 2040 { 2041 $('#megaName_'+id_group).html(''); 2042 mpgroup['selectedname'] = ''; 2043 } 2044 //showStepResult(); 2045}; 2046function getMegaGroupById(id_group) 2047{ 2048 if(typeof megaGroups!='undefined' && megaGroups.length>0) 2049 { 2050 for (i=0; i< megaGroups.length; i++) 2051 { 2052 if(megaGroups[i]['id_addgroup']==id_group) 2053 return megaGroups[i]; 2054 } 2055 } 2056 return null; 2057} 2058 2059function updateMPProductSelect(id_group) 2060{ 2061 mpgroup = getMegaGroupById(id_group); 2062 if(mpgroup!=null) 2063 { 2064 var id_attribute = $('#megafield_'+id_group).val(); 2065 if(mpgroup['show']=='4') 2066 { 2067 id_attribute = $('#megagroups input:radio[name=megafield_'+id_group+']:checked').val(); 2068 } 2069 2070 changeTitleSelected(mpgroup,id_group,id_attribute); 2071 changeImageSelected(mpgroup,id_group,id_attribute); 2072 2073 mpgroup['selected']=id_attribute; 2074 showStepResult(); 2075 } 2076 2077 2078} 2079function findMegaCombination(id_group) 2080{ 2081 //_MP.changePrice(); 2082 id_attribute = $('#megagroup_'+id_group).val(); 2083 updateMegaAttrSelect(id_group,id_attribute); 2084}; 2085function findMegaCombo(id_group) 2086{ 2087 id_attribute = $('#megafield_'+id_group).val(); 2088 $('#group_'+id_group).val(id_attribute); 2089 //$('#group_'+id_group).change(); 2090 updateMegaAttrSelect(id_group,id_attribute); 2091}; 2092 2093function getMPGroupById(id_group) 2094{ 2095 if(typeof megaGroups!='undefined' && megaGroups.length>0) 2096 { 2097 for (i=0; i< megaGroups.length; i++) 2098 { 2099 if(megaGroups[i]['id_addgroup']==id_group) 2100 return megaGroups[i]; 2101 } 2102 } 2103 return null; 2104} 2105function removeMegaSelect(mpgroup,id_attribute) 2106{ 2107 var id_addgroup = mpgroup['id_addgroup']; 2108 $('#megafield_'+id_addgroup+'_'+id_attribute).removeClass('selectAttr'); 2109 if ($('#megafield_'+id_addgroup+'_'+id_attribute).is(':radio')) { 2110 $('#megafield_'+id_addgroup+'_'+id_attribute).attr('checked', false); 2111 $('#megafield_'+id_addgroup+'_'+id_attribute).parent().removeClass('checked'); 2112 } 2113 2114 2115 $('#megaName_'+id_addgroup).html(''); 2116 mpgroup['selected'] = ''; 2117 mpgroup['weight'] = 0; 2118 2119} 2120function updateMegaAttrSelect(id_group,id_attribute) 2121{ 2122 mpgroup = getMegaGroupById(id_group); 2123 2124 if(mpgroup==null) 2125 return true; 2126 2127 if(mpgroup['selected']==id_attribute && mpgroup['dep']==1) 2128 { 2129 removeMegaSelect(mpgroup,id_attribute); 2130 showStepResult(); 2131 return true; 2132 } 2133 2134 var id_megagroup = $('#id_megagroup'+id_group).val(); 2135 2136 var megafield = getMegaField(mpgroup,id_group,id_attribute); 2137 2138 2139 if($(megafield).find('img').length>0) 2140 { 2141 $('#megazoomimg_'+id_group).show(); 2142 } 2143 else 2144 { 2145 $('#megazoomimg_'+id_group).hide(); 2146 } 2147 changeOptionSelected(megafield); 2148 2149 var arrayAttr = new Array();
2150 arrayAttr[0] = id_attribute; 2151 changeTitleSelected(mpgroup,id_group,arrayAttr); 2152 changeImageSelected(mpgroup,id_group,id_attribute); 2153 2154 2155 if(mpgroup['dep']=='0') 2156 { 2157 2158 setAttrSelectedId(id_megagroup,id_attribute); 2159 //if(typeof productHasAttributes!='undefined' && productHasAttributes) 2160 //{ 2161 if($('#group_'+id_megagroup).length>0) 2162 { 2163 $('#group_'+id_megagroup).change(); 2164 } 2165 else if($('#color_'+id_attribute).length>0) 2166 { 2167 $('#color_'+id_attribute).click(); 2168 setAttrSelectedId(id_megagroup,id_attribute); 2169 } 2170 //} 2171 } 2172 2173 mpgroup['selected'] = id_attribute; 2174 2175 showStepResult(); 2176 2177}; 2178function setAttrSelectedId(id_group,value) 2179{ 2180 if($('#group_'+id_group).length>0) 2181 { 2182 $('#group_'+id_group).val(value); 2183 } 2184 else if($('#color_pick_hidden[name="group_'+id_group+'"]').length>0) 2185 { 2186 $('#color_pick_hidden[name="group_'+id_group+'"]').val(value); 2187 } 2188 else if($('.color_pick_hidden[name="group_'+id_group+'"]').length>0) 2189 { 2190 $('.color_pick_hidden[name="group_'+id_group+'"]').val(value); 2191 } 2192 2193 return 0; 2194} 2195function stepCalculeMegaGroups(id_step) 2196{ 2197 2198 if($('#id_step_quantity').length>0) 2199 $('#quantity_wanted').val($('#id_step_quantity').val()); 2200 /*if($('#btnCalculeService').length>0) 2201 { 2202 $('#btnCalculeService').click(); 2203 }*/ 2204 if($('#btnAddProduct').length>0) 2205 { 2206 $('#btnAddProduct').click(); 2207 } 2208 else if($('#btnAddCalculeService').length>0) 2209 { 2210 $('#btnAddCalculeService').click(); 2211 } 2212 2213 2214 2215}; 2216// ** STEP FUNCTIONS **/ 2217function stepBreadCrumbs(id_step) 2218{ 2219 if(id_step<=mpMaxStep){ 2220 mpIdStep = id_step; 2221 stepMegaGroups(id_step); 2222 } 2223 2224} 2225function applyStepValidation(megaGroup) 2226{ 2227 if(mpIdStep==mpSteps) 2228 return true; 2229 2230 if(typeof mpSteps=='undefined' || mpSteps<2 || mpLastStep==0) 2231 return true; 2232 2233 var step = parseInt(megaGroup['step']); 2234 2235 if(mpLastStep==step) 2236 return true; 2237 return false; 2238} 2239function stepNextMegaGroups() 2240{ 2241 var id = parseInt(mpIdStep)+1; 2242 mpIdStep = id; 2243 if(typeof mpOnlaunch!='undefined') 2244 mpOnlaunch = 1; 2245 2246 stepMegaGroups(id); 2247 2248}; 2249function stepPreviousMegaGroups() 2250{ 2251 var id = parseInt(mpIdStep)-1; 2252 mpIdStep = id; 2253 stepMegaGroups(id); 2254}; 2255 2256function stepMegaGroups(id_step) 2257{ 2258 if(mpIdStep>mpLastStep && getSendGroups()===false) 2259 { 2260 mpIdStep = mpLastStep; 2261 return false; 2262 2263 } 2264 2265 if(id_step>mpSteps) 2266 { 2267 mpIdStep = 1; 2268 id_step=1; 2269 } 2270 if(id_step >=mpMaxStep) 2271 mpMaxStep = id_step; 2272 2273 $('.mpstep').hide(); 2274 $('.megacombo_step').hide(); 2275 $('.step'+id_step).show(); 2276 //$('#mp-step-result').hide(); 2277 $('#mpStepPrevious').hide(); 2278 //$('#mpStepNext').hide(); 2279 if(id_step==1) 2280 { 2281 $('#mpStepNext').show(); 2282 } 2283 else 2284 { 2285 $('#mpStepNext').show(); 2286 $('#mpStepPrevious').show(); 2287 } 2288 if(id_step==mpSteps) 2289 { 2290 $('#mpStepNext').hide(); 2291 $('#mp-step-result').show(); 2292 showStepResult(); 2293 } 2294 mpLastStep = id_step; 2295 if($('.mp-breadcrumb').length) 2296 { 2297 if($('.mp-breadcrumb-select').length) 2298 $('.mp-breadcrumb-select').removeClass('mp-breadcrumb-select'); 2299 if($('#mpbreadcrumb'+id_step).length) 2300 $('#mpbreadcrumb'+id_step).addClass('mp-breadcrumb-select'); 2301 } 2302 //$('#quantity_wanted').parent().hide(); 2303} 2304function checkActionQuantities() 2305{ 2306 _MP.quantityGroups = 0; 2307 if(typeof megaGroups!='undefined' && megaGroups.length>0 ) 2308 { 2309 var totalqty = 0; 2310 var changeQty = false; 2311 for (k=0; k<megaGroups.length; k++) 2312 { 2313 if(typeof megaGroups[k]!='undefined' ) 2314 { 2315 var mpgroup = megaGroups[k]; 2316 var id_addgroup = megaGroups[k]['id_addgroup']; 2317 if(mpgroup['show']=='3' && (mpgroup['action']=='2' || mpgroup['action']=='4')) 2318 { 2319 var qty = 0; 2320 $('#megagroup'+id_addgroup+' .mega-qty-list').each(function(){ 2321 qty += parseInt($(this).val()); 2322 }); 2323 totalqty +=qty; 2324 changeQty = true; 2325 2326 } 2327 if(mpgroup['show']=='3' && mpgroup['groupquantity']=='1') 2328 { 2329 $('#megagroup'+id_addgroup+' .mega-qty-list').each(function(){ 2330 _MP.quantityGroups += parseInt($(this).val()); 2331 }); 2332 } 2333 2334 2335 } 2336 } 2337 if(changeQty) 2338 { 2339 if(totalqty==0) 2340 totalqty=1; 2341 $('#quantity_wanted').val(totalqty); 2342 if($('#id_step_quantity').length) 2343 $('#id_step_quantity').val(totalqty); 2344 } 2345 } 2346} 2347function selectMultiTab(tab) 2348{ 2349 $('.mpCustomTab').hide(); 2350 $('#mp-custom-'+tab).fadeIn('slow'); 2351 2352} 2353function showMultiPersonalization() 2354{ 2355 if(typeof megaGroups!='undefined' && megaGroups.length>0 ) 2356 { 2357 if(typeof fileupload!='undefined') 2358 $('#multi-personalization .fileupload').fileupload('destroy'); 2359 var qty = 0; 2360 if($('#id_step_quantity').length) 2361 qty = parseInt($('#id_step_quantity').val()); 2362 else 2363 qty = parseInt($('#quantity_wanted').val()); 2364 if(_MP.quantityGroups>0) 2365 qty = qty*_MP.quantityGroups; 2366 2367 if(_MP.lastPersonalization==qty) 2368 return; 2369 _MP.lastPersonalization=qty; 2370 multiqty = qty; 2371 $('#mpCustomTabs').html(''); 2372 $('#mpCustomContent').html(''); 2373 for(var i=0;i<qty;i++) 2374 { 2375 var active = ''; 2376 if(i==0) 2377 active='active'; 2378 var k = i+1; 2379 var $customgroup = null; 2380 2381 $('#mpCustomTabs').append('<li class="'+active+'"><a id="mpTab'+i+'" onclick="selectMultiTab('+i+')" href="#'+i+'a" data-toggle="tab"> - '+k+' - </a></li>'); 2382 2383 $customgroup = $('<div id="mp-custom-'+i+'" class="tap-pane mpCustomTab box"></div>'); 2384 2385 for (k=0; k<megaGroups.length; k++) 2386 { 2387 megagroup = megaGroups[k]; 2388 2389 if(typeof megagroup!='undefined' && megagroup['type']=='3' && megagroup['customquantity']=='1') 2390 { 2391 $('#multi-personalization').show(); 2392 2393 // if($customgroup==null) 2394 // $customgroup = $('<div id="mp-custom-'+qty+'" class="box"></div>'); 2395 2396 var customtype = megagroup['id_group']; 2397 var id_addgroup = megagroup['id_addgroup']; 2398 2399 if($('#megagroup'+id_addgroup).length && $('#megagroup'+id_addgroup).hasClass('hideMegaField')) 2400 continue; 2401 2402 var required = ''; 2403 if(megagroup['required']==1) 2404 required = ' required'; 2405 $('<label>'+$('#megagroup'+id_addgroup+' .custom_title').html()+'</label>').appendTo($customgroup); 2406 2407 var id = id_addgroup + '_' + i; 2408 if(customtype==0) 2409 { 2410 $('<div class="mp-personalization"><input type="text" id="megafield_'+id+'" class="mega-input" value="" '+required+' /></div>').appendTo($customgroup); 2411 } 2412 else if(customtype==1) 2413 { 2414 $('<div class="mp-personalization"><textarea id="megafield_'+id+'" class="mega-input mp-personalization" value="" '+required+' /></div>').appendTo($customgroup); 2415 } 2416 else if(customtype==2) 2417 { 2418 $('#megafield_'+id_addgroup).parents('.mpstep').addClass('hideMegaField'); 2419 $('<div class="mp-personalization"><select id="megafield_'+id+'" name="megafield_'+id+'">'+$('#megafield_'+id_addgroup).html()+'</select></div>').appendTo($customgroup); 2420 2421 2422 } 2423 else if(customtype==5) 2424 { 2425 $('<input id="fileupload'+id+'" data-group="'+id+'" data-name="'+id+'" class="fileupload" type="file" name="files[]"><br><div id="progress'+id+'" class="progress"><div class="progress-bar progress-bar-success"></div></div><input type="hidden" id="megafield_'+id+'" class="mega-input" type="text" value=""><div id="megafieldfiles_'+id+'" class="files"></div>').appendTo($customgroup); 2426 } 2427 else if(customtype==6) 2428 { 2429 $('<div class="mp-personalization"><input id="megafield_'+id+'" class="mega-input mp-custom-calendar" style="text-align:center;" type="text" value=""></div>').appendTo($customgroup); 2430 } 2431 2432 } 2433 } 2434 $('#mpCustomContent').append($customgroup).fadeIn('slow'); 2435 2436 } 2437 $('.mp-custom-calendar').datepicker({dateFormat: "dd-mm-yy"}); 2438 $('.mpCustomTab').hide(); 2439 $('.mpCustomTab:first').show(); 2440 addFileUpload('#multi-personalization .fileupload'); 2441 if (typeof uniform != "undefined") 2442 { 2443 $('#multi-personalization input[type="file"]').uniform(); 2444 } 2445 } 2446} 2447function parseMPDate(input, format) { 2448 format = format || 'yyyy-mm-dd'; // default format 2449 var parts = input.match(/(\d+)/g), 2450 i = 0, fmt = {}; 2451 // extract date-part indexes from the format 2452 format.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; }); 2453 2454 return new Date(parts[fmt['yyyy']], parts[fmt['mm']]-1, parts[fmt['dd']]); 2455} 2456function applyDefaultDate() 2457{ 2458 if(typeof _MP.attrDefaultDates!='undefined' && _MP.attrDefaultDates.length) 2459 { 2460 var listAttrIds = getAllIds(); 2461 2462 for(var i=0;i<_MP.attrDefaultDates.length;i++) 2463 { 2464 var attrs = _MP.attrDefaultDates[i]['attributes']; 2465 var date_start = _MP.attrDefaultDates[i]['date_start']; 2466 var date_end = _MP.attrDefaultDates[i]['date_end']; 2467 if(typeof attrs!='undefined' && attrs!='') 2468 { 2469 attrs = attrs.split("-"); 2470 var newArray = new Array(); 2471 for(var j=0;j<attrs.length;j++) 2472 { 2473 attrs[j] = parseInt(attrs[j]); 2474 if(attrs[j]!=0) 2475 newArray.push(attrs[j]); 2476 } 2477 attrs = newArray; 2478 } 2479 else 2480 attrs = new Array(); 2481 if(typeof attrs!='undefined') 2482 { 2483 var apply = true; 2484 2485 if(attrs.length) 2486 for(var j=0;j<attrs.length;j++) 2487 { 2488 var id = parseInt(attrs[j]); 2489 if(apply && $.inArray(id,listAttrIds)<0) 2490 apply= false; 2491 } 2492 if(apply) 2493 { 2494 if($('#id_date_start').length) 2495 { 2496 $('#id_date_start').datepicker("setDate", new Date(date_start)); 2497 _MP.date_start = $('#id_date_start').datepicker("getDate"); 2498 } 2499 else 2500 { 2501 _MP.date_start = parseMPDate(date_start, 'yyyy-mm-dd'); 2502 } 2503 if(date_end!='') 2504 { 2505 if($('#id_date_end').length) 2506 $('#id_date_end').datepicker("setDate", new Date(date_end)); 2507 2508 var date1 = parseMPDate(date_start, 'yyyy-mm-dd'); 2509 var date2 = parseMPDate(date_end, 'yyyy-mm-dd'); 2510 var timeDiff = Math.abs(date2.getTime() - date1.getTime()); 2511 var diffDays = Math.round(timeDiff / (1000 * 3600 * 24)); 2512 _MP.days = diffDays; 2513 } 2514 2515 } 2516 } 2517 } 2518 } 2519 if(checkTimeSlot()) 2520 loadTimeSlots(); 2521 2522} 2523function getAllIds() 2524{ 2525 var ids = new Array(); 2526 var groupIds = listAttrIds(); 2527 2528 if(typeof groupIds[2]!='undefined') 2529 { 2530 ids = groupIds[2]; 2531 } 2532 2533 2534 var idComb = getIdCombination(); 2535 2536 if (typeof combinations == 'undefined' || !combinations) 2537 combinations = []; 2538 //testing every combination to find the conbination's attributes' case of the user 2539 for (var combination = 0; combination < combinations.length; ++combination) 2540 { 2541 if(combinations[combination]['idCombination']==idComb) 2542 {
2543 var combAttr = combinations[combination]['idsAttributes']; 2544 ids = $.merge(ids, combAttr); 2545 return ids; 2546 } 2547 } 2548 for (var i=0; i<ids.length;++i) 2549 { 2550 ids[i]=parseInt(ids[i]); 2551 } 2552 return ids; 2553} 2554 2555function showStepResult() 2556{ 2557 if(typeof(_MP)=='undefined') 2558 return; 2559 2560 removeShowErrors(); 2561 disableMegaFields(); 2562 checkActionQuantities(); 2563 applyDefaultDate(); 2564 2565 2566 if(_MP.ajax_price==1) 2567 { 2568 showprice( getIdProduct(), getIdCombination(), true, null, $('#quantity_wanted').val(), null); 2569 } 2570 else 2571 { 2572 _MP.changePrice(); 2573 } 2574 if(typeof megaGroups!='undefined' && megaGroups.length>0 && $('#mp-step-result').length) 2575 { 2576 $('#mp-step-result').html(''); 2577 var images = $('<div>'); 2578 for (k=0; k<megaGroups.length; k++) 2579 { 2580 if(typeof megaGroups[k]!='undefined' && megaGroups[k]['type']!='2') 2581 { 2582 var id_group = megaGroups[k]['id_group']; 2583 var id_addgroup = megaGroups[k]['id_addgroup']; 2584 var mpgroup = megaGroups[k]; 2585 2586 if($('#megalabel_'+id_addgroup+' .mega_title').length && !$('#megagroup'+id_addgroup).hasClass('hideMegaField') && mpgroup['action']!=1) 2587 { 2588 images.append('<span class="mp-label-result">'+$('#megalabel_'+id_addgroup+' .mega_title').html()+'</span>'); 2589 if(mpgroup['type']!='7' && mpgroup['type']!='3' && mpgroup['show']!='3') 2590 { 2591 images.append('<br/><span class="mp-data-result">'+$('#megalabel_'+id_addgroup+' .megaattr_name').html()+'</span><br/>'); 2592 } 2593 else if(mpgroup['show']!='3') 2594 { 2595 images.append('<br/><span class="mp-data-result">'+$('#megafield_'+id_addgroup).val()+'</span><br/>'); 2596 } 2597 if(mpgroup['show']=='3') 2598 { 2599 $('#megagroup'+id_addgroup+' .mega-qty-list').each(function(){ 2600 var qty = $(this).val(); 2601 if(qty!=0) 2602 { 2603 var attrId = $(this).attr('data-attr'); 2604 var labelQty = ''; 2605 if($('#productName_'+attrId).length) 2606 labelQty = $('#productName_'+attrId).html(); 2607 else if($('#qty-label-'+attrId).length) 2608 labelQty = $('#qty-label-'+attrId).html(); 2609 images.append('<br/><span class="mp-data-result">'+qty+'x'+labelQty+'</span>'); 2610 2611 } 2612 }); 2613 images.append('<br/>'); 2614 } 2615 } 2616 2617 } 2618 } 2619 var dates = '<div class="mp-result-dates">'; 2620 if($('#id_date_start').length) 2621 { 2622 dates +='<span class="mp-result-start">'+$('#id_date_start').datepicker().val()+'</span>'; 2623 } 2624 if($('#id_date_end').length) 2625 { 2626 dates +='<span class="mp-result-end"> / '+$('#id_date_end').datepicker().val()+'</span>'; 2627 } 2628 if($('#id_days').length && $('label[for="id_days"]').length) 2629 { 2630 dates +='<br/><span class="mp-result-days">'+$('label[for="id_days"]').html()+' '+$('#id_days').val()+'</span>'; 2631 } 2632 if(checkTimeSlot()) 2633 { 2634 dates +='<br/><span class="mp-result-time">'+$('#id_time_slots option:selected').text()+'</span>'; 2635 } 2636 /*if(_MP.multiAvailability.length) 2637 { 2638 for(var k;k<_MP.multiAvailability.length;k++) 2639 { 2640 var event = _MP.multiAvailability[k]; 2641 dates +='<br/><span class="mp-result-time">'+event.start._i+'</span>'; 2642 } 2643 2644 }*/ 2645 if($('#quantity_wanted_p').length) 2646 { 2647 dates +='<br/><span class="mp-result-quantity">'; 2648 if($('#quantity_wanted_p label').length) 2649 dates +=$('#quantity_wanted_p label').html()+' '; 2650 else if($("#label_id_step_quantity").length) 2651 dates +=$('#label_id_step_quantity').html()+' '; 2652 2653 dates += $('#quantity_wanted').val()+'</span>'; 2654 } 2655 dates += '</div>'; 2656 images.append(dates); 2657 2658 $('#mp-step-result').append(images); 2659 } 2660 refreshCalendar(); 2661 //if(typeof rulesArray!='undefined' && rulesArray.length>0) 2662 showMultiPersonalization(); 2663 2664 // Change Urls Status 2665 changeFilterMPUrlStatus(); 2666 2667 2668} 2669function hideStepMegaGroups() 2670{ 2671 if(typeof megaGroups!='undefined' && megaGroups.length>0) 2672 { 2673 $('#megaproduct').hide(); 2674 $('#quantity_wanted_p').addClass('mpHide'); 2675 if($('#btnRanges').length>0) 2676 { 2677 $('#id_step_prices').show(); 2678 $('#id_step_prices').click(function(){ 2679 $('#btnRanges').click(); 2680 }); 2681 2682 } 2683 } 2684 showMultiPersonalization(); 2685 2686} 2687function showMegaproductTab(id) 2688{ 2689 $('.showTab').hide(); 2690 $('.showTab'+id).show(); 2691 $('.mp-tab').removeClass('selected'); 2692 $('#mp-tab'+id).addClass('selected'); 2693 2694} 2695function disableMegaFields() 2696{ 2697 if(typeof megaGroups=='undefined') 2698 return 2699 $('.hideMegaField').removeClass('hideMegaField'); 2700 if(rulesArray.length>0) 2701 { 2702 for (var i=0; i<rulesArray.length; i++) 2703 { 2704 var applyRule = true; 2705 var selected_fields = rulesArray[i]['selected_fields'].split("|"); 2706 var disabled_fields = rulesArray[i]['disabled_fields'].split("|"); 2707 var date_start = rulesArray[i]['date_start']; 2708 var date_end = rulesArray[i]['date_end']; 2709 var days = rulesArray[i]['days']; 2710 var type = rulesArray[i]['rule']; 2711 var time = rulesArray[i]['time']; 2712 var timelogic = rulesArray[i]['timelogic']; 2713 var logical = rulesArray[i]['logical']; 2714 2715 if(date_start!='' && typeof _MP.date_start!='undefined') 2716 { 2717 var yyyy = _MP.date_start.getFullYear().toString(); 2718 var mm = (_MP.date_start.getMonth()+1).toString(); // getMonth() is zero-based 2719 var dd = _MP.date_start.getDate().toString(); 2720 2721 var dateselect = yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]); 2722 if(dateselect<date_start || dateselect>date_end) 2723 { 2724 applyRule = false;
2725 } 2726 else 2727 { 2728 if(days!='') 2729 { 2730 var arraydays = days.split("-"); 2731 var day = _MP.date_start.getDay().toString(); 2732 if(arraydays.indexOf(day)<0) 2733 applyRule = false; 2734 } 2735 } 2736 } 2737 if(time!='') 2738 { 2739 if($('#id_time_slots').length==0) 2740 applyRule = false; 2741 else if($("#id_time_slots").is(":hidden") && $("#id_time_slots").val()!='') 2742 { 2743 var timsel = $("#id_time_slots").val(); 2744 if(typeof timsel=='string') 2745 { 2746 var arrayTime = timsel.split('-'); 2747 if(arrayTime.length==3) 2748 { 2749 var n = arrayTime[1]; 2750 if(timelogic==0 && n<time) 2751 applyRule = false; 2752 else if(timelogic==1 && n>=time) 2753 applyRule = false; 2754 } 2755 } 2756 2757 } 2758 else if($('#id_time_slots option:selected').attr('date-start')) 2759 { 2760 var n = $('#id_time_slots option:selected').attr('date-start'); 2761 if(timelogic==0 && n>=time) 2762 applyRule = false; 2763 else if(timelogic==1 && n<time) 2764 applyRule = false; 2765 } 2766 } 2767 var existAttr = false; 2768 if(applyRule && rulesArray[i]['selected_fields']!='') 2769 for(var j=0; j<selected_fields.length; j++) 2770 { 2771 arraySelect = selected_fields[j].split('-'); 2772 2773 if(type==0) 2774 var selectedRule = false; 2775 else 2776 var selectedRule = true; 2777 if(arraySelect.length==2) 2778 { 2779 for (var k=0; k<megaGroups.length; k++) 2780 { 2781 if(megaGroups[k]['multiselect']==1) 2782 { 2783 var selectAttr = getMultiSelectGroup(megaGroups[k]['id_addgroup']); 2784 if($.inArray(arraySelect[1],selectAttr)>=0) 2785 { 2786 existAttr = true 2787 if(type==0) 2788 selectedRule = true; 2789 else 2790 selectedRule = false; 2791 } 2792 } 2793 else if((megaGroups[k]['type']==1 && arraySelect[0]=='p') || (megaGroups[k]['type']==0 && arraySelect[0]=='a')) 2794 { 2795 if(typeof megaGroups[k]['selected']!='undefined' && megaGroups[k]['selected']==arraySelect[1]) 2796 { 2797 existAttr = true 2798 if(type==0) 2799 selectedRule = true; 2800 else 2801 selectedRule = false; 2802 } 2803 } 2804 } 2805 if(arraySelect[0]=='t') 2806 { 2807 var id_time_slot = $('#id_time_slots').val(); 2808 if(checkTimeSlot() && id_time_slot==arraySelect[1]) 2809 { 2810 selectedRule = true; 2811 } 2812 } 2813 } 2814 if(logical=='and' && !selectedRule) 2815 applyRule = false; 2816 } 2817 if(!existAttr && type!=2) 2818 applyRule = false; 2819 if(applyRule) 2820 { 2821 for(var j=0; j<disabled_fields.length; j++) 2822 { 2823 $arrayDisabled = disabled_fields[j].split('-'); 2824 if($arrayDisabled.length==2) 2825 { 2826 if($arrayDisabled[0]=='g') 2827 { 2828 $("#megagroup"+$arrayDisabled[1]).addClass('hideMegaField'); 2829 checkDisableQtyList($arrayDisabled[1]); 2830 } 2831 else 2832 { 2833 for (var k=0; k<megaGroups.length; k++) 2834 { 2835 if((megaGroups[k]['type']==1 && $arrayDisabled[0]=='p') || (megaGroups[k]['type']==0 && $arrayDisabled[0]=='a')) 2836 { 2837 hideRuleField($arrayDisabled[0],$arrayDisabled[1],megaGroups[k]['id_addgroup']); 2838 } 2839 } 2840 } 2841 } 2842 } 2843 } 2844 } 2845 } 2846} 2847function checkDisableQtyList(id_addgroup) 2848{ 2849 for (var m=0; m<megaGroups.length; m++) 2850 { 2851 if(megaGroups[m]['id_addgroup']==id_addgroup) 2852 { 2853 if(megaGroups[m]['type']==0 && megaGroups[m]['show']==3) 2854 { 2855 $('#megagroup'+id_addgroup+' .mega-qty-list').each(function(){ 2856 $(this).val(0); 2857 2858 }); 2859 $('#quantity_wanted').val(1); 2860 } 2861 } 2862 } 2863} 2864function selectRuleOptions(megagroup,idattr) 2865{ 2866 if(typeof megagroup=='undefined' || megagroup==null) 2867 return; 2868 id_group = megagroup['id_group']; 2869 id_addgroup = megagroup['id_addgroup']; 2870 var megafield = getMegaField(megagroup,id_addgroup,idattr); 2871 2872 megagroup['selected'] = idattr; 2873 changeOptionSelected(megafield); 2874 if(idattr!=0 && megagroup['show']!='3') 2875 { 2876 if(megagroup['show']=='4') 2877 { 2878 $(megafield).prop("checked", true); 2879 } 2880 if(megagroup['show']=='0') 2881 { 2882 $(megafield).parent('select').val(idattr); 2883 } 2884 var arrayAttr = new Array(); 2885 arrayAttr.push(idattr); 2886 changeTitleSelected(megagroup,id_addgroup,arrayAttr); 2887 2888 changeImageSelected(megagroup,id_addgroup,idattr); 2889 2890 if(megagroup['dep']=='0') 2891 { 2892 setAttrSelectedId(id_group,idattr); 2893 if(typeof productHasAttributes!='undefined' && productHasAttributes) 2894 { 2895 if($('#group_'+id_group).length>0) 2896 { 2897 $('#group_'+id_group).change(); 2898 } 2899 else if($('#color_'+idattr).length>0) 2900 { 2901 $('#color_'+idattr).click(); 2902 setAttrSelectedId(id_group,idattr); 2903 } 2904 } 2905 } 2906 2907 megagroup['selected'] = idattr; 2908 2909 } 2910} 2911function ruleMeasure(rule,measure,option) 2912{ 2913 if((rule>measure && option==0) || (rule<measure && option==1) || (rule==measure && option==2)) 2914 return true; 2915 else 2916 return false;
2917} 2918function checkDisableSelected(id_group,id) 2919{ 2920 var hasSelect = false; 2921 for (n=0; n<megaGroups.length; n++) 2922 { 2923 if(megaGroups[n]['id_addgroup']==id_group) 2924 { 2925 if(megaGroups[n]['selected']==id || in_array(id, megaGroups[n]['selections'])) 2926 { 2927 if(megaGroups[n]['selected']==id) 2928 { 2929 megaGroups[n]['selected']=''; 2930 hasSelect = true; 2931 } 2932 else if (in_array(id, megaGroups[n]['selections'])) 2933 { 2934 var index = megaGroups[n]['selections'].indexOf(id); 2935 if (index > -1) 2936 { 2937 megaGroups[n]['selections'].splice(index, 1); 2938 hasSelect = true; 2939 } 2940 } 2941 removeMegaSelect(megaGroups[n],id); 2942 } 2943 } 2944 } 2945 return hasSelect; 2946} 2947function hideRuleField(type,id, id_group) 2948{ 2949 if(type=='a' || type=='p') 2950 { 2951 var hasSelected = checkDisableSelected(id_group,id); 2952 var changeSelected = false; 2953 if($('#megafield_'+id_group+'_'+id).length>0) 2954 { 2955 if($('#megafield_'+id_group+'_'+id).parent('li').length>0) 2956 { 2957 $('#megafield_'+id_group+'_'+id).parent('li').addClass('hideMegaField'); 2958 if(hasSelected) 2959 { 2960 $('#megafield_'+id_group+'_'+id).parent('li').parent().find('li').each(function(){ 2961 if(!changeSelected && !$(this).hasClass('hideMegaField')) 2962 { 2963 changeSelected = true; 2964 id = $(this).attr('alt'); 2965 if($('#megafield_'+id_group+'_'+id).is(':radio')){ 2966 $('#megafield_'+id_group+'_'+id).prop('checked',true); 2967 updateMegaAttrSelect(id_group,id); 2968 } 2969 else if($('#megafield_'+id_group+'_'+id).length) 2970 $('#megafield_'+id_group+'_'+id).click(); 2971 } 2972 }); 2973 } 2974 } 2975 else 2976 { 2977 $('#megafield_'+id_group+'_'+id).addClass('hideMegaField'); 2978 if(hasSelected) 2979 { 2980 /*$('#megafield_'+id_group+'_'+id).parent().find('li').each(function(){ 2981 if(!changeSelected && !$(this).hasClass('hideMegaField')) 2982 { 2983 changeSelected = true; 2984 id = $(this).attr('alt'); 2985 $('#megafield_'+id_group+'_'+id).click(); 2986 } 2987 });*/ 2988 } 2989 } 2990 2991 } 2992 else if($('#megafield_'+id_group+' option[value="'+id+'"]').length>0) 2993 { 2994 $('#megafield_'+id_group+' option[value="'+id+'"]').addClass('hideMegaField'); 2995 if(hasSelected) 2996 { 2997 $('#megafield_'+id_group+' option').each(function(){ 2998 if(!changeSelected && !$(this).hasClass('hideMegaField')) 2999 { 3000 changeSelected = true; 3001 $('#megafield_'+id_group).val($(this).val()); 3002 $('#megafield_'+id_group).change(); 3003 3004 } 3005 }); 3006 } 3007 } 3008 } 3009 else if(type=='g') 3010 { 3011 $("#megagroup"+id_group).addClass('hideMegaField'); 3012 } 3013} 3014function hideMegaAttributeGroups() 3015{ 3016 if(typeof megaGroups!='undefined' && megaGroups.length>0) 3017 { 3018 for (i=0; i<megaGroups.length; i++) 3019 { 3020 if(typeof megaGroups[i]!='undefined') 3021 { 3022 var id_megagroup = megaGroups[i]['id_group']; 3023 var id_group = megaGroups[i]['id_addgroup']; 3024 var megagroup = megaGroups[i]; 3025 if(megagroup['hide']==1) 3026 { 3027 if(megagroup['dep']=='0' && megagroup['type']=='0') 3028 { 3029 if($('#group_'+id_megagroup).length>0) 3030 { 3031 $('#group_'+id_megagroup).parents('.attribute_fieldset').hide(); 3032 } 3033 else if($('label[for="group_'+id_megagroup+'"]').length) 3034 { 3035 $('label[for="group_'+id_megagroup+'"]').parents('.attribute_fieldset').hide(); 3036 } 3037 else if($('.color_pick_hidden[name="group_'+id_megagroup+'"]').length) 3038 { 3039 $('.color_pick_hidden[name="group_'+id_megagroup+'"]').parents('.attribute_fieldset').hide(); 3040 } 3041 else if($('#color_to_pick_list').length>0) 3042 { 3043 $('#color_to_pick_list').parents('.attribute_fieldset').hide(); 3044 } 3045 } 3046 else if(megagroup['dep']=='1') 3047 { 3048 $('#mpgroup_'+id_megagroup).parent().hide(); 3049 } 3050 } 3051 var idattr = 0; 3052 if(megagroup['default_id']!='') 3053 { 3054 idattr = parseInt(megagroup['default_id']); 3055 } 3056 else if(megagroup['dep']=='0' && megagroup['type']=='0') 3057 { 3058 idattr = getAttrSelectedId(id_megagroup); 3059 } 3060 else 3061 { 3062 idattr = getFisrtAttrSelectedId(id_group); 3063 } 3064 3065 var megafield = getMegaField(megagroup,id_group,idattr); 3066 3067 megagroup['selected'] = idattr; 3068 changeOptionSelected(megafield); 3069 if(idattr!=0 && megagroup['show']!='3') 3070 { 3071 var arrayAttr = new Array(); 3072 arrayAttr.push(idattr); 3073 if(megagroup['show']=='4') 3074 { 3075 $(megafield).prop("checked", true); 3076 } 3077 else if(megagroup['multiselect']=='1' && megagroup['show']=='1') 3078 { 3079 if(megagroup['multiselectmin']>1){ 3080 arrayAttr = new Array(); 3081 $('#megagroup'+id_group+' .mpcheckbox').slice(0,megagroup['multiselectmin']).each(function(){ 3082 $(this).prop("checked", true); 3083 arrayAttr.push($(this).val()); 3084 3085 }); 3086 changeTitleSelected(megagroup,id_group,arrayAttr); 3087 3088 } else { 3089 $(megafield).prop("checked", true); 3090 } 3091 3092 } 3093 else if(megagroup['show']=='0') 3094 { 3095 $(megafield).parent('select').val(idattr); 3096 } 3097 3098 3099 changeTitleSelected(megagroup,id_group,arrayAttr); 3100 3101 changeImageSelected(megagroup,id_group,idattr); 3102 } 3103 } 3104 } 3105 3106 3107 } 3108 3109 if(typeof mpAddProduct!='undefined' && mpAddProduct==0) 3110 { 3111 $('#mp-step-quantity').hide(); 3112 } 3113 3114 if(typeof _MP!="undefined" && _MP.ajax_price==1) 3115 { 3116 if($('#id_date_start').length && $('#id_date_start').val()!='') 3117 _MP.date_start = $('#id_date_start').datepicker("getDate"); 3118 } 3119 showStepResult(); 3120}; 3121function getMultiSelectGroup(id_group) 3122{ 3123 var mpgroup = getMPGroupById(id_group); 3124 var selections = new Array(); 3125 if(mpgroup['show']=='0') 3126 { 3127 selections = $('#megafield_'+id_group).val(); 3128 } 3129 else if(mpgroup['show']=='1' || mpgroup['show']=='4') 3130 { 3131 3132 $('#megagroup'+id_group+ ' .mpcheckbox:checked').each(function(item){ 3133 selections.push($(this).val()); 3134 }); 3135 } 3136 else 3137 { 3138 if(typeof mpgroup['selection']!='undefined') 3139 selections.push(mpgroup['selection']); 3140 } 3141 if(selections==null) 3142 selections = new Array(); 3143 3144 return selections; 3145 3146} 3147function listDirectOrder() 3148{ 3149 var sendgroups = '&directorder=1'; 3150 var resultgroups= new Array(); 3151 resultgroups[0]=0; 3152 resultgroups[1]=''; 3153 resultgroups[2]= new Array(); 3154 3155 if($('.mp-directorder-form').length) 3156 { 3157 3158 var email = ''; 3159 $('.mp-directorder-form input').each(function(){ 3160 if($(this).val()=='') 3161 { 3162 resultgroups[0]=1; 3163 resultgroups[1]= errorInfoDirectOrder; 3164 3165 } 3166 else if(resultgroups[0]==0) 3167 { 3168 var idfield = $(this).attr('id'); 3169 var valueField = $(this).val(); 3170 valueField = valueField.trim(); 3171 if(idfield=='mpdo-email') 3172 { 3173 email = valueField; 3174 } 3175 sendgroups+= '&'+idfield+'='+valueField; 3176 } 3177 }); 3178 if(email!='') 3179 { 3180 var existemail = false;
3181 url = baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxservices&type=checkemail&email='+email; 3182 $.ajax({ 3183 type : "GET", 3184 async : false, 3185 url : url, 3186 success : function(data) { 3187 if(data) 3188 { 3189 existemail= true; 3190 } 3191 } 3192 3193 }); 3194 3195 if(existemail) 3196 { 3197 resultgroups[0]=1; 3198 resultgroups[1]= errorInfoExitEmail; 3199 } 3200 } 3201 } 3202 if(resultgroups[0]==0) 3203 resultgroups[1]= sendgroups; 3204 return resultgroups; 3205} 3206function getQuantityMegaSeats() 3207{ 3208 var qty = 0; 3209 if($('#addTicketZones').length) 3210 { 3211 $('#addTicketZones tr').each(function(){ 3212 qty += parseInt($(this).data('qty')); 3213 }); 3214 } 3215 return qty; 3216} 3217 3218function getMegaSeats() 3219{ 3220 var seats = ''; 3221 if($('#addTicketZones').length) 3222 { 3223 var arraySeats = new Array(); 3224 $('#addTicketZones tr').each(function(){ 3225 arraySeats.push($(this).data()); 3226 }); 3227 seats = '&seats='+JSON.stringify(arraySeats); 3228 } 3229 return seats; 3230} 3231function showCustomSeats(){ 3232 $('#mp-zone-map-cont,#mp-cart-info').show(); 3233 $('#customContentMPForm').hide(); 3234} 3235function showMPCustomData(){ 3236 if(typeof applyMPCustomPersonalization!='undefined') 3237 applyMPCustomPersonalization(); 3238 $('#customContentMPForm').fadeIn('1500'); 3239 if($('#mp-zone-map-cont').length){ 3240 $('#mp-zone-map-cont,#mp-cart-info').hide(); 3241 $('#mpshowseats').show(); 3242 } 3243 3244 if(_MP.modal_info==1 && $('#calculePriceData').length && $("#calculePriceData").hasClass("ui-dialog-content")){ 3245 3246 $(".ui-dialog-content").dialog("close"); 3247 goToByScroll('customMPData'); 3248 } 3249 3250} 3251 3252/*function blockCartbutton(){ 3253 $('#anadiendo').fadeIn();setTimeout(function(){$("#addListSeat").fadeOut();},100); 3254 $("#addListSeat").css('pointer-events', 'none'); 3255 3256} 3257function unblockCartbutton(){ 3258 $('#addListSeat').fadeIn();setTimeout(function(){$("#anadiendo").fadeOut();},100); 3259 $("#addListSeat").css('pointer-events', 'auto'); 3260}*/ 3261 3262 3263 3264function addMegaProduct (idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist, directOrder) 3265{ 3266 if($('#mp-cgv').length && !$("#mp-cgv").is(':checked')) 3267 { 3268 showErrorAlert(errorInfoAcceptterms); 3269 return; 3270 } 3271 3272 3273 3274 3275 var checkdates = true; 3276 if($('#id_date_start').length && $('#id_date_start').parents('.mpstep').length && $('#id_date_start').parents('.mpstep').hasClass('hideMegaField')) 3277 checkdates = false; 3278 3279 if(checkdates) 3280 { 3281 if(checkTimeSlot() && ($('#id_time_slots').val()==0 || $('#id_time_slots').val() ==null)){ 3282 showErrorAlert(errorInfoSelectTime); 3283 return; 3284 } 3285 if(($('#id_date_start').length>0 && $('#id_date_start').val()=='') || 3286 ($('#id_date_end').length>0 && $('#id_date_end').val()=='')) 3287 { 3288 showErrorAlert(errorInfo0); 3289 3290 return; 3291 } 3292 // Send all event data correctly 3293 if(_MP.multiAvailability.length) 3294 { 3295 var event = _MP.multiAvailability[_MP.sendEvent]; 3296 if($('#id_date_start')){ 3297 $('#id_date_start').datepicker("setDate", new Date(event.start._i)); 3298 } 3299 if(typeof(_MP)!="undefined") 3300 { 3301 _MP.date_start = new Date(event.start._i); 3302 } 3303 if(checkTimeSlot()) 3304 $('#id_time_slots').val(event.id_timeslot); 3305 3306 _MP.sendEvent++; 3307 3308 } 3309 } 3310 3311 3312 if(_MP.modal_info==1) 3313 closeMPInfo('#calculePriceData'); 3314 3315 3316 if(typeof mpOnlaunch!='undefined') 3317 mpOnlaunch = 1; 3318 3319 3320 if (addedFromProductPage && !checkCustomizations()) 3321 { 3322 if (!!$.prototype.fancybox) 3323 $.fancybox.open([ 3324 { 3325 type: 'inline', 3326 autoScale: true, 3327 minHeight: 30, 3328 content: '<p class="fancybox-error">' + fieldRequired + '</p>' 3329 } 3330 ], { 3331 padding: 0 3332 }); 3333 else 3334 3335 alert(fieldRequired); 3336 return; 3337 } 3338 emptyCustomizations(); 3339 //disabled the button when adding to not double add if user double click 3340 if (addedFromProductPage) 3341 { 3342 $('#add_to_cart button').prop('disabled', 'disabled').addClass('disabled'); 3343 $('.filled').removeClass('filled'); 3344 3345 } 3346 else 3347 $(callerElement).prop('disabled', 'disabled'); 3348 3349 if ($('.cart_block_list').hasClass('collapsed')) 3350 this.expand(); 3351 3352 3353 var sendgroups = getSendGroups(quantity); 3354 if(sendgroups===false){ 3355 3356 return false; 3357 } 3358 3359 if(directOrder) 3360 { 3361 var resultDirectOrder = listDirectOrder(); 3362 if(resultDirectOrder[0]==1) 3363 { 3364 showErrorAlert(resultDirectOrder[1]); 3365 return; 3366 } 3367 else 3368 { 3369 sendgroups +=resultDirectOrder[1]; 3370 } 3371 } 3372 3373 //sendgroups += listCombinationIds(); 3374 3375 3376 dataoptions = getDataServices(); 3377 3378 sendgroups += getMegaSeats(); 3379 3380 if($('#customContentMPForm').length){ 3381 var qtycheck = quantity; 3382 3383 if($('#addTicketZones').length) 3384 { 3385 qtycheck = getQuantityMegaSeats(); 3386 3387 } 3388 if(_MP.arrayCustom.length!=qtycheck){ 3389 showMPCustomData(); 3390 return; 3391 } 3392 else if(_MP.arrayCustom.length>0) 3393 { 3394 if(_MP.multiAvailability.length){ 3395 var arraySend = new Array(); 3396 arraySend.push(_MP.arrayCustom[_MP.sendEvent]);
3397 sendgroups += '&mpcustom='+JSON.stringify(arraySend); 3398 } 3399 else{ 3400 sendgroups += '&mpcustom='+JSON.stringify(_MP.arrayCustom); 3401 } 3402 3403 } 3404 } 3405 3406 3407 if($('#btnAddCalculeService').length) 3408 $('#btnAddCalculeService').attr('disabled','disabled').addClass('disabled'); 3409 3410 if(_MP.multiAvailability.length && _MP.sendEvent==1){ 3411 sendgroups += '&multiEvents='+_MP.multiAvailability.length; 3412 } 3413 3414 /* LABEL_ADD - JJMARTIN. */ 3415 $('#btnAddCalculeService').addClass('processing-add'); 3416 3417 3418 3419 3420 $.ajax({ 3421 type: 'POST', 3422 url: baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxservices&type=checkdate', 3423 async: false, 3424 cache: false, 3425 dataType : "html", 3426 data: '&1'+dataoptions+sendgroups+'&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''), 3427 beforeSend: function() { 3428 }, 3429 complete: function(xhr, status) { 3430 }, 3431 success: function(jsonData,textStatus,jqXHR) 3432 { 3433 $('#calculePrice').remove(); 3434 if(jsonData.indexOf("megaerror")>0){ 3435 if($('#btnAddCalculeService').length) 3436 $('#btnAddCalculeService').removeProp('disabled').removeClass('disabled').attr('disabled', false); 3437 3438 $('#main').append(jsonData); 3439 $('#calculePrice').hide(); 3440 3441 showMPInfo('#calculePriceData','',''); 3442 if($('#btnAddCalculeService').length){ 3443 $('#btnAddCalculeService').removeProp('disabled').removeClass('disabled').attr('disabled', false); 3444 /* LABEL_ADD - JJMARTIN. */ 3445 $('#btnAddCalculeService').removeClass('processing-add'); 3446 } 3447 _MP.sendEvent = 0; 3448 3449 } 3450 else if(jsonData && jsonData!='\n' && jsonData!='\r\n') 3451 { 3452 $('#main').append(jsonData); 3453 $('#calculePrice').hide(); 3454 3455 showMPInfo('#calculePriceData','',''); 3456 3457 if($('#btnAddCalculeService').length){ 3458 $('#btnAddCalculeService').removeProp('disabled').removeClass('disabled'); 3459 /* LABEL_ADD - JJMARTIN. */ 3460 $('#btnAddCalculeService').removeClass('processing-add'); 3461 } 3462 3463 3464 3465 _MP.sendEvent = 0; 3466 return; 3467 } 3468 else 3469 { 3470 3471 //send the ajax request to the server 3472 $.ajax({ 3473 type: 'POST', 3474 headers: { "cache-control": "no-cache" }, 3475 /*url: baseDir + '?rand=' + new Date().getTime(),*/ 3476 url: prestashop.urls.pages.cart, 3477 async: true, 3478 cache: false, 3479 dataType : "json", 3480 /*data: 'action=update&controller=cart&add=1&ajax=true'+sendgroups+dataoptions+'&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''),*/ 3481 data: 'action=update&add=1'+sendgroups+dataoptions+'&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''), 3482 success: function(jsonData,textStatus,jqXHR) 3483 { 3484 if(typeof jsonData.success) 3485 { 3486 setTimeout(function(){document.location.href = "index.php?controller=order"},500); 3487 3488 return; 3489 if(directOrder && typeof jsonData.directOrder!='undefined' && jsonData.url!='undefined') 3490 setTimeout(function(){document.location.href = jsonData.url},10); 3491 3492 if(typeof jsonData.errors && jsonData.errors!=''){ 3493 showErrorAlert(jsonData.errors); 3494 return; 3495 } 3496 3497 if(_MP.multiAvailability.length && _MP.multiAvailability.length>_MP.sendEvent) 3498 { 3499 $('#btnAddCalculeService').removeProp('disabled').removeClass('disabled'); 3500 $('#btnAddCalculeService').click(); 3501 $('#btnAddCalculeService').attr('disabled','disabled').addClass('disabled'); 3502 return; 3503 } 3504 if(_MP.multiAvailability.length && _MP.multiAvailability.length==_MP.sendEvent) 3505 { 3506 setTimeout(function(){document.location.href = "index.php?controller=cart&action=show"},500); 3507 return; 3508 } 3509 if($('#mp-place-seats').length) 3510 closeMPInfo('#mp-place-seats'); 3511 3512 prestashop.emit('updateCart', { 3513 reason: { 3514 idProduct: jsonData.id_product, 3515 idProductAttribute: jsonData.id_product_attribute, 3516 idMegacart: jsonData.id_megacart, 3517 linkAction: 'add-to-cart' 3518 }}); 3519 loadTimeSlots(); 3520 } 3521 //setTimeout(function(){document.location.href = cartURL+"?action=show"},500); 3522 3523 3524 3525 3526 3527 3528 if (typeof contentOnly!='undefined' && contentOnly) 3529 parent.$.fancybox.close(); 3530 goToByScroll('shopping_cart'); 3531 3532 $('#btnAddCalculeService').removeProp('disabled').removeClass('disabled'); 3533 3534 /* LABEL_ADD - JJMARTIN. */ 3535 $('#btnAddCalculeService').removeClass('processing-add'); 3536 3537 }, 3538 error: function(XMLHttpRequest, textStatus, errorThrown) 3539 { 3540 3541 setTimeout(function(){document.location.href = cartURL+"?action=show"},500); 3542 return; 3543 3544 3545 } 3546 3547 }); 3548 3549 3550 } 3551 3552 } 3553 }); 3554 3555 3556}; 3557function restarFechas(first, second) { 3558 3559 // Copy date parts of the timestamps, discarding the time parts. 3560 var one = new Date(first.getFullYear(), first.getMonth(), first.getDate()); 3561 var two = new Date(second.getFullYear(), second.getMonth(), second.getDate()); 3562 3563 // Do the math. 3564 var millisecondsPerDay = 1000 * 60 * 60 * 24; 3565 var millisBetween = two.getTime() - one.getTime(); 3566 var days = millisBetween / millisecondsPerDay; 3567 days = Math.round(days); 3568 // Round down. 3569 return Math.floor(days); 3570} 3571 3572// Type 0 => Return Url, 1 => Return Diff days 3573function getDataServices(type) 3574{ 3575 if(typeof type =='undefined') 3576 type = 0; 3577 var normaly = ''; 3578 if($('#id_date_start').length && $('#id_date_start').parents('.mpstep').length && $('#id_date_start').parents('.mpstep').hasClass('hideMegaField')) 3579 normaly ='&mptype=N'; 3580 3581 var days = 1; 3582 if(typeof _MP.days!='undefined' && _MP.days>1) 3583 days = _MP.days; 3584 if($('#id_drop_date').length){ 3585 if ($('#id_drop_date').is(':radio')) 3586 var date_start = new Date($('#id_drop_date:checked').val()); 3587 else 3588 var date_start = new Date($('#id_drop_date').val()); 3589 } 3590 else if($('#id_date_start').length) 3591 var date_start = $('#id_date_start').datepicker('getDate'); 3592 else 3593 var date_start = _MP.date_start; 3594 if(date_start==null) 3595 date_start = _MP.date_start; 3596 if(date_start==null) 3597 date_start = new Date(); 3598 if(typeof(_MP)!="undefined" && _MP.service_select==100) 3599 { 3600 date_start = new Date(date_start.getFullYear(), date_start.getMonth(), date_start.getDate() - date_start.getDay()-1); 3601 if($('#id_date_end').length>0) 3602 { 3603 // var dateend = $('#id_date_end').datepicker('getDate'); 3604 if(typeof _MP.date_end=="undefined"){ 3605 _MP.date_end= $('#id_date_end').datepicker('getDate'); 3606 } 3607 var dateend = _MP.date_end; 3608 date_end = new Date(dateend.getFullYear(), dateend.getMonth(), dateend.getDate() - dateend.getDay() + 8); 3609 3610 if(date_end!=null) 3611 { 3612 days = restarFechas(date_start,date_end); 3613 //days = Math.round((date_end - date_start) / (1000 * 60 * 60 * 24)); 3614 } 3615 3616 } 3617 else 3618 { 3619 days = 1; 3620 if($('#id_days').length) 3621 days = days * parseInt($('#id_days').val()); 3622 } 3623 } 3624 else 3625 {
3626 //date_start = $('#id_date_start').datepicker('getDate'); 3627 if($('#id_days').length>0) 3628 { 3629 days=$('#id_days').val(); 3630 } 3631 else if($('#id_date_end').length>0) 3632 { 3633 3634 // var date_end = $('#id_date_end').datepicker('getDate'); 3635 var date_end = _MP.date_end; 3636 if(date_end!=null) 3637 { 3638 days = restarFechas(date_start,date_end); 3639 if(_MP.end_date==0) 3640 days++; 3641 3642 if(days<0) 3643 days = 0; 3644 //days = Math.round((date_end - date_start) / (1000 * 60 * 60 * 24)); 3645 } 3646 3647 } 3648 3649 } 3650// date_start = convertTZ(date_start,'Europe/London'); 3651 var day = date_start.getUTCDate(); 3652 var month = date_start.getUTCMonth()+1; 3653 var year = date_start.getUTCFullYear(); 3654 3655 3656 if(days==0) 3657 days=1; 3658 3659 if(type==1) 3660 return days; 3661 var timeslots = ''; 3662 if(checkTimeSlot()) 3663 { 3664 var times = $('#id_time_slots').val(); 3665 if(times!='' && times!=null) 3666 { 3667 var arrayTime = times.split('-'); 3668 if(arrayTime.length>0) 3669 timeslots = '&id_timeslot='+arrayTime[0]; 3670 if(arrayTime.length>1) 3671 timeslots += '×tart='+arrayTime[1]; 3672 if(_MP.time==5) 3673 { 3674 var timeend = $('#id_time_end').val(); 3675 var arrayTime2 = timeend.split('-'); 3676 timeslots += '&timeend='+arrayTime2[1]; 3677 timeslots += '&id_timeslotend='+arrayTime2[0]; 3678 } 3679 else if(arrayTime.length>2) 3680 timeslots += '&timeend='+arrayTime[2]; 3681 else{ 3682 timeslots += '&timeend='+arrayTime[1]; 3683 } 3684 } 3685 } 3686 return '&day='+day+'&month='+month+'&year='+year+timeslots+'&days='+days+normaly; 3687}; 3688function convertTZ(date, tzString) { 3689 return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString})); 3690} 3691function checkMegaTimes(showalert) 3692{ 3693 var startime = ''; 3694 if(_MP.time==2 || _MP.time==3 || _MP.time==6) 3695 { 3696 if($('#starttime').length) 3697 { 3698 startime = $('#starttime').val(); 3699 if($('#starttime').val()=='' || $('#starttime').val() == null) 3700 { 3701 $('#id_time_slots').val(''); 3702 if(showalert) 3703 showErrorAlert(errorInfoSelectTime); 3704 return false; 3705 } 3706 } 3707 3708 } 3709 if(_MP.time==3 || _MP.time==6) 3710 { 3711 if($('#endtime').length) 3712 { 3713 if($('#endtime').val()=='' || $('#endtime').val()==null) 3714 { 3715 $('#id_time_slots').val(''); 3716 if(showalert) 3717 showErrorAlert(errorInfoSelectTime); 3718 return false; 3719 } 3720 if(dateDiff($('#endtime').val(),startime)<0) 3721 { 3722 // Check distinct days 3723 if(_MP.time==6) 3724 { 3725 days = getDataServices(1); 3726 if(days>1) 3727 return true; 3728 } 3729 $('#id_time_slots').val(''); 3730 if(showalert) 3731 showErrorAlert(errorInfoSecondTime); 3732 return false; 3733 } 3734 } 3735 } 3736 return true; 3737} 3738function dateDiff(time1,time2) 3739{ 3740 var t1 = new Date(); 3741 var parts = time1.split(":"); 3742 if(typeof parts[2]=='undefined') 3743 parts[2]='00'; 3744 t1.setHours(parts[0],parts[1],parts[2],0); 3745 var t2 = new Date(); 3746 parts = time2.split(":"); 3747 if(typeof parts[2]=='undefined') 3748 parts[2]='00'; 3749 t2.setHours(parts[0],parts[1],parts[2],0); 3750 3751 return parseInt((t1.getTime()-t2.getTime())/1000); 3752} 3753function getMegaTimes() 3754{ 3755 var timesend = ''; 3756 3757 if(_MP.time==2 || _MP.time==3 || _MP.time==6) 3758 { 3759 if($('#starttime').length) 3760 { 3761 timesend += '&loadtimestart='+$('#starttime').val(); 3762 } 3763 } 3764 if(_MP.time==3 || _MP.time==6) 3765 { 3766 if($('#endtime').length) 3767 { 3768 timesend += '&loadtimeend='+$('#endtime').val(); 3769 } 3770 } 3771 if($('#starttime').length && ($('#starttime').val()!='' && $('#starttime').val()!=0)) 3772 { 3773 timesend += '&startselect='+$('#starttime').val(); 3774 } 3775 return timesend; 3776} 3777function removeLastTimeOptions() 3778{ 3779 3780} 3781function getIdProduct() 3782{ 3783 if($('#product_page_product_id').length) 3784 return $('#product_page_product_id').val(); 3785 if($('.mph-home-container').length) 3786 return $('.mph-home-container').data('product'); 3787 if($('#id_product').length) 3788 return $('#id_product').val(); 3789 return 0; 3790} 3791function loadTimeSlots() 3792{
3793 var result = true; 3794 var selected = $('#id_time_slots').val(); 3795 3796 if(!checkMegaTimes(false)) 3797 return; 3798 3799 var timesend = getMegaTimes(); 3800 3801 3802 3803 var sendgroups = getSendGroups(1); 3804 if(sendgroups===false) 3805 return false; 3806 3807 3808 var datasevices = getDataServices(0); 3809 3810 var async = true; 3811 if(_MP.time==2 || _MP.time==3 || _MP.time==6) 3812 async = false; 3813 if(typeof applysearch!='undefined' && !applysearch) 3814 async = false; 3815 3816 currentTime = new Date(); 3817 time = currentTime.getTime(); 3818 timesend += '&timenow='+time; 3819 //hours = currentTime.getHours(); 3820 3821 $.ajax({ 3822 type: 'POST', 3823 url: baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxservices'+timesend, 3824 async: async, 3825 cache: false, 3826 dataType : "json", 3827 data: 'type=loadtimeslots'+sendgroups+datasevices+ '&id_product=' + getIdProduct()+'&qty='+$('#quantity_wanted').val(), 3828 success: function(jsonData,textStatus,jqXHR) 3829 { 3830 if(jsonData.error!='') 3831 { 3832 if(jsonData.error=='nextday') 3833 { 3834 if($("#id_date_start").length) 3835 { 3836 var day = $("#id_date_start").datepicker("getDate"); 3837 day.setDate(day.getDate()+1); 3838 $('#id_date_start').datepicker("setDate", day); 3839 _MP.date_start = day; 3840 loadTimeSlots(); 3841 } 3842 3843 3844 return; 3845 } 3846 $('#id_time_slots').val(''); 3847 showErrorAlert(jsonData.error); 3848 result = false;
3849 } 3850 if(_MP.time==0) 3851 { 3852 $('#id_time_slots').find('option').remove().end(); 3853 if(jsonData.html!='') 3854 { 3855 $('#id_time_slots').html(jsonData.html); 3856 if($("#id_time_slots option[value='"+selected+"']").length) 3857 $('#id_time_slots').val(selected); 3858 } 3859 } 3860 if(_MP.time==4 || _MP.time==5) 3861 { 3862 var start = $('#id_time_start').val(); 3863 var end = $('#id_time_end').val(); 3864 3865 $('#starttime').find('option').remove().end(); 3866 $('#endtime').find('option').remove().end(); 3867 if(jsonData.html!='') 3868 { 3869 var addoption = false; 3870 $('#starttime').html(jsonData.html); 3871 if(typeof start!='undefined' && start!='') 3872 { 3873 if($("#starttime option[value='"+start+"']").length) 3874 $('#starttime').val(start); 3875 } 3876 else 3877 { 3878 addoption=true; 3879 } 3880 3881 $('#starttime option').each(function(){ 3882 if(!addoption && $(this).val()>=start) 3883 { 3884 addoption = true; 3885 } 3886 if(addoption) 3887 { 3888 var dateend = $(this).attr('date-end'); 3889 $('#endtime').append($('<option></option>').val(dateend).html(dateend)); 3890 } 3891 3892 }); 3893 if(_MP.time==5 && $('#endtime').length) 3894 { 3895 $('#endtime').html(jsonData.html2); 3896 } 3897 if(typeof end!='undefined' && end!='') 3898 { 3899 if($("#endtime option[value='"+end+"']").length) 3900 $('#endtime').val(end); 3901 } 3902 var start = $('#starttime').val(); 3903 var end = $('#endtime').val(); 3904 $('#id_time_slots').val(start+'-'+end); 3905 $('#id_time_start').val(start); 3906 $('#id_time_end').val(end); 3907 } 3908 else 3909 { 3910 $('#id_time_slots').val(''); 3911 $('#id_time_start').val('') 3912 } 3913 3914 } 3915 if(_MP.time==1) 3916 { 3917 $('#id_time_slots').val(''); 3918 $('#id_buttons_slot').html(''); 3919 if(jsonData.html) 3920 { 3921 $('#id_buttons_slot').html(jsonData.html); 3922 if($("#id_buttons_slot li a[value='"+selected+"']").length) 3923 { 3924 $('#id_time_slots').val(selected); 3925 $("#id_buttons_slot li a[value='"+selected+"']").addClass('selectAttr'); 3926 } 3927 else 3928 { 3929 selected = $("#id_buttons_slot li a:first").attr('value'); 3930 $('#id_time_slots').val(selected); 3931 $("#id_buttons_slot li a[value='"+selected+"']").addClass('selectAttr'); 3932 } 3933 } 3934 $('#id_buttons_slot a').click(function(){ 3935 $('#id_buttons_slot a').removeClass('selectAttr'); 3936 selected = $(this).attr('value'); 3937 $('#id_time_slots').val(selected); 3938 $(this).addClass('selectAttr'); 3939 showStepResult(); 3940 }); 3941 } 3942 if(_MP.time==2 || _MP.time==3 || _MP.time==6) 3943 { 3944 $('#id_time_slots').val(jsonData.html); 3945 } 3946 if(typeof jsonData.attrservices != 'undefined' && jsonData.attrservices) 3947 { 3948 var parentAttr = null; 3949 var selectAttr = 0; 3950 for (var k in jsonData.attrservices) 3951 { 3952 var id_attribute = k; 3953 var hasService = jsonData.attrservices[k]; 3954 if(parentAttr==null){ 3955 parentAttr = $('option[value="'+id_attribute+'"]').parent(':first'); 3956 selectAttr = $(parentAttr).val(); 3957 } 3958 if(hasService=='0'){ 3959 if(selectAttr==id_attribute){ 3960 selectAttr = 0; 3961 $('option[value="'+id_attribute+'"]').attr('selected',''); 3962 } 3963 $('option[value="'+id_attribute+'"]').hide(); 3964 } 3965 else{ 3966 if(selectAttr==0){ 3967 selectAttr = id_attribute; 3968 $('option[value="'+id_attribute+'"]').attr('selected','selected'); 3969 } 3970 $('option[value="'+id_attribute+'"]').show(); 3971 } 3972 } 3973 $(parentAttr).val(selectAttr); 3974 } 3975 } 3976 }); 3977 return result; 3978}; 3979function refreshCalendar() 3980{ 3981 3982 if($('#productcalendar').length) 3983 { 3984 var resultAttrs = listAttrIds(); 3985 urldataservices = '&frontal=1&ipa='+getIdCombination(); 3986 3987 if(resultAttrs[0]!=1) 3988 { 3989 urldataservices =resultAttrs[1]; 3990 } 3991 if(typeof loadFullCalendar!='undefined') 3992 { 3993 //$('#productcalendar').fullCalendar('destroy'); 3994 loadFullCalendar(); 3995 // _MP.multiAvailability = new Array(); 3996 } 3997 3998 } 3999} 4000function getEventDate(event) { 4001var dateobj = event._start; 4002date = dateobj.getFullYear()+'-'+dateobj.getMonth()+1+'-'+dateobj.getDate(); 4003return date; 4004} 4005function addFullCalendarEvent(event) 4006{ 4007 if(_MP.actionAvailability==0) 4008 return; 4009 4010 if(event.color=='red') 4011 return; 4012 //console.log(event); 4013 if(_MP.actionAvailability==1) 4014 $('.mp-select').removeClass('mp-select'); 4015 4016 var name = '#'+event.id+'-'+event.id_timeslot.replace(':','').replace(':',''); 4017 var removeEvent = false;
4018 if($(name).length) 4019 { 4020 if($(name).parent().hasClass('mp-select')){ 4021 removeEvent = true; 4022 $(name).parent().removeClass('mp-select'); 4023 } 4024 else 4025 $(name).parent().addClass('mp-select'); 4026 } 4027 4028 4029 if(_MP.actionAvailability==2) 4030 { 4031 if(removeEvent){ 4032 for (var key in _MP.multiAvailability) { 4033 if(_MP.multiAvailability[key].id==event.id){ 4034 _MP.multiAvailability.splice(key, 1); 4035 break; 4036 } 4037 4038 } 4039 } 4040 else 4041 _MP.multiAvailability.push(event); 4042 } 4043 4044 if($('#id_date_start')){ 4045 $('#id_date_start').datepicker("setDate", new Date(event.start._i)); 4046 } 4047 if(typeof(_MP)!="undefined") 4048 { 4049 _MP.date_start = new Date(event.start._i); 4050 } 4051 if(checkTimeSlot()) 4052 $('#id_time_slots').val(event.id_timeslot); 4053 4054 if(_MP.actionAvailability==1) 4055 { 4056 if($('#btnCalculeService').length) 4057 { 4058 $('#btnCalculeService').click(); 4059 } 4060 else if($('#btnAddCalculeService').length) 4061 { 4062 goToByScroll('shopping_cart'); 4063 $('#btnAddCalculeService').click(); 4064 } 4065 } 4066 4067 showStepResult(); 4068 4069} 4070function checkTimeSlot() 4071{ 4072 if(!$('#id_time_slots').length) 4073 return false; 4074 if($('#mp-time-slots').length && $('#mp-time-slots').hasClass('mpHide')) 4075 return false; 4076 return true; 4077} 4078function addMPDate(start,end,days,type){ 4079 var dayArray = new Array(); 4080 dayArray['start'] = start; 4081 dayArray['end'] = end; 4082 dayArray['type'] = type; 4083 if(days!='') 4084 dayArray['days'] = days.split('-'); 4085 else 4086 dayArray['days'] = new Array(); 4087 for(var i=0; i<dayArray['days'].length; i++) { dayArray['days'][i] = parseInt(dayArray['days'][i]); } 4088 disableDays.push(dayArray); 4089}; 4090function addMPStartDate(start,end,days){ 4091 var dayArray = new Array(); 4092 dayArray['start'] = start; 4093 dayArray['end'] = end; 4094 if(days!='') 4095 dayArray['days'] = days.split('-'); 4096 else 4097 dayArray['days'] = new Array(); 4098 4099 for(var i=0; i<dayArray['days'].length; i++) { dayArray['days'][i] = parseInt(dayArray['days'][i]); } 4100 startDays.push(dayArray); 4101}; 4102function get_next_month_with_event() { 4103 var date = new Date(); 4104 var start = new Date(); 4105 4106 if(_MP.calendar_start!=0 && _MP.calendar_start!=''){ 4107 if(_MP.calendar_start.indexOf('D') !== -1){ 4108 date.setHours(0,0,0,0) 4109 var adddays = parseInt(_MP.calendar_start); 4110 date.setDate(date.getDate() + adddays); 4111 4112 4113 } else { 4114 startdays = parseInt((parseInt(_MP.calendar_start)+24)/24); 4115 date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); 4116 date.setDate(date.getDate() + startdays ); 4117 } 4118 _MP.date_start = date; 4119 4120 4121 } 4122 4123 var finish = new Date(); 4124 finish.setDate(finish.getDate()+1200); 4125 var available = false; 4126 if(disableDays.length) 4127 { 4128 while(!available && date<finish) { 4129 available = isAvailable(date)[0]; 4130 4131 if(!available) 4132 date.setDate(date.getDate()+1); 4133 } 4134 } 4135 if(bookedDays.length){ 4136 var dateAsString = date.getFullYear().toString() + "-" + ('0' + (date.getMonth()+1)).slice(-2) + "-" + ('0' + date.getDate()).slice(-2); 4137 available = $.inArray( dateAsString, bookedDays ) ==-1 ? true : false; 4138 while(!available && date<finish) { 4139 available = isAvailable(date)[0]; 4140 if(!available) 4141 date.setDate(date.getDate()+1); 4142 } 4143 4144 } 4145 if(available) 4146 { 4147 _MP.date_start = date; 4148 return date; 4149 } 4150 else 4151 return date; 4152}; 4153function selectCurrentDays() { 4154 var days = $('#id_days').val(); 4155 window.setTimeout(function () { 4156 var cell = $('#id_date_start').find('.ui-datepicker-current-day'); 4157 var parent = $(cell).parent('tr'); 4158 var newLine = false; 4159 for(var i=1;i<days;i++) 4160 { 4161 parent = $(cell).parent('tr'); 4162 if(!newLine) 4163 { 4164 cell = $(cell).next('td'); 4165 4166 } 4167 newLine = false; 4168 if($(cell).length){ 4169 if($(cell).find('a').length) 4170 $(cell).find('a').addClass('ui-state-active'); 4171 else if($(cell).find('span').length) 4172 $(cell).find('span').addClass('ui-state-active'); 4173 } 4174 /*else if($(cell).hasClass('ui-state-disabled')) 4175 { 4176 //cell = $(cell).next('td'); 4177 i--; 4178 }*/ 4179 else 4180 { 4181 i--; 4182 if($(parent).next('tr').length){ 4183 newLine = true; 4184 cell = $(parent).next('tr').find('td:first'); 4185 } 4186 else 4187 i = 100000; 4188 } 4189 } 4190 4191 // $('#id_date_end').find('.ui-datepicker-current-day a').parents('tr:first').find('a').addClass('ui-state-active') 4192 }, 1); 4193} 4194function addMonthYear() 4195{ 4196 if($('#id_month_select').length) 4197 { 4198 var d = new Date(); 4199 var m = d.getMonth(); 4200 var year = d.getFullYear(); 4201 var nextYear = year+1; 4202 4203 $('#id_month_select option').each(function(){ 4204 var itemMonth = parseInt($(this).val()); 4205 var option = $(this).text(); 4206 if(itemMonth<=m) 4207 $(this).text(option+' '+nextYear); 4208 else 4209 $(this).text(option+' '+year); 4210 }); 4211 } 4212} 4213function selectionMPDate() 4214{ 4215 var type = $('#id_date_select').val(); 4216 if(typeof _MP!='undefined') 4217 _MP.service_select = type; 4218 4219 $('#mp-select-months').hide(); 4220 $('#mp-select-week').hide(); 4221 $('#mp-date-start').hide(); 4222 $('#mp-date-end').hide(); 4223 $('#mp-time-slots').hide().addClass('.mpHide'); 4224 $('#id_time_slots').hide(); 4225 $('#mp-days').hide(); 4226 $('#productcalendar').hide(); 4227 if(type==4 || type==3) 4228 { 4229 $('#mp-date-start').show(); 4230 $('#mp-date-end').show(); 4231 $('#mp-days').show(); 4232 $('#productcalendar').show(); 4233 selectMPDay(); 4234 } 4235 if(type==2) 4236 { 4237 $('#mp-select-months').show(); 4238 selectMPMonth(); 4239 } 4240 if(type==3) 4241 { 4242 $('#mp-time-slots').show().removeClass('.mpHide'); 4243 $('#id_time_slots').show(); 4244 loadTimeSlots(); 4245 } 4246 if(type==1) 4247 { 4248 $('#mp-select-week').show(); 4249 selectMPWeek(); 4250 } 4251} 4252function selectMPDay(){ 4253 _MP.days = 1; 4254 if($('#id_days').length) 4255 $('#id_days').val(1); 4256} 4257function selectMPMonth(){
4258 var month = parseInt($('#id_month_select').val()); 4259 var d = new Date(); 4260 var n = d.getFullYear(); 4261 var m = d.getMonth(); 4262 var days = daysInThisMonth(month); 4263 if(month<=m) 4264 n++; 4265 var date = parseMPDate(n+'-'+month+'-01','yyyy-mm-dd'); 4266 // Add date start 4267 if($('#id_date_start').length) 4268 $('#id_date_start').datepicker("setDate", new Date(date)); 4269 _MP.date_start = date; 4270 // Add date end 4271 if($('#id_date_end').length){ 4272 date.setDate(date.getDate()+days); 4273 _MP.date_end = date; 4274 $('#id_date_end').datepicker("setDate", new Date(date)); 4275 } 4276 // Add days 4277 _MP.days = days; 4278 if($('#id_days').length) 4279 $('#id_days').val(days); 4280} 4281function selectMPWeek(){ 4282 var date_start = $('#id_week_select option:selected').data('start'); 4283 _MP.date_start = parseMPDate(date_start,'yyyy-mm-dd'); 4284 // Add date start 4285 if($('#id_date_start').length) 4286 $('#id_date_start').datepicker("setDate", new Date(_MP.date_start)); 4287 4288 // Add date end 4289 if($('#id_date_end').length){ 4290 4291 _MP.date_end = parseMPDate($('#id_week_select option:selected').data('end'),'yyyy-mm-dd'); 4292 $('#id_date_end').datepicker("setDate", new Date(_MP.date_end)); 4293 } 4294 days = 7; 4295 // Add days 4296 _MP.days = days; 4297 if($('#id_days').length) 4298 $('#id_days').val(days); 4299} 4300function daysInThisMonth(month) { 4301 var d = new Date(); 4302 var n = d.getFullYear(); 4303 var date = parseMPDate(n+'-'+month+'-01','yyyy-mm-dd'); 4304 4305 return new Date(date.getFullYear(), date.getMonth()+1, 0).getDate(); 4306} 4307function loadMPWeeks() 4308{ 4309 var d = new Date(); 4310 var month = d.getMonth(); 4311 var year = d.getFullYear(); 4312 var weeks = getBeforeWeeks(6); 4313 if($('#id_week_select').length) 4314 { 4315 for(var i=0;i<weeks.length;i++) 4316 { 4317 $('#id_week_select').append('<option data-start="'+formatDate(weeks[i]['startDate'])+'" data-end="'+formatDate(weeks[i]['endDate'])+'" value="">'+formatDate(weeks[i]['startDate'])+' / '+formatDate(weeks[i]['endDate'])+'</option>') 4318 } 4319 } 4320} 4321function formatDate(date) { 4322 var d = new Date(date), 4323 month = '' + (d.getMonth() + 1), 4324 day = '' + d.getDate(), 4325 year = d.getFullYear(); 4326 4327 if (month.length < 2) month = '0' + month; 4328 if (day.length < 2) day = '0' + day; 4329 4330 return [year, month, day].join('-'); 4331} 4332function getBeforeWeeks(months){ 4333 var start = new Date(); 4334 var end = new Date(); 4335 end.setMonth(end.getMonth()+months); 4336 var sDate; 4337 var eDate; 4338 var dateArr = []; 4339 4340 while(start <= end){ 4341 if (start.getDay() == 1 || (dateArr.length == 0 && !sDate)){ 4342 sDate = new Date(start.getTime()); 4343 } 4344 4345 if ((sDate && start.getDay() == 0) || start.getTime() == end.getTime()){ 4346 var endDate = new Date(start); 4347 if(_MP.end_date==1) 4348 endDate.setDate(endDate.getDate() + 1); 4349 eDate = new Date(endDate.getTime()); 4350 } 4351 4352 if(sDate && eDate){ 4353 dateArr.push({'startDate': sDate, 'endDate': eDate}); 4354 sDate = undefined; 4355 eDate = undefined; 4356 } 4357 4358 start.setDate(start.getDate() + 1); 4359 } 4360 return dateArr; 4361} 4362/* URL CHANGE VALUES */ 4363function resetGroupsByUrl(urlcode) 4364{ 4365 if(urlcode=='') 4366 urlcode = getParameterByName('mpurl'); 4367 if(urlcode!='') 4368 { 4369 var arrayGroups = urlcode.split('/'); 4370 if(arrayGroups.length>1) 4371 { 4372 for(var i=1;i<arrayGroups.length;i++) 4373 { 4374 id_addgroup = 0; 4375 var group = arrayGroups[i].split('-'); 4376 if(group.length>0) 4377 { 4378 id_addgroup = parseInt(group[0]); 4379 } 4380 if(group.length>2) 4381 { 4382 for(var j=2;j<group.length;j=j+2) 4383 { 4384 id = parseInt(group[j]); 4385 if(typeof id!='undefined' && !isNaN(id)) 4386 { 4387 var megagroup = getMPGroupById(id_addgroup); 4388 selectRuleOptions(megagroup,id); 4389 } 4390 } 4391 } 4392 } 4393 } 4394 findCombination(); 4395 } 4396 resetUrlMeasures(); 4397} 4398 4399function resetUrlMeasures() 4400{ 4401 var mpquantity = getParameterByName('mpquantity'); 4402 if(typeof mpquantity!='undefined' && mpquantity!='') 4403 { 4404 addMPQuantity(mpquantity); 4405 /*if($('#id_step_quantity').length) 4406 $('#id_step_quantity').val(mpquantity); 4407 $('#quantity_wanted').val(mpquantity);*/ 4408 } 4409} 4410function getParameterByName(name) { 4411 name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); 4412 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 4413 results = regex.exec(location.search); 4414 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 4415} 4416function updateQueryStringParam(key, value) 4417{ 4418 baseUrl = [location.protocol, '//', location.host, location.pathname].join(''); 4419 urlQueryString = document.location.search; 4420 var newParam = key + '=' + value, 4421 params = '?' + newParam; 4422 4423 // If the "search" string exists, then build params from it 4424 if (urlQueryString) {
4425 keyRegex = new RegExp('([\?&])' + key + '[^&]*'); 4426 // If param exists already, update it 4427 if (urlQueryString.match(keyRegex) !== null) { 4428 params = urlQueryString.replace(keyRegex, "$1" + newParam); 4429 } else { // Otherwise, add it to end of query string 4430 params = urlQueryString + '&' + newParam; 4431 } 4432 } 4433 window.history.replaceState({}, "", baseUrl + params); 4434} 4435function addMPQuantity(qty) 4436{ 4437 if($('#id_step_quantity').length) 4438 $('#id_step_quantity').val(qty); 4439 if($('#id_step_quantity_range').length) 4440 $('#id_step_quantity_range').html(qty); 4441 $('#quantity_wanted').val(qty); 4442 4443} 4444function addInputValidation(result) 4445{ 4446 if(typeof _MP!='undefined' && _MP.validation==1 && typeof result[3]!='undefined' && result[3]!='') 4447 { 4448 var id = result[3]; 4449 type = 'error'; 4450 if(typeof result[4]!='undefined' && result[4]!='') 4451 type = result[4]; 4452 4453 if($(id).parents('.mpstep').find('.mp-error').length) 4454 $(id).parents('.mpstep').find('.mp-error').remove(); 4455 else if($(id).find('.mp-error').length) 4456 $(id).find('.mp-error').remove(); 4457 if(type=='required') 4458 { 4459 $(id).parent().addClass('mp-error-required'); 4460 $('<div class="mp-error alert alert-danger">'+requiredfieldtext+'</div>').insertBefore(id); 4461 } 4462 else if(type=='minqty' || type=='maxqty') 4463 { 4464 $('<div class="mp-error alert alert-danger">'+result[1]+'</div>').insertAfter(id); 4465 } 4466 else if(type=='limitqty') 4467 { 4468 $(id).append($('<div class="mp-error alert alert-danger">'+result[1]+'</div>')); 4469 } 4470 4471 } 4472 else 4473 showErrorAlert(result[1]); 4474} 4475function removeShowErrors() 4476{ 4477 $('.mp-error').each(function(){ 4478 $(this).remove(); 4479 }); 4480 4481} 4482function getGoogleMapsData(address) 4483{ 4484 var address = encodeURIComponent(address); 4485 $.ajax({ 4486 type: "GET", 4487 url: "https://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&sensor=false&key=AIzaSyBctDG6P382nFyA_CBCZLLODOx54aHH7F8", 4488 dataType: "json", 4489 success: processJSON 4490 }).success(function(data){ 4491 processJSON(data); 4492 }); 4493} 4494function processJSON(json) { 4495 // Do stuff here 4496 console.log(json); 4497 var result = ''; 4498 if(typeof (json.results[0])) 4499 { 4500 for(var i=0;i<json.results[0].address_components.length;i++) 4501 { 4502 if(result!='') 4503 result+=' '; 4504 result+=json.results[0].address_components[i].long_name; 4505 } 4506 } 4507 return result; 4508 //alert("Postal Code:" + json.results[0].address_components[6].long_name); 4509 } 4510/* RESET URL FUNCTIONS */ 4511function getMPTitleById(mpgroup,id) 4512{ 4513 var id_addgroup = mpgroup['id_addgroup']; 4514 var title = ''; 4515 if(mpgroup['show']=='0') 4516 { 4517 return $('#megagroups #megafield_'+id_addgroup+' option[value="' + id + '"]').html(); 4518 } 4519 else if(mpgroup['show']=='4' && mpgroup['multiselect']=='0') 4520 { 4521 return $('#megagroups input:radio[name=megafield_'+id_addgroup+']:checked').attr('title'); 4522 4523 } 4524 else if(mpgroup['show']=='4' && mpgroup['multiselect']=='1') 4525 { 4526 return $('[for=mpcheckbox_'+id_addgroup+'_'+id+']').text(); 4527 } 4528 else 4529 { 4530 var megafield = getMegaField(mpgroup,id_addgroup,id); 4531 if ($(megafield).attr('title') != "undefined" && $(megafield).attr('title')!='') 4532 return $(megafield).attr('title'); 4533 else if($(megafield).attr('data-title') != "undefined" && $(megafield).attr('data-title')!='') 4534 return $(megafield).attr('data-title'); 4535 else if($(megafield).html()!='') 4536 return $(megafield).html(); 4537 } 4538 return title; 4539} 4540 4541function resetGroupsByUrl(urlcode) 4542{ 4543 if(urlcode=='') 4544 urlcode = getParameterByName('mpurl'); 4545 if(urlcode!='') 4546 { 4547 var arrayGroups = urlcode.split('/'); 4548 if(arrayGroups.length>1) 4549 { 4550 for(var i=1;i<arrayGroups.length;i++) 4551 { 4552 id_addgroup = 0; 4553 var group = arrayGroups[i].split('-'); 4554 if(group.length>0) 4555 { 4556 id_addgroup = parseInt(group[0]); 4557 } 4558 if(group.length>2) 4559 { 4560 for(var j=2;j<group.length;j=j+2) 4561 { 4562 id = parseInt(group[j]); 4563 if(typeof id!='undefined' && !isNaN(id)) 4564 { 4565 var megagroup = getMPGroupById(id_addgroup); 4566 selectRuleOptions(megagroup,id); 4567 } 4568 } 4569 } 4570 } 4571 } 4572 findCombination(); 4573 } 4574 resetUrlMeasures(); 4575} 4576function findGroupByAttr(id) 4577{ 4578 if(typeof megaGroups!='undefined' && megaGroups.length>0 ) 4579 { 4580 for(var i=0;megaGroups.length>i;i++) 4581 { 4582 var id_group =megaGroups[i]['id_addgroup']; 4583 if($('#megafield_'+id_group+' option[value="'+id+'"]').length) 4584 return megaGroups[i]; 4585 } 4586 4587 } 4588 return 0; 4589} 4590function resetUrlMeasures() 4591{ 4592 4593 var mpquantity = getParameterByName('mpquantity'); 4594 if(typeof mpquantity!='undefined' && mpquantity!='') 4595 { 4596 addMPQuantity(mpquantity); 4597 /*if($('#id_step_quantity').length) 4598 $('#id_step_quantity').val(mpquantity); 4599 $('#quantity_wanted').val(mpquantity);*/ 4600 } 4601 var mpattrs = getParameterByName('search_attrs'); 4602 if(typeof mpattrs!='undefined' && mpattrs!='') 4603 { 4604 var attrs = mpattrs.split('-'); 4605 for(var i=0;i<attrs.length;i++) 4606 { 4607 var id = attrs[i]; 4608 var megagroup = findGroupByAttr(id);
4609 selectRuleOptions(megagroup,id); 4610 } 4611 } 4612} 4613 4614function getParameterByName(name) { 4615 name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); 4616 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 4617 results = regex.exec(location.search); 4618 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 4619} 4620function updateQueryStringParam(key, value) 4621{ 4622 baseUrl = [location.protocol, '//', location.host, location.pathname].join(''); 4623 urlQueryString = document.location.search; 4624 var newParam = key + '=' + value, 4625 params = '?' + newParam; 4626 4627 // If the "search" string exists, then build params from it 4628 if (urlQueryString) { 4629 keyRegex = new RegExp('([\?&])' + key + '[^&]*'); 4630 // If param exists already, update it 4631 if (urlQueryString.match(keyRegex) !== null) { 4632 params = urlQueryString.replace(keyRegex, "$1" + newParam); 4633 } else { // Otherwise, add it to end of query string 4634 params = urlQueryString + '&' + newParam; 4635 } 4636 } 4637 window.history.replaceState({}, "", baseUrl + params); 4638} 4639function changeFilterMPUrlStatus() 4640{ 4641 if(typeof _MP!='undefined' && _MP.urls==0) 4642 return; 4643 var arrayUrl=''; 4644 var arrayValues = ''; 4645 if(typeof megaGroups!='undefined' && megaGroups.length>0) 4646 { 4647 for (i=0; i<megaGroups.length; i++) 4648 { 4649 if(typeof megaGroups[i]!='undefined') 4650 { 4651 var group = megaGroups[i]; 4652 var id_addgroup = group['id_addgroup']; 4653 arrayUrl += '/'+id_addgroup; 4654 var searchStr = "-"; 4655 var replaceStr = ""; 4656 var re = new RegExp(searchStr, "g"); 4657 4658 if($('#megagroup' + id_addgroup).find('.mega_title').length) 4659 { 4660 var gt = $('#megagroup'+id_addgroup).find('.mega_title').html(); 4661 gt = gt.replace(':',''); 4662 gt = gt.replace(' ','_'); 4663 arrayUrl += '-' + encodeURI(gt.toLowerCase()); 4664 } 4665 if(typeof group['selections']!='undefined' && group['selections'].length) 4666 { 4667 for (var j = 0; j < mpgroup['selections'].length; j++) 4668 { 4669 var id = mpgroup['selections'][j]; 4670 var selectTitle = getMPTitleById(group,id); 4671 selectTitle = selectTitle.toLowerCase(); 4672 selectTitle = selectTitle.replace(' ','_'); 4673 4674 selectTitle = selectTitle.replace(re, replaceStr); 4675 //selectTitle = selectTitle.replace('-',''); 4676 // arrayUrl += '-'+group['selected']+'-'+encodeURIComponent(selectTitle); 4677 arrayUrl += '-'+id+'-'+encodeURIComponent(selectTitle); 4678 } 4679 } 4680 else if(typeof group['selected']!='undefined' && group['selected']>0) 4681 { 4682 var id = group['selected']; 4683 var selectTitle = getMPTitleById(group,id); 4684 if(typeof selectTitle=='undefined') 4685 selectTitle = ''; 4686 if(selectTitle!='') 4687 { 4688 selectTitle = selectTitle.trim().toLowerCase(); 4689 selectTitle = selectTitle.replace('\n',''); 4690 selectTitle = selectTitle.replace(' ','_'); 4691 selectTitle = selectTitle.replace(re, replaceStr); 4692 } 4693 arrayUrl += '-'+group['selected']+'-'+encodeURIComponent(selectTitle); 4694 } 4695 } 4696 } 4697 } 4698 // Measures 4699 if(arrayUrl.length) 4700 { 4701 updateQueryStringParam('mpurl',arrayUrl); 4702 } 4703 4704 if($('#quantity_wanted').length && $('#quantity_wanted').val()!='') 4705 { 4706 updateQueryStringParam('mpquantity',$('#quantity_wanted').val()); 4707 } 4708 4709} 4710/* END RESET URL FUNCTIONS */ 4711function in_array(id,ids) 4712{ 4713 for (var i in ids) { 4714 if (i == id) { 4715 return true; 4716 } 4717 } 4718 return false; 4719} 4720function loadMPTicketMail(id_ticket){ 4721 $('#mpSendTicketEmail').show(); 4722 $('#mpSendTicketEmail #id_ticket').val(id_ticket); 4723 goToByScroll('mpSendTicketEmail'); 4724} 4725function checkLimitCartQuantities(){ 4726 if($('#mp-quantity-limits').length) 4727 $.ajax({ 4728 type: 'POST', 4729 url: baseDir + 'index.php?fc=module&module=megaproduct&controller=ajaxservices', 4730 async: false, 4731 cache: false, 4732 dataType : "html", 4733 data: '&type=checkcartquantity', 4734 success: function(jsonData,textStatus,jqXHR) 4735 { 4736 $('#mp-quantity-limits').html(jsonData); 4737 4738 } 4739 }); 4740} 4741function mpShowCartProducts(){ 4742 $('.mp-cart-info-cart').toggle(); 4743 if($('#mp-icon-open').is(":visible")){ 4744 $('#mp-icon-open').hide(); 4745 $('#mp-icon-close').show(); 4746 } else { 4747 $('#mp-icon-open').show(); 4748 $('#mp-icon-close').hide(); 4749 } 4750} 4751function refreshMPCountdown(id_cart) 4752{ 4753 $.ajax({ 4754 type: 'POST', 4755 url: baseDir + 'index.php?fc=module&module=megaproduct&controller=cron&type=refresh&id_cart='+id_cart, 4756 success: function(jsonData,textStatus,jqXHR) 4757 { 4758 location.reload(); 4759 } 4760 }); 4761} 4762function getIdCombination(){ 4763 if($('#idCombination').length) 4764 return parseInt($('#idCombination').val()); 4765 var data = $('#product-details').data('product'); 4766 if(typeof data!="undefined") 4767 return data.id_product_attribute; 4768 return 0; 4769}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.