//******************************************************************************
//Function: 	Open_Popup
//------------------------------------------------------------------------------
//Description: 	Ouvre un popup passe en parametres : url, nom de la barre de titre, options(taille,status bar,toolbar)
//******************************************************************************
function Open_Popup(theURL, awidth, aheight) 
{  //window.open(theURL,winName,features+',resizable=yes,statusbar=no');
	window.open(theURL,'_blank','left=100, top=100,resizable=yes,width='+awidth+',height='+aheight);
}

//******************************************************************************
//Function: 	CheckEmail
//------------------------------------------------------------------------------
//Description: 	Vérifie qu'une valeur est composée de @ et du .
//******************************************************************************
function CheckEmail(adresse)
{	var arobase = adresse.indexOf("@", 1);
	var point = adresse.indexOf(".", arobase + 1);
	return ((adresse.length > 2) && (arobase > -1) && (point > 1))
}

//******************************************************************************
//Function: 	Is_Numeric
//------------------------------------------------------------------------------
//Description: 	Vérifie qu'une valeur est numérique
//******************************************************************************
function Is_Numeric(num)
{	var exp = new RegExp("^[0-9-.]*$","g");
	return exp.test(num);
}
//******************************************************************************
//Function: 	CheckDateValue
//------------------------------------------------------------------------------
//Description: 	Vérifie si une date est bien formée
//******************************************************************************
function CheckDateValue(d,j,m,a) 
{	if ( (isNaN(j)) || (j<1) || (j>31) || (j.substring(0,1) == " ") || (j.substring(1,2) == " ")
			|| (isNaN(m)) || (m<1) || (m>12) || (m.substring(0,1) == " ") || (m.substring(1,2) == " ")
			|| (isNaN(a)) || (a.substring(0,1) == " ") || (a.substring(1,2) == " ") 
			|| (a.substring(2,3) == " ") || (a.substring(3,4) == " ") ) 
	{	alert("La date " + d + " est incorrecte"); 
		return false;
	}
	else 
	{	var d2= new Date(a,m-1,j);
		j2= d2.getDate();
		m2= d2.getMonth()+1;
		a2= d2.getFullYear();
		
		if ( (j!=j2)||(m!=m2)||(a!=a2) ) 
		{	alert("La date " +d + " n'existe pas !");
			return false;
		}
		else 
			return true;
	}
}
//******************************************************************************
//Function: 	CheckDate
//------------------------------------------------------------------------------
//Description: 	Récupére le jour, mois, année d'une saisie sur 2/4/5/8/10 chiffres
//******************************************************************************
function CheckDate(d) 
{	if (d == "") return true;

	var today=new Date();
	var j=today.getDate();
	var m=today.getMonth()+1;
	var a=today.getFullYear();
	//convertit les nombre en chaine
	j=j.toString();
	m=m.toString();
	a=a.toString(); 
								
	if (d.length < 10)
	{	alert("La date " + d + " est incorrecte !\n Elle doit être du type jj/mm/aaaa."); 
		return false;
	}			
	else if (d.length == 10) 		//01/01/2003
	{	j=(d.substring(0,2));
		m=(d.substring(3,5));
		a=(d.substring(6)); 	
	}
	
	return CheckDateValue(d,j,m,a); 		
}
//******************************************************************************
//Function: 	verify
//------------------------------------------------------------------------------
//Description: 	Cette fonction verifie que tous les champs sont remplis et retourne
//				le focus sur les non remplis
//******************************************************************************
function verify(form)
{	if (form.nom.value == "")
	{	alert("Veuillez saisir un nom !");
		form.nom.focus();
		return false;
	}	
	if (form.email.value == "")
	{	alert("Veuillez saisir un email !");
		form.email.focus();
		return false;
	}
	if (!CheckEmail(form.email.value))
	{	alert("Veuillez saisir une adresse e-mail du type 'contact@chambre-hotes-casiopee.com'.\n'" + form.email.value + "' n'est pas valide.");
		form.email.focus();
		return(false);
	}
// Tout est bon, on envoit
	form.submit();
}

function verify_cmde(form)
{	if (form.nom.value == "")
	{	alert("Veuillez saisir un nom !");
		form.nom.focus();
		return false;
	}
	if (form.prenom.value == "")
	{	alert("Veuillez saisir un prenom !");
		form.prenom.focus();
		return false;
	}
	if (form.adresse.value == "")
	{	alert("Veuillez saisir une adresse!");
		form.adresse.focus();
		return false;
	}
	if (form.cp.value == "")
	{	alert("Veuillez saisir un code postal !");
		form.cp.focus();
		return false;
	}
	if (form.tel.value == "")
	{	alert("Veuillez saisir un numéro de téléphone !");
		form.tel.focus();
		return false;
	}
	if (!Is_Numeric(form.tel.value))
	{	alert("'" + form.tel.value + "' n'est pas un numéro de téléphone valide.\nVeuillez re-saisir le numéro de téléphone.");
		form.tel.focus();
		return false
	}
	if (form.email.value == "")
	{	alert("Veuillez saisir un email !");
		form.email.focus();
		return false;
	}
	if (!CheckEmail(form.email.value))
	{	alert("Veuillez saisir une adresse e-mail du type 'contact@chambre-hotes-casiopee.com'.\n'" + form.email.value + "' n'est pas valide.");
		form.email.focus();
		return(false);
	}
// Tout est bon, on envoit
	form.submit();
}

//v3.0
function ImgRestore() 
{	var i,x,a=document.MM_sr; 
	for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) 
		x.src=x.oSrc;
}
//v4.01
function FindObj(n, d) {
	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 = FindObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x = d.getElementById(n); 
	return x;
}
//v3.0
function SwapImage() 
{	var i, j = 0,x, a = SwapImage.arguments; 
	document.MM_sr=new Array; 
	for(i = 0; i < (a.length-2); i += 3)
   		if ( (x = FindObj(a[i])) != null )
		{	document.MM_sr[j++] = x; 
			if(!x.oSrc) x.oSrc = x.src; 
			x.src = a[i + 2];
		}
}
