/**
 * Contact
 */
function checkEmail() {
	var contact_email = $("#contact_email").val();
	
	$.getJSON( basePath+'/tools/email/?email='+contact_email+"&callback=?",
			function(data){
				if(!data.success){
					// E-mail invalide
					alert('E-mail not valid. Please type it again.');
				}
			});
	
	return false;
}

function checkEmailFinal() {
	var contact_email = $("#contact_email").val();
	
	// Vérification qu'une région a été choisie
	if ($('#contact_us').attr('checked')==false && $('#contact_us').attr('checked')==false) {
		alert('Please choose a destination before sending your message.');
		return false;
	}
	
	$.getJSON( basePath+'/tools/email/?email='+contact_email+"&callback=?",
			function(data){
				if (data.success) {
					document.forms['formcontact'].submit();
					return true;
				}
				else {
					alert('E-mail not valid. Please type it again.');
					// $("#contact_email").focus();
				}
			});
	return false;
}

/**
 *
 */
$(document).ready(function(){
	// Ouverture de la Thickbox si le formulaire a été validé
	if (wasFormSent) {
		tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage;
		tb_show(null, basePath+'/'+lan+'/contact/confirm/?KeepThis=true&TB_iframe=true&width=244&height=200&modal=true', false);
	}
	
	// Listeners
	$("#contact_email").blur(checkEmail);
	$("#contact_submit").click(checkEmailFinal);
});
