/* ================================================================================ */
/* = fonctions = */
/* ================================================================================ */

$(document).ready(function() {
	$("#togglerVols").click(function() {
		// toggle all .toggable classed elements
		//$(".toggable").toggle();
		$("#rechercheCETOVols").show();
		$("#rechercheCETO").hide();
		$("#btn_vols").show();
		$("#btn_vols_off").hide();
		$("#btn_sejours").show(); // id label incoherent
		$("#btn_sejours_off").hide(); // id label incoherent
		return false;
	});
	$("#togglerSejours").click(function() {
		// toggle all .toggable classed elements
		//$(".toggable").toggle();
		$("#rechercheCETOVols").hide();
		$("#rechercheCETO").show();
		$("#btn_vols").hide();
		$("#btn_vols_off").show();
		$("#btn_sejours_off").show(); // id label incoherent
		$("#btn_sejours").hide(); // id label incoherent
		return false;
	});
	
	// menu
	$('#nav ul').hide();
	//$("#nav li").mouseover(function(){$(this).addClass("curent");$(this).children("ul").show();});
	$("#nav li").mouseover(function(){$(this).children("ul").show();});
	//$("#nav li").mouseout(function(){$(this).removeClass();$(this).children("ul").hide();});
	$("#nav li").mouseout(function(){$(this).children("ul").hide();});
		
	// home page cyclage bandeau		
	//$('.slideshow').cycle('fade');	
	// if there's any .slideshow elem out there :
	if($('.slideshow').length)
	{
		$('.slideshow').cycle({
			fx:			'fade',
			autostop: 	1
		});
	}

});

function checkEmail(str) {
	if (/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/.test(str)){
		return true;
	} else {	
	return false;
	}
}

function checkCodepostal(str) {
	if (/^[0-9]{5}$/.test(str)){
		return true;
	} else {	
	return false;
	}
}

function isEmpty(str) {
	return (str == "")
}

function isMailOk(str) {
	if(isEmpty(str) || checkEmail(str))
	{
		return true;
	} else {
		return false;
	}
}

function inscription(email, general, fret) {
	//alert('inscription ' + email + '-' + general + '-' + fret);
	$.post(	'/newsletter/register', 
			{ _email : email, _general:general, _fret:fret},
			function(data){
		    	if(data.substr(0, 2) == 'OK') 
		    	{
		    		alert("Votre inscription a bien été pris en compte, merci.");
		    	} 
		    	else 
		    	{
		    		alert("Un problème est survenue lors de votre inscription, veuillez vérifier les données de ce formulaire, merci.");
		    	}
		     	
		    }
	);	
	return false;	
}

