function getURLVar(key){var value=[];var query=String(document.location).split('?');if(query[1]){var part=query[1].split('&');for(i=0;i<part.length;i++){var data=part[i].split('=');if(data[0]&&data[1]){value[data[0]]=data[1];}}
if(value[key]){return value[key];}else{return'';}}}
function isEmpty(el){return!$.trim(el.html())}
$(document).ajaxStop(function(){function isEmpty(el){return!$.trim(el.html())}
if(!isEmpty($('#product'))){$('#product').addClass('has-option');}});function customResponsive(){var window_w=parseInt($(window).width());if(window_w<=480){$('.home2 .logo-container').after($('.home2 .search-containers'));$('.home4 .search-container.col-sm-3').before($('.home4 .logo-container'));}else{$('.home2 .block-right').prepend($('.home2 .search-containers'));$('.home4 .search-container.col-sm-3').after($('.home4 .logo-container'));}}
$(window).resize(function(){customResponsive();});function stickyMenu(){var winInnW=window.innerWidth;var winScrT=$(window).scrollTop();var s0w991=winScrT>300&&winInnW>1024;$(".header-inner").toggleClass("fix-header",s0w991);}
stickyMenu();$(window).on('resize scroll',stickyMenu);$(document).ready(function(){customResponsive();if(!isEmpty($('#product'))){$('#product').addClass('has-option');}
if(!isEmpty($('#product2'))){$('#product2').addClass('has-option');}
$('header').after('<div class="title-category"><div class="container"><div class="container-inner"></div></div></div>');var category_name=$('h2.category-name');category_name.appendTo('.title-category .container-inner');var breadcrumb=$('ul.breadcrumb');breadcrumb.appendTo('.title-category .container-inner');$('.text-danger').each(function(){var element=$(this).parent().parent();if(element.hasClass('form-group')){element.addClass('has-error');}});$('#form-currency .currency-select').on('click',function(e){e.preventDefault();$('#form-currency input[name=\'code\']').val($(this).attr('name'));$('#form-currency').submit();});$('#form-language .language-select').on('click',function(e){e.preventDefault();$('#form-language input[name=\'code\']').val($(this).attr('name'));$('#form-language').submit();});$('#search input[name=\'search\']').parent().find('button').on('click',function(){var url=$('base').attr('href')+'index.php?route=product/search';var value=$('#search input[name=\'search\']').val();if(value){url+='&search='+encodeURIComponent(value);}
location=url;});$('#search input[name=\'search\']').on('keydown',function(e){if(e.keyCode==13){$('#search input[name=\'search\']').parent().find('button').trigger('click');}});$('#menu .dropdown-menu').each(function(){var menu=$('#menu').offset();var dropdown=$(this).parent().offset();var i=(dropdown.left+$(this).outerWidth())-(menu.left+$('#menu').outerWidth());if(i>0){$(this).css('margin-left','-'+(i+10)+'px');}});$('#list-view').click(function(){$(this).addClass('selected');$('#grid-view').removeClass('selected');$('#content .product-grid > .clearfix').remove();$('#content .product-layout').attr('class','product-layout product-list clearfix');$('#content .product-list .col-image').addClass('col-sm-4 col-sms-4 col-smb-12');$('#content .product-list .col-des').addClass('col-sm-8 col-sms-8 col-smb-12');localStorage.setItem('display','list');});$('#grid-view').click(function(){$(this).addClass('selected');$('#list-view').removeClass('selected');cols=$('#column-right, #column-left').length;if(cols==2){$('#content .product-layout').attr('class','product-layout product-grid module-style1 col-md-6 col-sm-6 col-xs-6 two-items');}else if(cols==1){$('#content .product-layout').attr('class','product-layout product-grid module-style1 col-xlg-3 col-md-4 col-sm-6 col-xs-6 category');}else{$('#content .product-layout').attr('class','product-layout product-grid module-style1 col-md-3 col-sm-6 col-xs-6 four-items');}
$('#content .product-grid .col-image').removeClass('col-sm-4 col-sms-4 col-smb-12');$('#content .product-grid .col-des').removeClass('col-sm-8 col-sms-8 col-smb-12');localStorage.setItem('display','grid');});if(localStorage.getItem('display')=='list'){$('#list-view').trigger('click');}else{$('#grid-view').trigger('click');}
$(document).on('keydown','#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']',function(e){if(e.keyCode==13){$('#collapse-checkout-option #button-login').trigger('click');}});$(document).ajaxStop(function(){});});var cart={'add':function(product_id,quantity){$.ajax({url:'index.php?route=checkout/cart/add',type:'post',data:'product_id='+product_id+'&quantity='+(typeof(quantity)!='undefined'?quantity:1),dataType:'json',beforeSend:function(){$('#cart-total').button('loading');},complete:function(){$('#cart-total').button('reset');},success:function(json){$('.alert, .text-danger').remove();if(json['redirect']){location=json['redirect'];}
if(json['success']){$('body').before('<div class="alert alert-success">'+json['success']+'<button type="button" class="close" data-dismiss="alert">&times;</button></div>');setTimeout(function(){$('#cart-total').html(json['total']);},100);$('html, body').animate({scrollTop:0},'slow');$('#cart > ul').load('index.php?route=common/cart/info ul li');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});},'update':function(key,quantity){$.ajax({url:'index.php?route=checkout/cart/edit',type:'post',data:'key='+key+'&quantity='+(typeof(quantity)!='undefined'?quantity:1),dataType:'json',beforeSend:function(){$('#cart-total').button('loading');},complete:function(){$('#cart-total').button('reset');},success:function(json){setTimeout(function(){$('#cart-total').html(json['total']);},100);if(getURLVar('route')=='checkout/cart'||getURLVar('route')=='checkout/checkout'){location='index.php?route=checkout/cart';}else{$('#cart > ul').load('index.php?route=common/cart/info ul li');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});},'remove':function(key){$.ajax({url:'index.php?route=checkout/cart/remove',type:'post',data:'key='+key,dataType:'json',beforeSend:function(){$('#cart-total').button('loading');},complete:function(){$('#cart-total').button('reset');},success:function(json){setTimeout(function(){$('#cart-total').html(json['total']);},100);if(getURLVar('route')=='checkout/cart'||getURLVar('route')=='checkout/checkout'){location='index.php?route=checkout/cart';}else{$('#cart > ul').load('index.php?route=common/cart/info ul li');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});}}
var voucher={'add':function(){},'remove':function(key){$.ajax({url:'index.php?route=checkout/cart/remove',type:'post',data:'key='+key,dataType:'json',beforeSend:function(){$('#cart-total').button('loading');},complete:function(){$('#cart-total').button('reset');},success:function(json){setTimeout(function(){$('#cart-total').html(json['total']);},100);if(getURLVar('route')=='checkout/cart'||getURLVar('route')=='checkout/checkout'){location='index.php?route=checkout/cart';}else{$('#cart > ul').load('index.php?route=common/cart/info ul li');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});}}
var wishlist={'add':function(product_id){$.ajax({url:'index.php?route=account/wishlist/add',type:'post',data:'product_id='+product_id,dataType:'json',success:function(json){$('.alert').remove();if(json['redirect']){location=json['redirect'];}
if(json['success']){$('body').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> '+json['success']+' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');}
$('#wishlist-total > span').html(json['total']);$('html, body').animate({scrollTop:0},'slow');},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});},'remove':function(){}}
var compare={'add':function(product_id){$.ajax({url:'index.php?route=product/compare/add',type:'post',data:'product_id='+product_id,dataType:'json',success:function(json){$('.alert').remove();if(json['success']){$('body').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> '+json['success']+' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');$('#compare-total').html(json['total']);$('html, body').animate({scrollTop:0},'slow');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});},'remove':function(){}}
$(document).delegate('.agree','click',function(e){e.preventDefault();$('#modal-agree').remove();var element=this;$.ajax({url:$(element).attr('href'),type:'get',dataType:'html',success:function(data){html='<div id="modal-agree" class="modal">';html+='  <div class="modal-dialog">';html+='    <div class="modal-content">';html+='      <div class="modal-header">';html+='        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';html+='        <h4 class="modal-title">'+$(element).text()+'</h4>';html+='      </div>';html+='      <div class="modal-body">'+data+'</div>';html+='    </div';html+='  </div>';html+='</div>';$('body').append(html);$('#modal-agree').modal('show');}});});(function($){$.fn.autocomplete=function(option){return this.each(function(){this.timer=null;this.items=new Array();$.extend(this,option);$(this).attr('autocomplete','off');$(this).on('focus',function(){this.request();});$(this).on('blur',function(){setTimeout(function(object){object.hide();},200,this);});$(this).on('keydown',function(event){switch(event.keyCode){case 27:this.hide();break;default:this.request();break;}});this.click=function(event){event.preventDefault();value=$(event.target).parent().attr('data-value');if(value&&this.items[value]){this.select(this.items[value]);}}
this.show=function(){var pos=$(this).position();$(this).siblings('ul.dropdown-menu').css({top:pos.top+$(this).outerHeight(),left:pos.left});$(this).siblings('ul.dropdown-menu').show();}
this.hide=function(){$(this).siblings('ul.dropdown-menu').hide();}
this.request=function(){clearTimeout(this.timer);this.timer=setTimeout(function(object){object.source($(object).val(),$.proxy(object.response,object));},200,this);}
this.response=function(json){html='';if(json.length){for(i=0;i<json.length;i++){this.items[json[i]['value']]=json[i];}
for(i=0;i<json.length;i++){if(!json[i]['category']){html+='<li data-value="'+json[i]['value']+'"><a href="#">'+json[i]['label']+'</a></li>';}}
var category=new Array();for(i=0;i<json.length;i++){if(json[i]['category']){if(!category[json[i]['category']]){category[json[i]['category']]=new Array();category[json[i]['category']]['name']=json[i]['category'];category[json[i]['category']]['item']=new Array();}
category[json[i]['category']]['item'].push(json[i]);}}
for(i in category){html+='<li class="dropdown-header">'+category[i]['name']+'</li>';for(j=0;j<category[i]['item'].length;j++){html+='<li data-value="'+category[i]['item'][j]['value']+'"><a href="#">&nbsp;&nbsp;&nbsp;'+category[i]['item'][j]['label']+'</a></li>';}}}
if(html){this.show();}else{this.hide();}
$(this).siblings('ul.dropdown-menu').html(html);}
$(this).after('<ul class="dropdown-menu"></ul>');$(this).siblings('ul.dropdown-menu').delegate('a','click',$.proxy(this.click,this));});}})(window.jQuery);