// JavaScript Document $(document).ready(function(){ //press release widget $(".pressCN").hide(); $(".pressReleaseButton").on("click", function(e){ $(".press").hide(); $(".pressPR").show(); $(".headerHalfWidthActive").removeClass("headerHalfWidthActive"); $(this).addClass("headerHalfWidthActive"); e.preventDefault(); }); $(".corporateNewsButton").on("click", function(e){ $(".press").hide(); $(".pressCN").show(); $(".headerHalfWidthActive").removeClass("headerHalfWidthActive"); $(this).addClass("headerHalfWidthActive"); e.preventDefault(); }); //top menu $('#top_menu nav .sub-menu').each(function(){ $(this).before('
 
'); var parentItem = eval($(this).parent()); var subMenu = $(this); var thisW = subMenu.width()+10; if(thisW < parentItem.width()+10){ thisW = parentItem.width()+10; } subMenu.css({ marginLeft: '-'+parentItem.css('padding-left'), marginTop: parentItem.css('padding-bottom'), width: thisW }); //subMenu.css('margin-top',parentItem.css('padding-bottom')); parentItem.mouseover(function(){ subMenu.show(); }); parentItem.mouseout(function(){ subMenu.hide(); }); }); $('a.btn-login').click(function(){ $('#top_loader .forget-password-form').stop(false,true).slideUp(300); $('#top_loader .login-form').stop(false,true).slideDown(300); $.scrollTo({top:'0px',left:'0px'}, 300); }); //ajax form $('.ajax-validate').submit(function(){ ajaxSubmit($(this)); return false; }); $('form input:text').attr('autocomplete','off'); //scroll to Top $('a.btn-to-top').click(function(){ $.scrollTo({top:'0px',left:'0px'}, 300); }); //wish list //checkWishlist(); //cart //checkAddtoCart(); //currency /*$('#top_currency a').click(function(){ var id_currency = $(this).attr('data-currency'); $.ajax({ url: urlRelative+'methods/change.currency.php?mode=change.currency&id='+id_currency }).done(function(data){ if(data == 'success'){ location.reload(); } }); });*/ //quick search $('#frm_quick_search').each(function(){ var searchForm = eval($(this)); var url = searchForm.attr('action')+lang+'/search/'; searchForm.validate({ submitHandler: function(form){ var para = searchForm.serializeArray(); for(p in para){ if(para[p].name == 'query'){ var query = para[p].value; } } window.open(url+query,'_self'); return false; } }); $(this).find('a.btn-submit').click(function(){ searchForm.submit(); }); }); //panels if($('#rightpanel').length > 0){ $('section#maincontent').addClass('column leftpanel'); } if($('#leftpanel').length > 0){ $('section#maincontent').addClass('column rightpanel'); } $('aside nav').each(function(){ $(this).find('a.block:last').css('border','none'); $(this).find('.submenu').each(function(){ $(this).find('a.block:last').css('border','none'); }); }); //header 1 $('section#maincontent h1').each(function(){ if($(this).find('span').length <= 0){ //$(this).css('padding','10px 20px'); } }); // if($('#product_attributes span.hRight a').length > 0){ $('#product_attributes span.hRight a').click(function(){ var stock = $(this).attr('data-stock'); var id_attribute = $(this).attr('data-id'); var filename = $(this).attr('data-filename'); var name = $(this).find('img').attr('title'); //console.log(filename); $(this).parent().find('a').removeClass('active'); $(this).addClass('active'); $('#id_attribute').val(id_attribute); $('#attribute_photo a').attr({ href: 'javascript:;', title: name }).unbind('click').click(function(){ $.prettyPhoto.open(urlRelative+'uploads/originals/'+filename,name,name); }); $('#attribute_photo a img').attr({ src: urlRelative+'pics/product-attributes/'+filename, alt: name, title: name }); }); } $('.product-tabs').each(function(){ if($(this).find('a').length > 0){ var countTab = $(this).find('a').length; var tabW = Math.floor($(this).width() / countTab); $(this).find('a').width(tabW).click(function(){ var article = $(this).attr('data-article'); changeProductTab(article); }); var article = $(this).find('a:first').attr('data-article'); changeProductTab(article); } }); //prettyPhotos if($('.prettyPhoto').length > 0){ $("", { rel: "stylesheet", type: "text/css", href: urlRelative+"js/prettyPhoto/css/prettyPhoto.css" }).appendTo("head"); $.getScript(urlRelative+"js/prettyPhoto/jquery.prettyPhoto.js",function() { $("a.prettyPhoto").prettyPhoto({ hideflash: false, //theme: 'lightsquare', social_tools: '' }); }); } $('form input:text').attr('autocomplete','off'); $('.nospecial').keyup(function(){ var str = $(this).val(); $(this).val(trimString(str,'nosymbol')); }); $('.digits').keyup(function(){ var str = $(this).val(); $(this).val(trimString(str,'integer')); }); $('.number').keyup(function(){ var str = $(this).val(); $(this).val(trimString(str,'number')); }); //autocomplete if($('input.autocomplete').length > 0){ $("", { rel: "stylesheet", type: "text/css", href: urlRelative+"js/autocomplete/jquery.autocomplete.css" }).appendTo("head"); $.getScript(urlRelative+"js/autocomplete/jquery.autocomplete.js",function() { $("input.autocomplete").each(function(){ var uri = $(this).attr('data-source'); var W = $(this).outerWidth(); $(this).autocomplete(uri, { delay: 10, width: W, matchSubset: false, matchContains: false, cacheLength: 0, noCache: true, //request for data every time onItemSelect: findValue, onFindValue: findValue, formatItem: function(row) { return "
"+row+"
"; }, autoFill: false, mustMatch: false //free input? } ); }); function findValue(li) { //$("#txtSymbol").val(li.extra[0]); // $("#txtCName").val(li.extra[1]); } }); } //autocomplete end //google map if($('.gmap').length > 0){ $.getScript(urlRelative+"js/google.map.js",function() { var LatLng = new Array(); var GoogleMap = new Array(); var Markers = new Array(); var InfoWin = new Array(); $('.gmap').each(function(){ var maxWidth = 450; var defaultopen = true; var _ID = $(this).attr('id').replace('gmap_',''); var _TITLE = $(this).attr('data-gmap-title'); var _CONTENT = $.trim($(this).html()); var _MINW = (typeof $(this).attr('data-gmap-width') != 'undefined') ? $(this).attr('data-gmap-width'):0; LatLng[_ID] = $(this).attr('data-gmap-ll').split(','); GoogleMap[_ID] = initGoogleMap(LatLng[_ID],'gmap_'+_ID,17,false); Markers[_ID] = GoogleMap_simpleMarker(GoogleMap[_ID],_TITLE,LatLng[_ID],true); if(_CONTENT != ''){ setTimeout(function(){ InfoWin[_ID] = GoogleMap_infoWindow(GoogleMap[_ID],Markers[_ID],_CONTENT,_MINW,true); },1000); } }); }); }; //add this var addthis_config = { "data_track_addressbar":true }; $.getScript("//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5225c9437e695eb3"); }); //function function trimString(str,type){ switch(type){ case 'nosymbol': return str.replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-'); break; case 'number': return str.replace(/[^0-9\.]/g,''); break; case 'integer': return str.replace(/[^0-9]/g,''); break; } } function ajaxSubmit(form){ $(form).find('.field').attr('readonly','readonly'); $(form).find('.btn').attr('disabled','disabled'); $.ajax({ type: 'POST', url: $(form).attr('action'), data: $(form).serialize(), success: function(response){ var str = response.split('|'); $(form).find('div.message p').hide().removeClass('red orange'); var msg = 0; if($(form).find('div.message p').length > 0){ var msgPos = $(form).find('div.message').offset(); //console.log(msgPos); var msgPos = msgPos.top - 150; msgPos = (msgPos < 0) ? 0:msgPos; msg = 1; //console.log(msgPos); // alert($('div.message').height()); } switch(str[0]){ case 'wishlist': checkWishlist(); case 'addtocart': checkAddtoCart(); case 'success': $(form).find('input[type="reset"]').click(); if(str[1] != ''){ if(msg == 1){ $(form).find('div.message p').html(str[1]).slideDown(500); $.scrollTo({top:msgPos, left:0}, 300); }else{ alert(str[1]); } } break; case 'fail': if(str[1] != ''){ if(msg == 1){ $(form).find('div.message p').html(str[1]).addClass('red').slideDown(500); $.scrollTo({top:msgPos, left:0}, 300); }else{ alert(str[1]); } } break; case 'miss': if(str[1] != ''){ if(msg == 1){ $(form).find('div.message p').html(str[1]).addClass('red').slideDown(500); $.scrollTo({top:msgPos, left:0}, 300); }else{ alert(str[1]); } } break; default: if(msg == 1){ $(form).find('div.message p').html('
'+str+'
').addClass('orange').slideDown(500); $.scrollTo({top:msgPos, left:0}, 300); }else{ alert(str); } //SysMsg('
'+str.toString()+'
','',0); break; } $(form).find('.field').removeAttr('readonly'); $(form).find('.btn').removeAttr('disabled'); if(typeof(str[2]) != "undefined" && str[2] !== null) { if(str[2] == 'refresh'){ location.reload(); }else if(str[2] == 'delayRefresh'){ setTimeout(function(){ location.reload(); },5000); }else{ setTimeout(function(){ window.open(urlRelative+lang+'/'+str[2],'_self'); },1000); } return; } }, error:function(response){ var msg = 0; if($(form).find('div.message p').length > 0){ var msgPos = $(form).find('div.message').offset(); var msgPos = msgPos.top - 150; msgPos = (msgPos < 0) ? 0:msgPos; msg = 1; } var str = 'Failed to load resources.'; if(msg == 1){ $(form).find('div.message p').html(str).addClass('red').slideDown(500); $.scrollTo({top:msgPos, left:0}, 300); }else{ alert(str); } } }); } // function number_format(number, decimals, dec_point, thousands_sep) { number = (number + '').replace(/[^0-9+-Ee.]/g, ''); var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function (n, prec) { var k = Math.pow(10, prec); return '' + Math.round(n * k) / k; }; // Fix for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/B(?=(?:d{3})+(?!d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } function urldecode(str) { return decodeURIComponent((str+'').replace(/\+/g, '%20')); }