
	function validateForm() {
		window.scrollTo(0,0);
		$('#msg_box').hide();
		msg = "";
		if($("#nom_organisme_id").val() == "") msg += "Vous devez spécifier votre nom d'organisme<br />";
		if($("#titre_projet_id").val() == "") msg += "Vous devez spécifier votre prénom<br />";
		if($("#nom_responsable_id").val() == "") msg += "Vous devez spécifier un responsable de l'organisme<br />";
		//if($("#certifie_rapport_id").val() == "") msg += "Vous devez certifier que les renseignements fournis dans le présent rapport final sont exacts. ";
		console.info($("#certifie_rapport_id").attr('checked'));
		// if($("courriel_id").getValue() == "") msg += "Vous devez spécifier votre courriel<br />"
		// 		if($("adresse_id").getValue() == "") msg += "Vous devez spécifier votre adresse<br />"
		// 		if($("ville_id").getValue() == "") msg += "Vous devez spécifier votre ville<br />"
		// 		if($("codepostal_1_id").getValue() == "" || $("codepostal_2_id").getValue() == "") msg += "Vous devez spécifier votre code postal<br />"
		// 		if($("tel_1_id").getValue() == "" || $("tel_2_id").getValue() == "" || $("tel_3_id").getValue() == "") msg += "Vous devez spécifier votre téléphone<br />"
		if(msg == "") {
			$("#form").submit();
		} else {
			$('#msg_box').html(msg);
			$('#msg_box').show();
		}
		return false;
	}


	// Function utilisé dans les calendrier pour changer la couleurs des date ou il y a des evenements
	function highLightCalendarDate() {
		clearTimeout(window.highlightTimeout);
		$("#calendar table tbody td a").each(function(i, el) {
			$(events).each(function(i, val) {
				if($(el).html() == val.day) {
					$(el).parent().addClass("hasEvent")
					$(el).parent().addClass("disc_"+val.discipline_id)
				} else {
					$(el).parent().addClass("disabled")
				}
			})
		})
	}

	function getNouvelleEtArtiste(idDiscipline) {
		$("#discipline a").each(function() {
			$(this).removeClass('active');
		})
		$("#discipline_menu_"+idDiscipline).addClass("active");
		$.post("action.php", {action:"getNouvelleEtArtiste",d:idDiscipline}, function(data){
			$("#nouvelle_et_artiste").html(data)
		})		
		return false
	}
	
	$(function(){
		$(".fancybox").fancybox(); 

		$('#nav_princ li, #menu_top ul li').hover(
			function(){
				if($(this).hasClass("actif") == false) $(this).addClass("over")
			},
			function(){
				if($(this).hasClass("actif") == false) $(this).removeClass("over")
			}
		);
		$('ul#sousmenu li').hover(
			function(){ $(this).addClass("over"); },
			function(){ $(this).removeClass("over"); }
		);
		$("div.en_savoir_plus").hover(
			function () {
				$(this).css("backgroundColor","#78756E");
			},
			function () {
				$(this).css("backgroundColor","#4f4f4f");
			}
		);
		
		// Menu Second Niveau
//*
	 	$('.scroll').click(function() {
			//$(this).next().slideToggle();
			//$(this).parent().toggleClass("forced")
			window.location = $(this).next().find('li a:first').attr("href");
			return false;
		}).next().hide();
//*/
/*
	 	$('.scroll').click(function() {
			$(".clicked").removeClass("clicked")
			$(this).addClass("clicked").parents().addClass("clicked")

			$('.scroll').next().slideUp();
			$('.scroll').parent().removeClass("forced")

			$(this).next().slideDown();
			$(this).parent().addClass("forced")
			return false;
		}).next().hide();
//*/
		
		$.datepicker.setDefaults({
			monthNames:['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
			dayNamesShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
			dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
			dateFormat: 'yyyy-mm-dd'
		})
		
		
		/* 
		 * Index - partenaires
		*/
		var compteur_logo = 2;
		function callAnimLogo(){
			$('#partenaires_div a').fadeOut('slow');
			$('#partenaires_div a:nth-child('+compteur_logo+')').fadeIn('slow');
			compteur_logo++;
			if(compteur_logo == $('#partenaires_div a').length) compteur_logo = 1;
		}
		var timer = setInterval(callAnimLogo,6000);
		
		
		$('#lien_demandeur_membre_collectif').click(
			function () {
				if($('#demandeur_membre_collectif').css("display") == "none"){
					$('#demandeur_membre_collectif').css("display","block")
					$('#demandeur_representant_collectif').css("display","none")
				}else{
					$('#demandeur_membre_collectif').css("display","none")
				}
		}
		);
		$('#lien_demandeur_representant_collectif').click(
			function () {
				if($('#demandeur_representant_collectif').css("display") == "none"){
					$('#demandeur_representant_collectif').css("display","block")
					$('#demandeur_membre_collectif').css("display","none")
				}else{
					$('#demandeur_representant_collectif').css("display","none")
				}
			}
		);
		
		$(".ajout_fichier").click(
			function () {
				$(this).before('<p><input type="file" name="'+ $(this).attr("id") +'[]" value="" id="" class="input_file" /></p>')
			}
		)
		
	});
	
	function formToText() {
		$("input[type='text'],textarea").each(function(e) {
			$(this).attr("readonly", "readonly")
			//$(this).before("<span class=\"form_input\">"+$(this).val()+"</span>")
			//$(this).remove();
		});
		$("select").each(function(e) {
			$(this).attr("disabled", "disabled")
			//$(this).before("<div class=\"form_input\">"+$(this).val()+"</div>")
			//$(this).remove();
		});
	}
	function loadAllSousTotal(){
	//revenus	
	sousTotal('revenus');
	sousTotal('autres');	
	sousTotal('subventions');
	//depenses	
	sousTotal('production');
	sousTotal('promotion');
	sousTotal('administration');
	
	}
	
	function loadAllSousTotal_bancessai(){
		sousTotal_bancessai('revenus');
		sousTotal_bancessai('financement');
		sousTotal_bancessai('frais');
		sousTotal_bancessai('communication');
		sousTotal_bancessai('generaux');
	}
	
	function loadAllSousTotal_recherche(){
		sousTotal_recherche('revenus');
		sousTotal_recherche('subventions');
		sousTotal_recherche('creation');
		sousTotal_recherche('promotion');
		sousTotal_recherche('administration');
		// sousTotal_recherche('financement');
		// sousTotal_recherche('frais');
		// sousTotal_recherche('communication');
		// sousTotal_recherche('generaux');	
	}
	
	function sousTotal(souscat){
		
		total_sous_total_prevu = 0;
		total_sous_total_reel = 0;
		
		total_revenus_prevu = 0;
		total_revenus_reel = 0;
		
		total_depenses_prevu = 0;
		total_depenses_reel = 0;
		
		total_deficit_prevu = 0;
		total_deficit_reel = 0;
		
		
		$(':regex(id,^'+souscat+'_)').each(function(e) {
			if(this.value != ""){
				if(this.id.substr(-9) == "_prevu_id") {
					total_sous_total_prevu = parseInt(total_sous_total_prevu) + parseInt(this.value);
				}else{
					total_sous_total_reel = parseInt(total_sous_total_reel) + parseInt(this.value);
				}
			}	
		});
		
		
		$(':regex(id,^(revenus|autres|subventions)_)').each(function(e) {
			if(this.value != ""){
				if(this.id.substr(-9) == "_prevu_id"){
					total_revenus_prevu = parseInt(total_revenus_prevu) + parseInt(this.value);
				}else{
					total_revenus_reel = parseInt(total_revenus_reel) + parseInt(this.value);
				}	
			}
		});
		
		$(':regex(id,^(production|promotion|administration|creation)_)').each(function(e) {
		if(this.value != ""){
			if(this.id.substr(-9) == "_prevu_id") {
				total_depenses_prevu = parseInt(total_depenses_prevu) + parseInt(this.value);
			}else{
				total_depenses_reel = parseInt(total_depenses_reel) + parseInt(this.value);
			}
		}
		});
		
		$('#sous_total_'+souscat+'_prevu_id').val(total_sous_total_prevu + " $");
		$('#sous_total_'+souscat+'_reel_id').val(total_sous_total_reel + " $");
		
		$('#total_revenus_prevu_id').val(total_revenus_prevu + " $");
		$('#total_revenus_reel_id').val(total_revenus_reel + " $");
			
		$('#total_depenses_prevu_id').val(total_depenses_prevu + " $");
		$('#total_depenses_reel_id').val(total_depenses_reel + " $");
			
	    $('#excedent_prevu_id').val(parseInt(total_revenus_prevu) - parseInt(total_depenses_prevu) + " $");
	    $('#excedent_reel_id').val(parseInt(total_revenus_reel) - parseInt(total_depenses_reel) + " $");
	}

	function sousTotal_recherche(souscat){
		total_sous_total_prevu = 0;
		total_sous_total_reel = 0;
		produits_totaux_prevu = 0;
		produits_totaux_reel = 0;
		charges_totaux_prevu = 0;
		charges_totaux_reel = 0;
		
		$(':regex(id,^'+souscat+'_)').each(function(e) {
			if(this.value != ""){
				if(this.id.substr(-9) == "_prevu_id") {
					total_sous_total_prevu = parseInt(total_sous_total_prevu) + parseInt(this.value);
				}else{
					total_sous_total_reel = parseInt(total_sous_total_reel) + parseInt(this.value);
				}
			}	
		});
		$(':regex(id,^(revenus|subventions)_)').each(function(e) {
			if(this.value != ""){
				if(this.id.substr(-9) == "_prevu_id"){
					produits_totaux_prevu = parseInt(produits_totaux_prevu) + parseInt(this.value);
				}else{
					produits_totaux_reel = parseInt(produits_totaux_reel) + parseInt(this.value);
				}	
			}
		});
		$(':regex(id,^(creation|promotion|administration)_)').each(function(e) {
			if(this.value != ""){
				if(this.id.substr(-9) == "_prevu_id"){
					charges_totaux_prevu = parseInt(charges_totaux_prevu) + parseInt(this.value);
				}else{
					charges_totaux_reel = parseInt(charges_totaux_reel) + parseInt(this.value);
				}	
			}
		});
		$('#sous_total_'+souscat+'_prevu_id').val(total_sous_total_prevu + " $");
		$('#sous_total_'+souscat+'_reel_id').val(total_sous_total_reel + " $");
		
		$('#total_revenus_prevu_id').val(produits_totaux_prevu + " $");
		$('#total_revenus_reel_id').val(produits_totaux_reel + " $");
		
		$('#total_depenses_prevu_id').val(charges_totaux_prevu + " $");
		$('#total_depenses_reel_id').val(charges_totaux_reel + " $");
		
		$('#excedent_prevu_id').val(parseInt(produits_totaux_prevu) - parseInt(charges_totaux_prevu) + " $");
		$('#excedent_reel_id').val(parseInt(produits_totaux_reel) - parseInt(charges_totaux_reel) + " $");
		
		
	}

	function sousTotal_bancessai(souscat){
		total_sous_total = 0;
		total_produits = 0;
		total_charges = 0;
		$(':regex(id,^(frais|frais2|frais3)_)').each(function(e) {
			if(this.value != ""){
				total_charges = parseInt(total_charges) + parseInt(this.value);	
			}
		});
		$(':regex(id,^(revenus|financement)_)').each(function(e) {
			if(this.value != ""){
				total_produits = parseInt(total_produits) + parseInt(this.value);	
			}
		});
		$(':regex(id,^'+souscat+'_)').each(function(e) {
			if(this.value != ""){
				total_sous_total = parseInt(total_sous_total) + parseInt(this.value);
			}	
		});
		$('#sous_total_'+souscat+'_id').val(total_sous_total + " $");
		$('#produits_totaux_id').val(total_produits + " $");
		$('#sommaire_produits_totaux_id').val(total_produits + " $");
		$('#charges_totales_id').val(total_charges + " $");
		$('#sommaire_charges_totales_id').val(total_charges + " $");
		$('#sommaire_surplus_deficit_id').val(parseInt(total_produits) - parseInt(total_charges) + " $");
	}
	
	