jQuery(document).ready(function($){ $.validator.addMethod("alphanumeric", function(value, element) { return /^[a-zA-Z0-9 ]{0,}$/.test(value); },"Letters, numbers or spaces only please"); $.validator.addMethod("numericspace", function(value, element) { return /^[0-9 ]{0,}$/.test(value); },"Letters and spaces only please"); //------------------------------ / //Name: image_add / //Description: Adds images after / //an element / //Args: id:element id / // img_id: image id / // image: the image name / //Returns: html image code / //------------------------------ / function image_add(id,img_id,image){ $(id).after(''); } // ------------------------------ / // Name: image_remove / // Description: Removes any element / // by its id / // Args: id:element id / // Returns: nothing / // ------------------------------ / function image_remove(id){ $(id).remove(); } // ------------------------------ / // Name: load_method / // Description: populates the / // delivery method dropdown box / // Args:None / // Returns: populates delivery / // method dropdown box / // ------------------------------ / //wpevent_quick_menu function load_method(){ //apply waiting image //remove any greentick images image_remove('#greentick_course'); image_remove('#greentick_method'); image_remove('#greentick_options'); image_remove('#greentick_city'); image_remove('#greentick_date'); image_add('#course','loading','loading.gif'); //disable all select field attributes but courses $('#wpevent_quick_method').attr("disabled", true); $('#wpevent_quick_options').attr("disabled", true); $('#wpevent_quick_city').attr("disabled", true); $('#wpevent_quick_date').attr("disabled", true); $('#wp_quick_book_button').attr("disabled", true); //if no course is selected, do nothing and remove loading image if($('#course').val() == 'void'){ image_remove('#loading'); } else{ var post_id = $('#course').val(); //send page/post id via post over ajax to function wpevent_ajax_quick_menu $.post('http://www.planittesting.co.nz/wp-load.php',{wpevent_quick_action:'course',wpevent_quick_menu_post_id:post_id},function(data){ //Remove select options from delivery method dropdown list so appended doesn't duplicate entries. $('#wpevent_quick_method >option').remove(); //if function wpevent_ajax_quick_menu is successful if(data.error == 'success'){ //append option to delivery options drowndown menu $('#wpevent_quick_method').append( $('').val('void').html('Select Delivery Method') ); //append option to delivery options drowndown menu from data returns from ajax query $.each(data, function(val, text) { //loop through data results, igonore the success message and populate delivery options drowndown list. if(text != 'success'){ $('#wpevent_quick_method').append( $('').val(val).html(text) ); } }); //enable delivery method dropdown list so its selectable $('#wpevent_quick_method').removeAttr("disabled"); //add greentick image image_add('#course','greentick_course','greentick.png'); //remove loading image image_remove('#loading'); } else{ //failed to recieve the correct data back from post so just add the select menu $('#wpevent_quick_method').append( $('').val('void').html('Select Delivery Method') ); //disable the delivery method dropdown list $('#wpevent_quick_method').attr("disabled", true); //Remove loading image image_remove('#loading'); }; }, "json" ); } } if($('#course').val() != 'void'){ $('#wpevent_quick_method').removeAttr("disabled"); load_method(); } //On course dropdown list change do the following $('#course').change(function(){ load_method(); }); //On delivery method dropdown list change do the following $('#wpevent_quick_method').change(function(){ image_remove('#greentick_method'); image_remove('#greentick_options'); image_remove('#greentick_city'); image_remove('#greentick_date'); image_add('#wpevent_quick_method','loading','loading.gif'); $('#wpevent_quick_options').attr("disabled", true); $('#wpevent_quick_date').attr("disabled", true); $('#wpevent_quick_city').attr("disabled", true); $('#wp_quick_book_button').attr("disabled", true); $("#wpevent_cart_event").remove(); var method_value = $("#wpevent_quick_method").val(); if(method_value == '2'){ $("#wpevent_quick_date").hide(); $("#wpevent_quick_city").hide(); } else{ $("#wpevent_quick_date").show(); $("#wpevent_quick_city").show(); } if($('#wpevent_quick_method').val() =='void'){ image_remove('#loading'); } else{ var post_id = $('#course').val(); $('#wpevent_quick_options').attr("disabled", true); $('#wp_quick_book_button').attr("disabled", true); $("#wpevent_cart_event").remove(); $.post('http://www.planittesting.co.nz/wp-load.php',{wpevent_quick_action:'method',wpevent_quick_menu_post_id:post_id,wpevent_quick_menu_method:$('#wpevent_quick_method').val()},function(data){ $('#wpevent_quick_options >option').remove(); $('#wpevent_quick_options').append( $('').val('void').html('Select Course Options') ); if(data.error == 'success'){ $.each(data, function(val, text) { if(text != 'success'){ $('#wpevent_quick_options').append( $('').val(val).html(text) ); } }); image_remove('#loading'); image_add('#wpevent_quick_method','greentick_method','greentick.png'); $('#wpevent_quick_options').removeAttr("disabled"); } if(data.error == 'fail'){ $('#wpevent_quick_city >option').remove(); $('#wpevent_quick_city').append( $('').val('void').html('No course available') ); image_remove('#loading'); $('#wpevent_quick_city').removeAttr("disabled"); } }, "json" ); } }); //on option dropdown list change do the following $('#wpevent_quick_options').change(function(){ image_remove('#greentick_options'); image_remove('#greentick_city'); image_remove('#greentick_date'); image_add('#wpevent_quick_options','loading','loading.gif'); $('#wpevent_quick_city').attr("disabled", true); $('#wpevent_quick_date').attr("disabled", true); $('#wp_quick_book_button').attr("disabled", true); $("#wpevent_cart_event").remove(); var post_id = $('#course').val(); var options_value = $("#wpevent_quick_options").val(); if(options_value == 'void'){ image_remove('#loading'); } else{ if($('#wpevent_quick_method').val() == '2'){ var price_id = $("#wpevent_quick_options").val(); $.post('http://www.planittesting.co.nz/wp-load.php',{wpevent_quick_action:'method_online',wpevent_quick_menu_post_id:post_id,wpevent_quick_menu_method:$('#wpevent_quick_method').val(),wpevent_quick_menu_price_id:price_id},function(data){ if(data != ""){ $('#wpevent_quick').append(''); image_add('#wpevent_quick_options','greentick_options','greentick.png'); } else{ $('#wp_quick_book_button').attr("disabled", true); } image_remove('#loading'); }, "html" ); // $('#wp_quick_book_button').removeAttr("disabled"); } else{ $('#wp_quick_book_button').attr("disabled", true); $('#wpevent_quick').append(''); $.post('http://www.planittesting.co.nz/wp-load.php',{wpevent_quick_action:'options',wpevent_quick_menu_post_id:post_id,wpevent_quick_menu_method:$('#wpevent_quick_method').val()},function(data){ $('#wpevent_quick_city >option').remove(); $('#wpevent_quick_city').append( $('').val('void').html('Select City') ); if(data.error == 'success'){ $.each(data, function(val, text) { if(text != 'success'){ $('#wpevent_quick_city').append( $('').val(val).html(text) ); } }); image_remove('#loading'); image_add('#wpevent_quick_options','greentick_options','greentick.png'); $('#wpevent_quick_city').removeAttr("disabled"); } if(data.error == 'fail'){ $('#wpevent_quick_city >option').remove(); $('#wpevent_quick_city').append( $('').val('void').html('No course available') ); image_remove('#loading'); $('#wpevent_quick_city').removeAttr("disabled"); } }, "json" ); // } } }); //On city dropdown list change do the following $('#wpevent_quick_city').change(function(){ image_remove('#greentick_date'); image_remove('#greentick_city'); image_add('#wpevent_quick_city','loading','loading.gif'); var city_id = $("#wpevent_quick_city").val(); if(city_id =='void'){ image_remove('#greentick_city'); $('#wpevent_quick_date >option').remove(); $('#wpevent_quick_date').attr("disabled", true); $('#wp_quick_book_button').attr("disabled", true); image_remove('#loading'); } else{ var post_id = $("#course").val(); var price_id = $("#wpevent_quick_options").val(); $.post('http://www.planittesting.co.nz/wp-load.php',{wpevent_quick_action:'city',wpevent_quick_menu_post_id:post_id,wpevent_quick_menu_city_id:city_id,wpevent_quick_menu_price_id:price_id},function(data){ $('#wpevent_quick_date >option').remove(); if(data.error == 'success'){ $('#wpevent_quick_date').append( $('').val('void').html('Select Date') ); $.each(data, function(val, text) { if(text != 'success'){ $('#wpevent_quick_date').append( $('').val(val).html(text) ); } }); image_remove('#loading'); image_add('#wpevent_quick_city','greentick_city','greentick.png'); $('#wpevent_quick_date').removeAttr("disabled"); } }, "json" ); } }); //On date dropdown list change do the following $('#wpevent_quick_date').change(function(){ image_remove('#greentick_date'); if($('#wpevent_quick_date').val() == 'void'){ $('#wp_quick_book_button').attr("disabled", true); } else{ $('#wp_quick_book_button').removeAttr("disabled"); image_add('#wpevent_quick_date','greentick_date','greentick.png'); } }); $('#wp_quick_book_button').click(function(){ if($('#wpevent_quick_menu_inline').val() == 'true'){ var event_online = $('#wpevent_cart_event').val(); if(event_online == 'false' || event_online ==''){ var event = $('#wpevent_quick_date').val(); } else{ event = event_online; } $.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_add',course_id:event},function(data){ if(data == 'success'){ $.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_items'},function(data){ $("#checkout_items").html(data); checkout_fetch_personel_details(); $("#addcourseform").dialog('close') },"html" ); } },"html" ); return false; } }); //wpevent_quick_menu end //wpevent_checkout_process $("#process").dialog({ bgiframe: true, autoOpen: false, height: 300, modal: true, closeOnEscape: false, open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); $("#validate_information").html("Validating Information. Please wait..."); } }); /*$("#bookButton").click(function(){ //$('#process').dialog('open'); var client = $("#details").serialize(); alert(client); //$("#validate_information").html(str); });*/ //wpevent_add_course $("#addcourseform").dialog({ autoOpen: false, height: 300, modal: true, closeOnEscape: true, beforeclose: function(event, ui) { return true; } }); $("#addrequestform").dialog({ autoOpen: false, height: 300, modal: true, closeOnEscape: true, beforeclose: function(event, ui) { return true; } }); $(".btn_register").click(function(){ $('#addcourseform').dialog('open'); return false; }); $(".btn_bookonline").click(function(){ $('#addcourseform').dialog('open'); return false; }); $(".btn_freeinfo").click(function(){ $('.copycourse').val($('h1').text()); //$('.copycourse').attr("disabled", true); $('#addrequestform').dialog('open'); return false; }); $("#addcourse").live('click',function(){ $('#addcourseform').dialog('open'); return false; }); $(".wpevent_cart_contents_delete").live("click",function(){ var id = $(this).attr("id"); $.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_delete',checkout_delete_id:id},function(data){ if(data == 'success'){ $.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_items'},function(data){ $("#checkout_items").html(data); checkout_fetch_personel_details(); },"html" ); } //$('#cart tr:last').after(data); },"html" ); return false; }); $(".wpevent_cart_contents_edit").live("click",function(){ $(".wpevent_cart_contents_edit").toggle( function () { var id = $(this).attr("id"); $('#quantity_'+id).removeAttr("disabled"); $(this).html("Save"); }, function () { var id = $(this).attr("id"); var amount = $('#quantity_'+id).attr("value"); $('#quantity_'+id).attr("disabled", true); $.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_update',checkout_update_id:id,checkout_update_amount:amount},function(data){ if(data == 'success'){ $.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_items'},function(data){ $("#checkout_items").html(data); checkout_fetch_personel_details(); },"html" ); } //$('#cart tr:last').after(data); },"html" ); $(this).html("Edit"); } ); return false; }); //checkout page populate personal details down $(".populate_down").live("click",function(){ var pop_id = $(this).attr("id").replace('pop_',''); pop_id = parseInt(pop_id); //add one fill_id = pop_id + 1; $("#first_name_"+fill_id).val($("#first_name_"+pop_id).val()); $("#last_name_"+fill_id).val($("#last_name_"+pop_id).val()); $("#email_"+fill_id).val($("#email_"+pop_id).val()); $("#phone_"+fill_id).val($("#phone_"+pop_id).val()); return false; }); $(".populate_down_checkout_details").live("click",function(){ $("#checkout_firstname").val($("#first_name_1").val()); $("#checkout_lastname").val($("#last_name_1").val()); $("#checkout_email").val($("#email_1").val()); $("#checkout_phone").val($("#phone_1").val()); return false; }); $("#checkout_details").validate({ errorPlacement: function(error, element) { error.insertBefore(element); }, submitHandler: function(form) { //remove all ticks and crosses image_remove('#loading'); //$('#process').dialog('open'); var client = $("#checkout_details").serialize(); var checkout_final_price = $("#checkout_final_price").html(); $('#process').dialog('open'); //send data for validation image_add('#validate_information','loading','loading.gif'); $.post('http://www.planittesting.co.nz/wp-load.php',client+'&action=checkout_process&amount='+checkout_final_price,function(data){ if(data == 'success'){ image_remove('#loading'); $("#validate_information").html("Booking Successful"); window.location = "https://www.planittesting.co.nz/checkout/thankyou/"; //$(".ui-dialog-titlebar-close").show(); } else{ image_remove('#loading'); $("#validate_information").html(data); $(".ui-dialog-titlebar-close").show(); } },"html"); } }); }); function checkout_fetch_personel_details(){ jQuery.post('http://www.planittesting.co.nz/wp-load.php',{action:'checkout_personel_details'},function(data){ jQuery('#personel_details').html(data); }, "html" ); }