$(document).ready(
	function()
	{
		
		$('#date').DatePicker({
			format:'d-m-y',
			date: $('#date').val(),
			current: $('#date').val(),
			starts: 1,
			position: 'r',
			onBeforeShow: function(){
				$('#date').DatePickerSetDate($('#date').val(), true);
			},
			onChange: function(formated, dates){
				$('#date').val(formated);
				$('#date').DatePickerHide();
			}
		});

		var testimonials_showing = false;
		$('#toggle_testimonial').click(function()
			{
				if (testimonials_showing == false){
					testimonials_showing = true;
					$(".testimonials_box").slideDown();
					$('#toggle_testimonial').html('Close organiser testimonials');
					$('#toggle_testimonial').attr("title","Close organiser testimonials");
				}else{
					testimonials_showing = false;
					$(".testimonials_box").hide();
					$('#toggle_testimonial').html('Read organiser testimonials');
					$('#toggle_testimonial').attr("title","Read organiser testimonials");
				}
			}
		);

		$('#close_testimonials').click(function()
			{
				$(".testimonials_box").hide();
				testimonials_showing = false;
				$('#toggle_testimonial').html('Read organiser testimonials');
				$('#toggle_testimonial').attr("title","Read organiser testimonials");
			}
		);
		
		
		$('#faq-list').accordion({ 
			header: '.faq-q', 
			active: 0, 
			alwaysOpen: false, 
			animated: 'slide', 
			autoheight: true 
		});

$.extend($.modal.defaults, {
	closeClass: "modalClose",
	closeHTML: "<a href='#' title='Close' class='close-x'>X</a>"
});

		$('#join_form').submit(function()
			{	
				var error = false;
				var eh = "<div>";
				eh += "<h2>Please correct the following errors:</h2>";
				eh += "<ul>";
				var fname = $('#first_name').val();
				if (fname == ""){
					error = true;
					eh += "<ul>Please provide your First Name.</ul>";
				}
				var sname = $('#surname').val();
				if (sname == ""){
					error = true;
					eh += "<ul>Please provide your Surname.</ul>";
				}
				var dob = $('#dob').val();
				if (dob == ""){
					error = true;
					eh += "<ul>Please provide your Date of Birth.</ul>";
				}
				var email = $('#email').val();
				if (email == ""){
					error = true;
					eh += "<ul>Please provide your Email Address.</ul>";
				}
				var city = $('#city').val();
				if (city == ""){
					error = true;
					eh += "<ul>Please provide your City.</ul>";
				}
				var add1 = $('#address1').val();
				if(add1 == "")
				{
					error = true;
					eh += "<ul>Please provide your Address.</ul>";
				}
				var add2 = $('#address2').val();
				//if(add2 == "")
				//{
				//	error = true;
				//	eh += "<ul>Please provide your Address</ul>";
				//}
				var post = $('#post').val();
				if (post == ""){
					error = true;
					eh += "<ul>Please provide your Post Code.</ul>";
				}
				var number = $('#number').val();
				if (number == ""){
					error = true;
					eh += "<ul>Please provide your Contact Number.</ul>";
				}
				var optin = $('#optin').attr("checked") ? $(this).val() : 0
				if (optin == "0"){
					optin = "N";
				}else{
					optin = "Y";
				}
				
				var age = $('#age').attr("checked") ? $(this).val() : 0
				if (age == "0"){
					error = true;
					eh += "<ul>Please agree that you are over 18 years of age.</ul>";
					age = "N";
				}else{
					age = "Y";
				}
				
				eh += "</ul>";
				eh += "</div>";
				
				if (error == true){
					$.modal(eh,{overlayClose:true});
				}else{
					var dataString = 'fname='+ fname + '&sname=' + sname + '&dob=' + dob + '&number=' + number + '&email=' + email + '&city=' + city + '&add1='+ add1 + '&add2=' + add2 + '&post=' + post + '&optin=' + optin + '&age=' + age + '&action=jointeam';
					$.ajax({  
					  type: "POST",  
					  url: "process.php",  
					  data: dataString,  
					  success: function() {  
							//alert("Success!!!");
							var sm = "<div>";
							sm += "<h2>Thank you</h2>";
							sm += "<p>Thank you for your interest in becoming an Ann Summers Party Organiser! We will we be contacting you soon with further information on joining the Ann Summers Party team with the details provided.</p>";
							sm += "</div>";
							$.modal(sm,{overlayClose:true,minHeight:110});
							$('#first_name').val("");
							$('#surname').val("");
							$('#dob').val("");
							$('#email').val("");
							$('#city').val("");
							$('#address1').val("");
							$('#address2').val("");
							$('#post').val("");
							$('#number').val("");
							$('#optin').attr('checked', true);
							$('#age').attr('checked', false);
					    }
					}); 
				}
				return false;
			}
		);
		
		$('#book_form').submit(function()
			{	
				var error = false;
				var eh = "<div>";
				eh += "<h2>Please correct the following errors:</h2>";
				eh += "<ul>";
				var date = $('#date').val();
				if (date == ""){
					error = true;
					eh += "<ul>Please provide your Preferred Date.</ul>";
				}
				var fname = $('#first_name').val();
				if (fname == ""){
					error = true;
					eh += "<ul>Please provide your FirstName.</ul>";
				}
				var sname = $('#surname').val();
				if (sname == ""){
					error = true;
					eh += "<ul>Please provide your Surname.</ul>";
				}
				var dob = $('#dob').val();
				if (dob == ""){
					error = true;
					eh += "<ul>Please provide your Date of Birth.</ul>";
				}
				var email = $('#email').val();
				if (email == ""){
					error = true;
					eh += "<ul>Please provide your Email Address.</ul>";
				}
				var city = $('#city').val();
				if (city == ""){
					error = true;
					eh += "<ul>Please provide your City.</ul>";
				}
				var post = $('#post').val();
				//if (post == ""){
				//	error = true;
				//	eh += "<ul>Please provide your Post Code</ul>";
				//}
				var number = $('#number').val();
				//if (number == ""){
				//	error = true;
				//	eh += "<ul>Please provide your Contact Number</ul>";
				//}
				var message = $('#message').val();
				if (message == ""){
					error = true;
					eh += "<ul>Please provide a Message.</ul>";
				}
				var optin = $('#optin').attr("checked") ? $(this).val() : 0
				if (optin == "0"){
					optin = "N";
				}else{
					optin = "Y";
				}
				
				var age = $('#age').attr("checked") ? $(this).val() : 0
				if (age == "0"){
					error = true;
					eh += "<ul>Please agree that you are over 18 years of age.</ul>";
					age = "N";
				}else{
					age = "Y";
				}
				
				eh += "</ul>";
				eh += "</div>";
				
				if (error == true){
					$.modal(eh,{overlayClose:true});
				}else{
					var dataString = 'fname='+ fname + '&sname=' + sname + '&dob=' + dob + '&date=' + date + '&number=' + number + '&email=' + email + '&city=' + city +'&post=' + post + '&message=' + message + '&optin=' + optin + '&age=' + age + '&action=bookparty';
					$.ajax({  
					  type: "POST",  
					  url: "process.php",  
					  data: dataString,  
					  success: function() {  
							//alert("Success!!!");
							var sm = "<div>";
							sm += "<h2>Thank you</h2>";
							sm += "<p>Thank you for your interest in hosting an Ann Summers Party! We will we be contacting you within 2 working days to finalise the details of your Party</p>";
							sm += "</div>";
							$.modal(sm,{overlayClose:true,minHeight:110});
							$('#first_name').val("");
							$('#surname').val("");
							$('#dob').val("");
							$('#email').val("");
							$('#city').val("");
							$('#post').val("");
							$('#number').val("");
							$('#message').val("");
							$('#optin').attr('checked', true);
							$('#age').attr('checked', false);
					    }
					}); 
				}
				return false;
			}
		);
	
	}
);

