/* Mootools - menu
********************/

function effaceCookie(){
	Cookie.remove('voir');
}
/* addRemoveEvent
********************/
function addRemoveEvent(add, el, evt, func){
	if(add){
		if(el.addEventListener) el.addEventListener(evt, func, false);
		else if (el.attachEvent) el.attachEvent("on" + evt, func);
	}else{
		if(el.removeEventListener) el.removeEventListener(evt, func, false);
		else if (el.detachEvent) el.detachEvent("on" + evt, func);
	}
}
/* anchors
********************/
function initAnchors(){
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; ++i){
		if (!anchors[i].getAttribute("href") || !anchors[i].getAttribute("rel")) continue;
		var relation = String(anchors[i].getAttribute("rel"));
		if (relation.match("popup")) anchors[i].onclick=popup;
		if (relation == "external") anchors[i].onclick=externalLink;
	}
}
function popup(){
	var relation = String(this.getAttribute("rel"));
	if(relation == "popup"){
		window.open(this, "pop", "scrollbars=no");
	}else{
		var arguments = relation.substring(6,relation.length-1).split(";");
		window.open(this,arguments[0],'toolbar=0,location=0,directories=0,status=0,menubar=0,' + arguments[1] + ',resizable=no,width=' + arguments[2] + ',height=' + arguments[3] + ',top=' + arguments[4] + ',left=' + arguments[5]);
	}
	return false;
}


function externalLink(){
	window.open(this);
	return false;
}

function startGallery() {
var myGallery = new gallery($('myGallery'), {
timed: true,
showArrows: false,
embedLinks: true,
showInfopane: false,
showCarousel: false
});
}

function startGalleryAssiette() {
var myGallery = new gallery($('myGalleryAssiette'), {
timed: true,
showArrows: true,
showCarousel: false,
showInfopane: false,
embedLinks: false
});
}

function startGalleryResto() {
var myGallery = new gallery($('myGalleryResto'), {
timed: true,
showArrows: true,
showCarousel: false,
showInfopane: false,
embedLinks: false
});
}

function startGalleryPriv() {
var myGallery = new gallery($('myGalleryPriv'), {
timed: true,
showArrows: true,
showCarousel: false,
showInfopane: false,
embedLinks: false
});
}



function is_numeric(field){
	return !isNaN(document.getElementById(field).value);
}
function is_email(field){
	rx=new RegExp("^[\\w\.-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
	if(!rx.test(document.getElementById(field).value)){
		return false;
	} else {
		return true;
	}
}
function is_empty(field){
	if(document.getElementById(field).value == ''){
		return true;
	} else {
		return false;
	}
}
function verifFormContact(){
	var erreurs = ''; // pas d'erreur par défaut
	// vérification des champs obligatoires
	if(is_empty('nom')){
		erreurs += 'Vous devez renseigner votre nom\n';
	}
	if(!is_email('email')){
		erreurs += 'Votre e-mail ne semble pas valide\n';
	}
	if(erreurs != ''){
		alert('Les informations requises sont incomplètes ou contiennent des erreurs:\t\t\t\t\t\n\n'+erreurs);
		return false;
	} else {
		return true;
	}
}




/* init
********************/
addRemoveEvent(true, window, "load", startGallery);
addRemoveEvent(true, window, "load", startGalleryAssiette);
addRemoveEvent(true, window, "load", startGalleryResto);
addRemoveEvent(true, window, "load", startGalleryPriv);
addRemoveEvent(true, window, "load", initAnchors);
