// JavaScript Document

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

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* FONCTION D'ECRITURE DU SWF */
function WriteSWF(path, file, width, height, wmode, bgcolor, id){
var EmbedSWF = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" id=\""+id+"\" width=\""+width+"\" height=\""+height+"\"><param name=\"movie\" value=\""+path+file+"\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"wmode\" value=\""+wmode+"\" /><param name=\"bgcolor\" value=\""+bgcolor+"\" /><param name=\"allowScriptAccess\" value=\"sameDomain\" /><embed src=\""+path+file+"\" bgcolor=\""+bgcolor+"\" wmode=\""+wmode+"\" menu=\"false\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" id=\""+id+"\" name=\""+id+"\" allowScriptAccess=\"sameDomain\" width=\""+width+"\" height=\""+height+"\"></embed></object>";

document.write(EmbedSWF);
}

/* DIV LAYER */
function NameDiv(id){
	if(document.all){ doc = document.all[id]; }
	if(document.getElementById){ doc = document.getElementById(id);}
	return doc;
}

function showLayer(id) {
	
	for (var i = 1; i<=7; i++) {
		
		if(i == id){
				resizemask();
				//$('Layer'+i).show();
				NameDiv('Layer'+i).style.visibility = "visible";
			}
	}
}


function hideLayer() {
	for (var i = 1; i<=7; i++) {
		//$('Layer'+i).hide();
		NameDiv('Layer'+i).style.visibility = "hidden";
	}
}

function closeLayer(id) {
	for (var i = 1; i<=7; i++) {
		
		if(i == id){
				//$('Layer'+i).hide();
				NameDiv('Layer'+i).style.visibility = "hidden";
			}
	}
}

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();
	for (var i = 1; i<=7; i++) {
	$('Layer'+i).setStyle({
	  left:(fsize[0]/2-409/2)+"px",
	  top:(fsize[1]/2-461/2)+"px"
	});
	}
}

/* Formulaire */
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 prnom.");
		$('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 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 checkMail(str) {
	var verif = /^[a-zA-Z0-9\-\_]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9\-\_]{1,}@[a-zA-Z0-9]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9]{1,}[.][a-zA-Z]{2,4}$/;
	if(verif.test(str)) return true;
	else return false;
}


function CheckNewsletter(f) {
	var errors = 'Attention :\n'
	var areErrors = true;
	
	if(f['email'].value == '') {
		errors += "\n - Tu n'as pas saisi ton email";
		areErrors = false;
	}else if(!checkMail(f['email'].value)) {
		errors += "\n - Ton adresse email comporte une erreur.";
		areErrors = false;
	}
	
	//
	if(!areErrors){
		alert(errors);
	}
	
	return areErrors;
}


