jQuery(function( $ ){
	$('#showform').click(function(){
		showContactForm();
		return false;
	});
	$('#contact_form_submit').click(function(){
		validateForm();
	});
});

var show = true;

function showContactForm() {
	if ( show ) {
		$('#contact_form').show();
		show = false;
	} else {
		$('#contact_form').hide();
		show = true;
	}
}

function validateForm() {
	var ok = true;

	var f = document.getElementById("contact_form_form");

	if ( f.name.value == "" ) {
		ok = false;
		f.name.focus();
		alert(msg_req);
		return false;
	}
	if ( f.email.value == "" ) {
		ok = false;
		f.email.focus();
		alert(msg_req);
		return false;
	}
	else if ( !checkEmail(f.email.value) ) {
		ok = false;
		f.email.focus();
		f.email.select();
		alert(msg_email);
		return false;
	}
	if ( f.phone.value == "" ) {
		ok = false;
		f.phone.focus();
		alert(msg_req);
		return false;
	}
	if ( f.comp.value == "" ) {
		ok = false;
		f.comp.focus();
		alert(msg_req);
		return false;
	}
	if ( f.offer.value == "" ) {
		ok = false;
		f.offer.focus();
		alert(msg_req);
		return false;
	}

	if ( ok ) f.submit();
}

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

