$(function(){var userAgent = window.navigator.userAgent.toLowerCase();if(userAgent.indexOf('msie') != -1 || userAgent.indexOf('trident') != -1) { $('#dummyBuyItNow').hide();} var buyItNowFlg=0;$('.dynamic-payment-button').hide();if(!getParam('variant')){$('#single-option-selector-product-template-0').val('');}$("input"). keydown(function(e) {if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { return false;}else { return true;}});var time_str=$.now(); var postList={};var prm={};if(!$.cookie('s_myid')){var s_myid = time_str+Math.random().toString(36).substr(2, 16);$.cookie('s_myid',s_myid,{ path: '/' }); }var cPid=meta.product.vendor; var sPid=meta.product.id;var variants=meta.product.variants;var title_sku_hash={};var sku_variant_id_hash={};$.each(variants, function(index, value) {title_sku_hash[value.public_title]=value.sku;sku_variant_id_hash[value.sku]=value.id;});$(document).on('click', '#dummyAddToCart', function(){buyItNowFlg=0;stock_check();});$('#dummyBuyItNow').click(function(){buyItNowFlg=1;stock_check();});var title_sku_json = JSON.stringify(title_sku_hash);postList=prm={};postList['time_str']=time_str;postList['product_id']=cPid;postList['title_sku_json']=title_sku_json;postList['ajax_mode']="look_stocks";prm['url']='https://zaikosys.kenkengems.com/s_look_stocks.php';ajaxExe(postList,prm);function stock_check(){var public_title=$('#single-option-selector-product-template-0').val();var sku=title_sku_hash[public_title];if(!sku){alert('Please select variant!');return false;}var num=$('#quantity_wanted').val();if(!num||num=="0"){return true;} postList=prm={};postList['s_myid']=$.cookie('s_myid');postList['sku']=sku;postList['variant_id']=sku_variant_id_hash[sku];postList['num']=num;postList['buyItNowFlg']=buyItNowFlg;if(!postList['s_myid']||!postList['sku']||!postList['variant_id']){alert('The parameter is not perfect!');return false;}postList['ajax_mode']="stock_check_product";prm['url']='https://zaikosys.kenkengems.com/new_s_stock_check.php';ajaxExe(postList,prm);}function ajaxExe(postList,prm){$.ajax({url: prm['url'],type: 'POST',data : postList,cache: false, success: function(res){ if(res){var restext=res;if(postList['ajax_mode']=="look_stocks"){if(restext!=''){$('#option_stock').html(restext);}}else if(postList['ajax_mode']=="stock_check_product"){if(restext.match('OK')){if(buyItNowFlg){$('.dynamic-payment-button button').click();}else{$('#AddToCart-product-template').click();}} else if(restext.match('OVER')){alert('The quantity is more than the stocks.');return false;} else if(restext.match('ERROR')){alert('An unexpected error occurred.');return false;}else{alert('An unexpected error occurred.');return false;} }}}});}function getParam(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " "));}});