//****************************************************************************//
//  NE PAS SAISIR LES BALISES JAVASCRIPT
//****************************************************************************//
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//******** CHANGEMENT COULEUR CELLULE
function cellOver(cell,color1,color2){
	if(color2 != ""){
		cell.style.color = color2;
	}
	if(color1 != ""){
		cell.style.background = color1;
	}
	return true;
}

function Change_objet(nObjet,nContenu) {
	  // nObjet = le nom de l'objet
	  // nContenu = Le contenu affiché dans l'objet
	
	  if (ns4) {
		document.eval(nObjet).document.write(nContenu);
		document.eval(nObjet).document.close();
	  }
	  else if (ns6) {
		document.getElementById(nObjet).innerHTML = nContenu;
	  }
	  else if (ie4) {
		eval(nObjet).innerHTML = nContenu;
	  }
}

function masqueSaisieChaineNum(obj, masque) {
  var ch = obj.value
  var tmp = ""
  var j = 0
  ch.toString()
  
  if (window.event.keyCode != 37 && window.event.keyCode != 39 && window.event.type != "keydown" && window.event.keyCode != 8 && window.event.keyCode != 46) {
    
		if (window.event.type == "keyup") {
		  
		      // reconstitution de la chaine ss espace ni lettre
			  for (i=0; i<ch.length; i++) {
					if (!isNaN(ch.charAt(i)) && ch.charAt(i) != " "){
						tmp += ch.charAt(i)
					}
			  }
			  
		      // vidage de la chaine
			  ch = ""
		  
		  	  // parsage
			  for (i=0; i<masque.length; i++) {
					if (masque.charAt(i)  == "0") { 
						  if (tmp.charAt(j) != "" ) {
							ch += tmp.charAt(j)
							j++
						  }else{
							ch += ""
						  }
					}else if(tmp.charAt(i) != ""){ 
						ch += masque.charAt(i)
					}
			  }
			  
		}
	  
		obj.value = ch
  }
  
}

// ******* OUVERTURE D'UNE POPup CENTREE
function PopupCentrer(page,nom,largeur,hauteur,options) {

	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
//appelle de la fonction :
//<a HREF='javascript:PopupCentrer("popup.php",".$largeur.",".$hauteur.","menubar=no,scrollbars=no,statusbar=no")'>lien</a>

// ******* redirection sur l'url spécifiée
function redirection(url){
	window.location = url;
	//<meta http-equiv="refresh" content=0;URL='.$url.'>
}

//******** demande de confirmation et redirection
function confirmation(conf,add){
	if (confirm(conf)){	
		window.location=add;
	}
}

//*********************************************************************************************
//  AFFICHE / CACHE UN BLOC DIV, TD, TR,...
//*********************************************************************************************
function swapLayer(objMenu,objImage,pref){

   var myElement = document.getElementById(objMenu,objImage); 
   if (myElement.style.display == "none"){
       myElement.style.display = "";
	   //if(objImage != ""){
       		objImage.src = pref+"images/moins.gif";
	   //}
   
   }else{
       myElement.style.display = "none";
	   //if(objImage != ""){
       		objImage.src = pref+"images/plus.gif";
	   //}
   }
}
//*********************************************************************************************


/********************************************************
*  FONCTION POPUP POUR LA NEWSLETTER
********************************************************/

function PopupCentrerNl(page,nom,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,'top='+top+',left='+left+',width='+largeur+',height='+hauteur+','+options);
}

function go(){
	PopupCentrerNl('','popup',500,300,'menubar=no,scrollbars=no,statusbar=no');
	document.forms['newsletter'].submit();
}


/********************************************************
*  FONCTION PERMETTANT DE VERIFIER LES CHAMP D'UN FORMULAIRE
********************************************************/

function verifForm(formobj, fieldRequired, fieldDescription){
	
	// intro des messages de la boite de dialogue
	var alertMsg = "Vous devez completer :\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == "rien"){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;

			case "checkbox":
					alert(obj.checked);
					if (obj.checked == false){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;

			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					obj.className = "contactErreur";
				}else{
					obj.className = "contact";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		var field = formobj.elements["email"];
		if(field.value != null && field.value != ""){
			if(!checkmail(field.value)){
					alert("votre email est incorrect");
					return false;
			}else{
				return true;
			}
		}else{
			return true;
		}
	}else{
		alert(alertMsg);
		return false;
	}
}


function checkmail(email) {
         var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
         return (reg.exec(email)!=null)
}


/********************************************************
*  PNG FILE
********************************************************/
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }