/**
 * Page regroupant toutes les fonctions Javascript utilisées dans l'architecture Client-Riche Ajax.
 * 
 * function DateChange()
 * Ce script permet de modifier la variable $_SESSION['date'] .
 * 
 * function DateOnChange()
 * Ce script s'exécute au moment où le champs <input id="dateJour"> est modifié.
 *
 * function showAll(a, b, c){}
 * Ce script Affiche l'onglet sélectionné.
 *
 * function ShowHide(a, b, c){}
 * Ce script masque les onglets non sélectionnés.
 *
 *
 * @since        01/07/2010
 * @version      V1
*/

var Attente = "<center><img src='./images/loading.gif' /><br/> chargement en cours...</center>";
var RechCrt = "&nbsp;&nbsp;<img src='./images/loading2.gif' />";
var LoginWait = "&nbsp;&nbsp;<img src='./images/loading.gif' />";


function formatCurrency(chaine){
temp = chaine.replace(/[.]/gi,"")
return temp
}

function specialcaracter(chaine) {
temp = chaine.replace(/[ ]/gi,"%20")
temp = temp.replace(/[']/gi,"\'")
return temp
}

function noaccent(chaine) {
temp = chaine.replace(/[àáâãäå]/gi,"a")
temp = temp.replace(/[èéêë]/gi,"e")
temp = temp.replace(/[ìíîï]/gi,"i")
temp = temp.replace(/[òóôõöø]/gi,"o")
temp = temp.replace(/[ùúûü]/gi,"u")
temp = temp.replace(/[ç]/gi,"c")
temp = temp.replace(/[ýÿ]/gi,"y")
temp = temp.replace(/[ñ]/gi,"n")
temp = temp.replace(/[ß]/gi,"ss")
temp = temp.replace(/[œ]/gi,"oe")
temp = temp.replace(/[æ]/gi,"ae")
temp = temp.replace(/[š]/gi,"s")

temp=temp.toUpperCase()
return temp
}

function showCarteDuJour(){
	$.post("ajax/ajax_afficher_carte_du_jour.php", {}, function(data){
		if(data.length >0) {
		//alert(data);
			Result = parseInt(data);
			switch (Result) {
			case 1:
				$('#menu_principal').html('<ul  class="gallery clearfix" ><li id="active"><a href="javascript:showCarteDuJour();"><span>Carte du jour</span></a></li><li ><a href="javascript:showGenerer(\'1\');"><span>Générer une carte</span></a></li><li ><a href="javascript:window.print();"><span>Imprimer la carte</span></a></li><li><a href="bilan_hauteur_mensuelle.php">Bilan</a></li></ul>');
				document.location.reload(true);
				break;
			default:
				break;
			}
		}
	});
}

//function GenererCarte(){

	//Récupération variables
	//var hh = $("#hh").val();
	//var mm = $("#mm").val();
	//var dd = $("#dd").val();
	//var yy = $("#yy").val();
	
	//$.post("ajax/ajax_generer_carte.php", {mm: ""+mm+"",dd: ""+dd+"",yy: ""+yy+"",hh: ""+hh+""}, function(data){
	//	if(data.length >0) {
		//alert(data);
	//		Result = parseInt(data);
	//		switch (Result) {
	//		case 1:
	//			document.location.reload(true);
	//			$('#menu_principal').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showCarteDuJour();"><span>Carte du jour</span></a></li><li id="active"><a href="javascript:showgenerer();"><span>Générer une carte</span></a></li><li ><a href="javascript:window.print();"><span>Imprimer la carte</span></a></li></ul>');

	//			break;
	//		case 2:
	//			alert('Veuillez indiquer le jour, le mois, et l\'année de la carte à générer.');
	//			break;
	//		}
	//	}
	//});
//}

function GenererCarte(){

	//Récupération variables
	var hh = $("#hh").val();
	var vardate_g = $("#datepicker").val();

	$.post("ajax/ajax_generer_carte.php", {date_g: ""+vardate_g+"",hh: ""+hh+""}, function(data){
		if(data.length >0) {
		//alert(data);
			Result = parseInt(data);
			switch (Result) {
			case 1:
				document.location.reload(true);
				$('#menu_principal').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showCarteDuJour();"><span>Carte du jour</span></a></li><li id="active"><a href="javascript:showGenerer(\'2\');"><span>Générer une carte</span></a></li><li ><a href="javascript:window.print();"><span>Imprimer la carte</span></a></li><li><a href="bilan_hauteur_mensuelle.php">Bilan</a></li></ul>');

				break;
			case 2:
				alert('Veuillez indiquer la date de la carte à générer.');
				break;
			}
		}
	});
}

function showGenerer(num){

	switch(num){

		case "1":
		$('#menu_principal').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showCarteDuJour();"><span>Carte du jour</span></a></li><li id="active"><a href="javascript:showGenerer(\'2\');"><span>Générer une carte</span></a></li><li ><a href="javascript:window.print();"><span>Imprimer la carte</span></a></li><li><a href="bilan_hauteur_mensuelle.php">Bilan</a></li></ul>');
		$('#generer_carte').show();
		break;

		case "2":
		$('#menu_principal').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showCarteDuJour();"><span>Carte du jour</span></a></li><li id="active"><a href="javascript:showGenerer(\'1\');"><span>Générer une carte</span></a></li><li ><a href="javascript:window.print();"><span>Imprimer la carte</span></a></li><li><a href="bilan_hauteur_mensuelle.php">Bilan</a></li></ul>');
		$('#generer_carte').hide();
		break;
	}

}


function DateChange(datestamp,txtStation,txtCarte){

	$.post("ajax/ajax_change_session_date.php", {datestamp: ""+datestamp+""}, function(data){
		if(data.length >0) {

			switch (txtCarte) {
				case 'H':
					document.location.href="Parametres.php?TxtStation="+ txtStation;
					break;

			}
		}
	});
}

function DateChangeMonth(datestamp,txtStation,txtPage){

	$.post("ajax/ajax_change_session_date.php", {datestamp: ""+datestamp+""}, function(data){
		if(data.length >0) {

			switch (txtPage) {
				case 'H':
					document.location.href="hauteur_mensuelle.php?TxtStation="+ txtStation;
					break;

				case 'BH':
					document.location.href="bilan_hauteur_mensuelle.php";
					break;
			}
		}
	});
}

function DateChangeYear(datestamp,txtStation,txtPage){

	$.post("ajax/ajax_change_session_date.php", {datestamp: ""+datestamp+""}, function(data){

		if(data.length >0) {

			switch (txtPage) {
				case 'H':
					document.location.href="hauteur_annuelle.php?TxtStation="+ txtStation;
					break;

				case 'BH':
					document.location.href="bilan_hauteur_annuelle.php";
					break;
			}
		}
	});
}


function DateOnChange(datestamp,txtStation,txtCarte){

	$.post("ajax/ajax_onchange_session_date.php", {datestamp: ""+datestamp+""}, function(data){
		if(data.length >0) {

			switch (txtCarte) {
				case 'H':
					document.location.href="Parametres.php?TxtStation="+ txtStation;
					break;
			}
		}
	});
}

function DateOnChangeMonth(datestamp,txtStation,txtCarte){

	$.post("ajax/ajax_onchange_session_date_month.php", {datestamp: ""+datestamp+""}, function(data){
		
		if(data.length >0) {

			switch (txtCarte) {
				case 'H':
					document.location.href="hauteur_mensuelle.php?TxtStation="+ txtStation;
					break;

				case 'BH':
					document.location.href="bilan_hauteur_mensuelle.php";
					break;
			}
		}
	});
}

function DateOnChangeYear(datestamp,txtStation,txtCarte){

	$.post("ajax/ajax_onchange_session_date_year.php", {datestamp: ""+datestamp+""}, function(data){
		if(data.length >0) {

			switch (txtCarte) {
				case 'H':
					document.location.href="hauteur_annuelle.php?TxtStation="+ txtStation;
					break;
				case 'BH':
					document.location.href="bilan_hauteur_annuelle.php";
					break;
			}
		}
	});
}

function showAll(a, b, c){
	//  récupération de la variable onglet
	Result = parseInt(c);
		switch (Result) {
			case 1:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li><a href="javascript:showHide(\'Graphe\',\'table_data\', 2);"><span>Graphe</span></a></li><li ><a href="javascript:showHide(\'table_data\',\'Graphe\', 3);"><span>Tableau</span></a></li><li id="active"><a href="javascript:showAll(\'Graphe\',\'table_data\', 1);"><span>Graphe & Tableau</span></a></li></ul>');
				break;
			case 2:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li id="active" ><a href="javascript:showHide(\'Graphe\',\'table_data\', 2);"><span>Graphe</span></a></li><li ><a href="javascript:showHide(\'table_data\',\'Graphe\', 3);"><span>Tableau</span></a></li><li><a href="javascript:showAll(\'Graphe\',\'table_data\', 1);"><span>Graphe & Tableau</span></a></li></ul>');
				break;
			case 3:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showHide(\'Graphe\',\'table_data\', 2);"><span>Graphe</span></a></li><li id=active ><a href="javascript:showHide(\'table_data\',\'Graphe\', 3);"><span>Tableau</span></a></li><li><a href="javascript:showAll(\'Graphe\',\'table_data\', 1);"><span>Graphe & Tableau</span></a></li></ul>');
				break;
		}

	$('#'+b).show();
	$('#'+a).show();
}

function showHide(a, b, c) {

	//  récupération de la variable onglet
	Result = parseInt(c);
		switch (Result) {
			case 1:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showHide(\'Graphe\',\'table_data\', 2);"><span>Graphe</span></a></li><li ><a href="javascript:showHide(\'table_data\',\'Graphe\', 3);"><span>Tableau</span></a></li><li id="active"><a href="javascript:showAll(\'Graphe\',\'table_data\', 1);"><span>Graphe & Tableau</span></a></li></ul>');
				break;
			case 2:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li id=active ><a href="javascript:showHide(\'Graphe\',\'table_data\', 2);"><span>Graphe</span></a></li><li ><a href="javascript:showHide(\'table_data\',\'Graphe\', 3);"><span>Tableau</span></a></li><li><a href="javascript:showAll(\'Graphe\',\'table_data\', 1);"><span>Graphe & Tableau</span></a></li></ul>');
				break;
			case 3:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li ><a href="javascript:showHide(\'Graphe\',\'table_data\', 2);"><span>Graphe</span></a></li><li id=active><a href="javascript:showHide(\'table_data\',\'Graphe\', 3);"><span>Tableau</span></a></li><li><a href="javascript:showAll(\'Graphe\',\'table_data\', 1);"><span>Graphe & Tableau</span></a></li></ul>');
				break;
		}

	$('#'+b).hide();
	$('#'+a).show();
}

function showHideBilan(a, b, c) {

	//  récupération de la variable onglet
	Result = parseInt(c);
		switch (Result) {
			case 1:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li id=active><a href="javascript:showHideBilan(\'premiere\',\'deuxieme\', 1);"><span>Première quinzaine</span></a></li><li><a href="javascript:showHideBilan(\'deuxieme\',\'premiere\', 2);"><span>Deuxième quinzaine</span></a></li></ul>');
				break;
			case 2:
				$('#Onglet').html('<ul  class="gallery clearfix" ><li><a href="javascript:showHideBilan(\'premiere\',\'deuxieme\', 1);"><span>Première quinzaine</span></a></li><li id=active><a href="javascript:showHideBilan(\'deuxieme\',\'premiere\', 2);"><span>Deuxième quinzaine</span></a></li></ul>');
				break;
		}

	$('#'+b).hide();
	$('#'+a).show();
}
