// JavaScript Document
/****************************/
/*  VARIABLE DE PARAMETRE  */
/**************************/



/****************************/
/*  Champs Obligatoires    */
/**************************/

	function Check_Input(tChamps_Oblig,tChamps_Oblig_Name) {
		var vValid_Message ="";
		var vSaisi = true
		var vEmail_Message = "";
		
		//variable pour champs radio
		var vRadio = true;
		var vPrevRadio = false;
		var vRadioName = "";
		
		
		for (i=0; i<tChamps_Oblig.length; i++) {
			vID_Champ = tChamps_Oblig[i];
			vID_Champ_Nom = tChamps_Oblig_Name[i];
			
			//alert (eval("$('"+vID_Champ+"').type"));
			var vType = eval("$('"+vID_Champ+"').type");

	if ((vType == 'text') || (vType == 'hidden')) {vSaisi = eval("$('"+vID_Champ+"').value != ''");}
			if (vType == 'select-one') {vSaisi = eval("$('"+vID_Champ+"').options[$('"+vID_Champ+"').selectedIndex].text != ''");}
			
			/*if (vType == 'radio') {
				var TempNomChamp = vID_Champ.substr(0,vID_Champ.length-3);
				var TempTabLength = eval("document.forms[0]."+TempNomChamp+".length");
				vSaisi = false;
				for (j=0; j<(TempTabLength) ;j++) {
					if(eval("document.forms[0]."+TempNomChamp+"["+j+"].checked")) {vSaisi = true;};
				}
			}*/		

			if (vType == 'radio') {
				var o = document.getElementById("11");
				//alert(o[1].value);
				var TempNomChamp = vID_Champ.substr(0,vID_Champ.length);
				//var TempTabLength = $(TempNomChamp).length;
				var TempTabLength = document.getElementById(vID_Champ).checked;
		//		var TempTabLength = eval("document.forms[1]."+TempNomChamp+".length");
				
				if ( document.getElementById(vID_Champ).checked ) {
					vRadio = true;
					vPrevRadio = true
				}
				else if ( !vPrevRadio ) {
					vRadio = false;
					vPrevRadio = false;
					vRadioName = vID_Champ_Nom;
				}
				vSaisi = true;
				/*
				vSaisi = false;
				
				alert (TempTabLength);
				for (j=0; j<(TempTabLength) ;j++) {
					if(eval("$('"+TempNomChamp+"["+j+"]').checked")) {vSaisi = true;};
				} */
			}/**/
			
			/**/
			if (vID_Champ_Nom == 'Email') {
				var my_email = document.getElementById(vID_Champ).value;	
				//alert ( my_email );			
				var new_string = new String(my_email);
    	    	//if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
				if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {	
    	    		vEmail_Message = "Email n'est pas une adresse valide.";
					//alert ( my_email );
    	    	}
			}			
			
			if (vSaisi == false) {
				vValid_Message = vValid_Message + "> \""+vID_Champ_Nom+"\" est obligatoire.\n"
			}
		}
		

		
		if ( vRadio == false && vPrevRadio == false ) {
			vValid_Message = vValid_Message + "> \""+vRadioName+"\" est obligatoire.\n"
		}
		
		if (vValid_Message != '') {
			//var vMessage = "Votre demande n'a pas été envoyé pour les raisons suivantes :\n";
			//var vMessage = vMessage + "----------------------------------------------------------------\n";
			alert (vValid_Message);
			return false;
		}
		else {
			if (vEmail_Message != '') { //Pour Verif Email
				alert (vEmail_Message);
				return false;
			}/**/
			return true;
		}
	}


/****************************/
/*  Test navigateur        */
/**************************/

function cherche_navigateur() {

// on crée la variable qui accueillera le message relatif au navigateur
var navigateur = "";

// Attention, l'ordre de recherche est important !! Parce que IE reprend la mention 'Mozilla' et Opera reprend la mention 'MSIE' !!
// on teste si on trouve la mention 'Opera...' dans le nom du navigateur
if ( navigator.userAgent.indexOf('Opera') != -1 ) { navigateur = 'Gecko';}

else if ( navigator.userAgent.indexOf('Firefox') != -1 ) { navigateur = 'Gecko'; }

else if ( navigator.userAgent.indexOf('Safari') != -1 ) { navigateur = 'Safari'; }

// on teste si on trouve la mention 'MSIE7...' dans le nom du navigateur
else if ( navigator.userAgent.indexOf('MSIE 7') != -1 ) { navigateur = 'IE7'; }

// on teste si on trouve la mention 'MSIE...' dans le nom du navigateur
else if ( navigator.userAgent.indexOf('MSIE') != -1 ) { navigateur = 'IE'; }

// on teste si on trouve la mention 'Mozilla...' dans le nom du navigateur
else if ( navigator.userAgent.indexOf('Mozilla/5.0') != -1 ) { navigateur = 'Gecko'; }

// si rien n'a été reconnu...
else { navigateur = 'Inconnu'; }

// on affecte la variable 'navigateur' au formulaire
return navigateur;
}



/********************************************************************/
/*  Remise à Zéro d'un champ                                       */
/******************************************************************/

function RAZ_champs(vTab_Ch_Supp){ 
	if(vTab_Ch_Supp) {
		for(var i = 0; i < vTab_Ch_Supp.length; i++){
			vTps = "document.forms[0]."+vTab_Ch_Supp[i]+".value = ''";
			//alert(vTps);
			eval(vTps);
		}
	} else {
			vTps = "document.forms[0]."+this.getAttribute("numrow")+".value = ''";
			//alert(vTps);
			eval(vTps);		
	}
}

function RAZ_champs_sf(){
		vTab_Ch_Supp = this.getAttribute("numrow").split("|");
		for(var i = 0; i < vTab_Ch_Supp.length; i++){
			vTps = "document.forms[0]."+vTab_Ch_Supp[i]+".value = ''";
			//alert(vTps);
			eval(vTps);
		}
}

/*********************************************************************/
/*  Transforme les . en , à la saisie                              */
/******************************************************************/

function Affect_Virg_Chps(element,event) {
 keycode = event.keyCode;
 if (keycode == "110"){
 var vInputName = element.name;
 var TMPValue = element.value;
 var vLastCar = TMPValue.charAt(TMPValue.length-1);
 var NewValue = TMPValue.substring(TMPValue.length-1, vLastCar)+",";
 element.value=NewValue;
 var TMPValue = "";
 }
}

function Verif_KPoint_UP() {
 var KP_Champs  = new Function("Affect_Virg_Chps(this,event)")
 for (var i=0;i<document.forms[0].elements.length;i++) {
   var vSelect_Champs = document.forms[0].elements[i];
   vSelect_Champs.onkeyup  = KP_Champs;
 }
}


/*************************************/
/*  Ouvrir une fenetre              */
/***********************************/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*************************************/
/*  Clear champs input              */
/***********************************/
 function clear_input(){
	var inputs = document.getElementsByTagName("input");
	for (var n=0; n<inputs.length; n++){
		if ((inputs[n].type == "text")||(inputs[n].type == "hidden")) inputs[n].setAttribute('value','');
	}
}

/*****************/
/* DATE DU JOUR */
/****************/
function date_jour(){
	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	curr_month++;
	if (curr_month<10) curr_month = "0"+curr_month;
	var curr_year = d.getFullYear();
	var vDay =curr_date + "/" + curr_month + "/" + curr_year;
	return vDay;
}

/********************************************************/
/* Ajouter une valeur à un attribut d'un element HTML */
/*******************************************************/

function Add_Value_Attribute(element,attribute,value){
		
		if(element.getAttribute(attribute)!=null)value = element.getAttribute(attribute) + value ; 

		//else value += element.getAttribute(attribute);
		element.setAttribute(attribute,value);

}


/***************/
/* DEBUG      */
/*************/

function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}


/********************************/
/* CONVERT STRING AVEC UNICODE */
/*******************************/

function convert_unicode(s){
	var s1=unescape(s.substr(0,s.length-1)); var t='';
	//alert(s1);
	for(i=0;i<s1.length;i++){
		t+=String.fromCharCode(s1.charCodeAt(i));
	}
	return(t);
}	

/********************************/
/* SEULEMENT NUMERO Decimal = True/false  */
/*******************************/
function numbersonly(e, decimal) {
	var key;
	var keychar;

	if (window.event) {
	   key = window.event.keyCode;
	}
	else if (e) {
	   key = e.which;
	}
	else {
	   return true;
	}
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	   return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1)) {
	   return true;
	}
	else if (decimal && (keychar == ".")) { 
	  return true;
	}
	else {
	   return false;
	}
}



