function validateAbonneProjet(nom, id){
	url = "?idChantier=" + id + "&evt=ok";
	redirect = true;

	 if ( confirm("Souhaitez vous ajouter un commentaire pour le MOA ? \nNom du projet: " + nom) ) { // Clic sur OK
		   var saisie = prompt("Veuillez saisir votre message:", "")
	       if (saisie!=null)
	       		url += "&commentaire="+saisie;
	       else
	       	redirect = false
     }else{
		redirect = confirm("Souhaitez vous tout de même valider ce projet ?");
     }

	if( redirect)
	     window.location.href = url;

}

function changerCategorie() {
	if (document.forms[0].elements["SauvegarderChantier[categorie]"].value == 8){ //Cas du lotissement
		$(".fichePourEquipement").hide();
		$(".fichePourLotissement").show();
		$("#allowUploadPDF").show();

	} else {
		$(".fichePourEquipement").show();
		$(".fichePourLotissement").hide();
		$("#allowUploadPDF").hide();
	}
}

function changePage(id){
	url = window.location.pathname + "?page=" + id;
	window.location.href = url;
}

function validerSuppression(type) {
	if (type=="")
		type = "cet \351l\351ment";
	var accord =confirm("\312tes-vous s\373r de vouloir supprimer " + type + " ?");
	if (accord)
		return true ;
	else
		return false ;
}


//utiliser pour la page FiltrerClients
function verifChampFiltre(){
	dateEcheance = $.trim( $('#dateEcheance').val() );
	nb_diff = $('#nb_diff').val();
	erreur = "";

	if( dateEcheance  != "" ){
		tab = dateEcheance.split('/');

		if( nb_diff != "" && !isFinite(nb_diff) )
			erreur = "Nombre de jours d'écart doit être un entier";
		if( !isFinite(tab[0])  || !isFinite(tab[1]) || !isFinite(tab[2]) )
			erreur = "Date d'échéance incorrect";

	}

	if( erreur == "" )
		return true;

	alert(erreur);
	return false;
}

//utiliser pour la page ModifierDateAbonnement
function modifDateAbonnementURL( link ){
    var elt = $("input:checked");
	param = "";

	if(elt.length == 0 ){
		alert("Vous devez séléctionner au moins 1 client");
		return false;
	}

    for( i=0; i < elt.length; i++){
    	reg = new RegExp("[0-9]+","g");
    	id = elt[i].id;
    	id = reg.exec(id); //ID du client

		if( i == 0)	param += id;
		else		param += "," + id;
    }

    window.location.replace( link + "?id=" + param);
}

//utiliser lors de l'ajout d'un nouveau projet par l'abonne
function loadCommune( val ){
	val = escape( val );

	$.get("AfficherLieu.do?nomCommune=" + val, function(data){
	  communes = data.split('|');
	  row = new Array();
	  html = "";


	  for( i = 0; i< communes.length ; i++){
		tmp = communes[i].split('@');
		row[i] = new Array();
		row[i]["id"] = tmp[0];
		row[i]["Nom"] = tmp[1];
		html += "<option value='" + row[i]["id"] + "'>" + row[i]["Nom"] + "</option>";
	  }

	  $("#listeCommune").html(html);
	});
}

//utiliser lors de l'ajout du filtre par MOA
function loadMOA( val ){
	val = escape( val );

	$.get("AfficherMOA.do?nomMoa=" + val, function(data){
	  communes = data.split('|');
	  row = new Array();
	  html = "";

	  for( i = 0; i< communes.length ; i++){
		tmp = communes[i].split('@');
		row[i] = new Array();
		row[i]["id"] = tmp[0];
		row[i]["Nom"] = tmp[1];
		html += "<option value='" + row[i]["id"] + "'>" + row[i]["Nom"] + "</option>";
	  }

	  $("#listeMOA").html(html);
	});
}

//utiliser lors de l'ajout d'un nouveau projet par l'abonne
function checkAjoutAbonne(){
	error = "";

	if( $.trim($("#nomProjet").val()) == "")
		error += "Veuillez remplir le nom du projet\n";

	if( $.trim($("#listeCommune").val()) == "-1")
		error += "Veuillez sélectionner une commune";

	if(error != ""){
		alert(error);
		return false;
	}
	return true;

}

//popup
function popup( url , width, height){
	window.open(url,"fenetre1","width="+ width +",height="+ height +",left=0,top=0,scrollbars=yes");

}

function cocher(nomdebase, testCocher, min, max) {
	for (var i = min; i <= max; i++) {
		//alert(typeof(document.getElementById(nomdebase + i)));
		if ((typeof(document.getElementById(nomdebase + i)) != 'undefined')&&
		(document.getElementById(nomdebase + i)) != null) {
			document.getElementById(nomdebase + i).checked = testCocher;
		}
	}
}
function MM_findObj(n, d) { //v4.01

var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_setTextOfLayer(objName,x,newText) { //v4.01

if ((obj=MM_findObj(objName))!=null) with (obj)

   if (document.layers) {document.write(unescape(newText)); document.close();}

   else innerHTML = unescape(newText);

}
