// SCRIPTS FOR ACTIVEHEALTHCLUBS.COM.AU - An AWD project, awd.com.au


// Initialisation scripts to be executed when the page has finished loading
$(document).ready( function() {
																												  // Load Boxy CSS
																														document.getElementById('boxy_css').href = '/library/styles_boxy.css';
																												})


// PAGE FADER
function doFade(showThisDiv,showThisHash) {
	  if (!$('#'+showThisDiv).length) {
					showThisDiv = $("#programs_content div:first").attr('id');
					myIndex = showThisDiv.indexOf('_') + 1;
					showThisHash = $('#'+showThisDiv).attr('id').substr(myIndex);
			}
	  $("div#programs_content div:visible").fadeOut(500,function() {
																																																																		  $('#'+showThisDiv).fadeIn(500);
																																																																		});
			window.location.hash = showThisHash;
}



// E-MAIL ADDRESS VALIDATOR
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}



// MEMBERSHIP ENQUIRY SUBMITTER
function submitEnquiry() {
  var name = document.getElementById('enq_name').value;
		var email = document.getElementById('enq_email').value;
		var phone = document.getElementById('enq_phone').value;
		var message = document.getElementById('enq_message').value;
		var subscribe = 	(document.getElementById('enq_subscribe').checked ? 'true' : 'false');
		
		if (isValidEmail(email) && name != '' && phone != '') {
			 jQuery.post('/library/ajax/membership_enquiry.php',{ 'enq_name': name, 'enq_email': email, 'enq_phone': phone, 'enq_message': message, 'enq_subscribe': subscribe }, function(data) {
																																																																					  if (data.status != 'success'){
																																																																								 Boxy.alert(data.message, null, {title: 'Submission error', draggable: false, modal: true});
																																																																							} else {
																																																																								 $("#form_fields").fadeOut("slow",function(){
																																																																																																																			  $("#submission_status").fadeIn("slow");
																																																																																																																			});
																																																																							}
																																																																					}, "json");
		} else if (name == '' || phone == '') {
		  Boxy.alert('Please enter both your name and phone number before submitting your enquiry.',null, {title: 'Submission error', draggable: false, modal: true});
		} else if (!isValidEmail(email)) {
			 Boxy.alert('Please enter a valid e-mail address before submitting your enquiry.',null, {title: 'Submission error', draggable: false, modal: true});
		}
}




// CONTACT FORM SUBMITTER
function submitContact() {
  var name = document.getElementById('contact_name').value;
		var email = document.getElementById('contact_email').value;
		var subject = document.getElementById('contact_subject').value;
		var message = document.getElementById('contact_message').value;
		// var subscribe = 	(document.getElementById('contact_subscribe').checked ? 'true' : 'false');
		
		if (isValidEmail(email)) {
			 jQuery.post('/library/ajax/contact_form.php',{ 'contact_name': name, 'contact_email': email, 'contact_subject': subject, 'contact_message': message }, function(data) {
																																																																					  if (data.status != 'success'){
																																																																								 Boxy.alert(data.message, null, {title: 'Submission error', draggable: false, modal: true});
																																																																							} else {
																																																																								 $("#form_fields").fadeOut("slow",function(){
																																																																																																																			  $("#submission_status").fadeIn("slow");
																																																																																																																			});
																																																																							}
																																																																					}, "json");
		}
}