var url = "";
function hideForm() {
	$(".form-container").toggle("fast");
}
$(document).ready(function() {
	/* text replacement */
	Cufon.replace('.replace, .dropdown-off, .dropdown-off-parts, .stock-dropdown-on, .aps-title, #price-block, .small-pinkhead, .bold-heading, #sale-strip, .pink-heading, #part-heading, .parts-name, .parts-price, .parts-code, .bottom-price, .parts-id, .parts-details, .pink-button, .shopping-title, .pink-findoutmore, .pink-details, .cart-title', {fontFamily: 'Helvetica'});
	
	$(".call-back, .cancel-advice").click(function() {
		$(".form-container").toggle("fast");
		return false;
	});	
	
	$(".advice-form").submit(function() {
		var name = this.advice_name.value;
		var phone = this.advice_number.value;
		var date = this.advice_date.value;
		var time = this.advice_time.value;
		
		if(name == "" || phone == "" || date == "" || time == "") {
			alert("Please fill in all fields.");
			return false;
		} else {
			$.ajax({
				type: "POST",
				url: ""+url+"/includes/callback.php",
				timeout: 7000,
				data: "name="+name+"&telephone="+phone+"&date="+date+"&time="+time,
				success: function() {
					$('.form_holder').fadeOut(500);
					setTimeout("$('.form_holder_2').fadeIn(500)", 600);
				}
			});
		}
		return false;
	});
	
	function validEmail (email) {
		reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4}|museum|travel)$/
		return reg.test (email); 
	}
	
	$("form#contact").submit(function() {
		var company = this.company.value;
		var name = this.name.value;
		var phone = this.telephone.value;
		var email = this.email.value;
		var enquiry = this.enquiry.value;
		var hiddencode = this.hiddencode.value;
		var code = this.code.value;
		
		if(company == "" || name == "" || phone == "" || email == "" || enquiry == "" || validEmail(email) == false) {
			alert("Please ensure all fields are filled in correctly and that you have entered a valid email address.");
			return false;
		} else {
			if(hiddencode !== code) {
				alert("Please enter the security verification code in the box shown.");
				return false;
			} else {
				$.ajax({
					type: "POST",
					url: ""+url+"/includes/submit-contact-form.php",
					timeout: 2000,
					data: "company="+company+"&name="+name+"&phone="+phone+"&email="+email+"&enquiry="+enquiry,
					success: function(){
						$('#success').fadeIn('fast');
						setTimeout("window.location='"+url+"/thank_you_contact_us.php'", 2000);
					}
				});
			}
		}
		return false;
	});

});