/* JAVASCRIPT ROLLOVER */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/* FONCTION DE DÉFINITION DES CALQUES */
function NameDiv(id){
	if(document.all){ doc = document.all[id]; }
	if(document.getElementById){ doc = document.getElementById(id);}
	return doc;
}

/* FONCTION D'AFFICHAGE/MASQUAGE DES ELEMENTS */
function SetObjDisplay(id, prop){
	NameDiv(id);
	doc.style.display=prop;
}

/* FONCTION D'AFFECTATION DE CLASSE AUX ELEMENTS */
function SetObjCss(id, cssName){
	NameDiv(id);
	doc.className=cssName;
}

/* FONCTION D'AFFICHAGE/MASQUAGE DU CONTENU TOUT SUR LES MITES */
function SwapRub(id){
	// TABLEAU DES RUBRIQUES */
	var Btn = new Array();
	Btn[0] = "Rub1";
	Btn[1] = "Rub2";
	Btn[2] = "Rub3";
	// TABLEAU DES CALQUES DES RUBRIQUES */
	var LayerBtn = new Array();
	LayerBtn[0] = "Menu1";
	LayerBtn[1] = "Menu2";
	LayerBtn[2] = "Menu3";
	
	for(i=0; i<Btn.length; i++){
		if(id==Btn[i]){
			SetObjDisplay(LayerBtn[i], "block");
			SetObjCss(Btn[i], "on")
		} else{
			SetObjDisplay(LayerBtn[i], "none");
			SetObjCss(Btn[i], "")
		}
	}
}

function SwapList(id){
	var pathlay = $('list'+id);
	if( pathlay.style.display=="none") {
		pathlay.style.display="block";
	}else{
		pathlay.style.display="none";
	}
}

/* LAYER PRODUITS */
function showLayer() {
	resizemask();
	$('Mask').show();
	$('Layer').show();
	window.document.body.style.overflow = "hidden";
}

function hideLayer() {
	$('Mask').hide();
	$('Layer').hide();
	window.document.body.style.overflow = "visible";
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	arrayPageSize = new Array(w,h)
	return arrayPageSize;
}

function resizemask(){
	var fsize=getPageSize();
	$('Layer').setStyle({
	  left:(fsize[0]/2-908/2)+"px",
	  top:(fsize[1]/2-498/2)+"px"
	});
	$('Mask').setStyle({
		width:fsize[0]+"px",
		height:fsize[1]+"px"
	});
	$('trame').setStyle({
		width:fsize[0]+"px",
		height:fsize[1]+"px"
	});
}


/* OUVERTURE POP UP */

function makecenter(){
	var winHeight = 630;
	var winWidth = 450;
	var Dessus=(screen.height/2)-(winHeight/2); var Gauche=(screen.width/2)-(winWidth/2);
	var features= 'height='+winHeight+',width='+winWidth+',top='+Dessus +',left='+Gauche; 
	return features;
}

function makecenter_ami(){
	var winHeight = 740;
	var winWidth = 450;
	var Dessus=(screen.height/2)-(winHeight/2); var Gauche=(screen.width/2)-(winWidth/2);
	var features= 'height='+winHeight+',width='+winWidth+',top='+Dessus +',left='+Gauche; 
	return features;
}

function openMentions() {
	var winmention = window.open('mentions_legales.php', 'mentions',  makecenter(), 'resizable=no');
	winmention.focus();
}

function openContact() {
	var wincontact = window.open('contact_presse.php', 'contact',  makecenter(), 'resizable=no');
	wincontact.focus();
}

function openSConso() {
	var winsconso = window.open('service_conso.php', 'sconso',  makecenter(), 'resizable=no');
	winsconso.focus();
}

function openReglement() {
	var winreglement = window.open('reglement.php', 'reglement',  makecenter(), 'resizable=no');
	winreglement.focus();
}



function envoisAmis(){
	strbasic = 'Email de votre ami';
	var email = $('bottom_envoi_ami').value;
	if(strbasic == email || email ==' ' || email ==''){
		alert("Veuillez saisir un email");
		return false;
	}if(checkEmail(email)==false){
		alert("Veuillez saisir un email valide");
		return false;
	}else{
		var winAmi = window.open('pu_envoi_amis.php?email='+email, 'winAmi', makecenter_ami(), 'resizable=no');
		winAmi.focus();
	}
	
}

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;
	}
}

function CheckService(){
	var validate=true;
	if($('nom').value==""){
		validate=false;
		alert("Veuillez saisir votre nom.");
		$('nom').focus();
		return false;
	}else if($('prenom').value==""){
		validate=false;
		alert("Veuillez saisir votre prénom.");
		$('prenom').focus();
		return false;
	}else if($('cp').value==""){
		validate=false;
		alert("Veuillez saisir votre code postal.");
		$('cp').focus();
		return false;
	}else if($('ville').value==""){
		validate=false;
		alert("Veuillez saisir votre ville.");
		$('ville').focus();
		return false;
	}else if($('tel').value==""){
		validate=false;
		alert("Veuillez saisir votre téléphone.");
		$('tel').focus();
		return false;
	}else  if($('email').value==""){
		validate=false;
		alert("Veuillez saisir votre email.");
		$('email').focus();
		return false;
	}else if(checkEmail($('email').value)==false){
		validate=false;
		alert("Veuillez saisir un email correct.");
		$('email').focus();
		return false;
	}
	return validate;
}

function CheckEnvoi(){
	var validate=true;
	if($('nom').value==""){
		validate=false;
		alert("Veuillez saisir votre nom.");
		$('nom').focus();
		return false;
	}else  if($('email').value==""){
		validate=false;
		alert("Veuillez saisir votre email.");
		$('email').focus();
		return false;
	}else if(checkEmail($('email').value)==false){
		validate=false;
		alert("Veuillez saisir un email correct.");
		$('email').focus();
		return false;
	}
	var countFriendEmail=0;
	for(tt=1;tt<7;tt++){
		if($('emailami'+tt).value!="" && checkEmail($('emailami'+tt).value)==true){
			countFriendEmail++;
		}
	}
	if(countFriendEmail==0){
		validate=false;
		alert("Veuillez saisir l'email d'un ami correct.");
		$('emailami1').focus();
		return false;
	}
	return validate;
}

