function getPrice(size, qty) { var returnval = 10; switch (size) { case '3x2': { returnval = 8.99; if (qty < 25) { returnval = 8.99; break;} if (qty < 100) { returnval = 7.99; break;} if (qty < 200) { returnval = 6.99; break;} if (qty < 500) { returnval = 5.99; break;} if (qty < 1000) { returnval = 5.25; break;} if (qty < 100000) { returnval = 4.99; break;} } break; case '3x3': { returnval = 18.99; if (qty < 25) { returnval = 18.99; break;} if (qty < 100) { returnval = 17.99; break;} if (qty < 200) { returnval = 16.99; break;} if (qty < 500) { returnval = 15.99; break;} if (qty < 1000) { returnval = 14.99; break;} if (qty < 100000) { returnval = 13.99; break;} } break; case '4x3': { returnval = 9.99; if (qty < 25) { returnval = 9.99; break;} if (qty < 100) { returnval = 8.99; break;} if (qty < 200) { returnval = 7.99; break;} if (qty < 500) { returnval = 6.99; break;} if (qty < 1000) { returnval = 5.25; break;} if (qty < 100000) { returnval = 5.75; break;} } break; case '443': { returnval = 19.99; } break; default: break;} return returnval; } var base_processing_time=12; var processing_time=12; var weights = new Array(); weights['3x2'] = 1.4; weights['3x3'] = 5.6; weights['4x3'] = 2.3; weights['443'] = 9.2; function serializeForm (theform) { var els = theform.elements; var len = els.length; var queryString = ""; this.addField = function(name,value) { if (queryString.length>0) { queryString += "&"; } queryString += encodeURIComponent(name) + "=" + encodeURIComponent(value); }; for (var i=0; i=0) { this.addField(el.name,el.options[el.selectedIndex].value); } break; case 'select-multiple': for (var j=0; j0) { var str = match[1]; var discount = parseFloat(str); document.getElementById('discount_span').innerHTML = formatCurrency("$"+discount); if (discount > 0) { if (document.getElementById('coupon_validation').style.visibility == 'visible') { document.getElementById("coupon_validation").innerHTML = "Applied Coupon Code!"; } } else { if (document.getElementById('coupon_code').value != '') { document.getElementById("coupon_validation").innerHTML = "Invalid Coupon Code."; } else { document.getElementById("coupon_validation").innerHTML = ""; } } cartform.discount.value = str; } if (!updating) { cart_md5 = updTotal(); } } } function calcTax(subtotal) { var tax = 0; if (subtotal > 0) { var cartform = document.getElementById('shopping_cart'); var state = cartform.state.value; var country = cartform.country.value; var caregex = /^ca$/i; if ((country=='United States of America') && (caregex.exec(state))) { tax = .0825; } } return tax * subtotal; } function get_selected_shipping_method() { var ship_method = ""; var cartform = document.getElementById('shopping_cart'); for (i=0;i"; weight = weight + package_weight(weight); //dbg.innerHTML += "weight: "+weight+"
"; var cartform = document.getElementById('shopping_cart'); var shipping = 0; var country = cartform.country.value; var weight_input = cartform.weight; weight_input.value = weight; //var ship_method = cartform.shipping_method.value; var ship_method = get_selected_shipping_method(); var ship_methods = get_shipping_methods(weight,country,num_books); //dbg.innerHTML += "ship_methods: "+ship_methods[ship_method]+"
"; set_shipping_inputs(ship_methods,ship_method); /* if (ship_methods[ship_method]) { // dbg.innerHTML += "keeping: "+ship_method+"("+ship_methods[ship_method]+")
"; } else { // TODO: make this the default ship_method = cartform.shipping_method.value;//get_shipping_method(weight,country); // dbg.innerHTML += "switching to: "+ship_method+"("+ship_methods+")
"; } */ var ship_method = get_selected_shipping_method(); var zip = cartform.zip.value; if (country=='United States of America') { if (isNaN(parseInt(zip))) { zip = 10010; } shipping = shipping_cost(weight,country,zip,ship_method); } else { shipping = shipping_cost(weight,country,0,ship_method);//'usps_global_express'); } if (ship_method == 'usps_media') { shipping = 0; } return shipping; } function adjustDay (cday) { TDay = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); if (cday > 6) { cday -= 6; CurDayOw = TDay[cday-1]; adjustDay(cday-1); } else { CurDayOw = TDay[cday]; return true; } } function isLeapYear (Year) { if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) { return true; } else { return false; } } function calcShippingTime(AddDays) { // TODO: fix for AddDays > 30 TDate = new Date(); var expdate = TDate.getTime() expdate += AddDays*24*3600*1000 //expires in 1 hour(milliseconds) TDate.setTime(expdate) TDay = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); TMonth = new Array('January', 'February', 'March', 'April', 'May','June', 'July', 'August', 'September', 'October', 'November', 'December'); CurYear = TDate.getYear(); CurMonth = TDate.getMonth(); CurDayOw = TDay[TDate.getDay()]; CurDay = TDate.getDate(); month = TMonth[CurMonth]; TheDate = CurDayOw + ', '; TheDate += month + ' '; TheDate += CurDay + ', '; if (CurYear<100) CurYear="19" + CurYear; TheDate += " "+(1900+CurYear); return TheDate; } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) { num = "0"; } if (num == "0") { return "$0.00"; } else { sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) { cents = "0" + cents; } for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '$' + num + '.' + cents); } } function updCoupon() { new_md5 = 0; document.getElementById('discount_span').innerHTML = '$0.00'; document.getElementById('coupon_validation').innerHTML = "Validating..."; updServer(); } function updServer() { //var dbg = document.getElementById('dbg'); var retval = ''; if (!updating) { if (cart_md5 == new_md5) { //document.getElementById('dbg').innerHTML = ''; //dbg.innerHTML = "\n
same\n
"; return; } else { cart_md5 = updTotal(); retval = submitForm(document.getElementById('shopping_cart'),"order.php"); new_md5 = cart_md5; } } //dbg.innerHTML += retval; return retval; } function StopTheClock() { if (timerRunning) { clearTimeout(timerID); } timerRunning = false; } function StartTheTimer() { StopTheClock(); updServer(); timerRunning = true; timerID = self.setTimeout("StartTheTimer()", delay); } function decQty(id) { var itemqty = document.getElementById('quantity['+id+']'); itemqty.value = parseInt(itemqty.value) - 1; if (parseInt(itemqty.value) < 0) { itemqty.value = 0; } updQty(id,parseInt(itemqty.value)); } function incQty(id) { var itemqty = document.getElementById('quantity['+id+']'); if (isNaN(parseInt(itemqty.value))) { itemqty.value = 1; } else { itemqty.value = parseInt(itemqty.value) + 1; } updQty(id,parseInt(itemqty.value)); } function updQty(id,qty) { new_md5 = 0; var itemqty = document.getElementById('quantity['+id+']'); if (itemqty.value != '') { if (isNaN(parseInt(qty))) { qty = 0; itemqty.value = 0; } else { itemqty.value = parseInt(qty); } //if (!updating) { updServer(); //} } } function updTotal() { //updating = 1; /* Update the server with the new shopping cart qties */ var elems = document.getElementsByTagName('INPUT'); var cartform = document.getElementById('shopping_cart'); var regex=/quantity/i; var idregex=/\[(\d+)\]/; var subtotal_amt = 0; var shipping_amt = 0; var discount_amt = 0; var tax_amt = 0; var total_amt = 0; var totalweight = 0; var md5_src = ''; num_books = 0; for (i=0;i\n"; post_estimate.innerHTML += "via "+ship_data.name+", arriving by "; post_estimate.innerHTML += ""+calcShippingTime(processing_time+delivery_time)+""; /* if (cartform.shipping_method.options[0]) { if (cartform.shipping_method.options[0].value == 'usps_media') { document.getElementById('economy_info_image').style.display='none'; economy_info_text.innerHTML = "Your order qualifies for FREE Economy Shipping!"; } else { if (country == 'United States of America') { document.getElementById('economy_info_image').style.display='block'; } else { document.getElementById('economy_info_image').style.display='none'; } economy_info_text.innerHTML = ""; } } else { if (country == 'United States of America') { document.getElementById('economy_info_image').style.display='block'; } else { document.getElementById('economy_info_image').style.display='none'; } economy_info_text.innerHTML = ""; } */ // add it all up total_amt = subtotal_amt - discount_amt + shipping_amt + tax_amt; if (total_amt < 0.01) { total_amt = 0; } discountspan.innerHTML = formatCurrency(discount_amt); subtotalspan.innerHTML = formatCurrency(subtotal_amt); shippingspan.innerHTML = formatCurrency(shipping_amt); taxspan.innerHTML = formatCurrency(tax_amt); totalspan.innerHTML = formatCurrency(total_amt); if (hex_md5(md5_src) != cart_md5) { cart_md5 = hex_md5(md5_src); //dbg.innerHTML += "\n
"+hex_md5(md5_src); } else { //dbg.innerHTML += "\n
same"; } if (totalweight == 0) { cart_md5 = 0; document.getElementById('noclips').style.display='block'; document.getElementById('order_form').style.display='none'; } //updating = 0; } function removefromcart(index) { document.getElementById("cart_row1["+index+"]").style.display = 'none'; document.getElementById("cart_row2["+index+"]").style.display = 'none'; document.getElementById("cart_row3["+index+"]").style.display = 'none'; var orderform_div = document.getElementById('order_form'); var maindiv = document.getElementById('maindiv'); orderformdiv_h -= rowheight; maindiv_h -= rowheight; orderform_div.style.height = orderformdiv_h+"px"; maindiv.style.height = maindiv_h+"px"; } function showcoupon() { document.getElementById("coupon_link").style.display = 'none'; //document.getElementById("coupon_text").style.display = 'inline'; document.getElementById("coupon_code").style.visibility = 'visible'; document.getElementById("coupon_validation").style.visibility = 'visible'; document.getElementById("updateImg").style.display = 'inline'; document.getElementById("updateBtn").style.display = 'inline'; document.getElementById("discount_td1").style.display = 'block'; document.getElementById("discount_td2").style.visibility = 'visible'; document.getElementById("discount_span").style.display = 'block'; }