
function isEmail(entry){var rex=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return rex.test(entry);}
function rgbToHex(rgb){if(!/^rgb\(/.test(rgb))return rgb;var rgbvals=/rgb\((.+),(.+),(.+)\)/i.exec(rgb);var rval=parseInt(rgbvals[1]);var gval=parseInt(rgbvals[2]);var bval=parseInt(rgbvals[3]);return'#'+((rval<10?'0':'')+rval.toString(16)+
(gval<10?'0':'')+gval.toString(16)+
(bval<10?'0':'')+bval.toString(16)).toUpperCase();}
var imageWin=null;function showImage(image_url,image_width,image_height){image_width=image_width==""?400:image_width;image_height=image_height==""?380:image_height;var w=screen.width;var h=screen.height;var ww=image_width*1+30;var wh=image_height*1+45;var wx=(w-ww)/2;var wy=(h-wh)/2;if(imageWin!=null){imageWin.close();}
imageWin=null;imageWin=window.open("","ProductImageWindow","titlebar=yes, toolbar=no, menubar=no, status=no, directories=no, resizable=yes, scrollbars=yes, top="+wy.toString()+", left="+wx.toString()+", width="+ww.toString()+", height="+wh.toString()+"");while(imageWin==null);imageWin.focus();imageWin.document.body.innerHTML="";imageWin.document.write('<body style="padding:5px;margin:0px">');imageWin.document.write('<div align="center"><img hspace="0" vspace="0" src="'+image_url+'"></div><br/>');imageWin.document.write('<div align="center" style="font-family:arial;font-color:black;font-size:11px;"><a href="javascript:window.close();" style="color:#0000AA;">Close Window</a></div>');imageWin.document.write('</body>');imageWin.width=ww;imageWin.height=wh;}
function showPrinterPage(url){var prWin=null;prWin=window.open(url,"PrintVer","titlebar=yes, toolbar=no, menubar=yes, status=yes, directories=no, resizable=yes, scrollbars=yes, top=20, left=20, width=810, height=600");while(prWin==null);prWin.focus();}
function urldecode(str){var ret=str;ret=ret.replace(/\+/g,'%20');ret=decodeURIComponent(ret);ret=ret.toString();return ret;}
function number_format(number,decimals,dec_point,thousands_sep)
{number=(number+'').replace(',','').replace(' ','');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;};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 ShowPopup(src){var bWin=null;bWin=window.open(src,"PopupWind","titlebar=no, toolbar=no, menubar=no, status=no, directories=no, resizable=no, scrollbars=no, top=20, left=20, width=320, height=240");while(bWin==null);bWin.focus();}
function ConfirmLogout(){if(typeof(ClearCartOnLogout)!='undefined'&&(orderItemsCount>0&&ClearCartOnLogout!=null&&ClearCartOnLogout)){if(confirm("You have items in your cart. Logging out will empty your cart\nAre you sure want to continue?")){document.location=urlLogout;}}
else{if(confirm("Do you really want to logout?")){document.location=urlLogout;}}}
function CartConfirmDeleteItem(ocid){if(confirm(msg.confirm_delete_item)){document.location=CartDeleteItemUrl+'&ocid='+ocid;}}
function CartConfirmEmpty(){if(confirm(msg.confirm_empty_cart)){document.location=CartEmptyUrl;}}
function LuhnCheck(str)
{var result=true;var sum=0;var mul=1;var strLen=str.length;for(i=0;i<strLen;i++)
{var digit=str.substring(strLen-i-1,strLen-i);var tproduct=parseInt(digit,10)*mul;if(tproduct>=10)
sum+=(tproduct%10)+1;else
sum+=tproduct;if(mul==1)
mul++;else
mul--;}
if((sum%10)!=0)result=false;return result;}
function CheckAddProduct(frm,min_order,max_order,allowed_max)
{if(product_may_be_added)
{var rex=/^(\d{1,})$/;var err=false;if(!rex.test(frm.elements["oa_quantity"].value))
{alert(msg.enter_numeric_product_quantity);frm.elements["oa_quantity"].focus();return false;}
var quantity=frm.elements["oa_quantity"].value*1;if($("meta[name='ddm-page']").attr('content')=='product')
{if(inventory_control!='No')
{if(((inventory_control=='Yes')||(inventory_control=='AttrRuleExc')||(inventory_control=='AttrRuleInc'&&inventory_hash_found))&&quantity>product_stock)
{alert(msg.number_of_items_exceed_inventory);err=true;}}}
else
{if((allowed_max!="-")&&(quantity>allowed_max))
{alert(msg.number_of_items_exceed_inventory);err=true;}}
if(quantity<min_order)
{alert(msg.number_of_items_exceeded_min);err=true;}
if((max_order!="-")&&(quantity>max_order))
{alert(msg.number_of_items_exceeded_max);err=true;}
if(err)
{frm.elements["oa_quantity"].focus();return false;}
return true;}
return false;}
function submitCartForm(action)
{$('#form-cart-oa-todo').val(action);$('#form-cart').submit();return false;}
$(document).ready(function(){$("#insureship_active").change(function(){submitCartForm("update");});$('#form-cart-continue-shopping').click(function(){submitCartForm("continue");return false;});$('#form-cart-update').click(function(){submitCartForm("update");return false;});$('#form-cart').submit(function(){return CheckCartForm();})
$('.checkout').click(function(){submitCartForm("checkout");return false;}).removeAttr('disabled');$('.page-cart .button-apply-promo').removeAttr('disabled');});function CheckCartForm()
{var frm=document.getElementById('form-cart');var irex=/^oa_quantity\[(\d{1,})\]$/;var prex=/^oa_pid_to_ocid\[(\d{1,})\]$/;var drex=/^(\d{1,})$/;var products=new Array();for(i=0;i<frm.elements.length;i++)
{if(irex.test(frm.elements[i].name))
{if(!drex.test(frm.elements[i].value))
{alert(msg.enter_numeric_product_quantity);frm.elements[i].focus();return false;}
if(frm.elements[i].value*1<(frm.elements["min_"+frm.elements[i].name].value)*1)
{alert(msg.number_of_items_exceeded_min);frm.elements[i].focus();return false;}
if((frm.elements["max_"+frm.elements[i].name].value!="-")&&(frm.elements[i].value*1>frm.elements["max_"+frm.elements[i].name].value*1))
{alert(msg.number_of_items_exceeded_max);frm.elements[i].focus();return false;}
if((frm.elements["allowed_"+frm.elements[i].name].value!="-")&&(frm.elements[i].value*1>frm.elements["allowed_"+frm.elements[i].name].value*1))
{alert(msg.number_of_items_exceed_inventory);frm.elements[i].focus();return false;}}
if(prex.test(frm.elements[i].name))
{var ocid=frm.elements[i].value;var pid=frm.elements["oa_ocid_to_pid["+ocid+"]"].value;if(products[pid])
{products[pid]=products[pid]+frm.elements["oa_quantity["+ocid+"]"].value*1;}
else
{products[pid]=frm.elements["oa_quantity["+ocid+"]"].value*1;}
if(frm.elements["oa_inventory_control["+ocid+"]"].value=="Yes")
{if(frm.elements["allowed_oa_quantity["+ocid+"]"].value<products[pid])
{alert(msg.number_of_items_exceed_inventory);frm.elements["oa_quantity["+ocid+"]"].focus();return false;}}}}
return true;}
