﻿// JavaScript Document
// ----------- RAZ TABLEAUX -------------

dept = new Array() ;
abo62 = false ;
assur = false ;
appel = false ;
var mode ;
var codeDejaValide ;
var TE ;
var nc = false ;
var NCPREFIX = "" ;
var typeValidation ; 

especes = new Array();
especes['0'] = new espece("GG","Grand Gibier") ;
especes['1'] = new espece("SANG","Sanglier") ;
especes['2'] = new espece("SACH","Sanglier et/ou Chevreuil") ;
especes['3'] = new espece("CHEV","Chevreuil") ;

// var typeValidation = 0 ; // 0 -> validation nationale , 1 -> validation depart., 2 -> validation BiDep , 10 -> national temporaire , 11 -> dept temporaire , 12 -> bidept temporaie
// ---------------------------------------------------------------------------------------------------

opera = ( window.opera == 1 || navigator.userAgent.indexOf('Opera') != -1 );

function espece( pcode, plabel){
    this.code = pcode ;
    this.label = plabel ;
};
function article( pcode, plabel , pprix , pespece ){
		this.code = pcode ;
		this.label = plabel ;
		this.prix = pprix ;
		this.status = false ;
		// this.temp = false ;
		this.printLabel = "" ; // le printLabel est un label "propre" pour afficher derriere les options
		if (pespece != '') this.printLabel = especes[pespece].label ;
		this.espece = pespece
		this.show = false ;

		// var prefix = codePrefix( pcode ) ;

		/*
		for ( i in prefixHidden )
			if ( prefixHidden[i] == prefix ) { this.show = false ; break ; }  // certain label sont à cachés dans le résumé de commande
        */
		/*
		for ( i in prefixOptions )
			if ( prefixOptions[i][prefix] ) // si le prefix existe dans le tableau
				this.printLabel = prefixOptions[i][prefix] ;
		*/
	     this.toString = function (){
			return ( this.code + ": " + this.label + " prix: " + this.prix + " € (show:" + this.show +")") ;
		}
		
		
		this.activate = function (){
			this.status = true ;
		};
		
		this.desactivate = function (){
			this.status = false ;
		};
};
// ---------------------------------------------------------------------------------------------------
function zone( pdept ){
	// this.mainArticle ;	
	
	this.dept = pdept ;
	if ( pdept != 0 ) this.label = code[pdept].label ;
	else this.label = "National" ;
	this.options  = new Array() ;
	
	this.pollOptions = function( zone ){    /* parcours le tableau avec tout les prefix d'option et active si il contient le code + le dept. ex : DGG042 ou DSANG045 */
		
		var suffix = '', a , modifier = '' ;
		if ( zone == 11 || zone == 10 ) suffix = "3J" ;
		if ( zone == 21 || zone == 20 ) suffix = "9J" ;
	    if ( zone == 11 || zone == 21 ) modifier = "T" ; // bidouille pour les codes nouveau chasseur : "NCTGG3J" et "NCTGG9J"
		if ( zone == 0 || zone == 10 || zone == 20 || zone == 30 || zone == 40 || zone == 50 || zone == 60) { // sauf pour les GNAT car on a pas le schema "prefix+dept" 
			this.options.push ( articles[NCPREFIX +  'TNGG' + suffix ] ) ;   
        }		
		else 
 			for ( var esp in especes ) 
 				if ( a = articles[ NCPREFIX + modifier + especes[esp].code + suffix + this.dept ] ) {
 				        this.options.push ( a ) ;
                }

 				 //  for (var esp in especes) console.log(NCPREFIX + modifier + especes[esp].code + suffix + this.dept + " > " + articles[NCPREFIX + modifier + especes[esp].code + suffix + this.dept])

	};
	
	this.add = function ( art ){
		this.options.push( art ) ;
	};
	
	this.toogleUsingCode = function ( code , value ){
		for ( i in this.options ) 
			if ( this.options[i].code == code )
				this.options[i].status = value ; 
	};


	this.getArticles = function() {
	    var tmp = new Array();
	    var a;
	    for (i in this.options) {
	        if (this.options[i].status) {
	            this.options[i].show = true; // active l'affichage de l'option (on affiche que les options en fait )
	            tmp.push(this.options[i]);
	        } else if (this.options[i].espece != '' && this.options[i].espece != '0') { //  ajoute une article 'sans' et l'espece si l'option n'est pas validée
	            // if (this.dept == 0 || this.dept == 10 || this.dept == 20 || this.dept == 30 || this.dept == 40 || this.dept == 50 || this.dept == 60) { tmp.push(articles["SGGN"]); }
	            if ( a = articles["S" + especes[this.options[i].espece].code + this.dept] )
	                tmp.push( a );
	        } else if ( this.options[i].code.indexOf("TNGG") >= 0 )  // les options restante ( gg )
					tmp.push( articles["STNGG"] ) ; //console.log( this.options[i].code )
	    }
	    return tmp;
	};
	
	this.toString = function (){
		var str = "dept: " + this.dept + " / label: "+ this.deptLabel +"\n" ;
		for ( i in this.articles ) 
			str += "article " +  i + " [" + this.articles[i] + "]\n" ;
		for ( i in this.options ) 
			str += "option #" + i + " status: " + this.options[i].status + " [" + this.options[i] + "]\n" ;
		return str ;
	}
	
}

// ---------------------------------------------------------------------------------------------------
	function cart(){
		this.articles = new Array() ;
		this.total = 0 ;
		this.label = "" ;

        var lnc = nc?" nouveau chasseur ":""
        		
		// ajout d'article obligatoire suivant le type de validation
		switch ( typeValidation ) {
			case 0:
				this.label = "Validation nationale" +lnc ;
				// if ( this.articles[0] )
				// 	if ( this.articles[0].code == "GNAT" ) // si l'option grand-gibier nat. est selectionné
				// 		this.articles.push( articles["GNAT2"] ) ; // bidouille
				this.articles.push( articles[NCPREFIX + "RN"] ) ;	
				this.articles.push( articles[NCPREFIX + "CFPN"] ) ; 
			break ;
			case 1:
				this.label = "Validation départementale " + lnc + "(" + dept[1].label + ")" ;
				this.articles.push( articles[NCPREFIX + "RD"] ) ;
				this.articles.push( articles[NCPREFIX + "CF"+dept[1].dept] ) ;
			break ;
			case 2:
				this.label = "Validation bi-départementale "+ lnc +" (" + dept[1].label + " + " + dept[2].label + ")" ;
				this.articles.push( articles[NCPREFIX + "RD"] ) ;
				this.articles.push( articles[NCPREFIX + "CF"+dept[1].dept] ) ;
				this.articles.push( articles[NCPREFIX + "RD2"] ) ;
				this.articles.push( articles[NCPREFIX + "CF"+dept[2].dept] ) ;
			break ;
			case 10:
				this.label = "Validation temporaire nationale 3 jours" + lnc ;
				this.articles.push( articles[NCPREFIX + "RTN3J"] ) ;	
                this.articles.push( articles[NCPREFIX + "CFPNT3J"] ) ; 
			break ; 
			case 11:
				this.label = "Validation temporaire départementale "+ lnc +" (" + dept[11].label + ") 3 jours" ;
				this.articles.push( articles[NCPREFIX + "RTD3J"] ) ;
				this.articles.push( articles[NCPREFIX + "TCF3J"+dept[11].dept] ) ;	
			break ;
			
			case 20:
			    this.label = "Validation temporaire nationale 9 jours" + lnc ;
				this.articles.push( articles[NCPREFIX +"RTN9J"] ) ;
				this.articles.push( articles[NCPREFIX + "CFPNT9J"] ) ; 
			break ; 
			case 21:
				this.label = "Validation temporaire départementale "+ lnc +"(" + dept[21].label + ") 9 jours" ;
				this.articles.push( articles[NCPREFIX +"RTD9J"] ) ;
				this.articles.push( articles[NCPREFIX +"TCF9J"+dept[21].dept] ) ;
			break ;
			case 30:
				this.articles.push( articles["CN"] ) ;	// complement national
				this.articles.push( articles["CND"] ) ;	// timbre federal
				this.label = "Extension départemental vers national"  + lnc ;
			break ;
			case 31:
				this.label = "Extension bi-départementale "+ lnc +"(" + dept[31].label + ")" ;
				this.articles.push( articles[NCPREFIX +"RD"] ) ;
				this.articles.push( articles[NCPREFIX +"CF"+dept[31].dept] ) ;
			break ;
			case 60:
			case 61:
				this.label = "Extension Timbre grand gibier et/ou espèce" + lnc ;
			break ;
		/* WorkInProgress
			case 40:
				this.label = "Extension temporaire nationale 3 jours vers national annuelle" ;
				this.articles.push( articles["ETN3J"] ) ;
			break ;
			case 50:
				this.label = "Extension temporaire departementale 3 jours vers national annuelle" ;
				this.articles.push( articles["ETA3J"] ) ;
			break ;
			case 51:
				this.label = "Extension temporaire départementale 3 jours  vers departemental annuelle (pour le 062)" ;
				this.articles.push( articles["ETD3J062"] ) ;
			break ;
			*/
		}
		
		// ceci ajoute dans le cart toutes les options validées pour chaque zones
		for (i in dept){
			if ( dept[i] ) {
				var tmp = dept[i].getArticles() ; // recupere les articles validés
				for ( j in tmp ) {
				    this.articles.push(tmp[j]);
				    //console.log( tmp[j].code );
				}
			}
		}
		
		// ajout de la taxe d'état si elle n'est pas déja payée
		if ( this.articles.length != 0 ) {
		    
		    if ( ! TE ) {
			    this.articles.push( articles["TE1"] ) ;
			    this.articles.push( articles["TE2"] ) ;
		    }
		    // cerfa 
		    this.articles.push( articles["CERFA"] );
		} else {
		    this.label = "Option Revue fdc62 ou assurance :";
		};
		
		// autres 
		if ( abo62 ) this.articles.push( articles["ABO062"] ); 
		if ( appel ) this.articles.push( articles["APPEL"] ) ;
		if ( assur ) this.articles.push( articles[NCPREFIX + 'ASS062'] ) ;
	
		this.addArt = function( art ){
			this.articles.push( art ) ;
			// return this.getTotal() ;
		};
		
		this.getTotal = function () {
			this.total = 0 ;
			for ( i in this.articles ){
				this.total += Number (this.articles[i].prix ) ;
				}
			return this.total ;
		};
		
		this.getLabels = function () {
			var tmp = new Array() ;
			for ( i in this.articles )
				if ( this.articles[i].show )
					tmp.push( this.articles[i].label ) ;
			return tmp ;
		};
		
		this.getCodes = function () {
			var tmp = new Array() ;
			for ( i in this.articles ){

			    tmp.push( this.articles[i].code ) ;
			}
			return tmp ;
		};
		
		 this.toString = function (){
			var str ="" ;
			for ( i in this.articles ) 
				str += i + " > " + this.articles[i].toString() + "\n" ;
			return str ;
		}
		
		
	};

// ---------------------------------------------------------------------------------------------------	
	
function departement( pcode, plabel){
		this.code = pcode ;
		this.label = plabel ;
};

/* ----------- fonctions --------------- */
	
function selectDept( pzone , pval ){
    
	dept[pzone] = new zone( pval ) ;
	dept[pzone].pollOptions( pzone );
	// typeValidation = typeValidation() ;
	// affichage(pzone);
	typeValidation = pzone ;
	//console.log( pzone + " / " + pval );
    
};

function unselectDept( zone ){
	dept[zone] = null ;
};

function selectAbo( val ){
	abo62 = val ;
	document.getElementById("abo62").checked = val ;
};

function selectAssurance( val ){
	assur = val ;
	document.getElementById("assurance").checked = val ;
};

function selectAppelant( val ){
	appel = val ;
};

function selectOption( zone , optionNum , obj ) {
	// l'option est forcement dispo dans le tableau des options - la valeur obj.checked renvoie true ou false suivant l'état
	dept[zone].options[optionNum].status = obj.checked ;
	
	// console.log( dept[zone] );
	
	if ( obj.checked ) { //  rechercher les options unique
	
		var code = obj.id ;
		for ( var opts in dept[zone].options ) {
			var opt = dept[zone].options[opts].code ;
			if ( opt != code ) {
					var op = document.getElementById( opt ) ;
					if ( op ) {	// si trouvé
						op.checked = false ; // desactive l'affichage
						dept[zone].toogleUsingCode( opt , false ); // desactive l'option dans sa zone
						
					}
			}
				
				
			// console.log( dept[zone].options[opts].code ) ;
		}
		
		
		/*
		m = new RegExp(code);
		
		
		for ( var esp in especes ) {
		    var opt = "" + NCPREFIX + especes[esp].code +  dept[zone].dept
			
		    if ( opt != code ) {
				
	                op = document.getElementById( opt ) ; // cherche l'option dans le DOM
					// console.log( opt + "  " + op )
					if ( op ) {	// si trouvé
						op.checked = false ; // desactive l'affichage
						dept[zone].toogleUsingCode( opt , false ); // desactive l'option dans sa zone
						
					}
		    
		    }
		    
		
		}
		*/
	
//		//  rechercher les options unique
//		var code = obj.id ;
//		// var listeCodes = new Array() ;
//		m = new RegExp(code);
//		for ( i in optionUnique )	{ // parcours le tableau des codes uniques
//			if ( m.test( optionUnique[i] ) ) { // teste si le code se trouve dans la chaine
//				var tmp = optionUnique[i].split(",") ; // eclate les codes dispo en tableau
//				for ( i in tmp ) {	// parcours le tableau créer par la ligne précedente
//					if ( tmp[i] != code ) {	// évite de désactiver le code actuellement cliqué
//						op = document.getElementById( tmp[i] ) ; // cherche l'option dans le DOM
//						if ( op ) {	// si trouvé
//							op.checked = false ; // desactive l'affichage
//							dept[zone].toogleUsingCode( tmp[i] , false ); // desactive l'option dans sa zone
//							
//						}
//						
//					}
//				}
//			}
//		}
	
	
	}
	
	
};

function showOptions( zone, place ){
    // alert ( zone + "-" + place + " " + dept[zone].dept + "\n" + dept[zone].options ) 
	// la fonction crée des checkBox à la volée avec les différentes options
	// RAZ du noeud d'affichage
	var node = document.getElementById( place ) ;	// localise la zone d'affichage
	
	if ( node.firstChild ) node.removeChild( node.firstChild ) ;	// nettoie si occupé
	Holder = node.appendChild( document.createElement("div") ) ;	// crée un nouveau noeud div.
	// ---------- AFFICHAGE OPTIONS ----------
	// création des boutons options
		for ( i in dept[zone].options ) {
		    
			newNode = Holder.appendChild( document.createElement("div") ) ;	// crée un nouveau noeud div.
			// crée les cases à cocher "à la volée"
			var label ;
			var checkbox ;
			
			//if NN6 then OK to use the standard setAttribute
			if ( (!document.all && document.getElementById) || opera ){
				checkbox = document.createElement("input");
				checkbox.setAttribute("type","checkbox");
				checkbox.setAttribute("name","option");
				checkbox.setAttribute("id", dept[zone].options[i].code );
				checkbox.setAttribute("value", dept[zone].options[i].code);	// le value de la checkbox = le code
				if ( dept[zone].options[i].status ) checkbox.setAttribute("checked" , "true" );	// valeur actuelle
				checkbox.setAttribute("onChange", "selectOption( " + zone + ", " + i + " , this );showCart();" ); // fonction à utiliser NN6
				newNode.appendChild( checkbox ) ;	// on envoie la checkbox au navigateur
			}
			//workaround for IE 5.x
			else if ( document.all && document.getElementById ) {
				checkbox = document.createElement("<input type=checkbox name=option>");
				checkbox.setAttribute("id", dept[zone].options[i].code );
				checkbox.setAttribute("value", dept[zone].options[i].code);	// le value de la checkbox = le code
			   	checkbox["onclick"] = new Function("selectOption( " + zone + ", " + i + " , this );showCart();"); // fonction à utiliser IE 5.x
				newNode.appendChild( checkbox ) ;
				if ( dept[zone].options[i].status ) checkbox.setAttribute("checked" , "true" );	// valeur actuelle
			}
			
			label =  dept[zone].options[i].printLabel ; //labelOption( dept[zone].options[i].code ) ; // label option crée un label "propre"
			newNode.appendChild( document.createTextNode( label ) ) ; // crée le commentaire après la checkbox

		}
};

function removeOptions( place ){
	var node = document.getElementById( place ) ;
	if ( node )
		if ( node.firstChild )
			node.removeChild( node.firstChild ) ;
};

/*
function typeValidation(){ // 0 -> validation nationale , 1 -> validation depart., 2 -> validation BiDep , 10 -> national temporaire , 11 -> dept temporaire , 12 -> bidept temporaie
	var type ;
	if ( dept[0] ) type = 0 ;
	else if ( dept[1] && !dept[2] ) type = 1 ;
	else if ( dept[1] && dept[2] ) type = 2 ;
	else if ( dept[10] ) type = 10 ;
	else if ( dept[11] ) type = 11 ;
	else if ( dept[20] ) type = 20 ;
	else if ( dept[21] ) type = 21 ;
	else if ( dept[30] ) type = 30 ;
	else if ( dept[31] ) type = 31 ;
	else if ( dept[40] ) type = 40 ;
	else if ( dept[50] ) type = 50 ;
	else if ( dept[51] ) type = 51 ;
	else if ( dept[60] ) type = 60 ;
	else if ( dept[61] ) type = 61 ;
	else if ( dept[62] ) type = 62 ;
	// alert(type)
	return type ;
};
*/
/*
function codePrefix(valeur){ // retourne le prefix d'un code (marche avec national ou non)
 	var expression = /([A-Z0-9]+)(\d\d[AB0-9])/;
	var res = expression.exec(valeur);
	if ( res ) return RegExp.$1 ;
	else return valeur ;
};
*/

/* ----------- showCart ----------- affiche le résumé de la commande    */

function showCart(){	
	
	var carta = new cart() ;
	
	var total = carta.getTotal() ;
	/* var total = carta.refresh( dept ) ; */
	/* affichage  */
	var nodeTotal = document.getElementById( "totalChoix" ) ;
	var nodeListe = document.getElementById( "details" ) ;	
	if ( a = nodeListe.firstChild  ) nodeListe.removeChild( a ) ;
	if ( b = nodeTotal.firstChild ) nodeTotal.removeChild( b ) ;
	nodeListeF = nodeListe.appendChild( document.createElement("ul") ) ;
	nodeTotalF = nodeTotal.appendChild( document.createElement("div") ) ;	
	
	var tmpListe = document.createElement("div");
	var tmpLabel = "";
	if ( carta.articles.length == 0) 
        tmpListe.appendChild( document.createTextNode( "Aucune option validée."  ) ) ; // crée un noeud avec le label du type de validation
    else 
	    tmpListe.appendChild( document.createTextNode( carta.label  ) ) ; // crée un noeud avec le label du type de validation
	// affichage du titre du résumé
	nodeListeF.appendChild( tmpListe ) ;
    // affichage de la liste des options
	// boucle pour le calcul du total et concat des articles
	var labels = carta.getLabels() ;
	for ( i in labels ){
		// texte liste
		tmpListe = document.createElement("li");
		tmpListe.appendChild( document.createTextNode( labels[i] ) ) ;
		nodeListeF.appendChild( tmpListe ) ;
		tmpLabel += "|" + labels[i]  ;
	} 

	// affichage total
	nodeTotalF.appendChild( document.createTextNode( "Prix total : " + formatAsMoney(total) + " €" ) ) ;
	// champ hidden de prix
	document.forms.campagne.prix.value = total ;
	// champ hidden d'articles
	document.forms.campagne.articles.value = carta.getCodes().join(",") ;
	// champ hidden libellé
	document.forms.campagne.libelle.value = carta.label + tmpLabel ;
    //console.log( carta );
	document.getElementById('sb').disabled = total<=0?"disabled":"" ;
	document.getElementById('sb').src = total<=0?"images/valider_off.gif":"images/valider_01.gif" ;
};

/* ------------ refillSelect  ---------------------
rafraichi le menu déroulant avec les code et noms des départements d'après le tableau 'code'
paramètres:
	- selectCtrl : le menu à rafraichir
	- codeToAvoid : un code à éviter (ou plusieurs)
	- defaultSelected : la valeur par defaut
*/

function refillSelect ( selectCtrl, codeToAvoid, defaultSelected  ) {
	var i, j=0, oldSel ;
	if (  defaultSelected == null ) oldSel = selectCtrl.value ;
	else oldSel = defaultSelected ;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) 
		if ( selectCtrl.options[i] )
		 	selectCtrl.options[i] = null ; 

	// add new items
	for ( i in code ) {
		m = new RegExp(i);
		// document.write( i + ": " + codeToAvoid + " = " + m.test( codeToAvoid  )  + "<br>" ) 
		if ( ! m.test( codeToAvoid )  ){
			selectCtrl.options[j] = new Option( code[i].code + " " + code[i].label , i ) ;
			if ( i == oldSel ) selectCtrl.options[j].selected = true;
			j++ ;
		}	
	}
	
	return selectCtrl.value ; 
};

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
};

/*
function affichage( pzone ){
	switch( pzone){
		case 1: dept[pzone].toogleUsingCode( "SANG062" , true );
				//document.getElementById("mentionsNat").style.display = "none" ;
				break ;
		case 0: dept[pzone].toogleUsingCode( "SANG062" , true );
		case 10: dept[pzone].toogleUsingCode( "XSANG3J062" , true );
		case 20: dept[pzone].toogleUsingCode( "XSANG9J062" , true );
		//case 30:
		
				//document.getElementById("mentionsNat").style.display = "block" ;
				break ;
		default :
		    if ( mentions = document.getElementById("mentionsNat") )
			    mentions.style.display = "none" ;
		}
		// alert( pzone);
	};
*/

function init(){
				var myform  = document.forms.campagne ;
                mode = myform.m$c1$mode.value ;
                codeDejaValide =  myform.m$c1$codeDejaValide.value ;
                TE = myform.m$c1$vte.value == "0"?false:true ;
                nc = myform.m$c1$nc.value == "0"?false:true ;
                var abo = myform.m$c1$abo.value == "0"?false:true ;
                NCPREFIX = nc?"NC":""
                // cerfa = myform.m$c1$lcerfa.value ;
                
                // myform.vnat.onclick = mainSel ;
                articles["ABO062"].show = true ;
                articles["ASS062"].show = true ;
                articles["NCASS062"].show = true ;
                
				switch ( mode ) {
					case "v" :
						refillSelect(myform.dept1 , null , "062" ) ;
						refillSelect(myform.dept2 , "062" , "059" ) ; // éviter le code 062 pour le dept 2  // selectionne le 059 par defaut
						selectDept(1,"062") ;
						showOptions(1,'optionDept1');
						selectAbo( ! abo ) ; 
						selectAppelant( false ) ;
						selectAssurance( false ) ;
						// attribution des evenements
						myform.vnat.onclick = fvnat ;
						myform.vdept1.onclick = fvdept1 ;
						myform.vdept2.onclick = fvdept2 ;
						myform.listDept1.onchange = fld1 ;
						myform.listDept2.onchange = fld2 ;
					break ;
					case "t3" :
						var seldept = refillSelect(myform.dept11 , codeDejaValide , "062"  ) ;
						selectDept(11,seldept) ;
						showOptions(11,'optionDept11');
						selectAbo( ! abo ) ; 
						selectAppelant( false ) ;
						selectAssurance( false ) ;
					break ;
					case "t9" :
						var seldept = refillSelect(myform.dept21 , codeDejaValide , "062" ) ;
						selectDept(21,seldept) ;
						showOptions(21,'optionDept21');
						selectAbo( ! abo ) ; 
						selectAppelant( false ) ;
						selectAssurance( false ) ;
					break ;
					
					/*
					case "cgg" :
						// codes déjà validés
						var codes = codeDejaValide.split(",") ;
						// console.log( codes );
						var enumcode 
						var num = 0 ;
                        // création d'un tableaux des timbres grands gibiers dispos
				        for ( enumcode=0 ; enumcode < codes.length ; enumcode++ )  {
				            var offset = enumcode + 61 ; // numéro d'option démarre à 61
							selectDept( offset, codes[enumcode] );
							
							if ( dept[offset].options.length > 0 ) {
							    var htmlCode = '<div style="border-top: 1px solid #DDDDDD;"><table><tr><td>' + code[codes[enumcode]].label + ' : </td><td><span id="option' + offset + '"></span></td></tr></table></div>' ;
							    document.getElementById("ggOptions").innerHTML = htmlCode ;
								showOptions( offset ,'option' + offset );
								// console.log( offset + " " + htmlCode );
								num ++ ;
							}
							
				         } 
						// si aucun dispo 
						 if ( num == 0 ) {
						    document.getElementById("m_c1_gg").style.display = "none" ;
						 }
						
						//var seldept = refillSelect(myform.dept31 , codeDejaValide  ) ;
						//selectDept(31,seldept) ;
						//showOptions(31,'optionDept31');
						selectAbo( ! abo ) ; ;
						selectAppelant( false ) ;
						selectAssurance( false ) ;
					break ;
                    */

                    case "cn" :
						selectDept(30,0);
						showOptions(30,'option30');
						selectAbo( ! abo ) ; 
						selectAppelant( false ) ;
						selectAssurance( false ) ;
					break ;
					
                    case "cd" :
						var seldept = refillSelect(myform.dept31 , codeDejaValide ,"062"  ) ;
						selectDept(31,seldept) ;
						showOptions(31,'optionDept31');
						selectAbo( ! abo ) ; 
						selectAppelant( false ) ;
						selectAssurance( false ) ;
						// evenement
						myform.listeDept31.onchange = fld31 ;
					break ;


                    case "cgg2" :
						var seldept = refillSelect(myform.dept61  ) ;
						selectDept(61,seldept) ;
						showOptions(61,'optionDept61');
						selectDept(60,0) ;
						showOptions(60,'optionDept60');
						selectAbo( ! abo ) ; 
						selectAppelant( false ) ;
						selectAssurance( false ) ;
						// evenement
						myform.listeDept61.onchange = fld61 ;
					break ;

				};
				

				showCart();

};
window.onload = init ;

function fvnat (){
    this.form.dept1.disabled=true;
    this.form.dept2.disabled=true;
    selectDept(0,0);
    showOptions(0,'optionNat');
    unselectDept(1);
    removeOptions('optionDept1');
    unselectDept(2);
    removeOptions('optionDept2');
    showCart()
};

function fvdept1(){
	this.form.dept1.disabled=false;
	this.form.dept2.disabled=true;
	unselectDept(0);
	removeOptions('optionNat');
	selectDept(1,this.form.dept1.value);
	showOptions(1,'optionDept1');
	unselectDept(2);
	removeOptions('optionDept2');
	showCart()
	};
	
function fvdept2(){
	this.form.dept1.disabled=false;
	this.form.dept2.disabled=false;
	unselectDept(0);
	removeOptions('optionNat');
	selectDept(1,this.form.dept1.value);
	showOptions(1,'optionDept1');
	selectDept(2,this.form.dept2.value);
	showOptions(2,'optionDept2');
	showCart();
	};
	
function fld1(){
	selectDept(1,this.value);
	showOptions(1,'optionDept1');
	showCart();
	refillSelect(this.form.dept2,this.value);
	};
		
function fld2(){
	selectDept(2,this.value);
	showOptions( 2,'optionDept2' );
	showCart();
	refillSelect(this.form.dept1,this.value);
	};
function fld31(){
    selectDept(31,this.value);
    showOptions(31,'optionDept31');
    showCart();
};
function fld61(){
    selectDept(61,this.value);
    showOptions(61,'optionDept61');
    showCart(); 
};
