// JavaScript Document
function isValidEmail(str) { 
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str)){
	return false
	}else{
		return true
	}
}
$(document).ready(function() {
	$(document).pngFix(); 
	$('#stats').innerfade({
				animationtype: 'slide',
				speed: 600,
				timeout: 7000,
				type: 'sequence',
				containerheight: '1em'
	});
	$("input[type='text'],input[type='password'],textarea").focus(function(){
		$(this).addClass("highlighted")
		if (!$(this).hasClass('changed')){

			$(this).addClass('changed')
				var index = $("input[type='text'],input[type='password'],textarea").index(this);
				window["input"+index] = $(this).val();
				$(this).val("")
		}
	
	})
	$("input[type='text'],input[type='password'],textarea").blur(function(){
		$(this).removeClass("highlighted")
			if ($(this).val()==""){
				var index = $("input[type='text'],input[type='password'],textarea").index(this);		
				$(this).val(window["input"+index])
				$(this).removeClass('changed')
			}
	})
	$('.footer form').ajaxForm({ beforeSubmit:  validateSubmit, success: response });	
});
function validateSubmit(){

	if (!$('#name').hasClass("changed")){
		alert('Please correct your name');
		$('#name').focus()
		return false
	}
	if (!isValidEmail($('#email').val())){
		alert('Please correct your email');
		$('#email').focus()
		return false
	}
	if (!$('#enquiry').hasClass("changed")){
		alert('Please enter your enquiry');
		$('#enquiry').focus()
		return false
	}
}
function response(){
//	alert('done');
$('.footer form').html("<p>Thank you for your enquiry. We will be in touch shortly.</p>")
}
