window.onload = function() {
	aideSaisie();
}

sfHover = function() {
var sfEls = document.getElementById("menu").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+="sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp("sfhover\\b"), "");
			}
		}
		}
		if (window.attachEvent) window.attachEvent("onload", sfHover);
				
function VerifFormulaireTelephone(pagevalidation) 
{	
var re = new RegExp("[^0-9]", "g");
var telephone = document.callback.telephone_call.value.replace(re, "");
var taille = telephone.length;

if(taille != 10)
	  {
        alert("Le numéro de téléphone ne peut être vide et doit comporter 10 chiffres.");
		document.callback.telephone_call.focus();
		document.callback.telephone_call.style.background="#f1f1f1";
		return false;
      } 
	  	else
	  {
        window.document.callback.action='formulaire-rappel.php?telephone='+document.callback.telephone_call.value;
		window.document.callback.submit();
	  } 
}

function VerifFormulaire(lettre) 
{	
var re = new RegExp("[^0-9]", "g");
var telephone = document.devis.telephone.value.replace(re, "");
var taille = telephone.length;
var new_string = new String(document.devis.emailclient.value);

   if (document.devis.emailclient.value != "")
    {
        if(!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) 
		  {
			alert("L'email indiqué est incorrect.");
			document.devis.emailclient.focus();
			document.devis.emailclient.style.background="#d6d6d6";
			return false; 
		  }
     }

   if(taille == 0)  
	  {
        alert("Insérer votre numéro de téléphone est obligatoire afin de vous contacter dans les plus brefs délais.");
        document.devis.telephone.focus();
		document.devis.telephone.style.background="#d6d6d6";
        return false;
      } 


   if(taille != 10)  
	  {
        alert("Votre numéro de téléphone semble incorrect. (10 chiffres)");
        document.devis.telephone.focus();
		document.devis.telephone.style.background="#d6d6d6";
        return false;
      }  

   if (document.devis.password.value != lettre)
	  {
        alert("Code Anti-Spam incorrect");
        document.devis.password.focus();
		document.devis.password.style.background="#d6d6d6";
        return false;
      }   
	  else
	  {
      document.devis.submit();
	  } 

}

function mailFormulaire() 
{	
var re = new RegExp("[^0-9]", "g");
var telephone = document.devis.telephone.value.replace(re, "");
var taille = telephone.length;
var new_string = new String(document.devis.emailclient.value);


   if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) 
      {
        alert("L'email indiqué est incorrect.");
		document.devis.emailclient.focus();
		document.devis.emailclient.style.background="#eeeeee";
		return false;
      }
	  
   if(taille != 10)  
	  {
        alert("Votre numéro de téléphone semble incorrect.");
        document.devis.telephone.focus();
		document.devis.telephone.style.background="#eeeeee";
        return false;
      }  	  
	  	else
	  {
		window.document.devis.submit();
	  } 
}


/////////////// liste déroulante liée pour le formulaire
var intervention = new Array; //nouveau tableau
intervention[0] = new Array("Urgence / Dépannage", "Urgence / Dépannage");
intervention[1] = new Array("Entretien / Réparation", "Entretien / Réparation");
intervention[2] = new Array("Travaux / Installation", "Travaux / Installation");

var type=new Array;
// Urgence / Dépannage
type["Urgence / Dépannage"] = new Array;
type["Urgence / Dépannage"][0] = new Array("Fuite", "Fuite");
type["Urgence / Dépannage"][1] = new Array("Panne sanitaire", "Panne sanitaire");
type["Urgence / Dépannage"][2] = new Array("Canalisation", "Canalisation");
type["Urgence / Dépannage"][3] = new Array("Autre", "Autre, à préciser");

// Entretien / Réparation
type["Entretien / Réparation"]=new Array;
type["Entretien / Réparation"][0] = new Array("Rénovation", "Rénovation");
type["Entretien / Réparation"][1] = new Array("Sanitaire / Plomberie", "Sanitaire / Plomberie");
type["Entretien / Réparation"][2] = new Array("Autre", "Autre, à préciser");

// Travaux / Installation
type["Travaux / Installation"] = new Array;
type["Travaux / Installation"][0] = new Array("Sanitaire / Plomberie", "Sanitaire / Plomberie");
type["Travaux / Installation"][1] = new Array("Canalisation", "Canalisation");
type["Travaux / Installation"][2] = new Array("Autre", "Autre, à préciser");

function filltheselect(liste, choix)
{switch (liste)
   {
   case "listeintervention":
      raz("listetype");
      for (i=0; i<type[choix].length; i++)
         {
         new_option = new Option(type[choix][i][1],type[choix][i][0]);
         document.devis.elements["listetype"].
 options[document.devis.elements["listetype"].length]=new_option;
         }
   }
}

function raz(liste)
{l=document.devis.elements[liste].length;
for (i=l; i>=0; i--)
   document.devis.elements[liste].options[i]=null;
}

function InterventionVisible(valeur,id) 
{
  if (valeur != "autre")
     {document.getElementById(id).style.display = "block";} 
   else
	 {document.getElementById(id).style.display = "none";}
}

function RaisonSocialVisible(valeur,id) 
{
  if (valeur != "particulier") 
     {document.getElementById(id).style.display = "block";} 
   else
	 {document.getElementById(id).style.display = "none";}
}


function aideSaisie()
{
	var e;
	var titre;
	var val;
	var balise		= new Array("input" , "textarea");

	for (var i=0 ; i<balise.length ; i++)
	{
		e = document.getElementsByTagName( balise[i] );

		for (var j=0 ; j<e.length ; j++)
		{
			titre = e[j].title;
			val   = e[j].value;

			if ((titre!=null && titre!='') && (val=='' || val==null))
			{
				e[j].value = titre;

				e[j].onfocus = function() { if (this.value == this.title) { this.value=''; } }
				e[j].onblur  = function() { if (this.value == '') { this.value=this.title; } }
			}
		}
	}
}