function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function openCloseMenu(champs,display) {
	if (champs.style.display == display)
		champs.style.display = display;
	else
		champs.style.display = display;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// CONTROLE GENERIQUE
// Controle que le champs est bien un nombre
function checkIsNum (champs,label)
{
	if (isNaN(champs.value))
	{
          setStyle(champs,label);
          return false;
     }
	else return true;
}

// Controle que le champs est contient bien X caract
function checkHadXCaract (value,msg,nb)
{
	if (value.length != nb)
		return "&#8226; " + msg + " doit contenir " + nb + " caractère<br>";
	else return '';
}

// Controle que la personne est bien cliquer sur un checked
function checkNumBetween (champs,msg)
{
	if (!champs.checked)
		return "&#8226; " + msg +"<br>"
	else return '';
}

// Controle que le champs est un email
function checkIsMail (champs,label)
{
    ctl = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/;
    if (champs.value.search(ctl) != -1)
    {
          resetStyle (champs,label);
          return true;
    }
    else 
    {
          setStyle (champs,label);
          return false;
    }
}
    
function checkIsNotNull (champs,label)
{
    if (champs.value)
    {
          resetStyle (champs,label);
          return true;
    }
    else 
    {
	     setStyle(champs,label);
	     return false;
    }
}

function checkStyleChamps (champs,type,label)
{
     if(type == "normal")
     {
          if (checkIsNotNull(champs,label))
          {
               resetStyle(champs,label);
          }
     }
     else if(type == "num")
     {
          if (checkIsNum(champs,label))
          {
               resetStyle(champs,label);
          }
     }
     else if(type == "email")
     {
          if (checkIsMail(champs,label))
          {
               resetStyle(champs,label);
          }
     }
}

function resetStyle(champs,label)
{
     champs.style.border = "1px solid #CACACA";
	   label.style.color = "#000000";
}     

function setStyle (champs,label)
{
     champs.style.border = "2px solid red";
	   label.style.color = "red";
}

function resetStyleText(label)
{
	if (label != null)
    label.style.color = "#000000";
}     

function setStyleText (label)
{
	if (label != null)
    label.style.color = "red";
}




// Controle que la liste déroulante est bien selectionnée
/*function checkLdSelected (champs,msg)
{
     if (champs.selectedIndex != -1 && champs.options[champs.selectedIndex].value != -1) return '';
    else return "&#8226; "+ msg +" est obligatoire<br>";
}*/


// Permet de formatter un champs téléphone
function formatPhoneNumber (chaine)
{
	  for (var i = 0;i<20;i++)
	  {
	  	chaine = chaine.replace(/(\s|-|\.)/, "");
	  }
	  if (chaine.length != 0)
		  return chaine.substr(0,3)+chaine.substr(3);
	  else
	  	return "";
}


function submit_formPartner(formulaire)
{
   var msgError = new Array();
   
   msgError.push (checkIsNotNull(formulaire.formNom,document.getElementById("lblFormNom")));
   msgError.push (checkIsNotNull(formulaire.formAdresse,document.getElementById("lblFormAdresse")));
   msgError.push (checkIsNotNull(formulaire.formNPA,document.getElementById("lblFormNPA")));
   msgError.push (checkIsNotNull(formulaire.formVille,document.getElementById("lblFormVille")));
   msgError.push (checkIsNotNull(formulaire.formPays,document.getElementById("lblFormPays")));
   msgError.push (checkIsNotNull(formulaire.formTelephone,document.getElementById("lblFormTelephone")));
   msgError.push (checkIsMail(formulaire.formEmail,document.getElementById("lblFormEmail")))
   
   msgError.push (checkIsNotNull(formulaire.formContact,document.getElementById("lblFormContact")));
   msgError.push (checkIsNotNull(formulaire.formContmail,document.getElementById("lblFormContmail")));
   
   msgError.push (checkIsNotNull(formulaire.formCA,document.getElementById("lblFormCA")));
   msgError.push (checkIsNotNull(formulaire.formCrea,document.getElementById("lblFormCrea")));
   msgError.push (checkIsNotNull(formulaire.formNb,document.getElementById("lblFormNb")));
   
   //On parse l'array pour contrôler si on a une valeur false    
   var estValide = new Boolean(true);
   for (var error in msgError)
   {
         if (!msgError[error])
              estValide = false;
   }
   
   if (estValide)
          return true;
   else
   {     
          document.getElementById("errorForm").style.visibility = "visible";
          //document.getElementById("errorForm").style.display  = 'block';
          return false; 
   }
          
}

    function submit_form(formulaire)
    {
        var msgError = new Array();

        msgError.push (checkIsNotNull(formulaire.formNom,document.getElementById("lblFormNom")));
        msgError.push (checkIsNotNull(formulaire.formContact,document.getElementById("lblFormContact")));
        msgError.push (checkIsNotNull(formulaire.formAdresse,document.getElementById("lblFormAdresse")));
        msgError.push (checkIsNotNull(formulaire.formNPA,document.getElementById("lblFormNPA")));
        msgError.push (checkIsNotNull(formulaire.formVille,document.getElementById("lblFormVille")));
        msgError.push (checkIsNotNull(formulaire.formPays,document.getElementById("lblFormPays")));
        msgError.push (checkIsNotNull(formulaire.formTelephone,document.getElementById("lblFormTelephone")));
        //msgError.push (checkIsNotNull(formulaire.formFiles,document.getElementById("lblFormFiles")));
        msgError.push (checkIsNum(formulaire.formTelephone,document.getElementById("lblFormTelephone")));
        msgError.push (checkIsMail(formulaire.formEmail,document.getElementById("lblFormEmail")));

        //On contrôle s'il y a au moins une circonstance de panne choisie
        /*if (!document.getElementById("formCirc_Autres").checked && !document.getElementById("formCirc_Bruit").checked && !document.getElementById("formCirc_Nature").checked && !document.getElementById("formCirc_Chute").checked && !document.getElementById("formCirc_OS").checked && !document.getElementById("formCirc_Format").checked)
        {
               setStyleText (document.getElementById("lblFormCirc_Format"));
                   
               msgError.push (false);
        }*/

        /*if(!document.getElementById("formTypeRecupLog").checked && !document.getElementById("formTypeRecupMat").checked)
        {
               setStyleText (document.getElementById("lblFormTypeRecupLog"));
               setStyleText (document.getElementById("lblFormTypeRecupMat"));
               msgError.push (false);
        }*/

        //else
        //{
               if (document.getElementById('formProvenance').value == "magasin")
               {
                    msgError.push (checkIsNotNull(formulaire.formProvenanceDetails,document.getElementById("lblFormProvenanceDetails")));
               }
        //}
        
        if(document.getElementById('formProvenance').value == "-1" || document.getElementById('formProvenance').value == "-2")
        {
               setStyleText (document.getElementById("lblFormProvenance"));
               msgError.push (false);
        }
        else
        {
               if (document.getElementById('formProvenance').value == "magasin")
               {
                    msgError.push (checkIsNotNull(formulaire.formProvenanceDetails,document.getElementById("lblFormProvenanceDetails")));
               }
               else
               {
                    resetStyleText (document.getElementById("lblFormProvenance"));
               }
        }
       
        
        /*if(!document.getElementById("formCGV2").checked && document.getElementById("formTypeRecupLog").checked)
        {
               setStyleText (document.getElementById("lblFormCGV2"));
               setStyleText (document.getElementById("lblLinkFormCGV2"));
               msgError.push (false);
        }*/
        /*else
        {
               resetStyleText (document.getElementById("lblFormCGV2"));
               resetStyleText (document.getElementById("lblLinkFormCGV2"));
        }*/
        
        if(!document.getElementById("formCGV1").checked)
        {
               setStyleText (document.getElementById("lblFormCGV1"));
               setStyleText (document.getElementById("lblLinkFormCGV1"));
               msgError.push (false);
        }
        /*{
               resetStyleText (document.getElementById("lblFormCGV1"));
               resetStyleText (document.getElementById("lblLinkFormCGV1"));
        }*/
        
        //On parse l'array pour contrôler si on a une valeur false    
        var estValide = new Boolean(true);
        for (var error in msgError)
        {
              if (!msgError[error])
	              estValide = false;
        }
        
        if (estValide)
               return true;
        else
        {     
               document.getElementById("errorForm").style.visibility = "visible";
               //document.getElementById("errorForm").style.display  = 'block';
               return false; 
        }
               
    }
    
    function testProvenance()
    {
        if(document.getElementById('formProvenance').value != "-1" && document.getElementById('formProvenance').value != "-2")
               resetStyleText (document.getElementById("lblFormProvenance"));
        else
               setStyleText (document.getElementById("lblFormProvenance"));
    
    }
    
    function testCirconstance()
    {
      if (document.getElementById("formCirc_Autres").checked || document.getElementById("formCirc_Bruit").checked || document.getElementById("formCirc_Nature").checked || document.getElementById("formCirc_Chute").checked)
      {
	      document.getElementById('divRecupSalleBlanche').style.visibility = 'visible';
	      document.getElementById('divRecupLogiciel').style.visibility = 'hidden';
	  
	      document.getElementById("tdRecuplogiciel").style.border = 'none';
	      document.getElementById("tdRecupMateriel").style.border = '1px solid #E87C00';
	  
	      document.getElementById("formTypeRecupMat").checked = true;
	      document.getElementById("formTypeRecupLog").checked = false;
	      
	      AfficheTarif('materiel');
	      
	      resetStyleText(document.getElementById("lblFormCirc_Format"));
	      resetStyleText(document.getElementById("lblFormTypeRecupLog"));
	      resetStyleText(document.getElementById("lblFormTypeRecupMat"));
      }
      else if (document.getElementById("formCirc_OS").checked || document.getElementById("formCirc_Format").checked)
      {
	      document.getElementById("divRecupLogiciel").style.visibility = 'visible';
	      document.getElementById("divRecupSalleBlanche").style.visibility = 'hidden';
	  
	      document.getElementById("tdRecuplogiciel").style.border = '1px solid #E87C00';
	      document.getElementById("tdRecupMateriel").style.border = 'none';
	  
	      document.getElementById("formTypeRecupMat").checked = false;
	      document.getElementById("formTypeRecupLog").checked = true;
	      
	      AfficheTarif('logiciel');
	      
	      resetStyleText(document.getElementById("lblFormCirc_Format"));
	      resetStyleText(document.getElementById("lblFormTypeRecupLog"));
	      resetStyleText(document.getElementById("lblFormTypeRecupMat"));
      }
      else
      {
	      document.getElementById("divRecupLogiciel").style.visibility = 'hidden';
	      document.getElementById("divRecupSalleBlanche").style.visibility = 'hidden';
	  
	      document.getElementById("tdRecuplogiciel").style.border = 'none';
	      document.getElementById("tdRecupMateriel").style.border = 'none';
	  
	      document.getElementById("formTypeRecupMat").checked = false;
	      document.getElementById("formTypeRecupLog").checked = false;

	      AfficheTarif('none');
	      
	      setStyleText(document.getElementById("lblFormCirc_Format"));
	      setStyleText (document.getElementById("lblFormTypeRecupLog"));
           setStyleText (document.getElementById("lblFormTypeRecupMat"));
      }
    }
    
    function AfficheTarif(strType)
    {
      if (strType == "logiciel")
      {
    	      document.getElementById("TarifRecupLog").style.visibility = 'visible';
	      document.getElementById("TarifRecupLog").style.display  = 'block';
	      
	      document.getElementById("TarifRecupMat").style.visibility = 'hidden';
	      document.getElementById("TarifRecupMat").style.display  = 'none';
	      
      }
      else if (strType == "materiel")
      {
    	      document.getElementById("TarifRecupLog").style.visibility = 'hidden';
	      document.getElementById("TarifRecupLog").style.display  = 'none';
	      
	      document.getElementById("TarifRecupMat").style.visibility = 'visible';
	      document.getElementById("TarifRecupMat").style.display  = 'block';
      } 
      else if (strType == "none")
      {
      	document.getElementById("TarifRecupLog").style.visibility = 'hidden';
	      document.getElementById("TarifRecupLog").style.display  = 'none';
	      
	      document.getElementById("TarifRecupMat").style.visibility = 'hidden';
	      document.getElementById("TarifRecupMat").style.display  = 'none';
      } 
    }
    
    
    function afficheDetailsProvenance(strProvenance)
    {
        if (strProvenance == "magasin")
        {
               document.getElementById("formProvenanceDetails").style.visibility = "visible";
               document.getElementById("labelNomProvenance").style.visibility = "visible";
        }
        else
        {
               document.getElementById("formProvenanceDetails").style.visibility = "hidden";
               document.getElementById("labelNomProvenance").style.visibility = "hidden";
        } 
     }
     
     function imposeMaxLength(Object, MaxLen)
     {
          return (Object.value.length <= MaxLen);
     }

