var selected_shipping_option=0; var shipping_amount=0; var discount_amount=0; var product_total=0; $(document).ready(function() { var options = { target: '#register_status', success: register_response // post-submit callback }; $('#f_register_form').ajaxForm(options); var options = { target: '#login_status', success: login_response // post-submit callback }; $('#f_login_form').ajaxForm(options); update_cart_total(); }); function submit_register_form() { var cart_form_serial=$("#cart_form").serialize(); $.ajax({ type: "POST", data: cart_form_serial, url: "../ajax/checkout_register.php", beforeSend: function() { $("#register_status").html("Loading..."+cart_form_serial); }, success: function(html){ $("#register_status").html(html); //register_response(html); }, error: function(html) { $("#billing_box").html(html); } }); } function register_response(responseText, statusText, xhr, $form) { if(responseText=='ok') { // show logged in box $('#register_form').fadeOut('slow', function() { update_welcome_box(); }); } } function submit_login_form() { $.ajax({ type: "POST", url: "ajax/checkout_login.php", data: "login_email="+$("#login_email").val()+"&login_password="+$("#login_password").val(), beforeSend: function() { }, success: function(html){ //alert(html); login_response(html); var qs1 = new Querystring(html); var success=qs1.get('log_in_successful'); if(success>0) { $("#welcome_box").slideDown(); $("#welcome_box").html("Welcome back!"); $("#checkout_errors").fadeOut(); setTimeout(" $('#welcome_box').slideUp();",5000) populate_billing_box(html); populate_loyalty_box(qs1.get('loyalty_points')); hide_hidden_login_rows(); } else { $("#checkout_errors").html("Sorry, your login information was incorrect."); $("#checkout_errors").fadeIn(); } }, error: function(html) { $("#welcome_box").html(html); } }); } //function login_response(responseText, statusText, xhr, $form) { function login_response(responseText) { //if(responseText=='ok') { { // show logged in box $('#login_form').fadeOut('slow', function() { update_welcome_box(); populate_billing_box(responseText); //update_billing_box(); //update_shipping_box(); update_address_finder("billing_postcode","billing_postcode_finder_link","billing") var qs1 = new Querystring(responseText); var pc = qs1.get('postcode'); var countryid = qs1.get('countryid'); /* $('#ship_to_billing').attr('checked', true); animatedcollapse.hide('shipping_box'); get_delivery_information(pc,countryid); }); */ }); } } function populate_loyalty_box(points) { if(!points)$("#loyalty_points_box").hide(); false; $("#loyalty_points_box").fadeIn() //alert("points="+points); //$("#loyalty_points_box").html(points); var str=""; $("#loyalty_points_box").html(str); } function update_billing_box() { $.ajax({ type: "POST", url: "../ajax/billing_box.php", beforeSend: function() { $("#billing_box").show(); $("#billing_box").html("Loading"); }, success: function(html){ $("#billing_box").html(html); $('#all_forms').fadeIn('slow'); bind_billing_form(); bind_shipping_form(); }, error: function(html) { $("#billing_box").html(html); } }); } function populate_billing_box(responseStr) { var qs1 = new Querystring(responseStr); //alert(responseStr); var v1 = qs1.get('billing_dob'); $('#billing_dob').val(v1); var v1 = qs1.get('billing_first_name'); $('#billing_first_name').val(v1); var v1 = qs1.get('billing_last_name'); $('#billing_last_name').val(v1); var v1 = qs1.get('billing_company'); $('#billing_company').val(v1); var v1 = qs1.get('billing_address1'); $('#billing_address1').val(v1); var v1 = qs1.get('billing_address2'); $('#billing_address2').val(v1); var v1 = qs1.get('billing_city'); $('#billing_city').val(v1); var v1 = qs1.get('billing_postcode'); $('#billing_postcode').val(v1); var v1 = qs1.get('billing_county'); $('#billing_county').val(v1); var v1 = qs1.get('billing_country'); $('#billing_country').val(v1); var v1 = qs1.get('billing_telephone'); $('#billing_telephone').val(v1); var v1 = qs1.get('shipping_first_name'); $('#shipping_first_name').val(v1); var v1 = qs1.get('shipping_last_name'); $('#shipping_last_name').val(v1); var v1 = qs1.get('shipping_address1'); $('#shipping_address1').val(v1); var v1 = qs1.get('shipping_address2'); $('#shipping_address2').val(v1); var v1 = qs1.get('shipping_city'); $('#shipping_city').val(v1); var v1 = qs1.get('shipping_postcode'); $('#shipping_postcode').val(v1); var v1 = qs1.get('shipping_country'); $('#shipping_country').val(v1); var v1 = qs1.get('shipping_telephone'); $('#shipping_telephone').val(v1); var v1 = qs1.get('shipping_company'); $('#shipping_company').val(v1); } function update_billing_with_summaries() { $.ajax({ type: "POST", url: "../ajax/get_billing_summary.php", beforeSend: function() { $("#billing_box").show(); $("#billing_box").html("Loading"); }, success: function(html){ $("#billing_box").html(html); $('#all_forms').fadeIn('slow'); bind_billing_form(); bind_shipping_form(); }, error: function(html) { $("#billing_box").html(html); } }); } function billing_save_response(responseText, statusText, xhr, $form) { if(responseText=='1') { // billing save is successfull // $("#billing_box").html("put summary here"); //update_billing_with_summaries(); } } function bind_billing_form() { var options = { target: '#order_status', success: billing_save_response }; $('#billing_form').ajaxForm(options); } // shipping functions function update_shipping_box() { // $("#shipping_box").show(); $.ajax({ type: "POST", url: "../ajax/shipping_box.php", beforeSend: function() { $("#shipping_box").html("Loading"); }, success: function(html){ $("#shipping_box").html(html); $('#all_forms').fadeIn('slow'); bind_shipping_form(); }, error: function(html) { $("#shipping_box").html(html); } }); } function update_shipping_with_summaries() { $.ajax({ type: "POST", url: "../ajax/get_shipping_summary.php", beforeSend: function() { $("#shipping_box").show(); $("#shipping_box").html("Loading"); }, success: function(html){ $("#shipping_box").html(html); $('#all_forms').fadeIn('slow'); bind_shipping_form(); }, error: function(html) { $("#shipping_box").html(html); } }); } function shipping_save_response(responseText, statusText, xhr, $form) { if(responseText=='1') { // shipping save is successfull // $("#shipping_box").html("put summary here"); update_shipping_with_summaries(); } } function bind_shipping_form() { var options = { target: '#shipping_result', success: shipping_save_response }; $('#shipping_form').ajaxForm(options); } // end shipping functions function update_welcome_box() { $.ajax({ type: "POST", url: "../ajax/welcome_box.php", beforeSend: function() { $("#welcome_box").show(); $("#welcome_box").html("Loading"); }, success: function(html){ $("#welcome_box").html(html); }, error: function(html) { $("#welcome_box").html(html); } }); } function get_delivery_information(postcode,countryid) { var debug_string; //alert(postcode+' '+countryid); if(!postcode && !countryid) { if($('#ship_to_billing:checked').val()!=null) { //postcode=$('#billing_postcode').val(); countryid=$('#billing_country').val(); } else { //postcode=$('#shipping_postcode').val(); countryid=$('#shipping_country').val(); } } debug_string="&postcode="+postcode+"&countryid="+countryid; $.ajax({ type: "POST", url: "../ajax/get_shipping_info.php", data: debug_string, beforeSend: function() { $("#cart_shipping_info").show(); $("#cart_shipping_info").html("Loading"); $("#cart_shipping_info").hide(); }, success: function(html){ if(html>=1) { $("#cart_shipping_info").html(html); update_shipping_options(postcode,countryid); } else { $("#cart_shipping_info").html("No address provided."+html); } }, error: function(html) { $("#cart_shipping_info").html(html); } }); } function update_shipping_options(postcode,countryid) { if(!postcode && !countryid) { if($('#ship_to_billing:checked').val()!=null) { postcode=$('#billing_postcode').val(); countryid=$('#billing_country').val(); } else { postcode=$('#shipping_postcode').val(); countryid=$('#shipping_country').val(); } } var debug_string="postcode="+postcode+"&countryid="+countryid; $.ajax({ type: "POST", url: "../ajax/get_shipping_option_box.php", data: debug_string, beforeSend: function() { $("#cart_shipping_options").show(); $("#cart_shipping_options").html("Loading"); }, success: function(html){ $("#cart_shipping_options").html(html); update_shipping_amount(postcode,countryid); }, error: function(html) { $("#cart_shipping_options").html(html); } }); } function set_shipping_option() { selected_shipping_option=$("#shipping_option_id").val(); } function update_shipping_amount(postcode,countryid) { set_shipping_option(); if(!postcode && !countryid) { countryid=$("#country").val(); } var debug_string="postcode="+postcode+"&countryid="+countryid+"&optionid="+selected_shipping_option; $.ajax({ type: "POST", url: "../ajax/get_shipping_price.php", data: debug_string, beforeSend: function() { }, success: function(html){ shipping_amount=parseFloat(html); //alert('updating totals '+debug_string+"...."+html); update_total(); //alert(html); $("#cart_shipping_price").html(html); }, error: function(html) { $("#cart_shipping_price").html(html); } }); } function format_price(amount) { return "£"+number_format(amount,2,'.',''); } function update_cart_total() { get_delivery_information('',$("#country").val()); $.ajax({ type: "POST", url: "../ajax/cart_total_data.php", beforeSend: function() { $("#cart_product_total_cell").show(); $("#cart_product_total_cell").html("Loading"); }, success: function(html){ var qs2 = new Querystring(html) var v1 = qs2.get("name1") //get the line totals and print them for each product line var lineTotals = qs2.get("line_totals"); for (var i=0; i
" + format_price(productInfo.discounted); } else { var resultStr = format_price(productInfo.total); } $("#cart_row_" + productInfo.productid + " td:last-child p strong").html(resultStr); } product_total=qs2.get("cart_total"); //product_total=qs2.get("initial_total"); //discount_amount=0-qs2.get("cart_savings"); update_total(); $("#cart_product_total_cell").html("£"+qs2.get("cart_total")); //$("#cart_product_discounts_cell").html("£"+qs2.get("cart_savings")+"."); $("#cart_num_items").html(qs2.get("num_items")+" items"); get_cart_summary(); if(product_total<=0) { $("#checkout_link").hide(); $("#checkout_link2").hide(); } else { $("#checkout_link").show(); $("#checkout_link2").show(); } }, error: function(html) { $("#cart_total_cell").html(html); } }); } function discount_load_sizes(productid) { if(!productid) { alert('no product specified'); die; } $.ajax({ type: "POST", url: "../ajax/cart_discount_select_product.php", data: "productid="+productid, success: function(html) { $("#cart_discount_dialogue").html("To use this coupon code you will need to add one of the following items to your cart: