

jQuery.extend({
	callModal : function(html, height, width, containerClass){
		$('<div class="'+containerClass+'">'+html+'</div>').modal({
			containerCss: {
			    height: height,
			    width: width,
			    
			    border: '3px solid #ccc'
			}
			, overlayCss: {
			    
			    cursor: 'wait'
			}
			, onOpen: function (dialog) {
				dialog.overlay.fadeIn('slow', function () {
					dialog.container.slideDown('slow', function () {
						dialog.data.fadeIn('slow');
					});
				});
			}
			, onClose: function (dialog) {
				dialog.data.fadeOut(200, function () {
				    dialog.container.slideUp(200, function () {
				      dialog.overlay.fadeOut(200, function () {
				        $.modal.close(); // must call this!
				      });
				    });
				});
			}
		});
	}
});

$(document).ready(function(){
	$('#simplemodal-overlay').live('click', function() {
		$.modal.close();
	});
	
	$('.btn_hotel').live('click', function() {
		$('#loadingOverLay').animate({opacity:'.5'}, 500).slideDown('slow');
		$.ajax({
			data: {Identifier: $(this).attr('id').replace('bTn_', ''), ajax: true}
			, dataType: 'html'
			, type: 'get'
			, url: './formcontact.php'
			, complete : function() {
				$('#loadingOverLay').slideUp('slow');
			}
			, success: function(html) {
				$.callModal(html, 515, 660, "simplemodal-scroll-medium");
			}
		});//fin $.ajax()
	});
	$('a[rel="simplemodal"], a.simplemodal').live('click', function() {
		$.modal.close();
		$('#loadingOverLay').animate({opacity:'.5'}, 500).slideDown('slow');
		$.ajax({
			data: {ajax: true}
			, dataType: 'html'
			, type: 'get'
			, url: $(this).attr('href')
			, complete : function() {
				$('#loadingOverLay').slideUp('slow');
			}
			, success: function(html) {
				$.callModal(html, 600, 760, "simplemodal-scroll-large");
				$('.simplemodal-scroll-large a.lightbox').lightBox();
			}
		});//fin $.ajax()
		return false;
	});
	
});


function isValidEmail(str) {
	   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function submitFormContact() {
	if( $('input[name=civilite]:checked').val() == null) {
		alert("Le champ civilité n'est pas sélectionné!")
		return false;
	}
	if( $('input[name=nom]').val() == ""){
		alert("Le champ nom n'est pas rempli!")
		return false;
	}
	if( $('input[name=prenom]').val() == ""){
		alert("Le champ prenom n'est pas rempli!")
		return false;
	}
	if( $('input[name=mail]').val() == ""){
		alert("Le champ email n'est pas rempli!")
		return false;
	}
	if( 
			$('input[name=type_hotel1]:checked').val() == null &&
			$('input[name=type_hotel2]:checked').val() == null &&
			$('input[name=type_hotel3]:checked').val() == null &&
			$('input[name=type_hotelNC]:checked').val() == null 
	  ) {
		alert("Il faut selectionner au moins un type d'hotel !")
		return false;
	}

	if(!checkEmail($('input[name=mail]').val()) ) {
		alert("Le champ email n'est pas au bon format!")
		return false;
	}
	$("form[name=formcontact]").submit();
}

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	}else {
		return true;
	}
}