// Function.js

/*
	Fonction d'écriture des encarts de PUB
	BUG possible : si dans la description on écrit un ' à mon avis ça plante.
*/
	function ecrire_encart(){
		var contenu = "";
		if(description != ""){
			if(image != ""){
				contenu += "<table><tr>";
				contenu += "<td class='pub_left'><img src='"+ image +"' alt='"+ chapo +"' border='0' width='80px' /></td>";
				contenu += "<td class='pub_right'><b>"+ chapo +"</b>"+ description +"</td>";
				contenu += "</tr></table>";
			}
			else{
				contenu += "<div class='texte_pub'><b>"+ chapo +"</b>"+ description +"</div>";
			}
		}
		else{
			contenu += "<div class='img_pub'><a href='"+ chapo +"' alt='"+ titre +"'><img src='"+ image +"' alt='"+ titre +"' border='0' /></a></div>";
		}
		document.write(contenu);
	}


/*
	<Gestion de l'affichage des cours>
*/
    function afficher_tableau(id_element, table_entetes, table_donnees){
        html = "";
        if(table_donnees[0][0]!=""){
			html += afficher_entete_tableau(table_entetes);
            for(i=0; i<table_donnees.length-1; i++){
                html += afficher_ligne(table_donnees[i][0], table_donnees[i][1]);
            }
        }
        document.getElementById(id_element).innerHTML=html;
    }
	function afficher_entete_tableau(entetes){
		var html = "<table>";
		html += "	<tr>";
		for(i=0; i<entetes.length; i++){
			html += "		<th>"+entetes[i]+"</th>";
		}
		html += "	</tr>";
        return html;
		//document.write(html);
	}
	
	function affiche_mois(num_mois){
		mois= new Array("janvier","f&eacute;vrier","mars","avril","mai","juin","juillet","ao&ucirc;t","septembre","octobre","novembre","d&eacute;cembre");
		return mois[num_mois];
	}
	
	function affiche_jour(a, m, j){
		d = new Date(a, m, j);
		tab_j= new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
		//alert(" annee = "+a+",\n mois = "+m+",\n jour = "+j+",\n date = "+d);
		return tab_j[d.getDay()];
	}
	
	function afficher_ligne(ref, stock){
		annee = ref.substr(0,4);
		num_mois = ref.substr(4,2);
		//alert(num_mois);
		jour = ref.substr(6,2);
		
		h1 = ref.substr(8,2) + "h" + ref.substr(10,2);
		h2 = ref.substr(12,2) + "h" + ref.substr(14,2);
		
		if(stock > 0){
			action = "<span class='bouton_commander' ><a href='mailto:?subject=www.oenoschool.com : Un excellent site pour apprendre le vin'>Informer un ami</a> / <a href='panier.php?action=ajouter&amp;ref="+ref+"'>S'inscrire</a></span>";
		}
		else {
			action = "<span class='complet'>Complet</span>";
		}
		date = new Date();
		annee_hoy = date.getFullYear();
		num_mois_hoy = parseInt(date.getMonth(),10)+1;
		if(num_mois_hoy<10)
			num_mois_hoy = "0"+num_mois_hoy;
		jour_hoy = date.getDate();
		
		var_de_compar = parseInt(annee_hoy + num_mois_hoy + jour_hoy,10);
//alert(parseInt(num_mois-1));
		if(parseInt(annee+num_mois+jour,10) >= var_de_compar){
			var html = "<tr>";
			html += "	<td>"+ affiche_jour(annee, parseInt(num_mois-1), jour) + " " + jour + " " + affiche_mois(parseInt(num_mois-1)) + " " + annee;
			html += "	</td>";
			html += "	<td>" + h1 + " &agrave; " + h2;
			html += "	</td>";
			html += "	<td align='center'>" + action;
			html += "	</td>";
			html += "</tr>";
			
            return html;
			//document.write(html);
		}
	}
	
	function afficher_fin_tableau(){
		var html = "</table>";
		//document.write(html);
        return html;
	}
	
	
    function horaire_de_cours(ref){
        if(ref.substr(0, 5)=="CHQKDO"){
			document.write(ref);
		}
		else{
			annee = ref.substr(0,4);
			num_mois = ref.substr(4,2);
			jour = ref.substr(6,2);
			
			h1 = ref.substr(8,2) + "h" + ref.substr(10,2);
			h2 = ref.substr(12,2) + "h" + ref.substr(14,2);
			
			html = affiche_jour(annee, parseInt(num_mois)-1, jour) + " " + jour + " " + affiche_mois(parseInt(num_mois)-1) + " " + annee;
			html += "<br />de " + h1 + " &agrave; " + h2;
			
			document.write(html);
		}
    }
