/* * General site javascript functions */ $(document).ready(function(){ //expandable menu functionality $('.menu_expands a.expandable').click(function() { if ('.menu_expands a.open') {$(this).next().toggle();} else {$(this).next().slideToggle('slow');} return false; }).next().hide(); //when go to an area, want that area's menu open $('.menu_expands a.open').click(); //expandable area functionality - click to show/hide $('div.toggle').toggle( function(){//odd clicks - show var toggleName = $(this).attr('name'); $('#' + toggleName).slideToggle('slow'); $(this).css('background-image', 'url(img/darrowup.gif)'); }, function(){//even ticks - hide var toggleName = $(this).attr('name'); $('#' + toggleName).slideToggle('slow'); $(this).css('background-image', 'url(img/darrowdown.gif)'); } ) //show appropriate dates for the selected course $(function() { var allOptions = $('#select_date option').clone(); var val = $('#select_course').val(); $('#select_date').html(allOptions.filter('.option-' + val)); if (val == "bm") { //for bike maintenance show options as basic and intermediate $('#course_age').addClass('hide_row'); $('#course_level').removeClass('hide_row'); } else { //for everything else show options as adult and child $('#course_age').removeClass('hide_row'); $('#course_level').addClass('hide_row'); } $('#select_course').change(function() { var val = $(this).val(); $('#select_date').html(allOptions.filter('.option-' + val)); if (val == "bm") { //for bike maintenance show options as basic and intermediate $('#course_age').addClass('hide_row'); $('#course_level').removeClass('hide_row'); } else { //for everything else show options as adult and child $('#course_age').removeClass('hide_row'); $('#course_level').addClass('hide_row'); } }); }); //make external links and pdfs open in a new tab/window and add pdf icon var myUrl = location.protocol + '//' + location.hostname; $('a[href^=http://]').not('[href^='+myUrl+']').attr('target','_blank'); $('a[href$=.pdf]').attr('target','_blank'); $('a[href$=.pdf] > h2 > div.text').css('width', '90%'); $('a[href$=.pdf] > h2').css('background', 'url(img/pdf.png) no-repeat 96% center'); //make text that does an action show the cursor as a pointer $('.menu_expands h2, h2.toggle').css('cursor', 'pointer'); //send email functionality for register interest form //hide any error messages by default $('tr.messages').addClass('hide_row'); $('#send_interest').click(function(e){ //stop the form from being submitted e.preventDefault(); var error = false; var name = $('#name').val(); var email = $('#email').val(); var select_date = $('#select_date').val(); var select_course = $('#select_course').val(); //reset the error messages and then show any that now apply $('tr.messages').addClass('hide_row'); if(name.length == 0) { var error = true; $('#name_error').removeClass('hide_row'); } if(email.length == 0 || email.indexOf('@') == '-1'){ var error = true; $('#email_error').removeClass('hide_row'); } if (select_course == "bm") { if ($("input[@name='course_level']:checked").val() == 'int') { var course_age = 'intermediate'; } else if ($("input[@name='course_level']:checked").val() == 'basic') { var course_age = 'basic'; } else //nothing selected { var error = true; $('#course_level_error').removeClass('hide_row'); } } else { if ($("input[@name='course_age']:checked").val() == 'adult') { var course_age = 'adult'; } else if ($("input[@name='course_age']:checked").val() == 'child') { var course_age = 'child'; } else //nothing selected { var error = true; $('#course_age_error').removeClass('hide_row'); } } if(select_date.length == 0){ var error = true; $('#select_date_error').removeClass('hide_row'); } if(select_course.length == 0){ var error = true; $('#select_course_error').removeClass('hide_row'); } if(error == false){ //temporarily disable submit button and change button text to Sending... $('#send_interest').attr({'disabled' : 'true', 'value' : 'sending...' }); // send email via ajax call to send_email.php using function serialize() to get all the form data $.post("send_email.php?type=interest", $("#interest_form").serialize(),function(result){ if(result == 'sent'){ // remove the submit paragraph and show the mail success div $('#errorInterest').addClass('hide_row'); $('#successInterest').removeClass('hide_row'); }else{ //show the mail failed div $('#errorInterest').removeClass('hide_row'); $('#successInterest').addClass('hide_row'); } //re-enable the submit button $('#send_interest').removeAttr('disabled').attr('value', 'submit'); }); } }); //send email functionality for contact us form //hide any error messages by default $('tr.messages').addClass('hide_row'); $('#send_contact').click(function(e){ //stop the form from being submitted e.preventDefault(); var error = false; var name = $('#name').val(); var email = $('#email').val(); var message = $('#message').val(); //reset the error messages and then show any that now apply $('tr.messages').addClass('hide_row'); if(name.length == 0) { var error = true; $('#name_error').removeClass('hide_row'); } if(email.length == 0 || email.indexOf('@') == '-1'){ var error = true; $('#email_error').removeClass('hide_row'); } if(message.length == 0){ var error = true; $('#message_error').removeClass('hide_row'); } if(error == false){ //disable submit button to avoid spamming and change button text to Sending... $('#send_contact').attr({'disabled' : 'true', 'value' : 'sending...' }); // send email via ajax call to send_email.php using function serialize() to get all the form data $.post("send_email.php?type=contact", $("#contact_form").serialize(),function(result){ if(result == 'sent'){ // remove the submit paragraph and show the mail success div with fadeIn $('#submit_button').remove(); $('#errorContact').hide(); $('#successContact').fadeIn(500); }else{ //show the mail failed div and reenable the submit button $('#errorContact').fadeIn(500); $('#send_contact').removeAttr('disabled').attr('value', 'send enquiry'); } }); } }); });