function checkLogin() { var emailfilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; document.getElementById('notifier').style.display = "none"; if (!emailfilter.test(document.getElementById('email').value) || (document.getElementById('email').value.length < 4)) { document.getElementById('email').focus(); document.getElementById('notifier').innerHTML = "
Please enter a valid e-mail address."; document.getElementById('notifier').style.display = "block"; return false; } else if ((document.getElementById('password').value == "") || (document.getElementById('password').value.length < 4)) { document.getElementById('password').focus(); document.getElementById('notifier').innerHTML = "
Please enter your password."; document.getElementById('notifier').style.display = "block"; return false; } confirmLogin(); } function confirmLogin() { var email = escape(document.getElementById('email').value); var password = escape(document.getElementById('password').value); var ajaxhttp = new sack(); ajaxhttp.requestFile = "datacontrols.php?email="+email+"&password="+password+"&type=login"; ajaxhttp.onCompletion = function() { try { if (ajaxhttp.response == "0") { document.getElementById('notifier').style.display = "none"; document.getElementById('notifier').innerHTML = "
Invalid login credentials."; document.getElementById('notifier').style.display = "block"; email=password=""; } else { top.location.href="checkout.php"; email=password=""; } } catch (e) { alert(e.description); } }; ajaxhttp.runAJAX(); } function checkCoupon() { document.getElementById('notifier').style.display = "none"; // basic check if ((document.getElementById('coupon').value == "") || (document.getElementById('coupon').value.length < 3)) { document.getElementById('coupon').focus(); document.getElementById('notifier').innerHTML = "
Please enter a valid coupon."; document.getElementById('notifier').style.display = "block"; return false; } else { // we have a coupon var coupon = document.getElementById('coupon').value; var ajaxhttp = new sack(); ajaxhttp.requestFile = "datacontrols.php?coupon="+coupon+"&type=coupon"; ajaxhttp.onCompletion = function() { try { document.getElementById('notifier').style.display = "none"; var licqty = document.getElementById('licqty').value; var couponval = ajaxhttp.response; // invalid coupon if (parseFloat(couponval) == 0) { document.getElementById('coupon').focus(); document.getElementById('notifier').innerHTML = "
That coupon is invalid and/or expired."; document.getElementById('notifier').style.display = "block"; } // valid coupon else { document.getElementById('notifier').style.display = "none"; var couponvalue = parseFloat(couponval).toFixed(2); document.getElementById('discount').innerText = "(" + couponvalue + ")"; // update price updatePrice(licqty); document.getElementById('ubutton').disabled='true'; } } catch (e) { alert(e.description); } }; ajaxhttp.runAJAX(); } } function SetCookie(cookieName,cookieValue) { var today = new Date(); var expire = new Date(); expire.setTime(today.getTime() + 900000*1); document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+";path=/"; } function ReadCookie(cookieName) { var theCookie=""+document.cookie; var ind=theCookie.indexOf(cookieName); if (ind==-1 || cookieName=="") return ""; var ind1=theCookie.indexOf(';',ind); if (ind1==-1) ind1=theCookie.length; return unescape(theCookie.substring(ind+cookieName.length+1,ind1)); } function updatePrice(qty) { var product_price = document.getElementById('price').innerText; var subtotal = parseFloat(product_price * qty); var discount = (document.getElementById('discount').innerText).replace(/[\(\)]/g, ""); var shipping = document.getElementById('shipping').innerText; var total = parseFloat(subtotal - discount) + parseFloat(shipping); if (!isNaN(tax) || tax != 0 || tax != "0.00") { var taxamount = total*(tax/100); total += taxamount; document.getElementById('tax').innerText = taxamount.toFixed(2); SetCookie("tax", document.getElementById('tax').innerText); total = parseFloat(total); } SetCookie("discount1", discount); SetCookie("subtotal", subtotal); SetCookie("qty", qty); document.getElementById('subtotal').innerText = subtotal.toFixed(2); document.getElementById('discount').innerText = '(' + discount + ')'; document.getElementById('total').innerText = total.toFixed(2); document.getElementById('paymentAmount').value = base64_encode(total.toFixed(2)); } function base64_encode( data ) { // http://kevin.vanzonneveld.net // + original by: Tyler Akins (http://rumkin.com) // + improved by: Bayron Guevara // + improved by: Thunder.m // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // - depends on: utf8_encode // * example 1: base64_encode('Kevin van Zonneveld'); // * returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA==' // mozilla has this native // - but breaks in 2.0.0.12! //if (typeof window['atob'] == 'function') { // return atob(data); //} var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, enc="", tmp_arr = []; data = utf8_encode(data); do { // pack three octets into four hexets o1 = data.charCodeAt(i++); o2 = data.charCodeAt(i++); o3 = data.charCodeAt(i++); bits = o1<<16 | o2<<8 | o3; h1 = bits>>18 & 0x3f; h2 = bits>>12 & 0x3f; h3 = bits>>6 & 0x3f; h4 = bits & 0x3f; // use hexets to index into b64, and append result to encoded string tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4); } while (i < data.length); enc = tmp_arr.join(''); switch( data.length % 3 ){ case 1: enc = enc.slice(0, -2) + '=='; break; case 2: enc = enc.slice(0, -1) + '='; break; } return enc; } function utf8_encode ( string ) { // http://kevin.vanzonneveld.net // + original by: Webtoolkit.info (http://www.webtoolkit.info/) // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: sowberry // * example 1: utf8_encode('Kevin van Zonneveld'); // * returns 1: 'Kevin van Zonneveld' string = string.replace(/\r\n/g,"\n"); var utftext = ""; var start, end; start = end = 0; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); var enc = null; if (c < 128) { end++; } else if((c > 127) && (c < 2048)) { enc = String.fromCharCode((c >> 6) | 192) + String.fromCharCode((c & 63) | 128); } else { enc = String.fromCharCode((c >> 12) | 224) + String.fromCharCode(((c >> 6) & 63) | 128) + String.fromCharCode((c & 63) | 128); } if (enc != null) { if (end > start) { utftext += string.substring(start, end); } utftext += enc; start = end = n+1; } } if (end > start) { utftext += string.substring(start, string.length); } return utftext; }