
window.addEvent('domready',function(){$each($$('.updateSubmit'),function(el){el.addEvent('click',function(){var updateCt=$(el).get('id');var thisUpdate=updateCt.replace('sub_','');if(isNaN(Number($(thisUpdate+'_quant').get('value')))){var quantNonNum=true;};if((Number($(thisUpdate+'_quant').get('value'))==0)||(quantNonNum)){$(thisUpdate+'_quant').set('value','1')}
var thisUpdateCt=Math.ceil($(thisUpdate+'_quant').get('value'));$(thisUpdate+'_quant').set('value',thisUpdateCt);var curPrice=el.getNext().getProperty('rel');var updateQuantNum=(curPrice*thisUpdateCt);var thisPriceRef=$(el).getPrevious().getPrevious();thisPriceRef.set('rel',updateQuantNum);thisPriceRef.set('html','Price: $'+addCommas(updateQuantNum.toFixed(2)));var priceUpdtPulse=new Fx.Morph(thisPriceRef,{duration:1000});priceUpdtPulse.start({'color':['#ff0000','#000']});var checkNum=parseInt(thisUpdateCt);if($type(checkNum)=='number'){doAddRem('add',thisUpdate,thisUpdateCt);}
var thisTotalPrice=thisUpdateCt*$(el).getNext().get('rel');var dispTotal=0;$each($$('.cartPrice'),function(el){thisVal=el.get('rel');thisVal=Number(thisVal);dispTotal=dispTotal+thisVal;});$('cartTotal').set('rel',dispTotal);var totalArr=$('cartTotal').get('rel');var totalArr=Number(totalArr);$('cartTotal').set('html','SubTotal: $'+addCommas(totalArr.toFixed(2)));var shipCost;if($$('.cartShipTiers')){$each($$('.cartShipTiers'),function(el){var thisId=el.get('id');var thisId=thisId.replace('p_','');if(dispTotal>=Number(thisId)){shipCost=el.get('rel');}});if(shipCost==0.00){$('cartTotalShip').set('html','Shipping: FREE');$('cartTotalWithShip').set('html','Total: $'+addCommas(totalArr.toFixed(2)));}
else{$('cartTotalShip').set('html','Shipping: $'+shipCost);$('cartTotalWithShip').set('html','Total: $'+(Number(totalArr)+Number(shipCost)).toFixed(2));}}
var cartTotalUpdtPulse=new Fx.Morph('cartTotalWithShip',{duration:1000});cartTotalUpdtPulse.start({'color':['#ff0000','#000']});var priceUpdtPulse=new Fx.Morph('cartTotal',{duration:1000});priceUpdtPulse.start({'color':['#ff0000','#000']});var cartTotalUpdtPulse=new Fx.Morph('cartTotalShip',{duration:1000});cartTotalUpdtPulse.start({'color':['#ff0000','#000']});});});$each($$('#cartProdAll div a.cartRemove'),function(el){$(el).addEvent('click',function(){var parDiv=$(el).getParent('div');var prodDivId=parDiv.getProperty('id');doAddRem('rem',prodDivId);var remPrice=Number($(el).getProperty('rel'))*Number($(el).getPrevious().getPrevious().value);var totPriceRef=Number($('cartTotal').getProperty('rel'));var newPrice=(totPriceRef.toFixed(2)-remPrice.toFixed(2));$('cartTotal').set('rel',newPrice);$('cartTotal').set('html','SubTotal: $'+addCommas(newPrice.toFixed(2)));$(el).dispose();var shipCost;if($$('.cartShipTiers')){$each($$('.cartShipTiers'),function(el){var thisId=el.get('id');var thisId=thisId.replace('p_','');if(newPrice>=Number(thisId)){shipCost=el.get('rel');}});if(shipCost==0.00){$('cartTotalShip').set('html','Shipping: FREE');$('cartTotalWithShip').set('html','Total: $'+addCommas(newPrice.toFixed(2)));}
else{$('cartTotalShip').set('html','Shipping: $'+shipCost);$('cartTotalWithShip').set('html','Total: $'+(Number(newPrice)+Number(shipCost)).toFixed(2));}}
var cartTotalUpdtPulse=new Fx.Morph('cartTotalWithShip',{duration:1000});cartTotalUpdtPulse.start({'color':['#ff0000','#000']});var priceUpdtPulse=new Fx.Morph('cartTotal',{duration:1000});priceUpdtPulse.start({'color':['#ff0000','#000']});var cartTotalUpdtPulse=new Fx.Morph('cartTotalShip',{duration:1000});cartTotalUpdtPulse.start({'color':['#ff0000','#000']});var parDivFadeOut=new Fx.Morph(parDiv,{duration:1000});parDivFadeOut.start({'opacity':['1','0'],'width':['130px','0'],'height':['100%'],'overflow':'hidden'});(function(){parDiv.dispose()}).delay(1800);if($('cartTotal').get('rel')=='0'){var cartFadeOut=new Fx.Morph('cartNav',{duration:1000});cartFadeOut.start({'opacity':['1','0']});(function(){$('cartNav').dispose()}).delay(1300);}
var mainCartWidth=new Fx.Morph('cartProdAll',{duration:1000});var cartProdAllWidth=$('cartProdAll').getStyle('width');(function(){var newWidth=(($$('#cartProdAll .cartProds').length-1)*130)+(($$('#cartProdAll .cartProds').length-1)*30);if(newWidth>967){newWidth=967}
mainCartWidth.start({'width':[cartProdAllWidth,newWidth+'px']});}).delay(10);});});$each($$('.addToCart'),function(el){el.addEvent('click',function(){cartElId=el.get('id');doAddRem('add',cartElId,1);});});var pUri=parseUri(document.location.href);if(parseInt(pUri.queryKey.step)==5){processOrder(1);}
if($('checkoutBtn')){$('checkoutBtn').addEvent('click',function(){if($('confirm').checked)
document.location.href='/cart.php?step=5';else
alert('Please click the check box to indicate that you authorize LAURASTAR to process your order.');});}
if($('aPCode'))$('aPCode').addEvent('click',function(e){e=new Event(e).preventDefault();new Request({url:'php/promoCode.php',onSuccess:function(tr){if(tr=='true')document.location.href='/cart.php?step=1';else $('pCode').value='';}}).send('code='+$('pCode').value);});});function addCommas(nStr){nStr+='';x=nStr.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,'$1'+','+'$2');}
return x1+x2;}
function doAddRem(cartChg,addRemId,quant){addRemId=addRemId.replace('p','');var pUri=parseUri(document.location.href);if(addRemId){var addId=addRemId}
if(cartChg){var cartChgTo=cartChg}
new Request({url:'/php/doAddRem.php',onSuccess:function(tr){if(pUri.path=='/products.php')document.location.href="/cart.php?step=1";if(tr=='empty'){var cartEmpty=new Element('div');cartEmpty.set({'html':'your cart is empty','id':'cartEmpty'});cartEmpty.inject('shoppingCart','after');(function(){$('mainCartDiv').dispose();}).delay(1000);}else{document.location.href='/cart.php?step=1';}}}).send('cartChg='+cartChgTo+'&id='+addId+'&quant='+quant);}
function processOrder(step){switch(step){case 1:new Request({url:'/php/processOrder.php',method:'get',onRequest:function(){$('divCheckoutStatus').innerHTML+='Processing Credit Card.....';},onSuccess:function(tr){if(parseInt(tr)==100){$('divCheckoutStatus').innerHTML+="Completed<br /><br />";processOrder(2);}else{var error_codes=new Array();error_codes[101]='The request is missing one or more required fields.';error_codes[102]='One or more fields in the request contains invalid data.'
error_codes[150]='Error: General system failure.'
error_codes[151]='Server Timeout: Unable to continue.'
error_codes[152]='Server Timeout: Unable to continue.'
error_codes[200]='Failed Address Verification Service (AVS) check.'
error_codes[202]='Credit Card has expired.'
error_codes[203]='Credit Card has been declined'
error_codes[204]='Credit Card has been declined'
error_codes[205]='Credit Card has been declined'
error_codes[207]='Issuing bank unavailable.'
error_codes[208]='Credit Card has been declined'
error_codes[209]='American Express Card Identification Digits (CID) did not match.'
error_codes[210]='Credit Card has been declined'
error_codes[211]='Invalid card verification number. (CCV/CCID)'
error_codes[221]='Credit Card has been declined'
error_codes[230]='Credit Card has been declined'
error_codes[231]='Invalid Credit Card account number.'
error_codes[233]='Credit Card has been declined'
error_codes[234]='Merchant Configuration Error.'
error_codes[240]='Credit Card type/number mis-match'
error_codes[250]='Server Timeout: Unable to continue.'
if(error_codes[parseInt(tr)]){$('divCheckoutStatus').innerHTML+=error_codes[parseInt(tr)]+'<br /><br />';$('divCheckoutStatus').innerHTML+='<a href="/cart.php?step=3" id="paymentMethodBack" style="float: none;">Back</a>';}else{$('divCheckoutStatus').innerHTML+="Transaction failed. Please contact us for assistance.";}}}}).send('step=1');break;case 2:$('divCheckoutStatus').innerHTML+='Finalizing Order.....';new Request({url:'/php/processOrder.php',method:'get',onSuccess:function(tr){$('divCheckoutStatus').innerHTML+=tr;}}).send('step=2');break;}}