//fonction de controle

// initialisation des controles et des blocages, 
// et je determine aussi tous les champs et leur controle respectif
function init () {
	
	//if ( document.getElementById("menu") ) initMenu();
	
	formulaire   = document.getElementById("form-devis");

	tabchamps    = new Array();
	//											[types de controle : date-, date+, ouinon, liste, tel, email]
	//														[types de blocage : date, chiffre, texte]
	//				nom du champs	requis		controle 	blocage		ligne				type coherence					message incoherence
	
	tabchamps[0]  = ["log", 	"requis",	"liste",		"", 			"log-ligne", 	"",					""];
	tabchamps[1]  = ["dateff", 	"requis",	"date+annee",	"date", 		"dateff-ligne", 	"",					""];
	tabchamps[2]  = ["echean", 	"facult",	"date+annee",	"date", 		"echean-ligne", 	"",					""];
	tabchamps[3]  = ["resil", 	"requis",	"ouinon",		"", 			"resil-ligne", 	"",					""];
	tabchamps[4]  = ["motif", 	"requis",	"liste",		"", 			"motif-ligne", 	"",					""];
	tabchamps[5]  = ["nbsin", "requis",	"texte",		"chiffre", 		"nbsin-ligne", 	"",					""];
	tabchamps[6]  = ["natsin1", "requis",	"liste",		"", 			"natsin1-ligne", 	"",					""];
	tabchamps[7]  = ["natsin2", "requis",	"liste",		"", 			"natsin2-ligne", 	"",					""];
	tabchamps[8]  = ["natsin3", "requis",	"liste",		"", 			"natsin3-ligne", 	"",					""];
	//tabchamps[6]  = ["typsin", "requis",	"texte",		"", 			"typsin-ligne", 	"",					""];
	
	
	/*var conditions 			= new Array()
	conditions[0] 			= ["log","A"];
	creer_condition (conditions, 
					 ["echean"], 
					 ["echean-ligne"] 
					 );
	*/
	
	var conditions 			= new Array()
	conditions[0] 			= ["resil","oui"];
	creer_condition (conditions, 
					 ["motif"], 
					 ["motif-ligne"] 
					 );
	
	/*var conditions 			= new Array()
	conditions[0] 			= ["nbsin","1"];
	creer_condition (conditions, 
					 ["typsin"], 
					 ["typsin-ligne"] 
					 );
	*/
	
	//conditions conducteur principal
	wFORMS.helpers.addEvent(formulaire["nbsin"],'change',afficher_sinsitres);
	
	wFORMS.helpers.addEvent(formulaire["log"],'change',change_statut_echeance);
	
	// fonctions d'affichage
	afficher_sinsitres ();
	change_statut_echeance ();
	
	Calendar.setup( 
	{ 
	inputField : "dateff", // ID of the input field 
	ifFormat : "%d/%m/%Y", // the date format
	weekNumbers : false,
	onUpdate : controle_depuis_cal,
	button : "cal1" // ID of the button 
	} 
	);
	Calendar.setup( 
	{ 
	inputField : "echean", // ID of the input field 
	ifFormat : "%d/%m/%Y", // the date format
	weekNumbers : false,
	onUpdate : controle_depuis_cal,
	button : "cal2" // ID of the button 
	} 
	);
}

///////////////////////////////////////////////////////////////
/////////////////////////// FONCTIONS AFFICHAGE
///////////////////////////////////////////////////////////////
function afficher_sinsitres () {
	
	var nomredesinistres = formulaire["nbsin"].value
	
	for (var x=1; x<=3; x++) { 
		
		//var bool0 = nomredesinistres > 0 ? "afficher" : "masquer";	
		//afficher_ou_masquer_un_champ(null,["natsin0-ligne"], bool0)
		
		var bool = nomredesinistres >= x ? "afficher" : "masquer";
		afficher_ou_masquer_un_champ(["natsin"+ x],["natsin"+ x +"-ligne"], bool)
		
	}
	
}

function change_statut_echeance () {
	if ( formulaire["log"].value == "A") {
		tabchamps[2][1] = "requis";
	}else{
		tabchamps[2][1] = "facult";
	}
}

