// ouverture de fenetre 
// P=url de la page
// T=nom ou titre de la fenetre
// W=width H=height
// S= 0 ou 1 pour scrollbars actifs
// R= 0 ou 1 pour fenetre resizable
function OpenW(P,T,W,H,S,R){
	window.open(P,T,'toolbar=0,location=0,directories=0,menuBar=0,statusBar=0,scrollbars=' + S + ',resizable=' + R + ',width=' + W + ',height=' + H +',screenX=250,screenY=150,left=150,top=50,statusBar=no');
}

function ShowCG(Prd) {
    var page = "../../../pages/showCG.aspx?PRD=" + Prd;
    OpenW(page, "infos", 800, 600, 1, 1);
}

/* affichage devis moto en PDF */
/* Id=identifiant, Dst=type de PDF */
function ShowMRHPDF(Id, Dst, hash) {		
	var Msg="";	
	switch (Dst)
	{
		case "dc": 	/* devis */
		    var page = "genpdf.aspx?&b=dc&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "c":	/* contrat */
		    var page = "genpdf.aspx?&b=c&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;	
		case "cc":	/* contrat */
		    var page = "genpdf.aspx?&b=cc&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;						
		case "ap":	/* autorisation prelevement */
		    var page = "genpdf.aspx?&b=ap&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;		 
		case "mew":	/* demande d'expertise */
		    var page = "genpdf.aspx?b=mew&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_mrh":	/* attestation MRH */
		    var page = "genpdf.aspx?b=att_mrh&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_mrh_prod":	/* attestation MRH depuis mrh_production */
		    var page = "genpdf.aspx?b=att_mrh_prod&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_mat":	/* attestation assistance maternelle */
		    var page = "genpdf.aspx?b=att_mat&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_sco":	/* attestation assurance scolaire */
		    var page = "genpdf.aspx?b=att_sco&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_pro":	/* attestation assurance pack pro */
		    var page = "genpdf.aspx?b=att_pro&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
			
		/** DEPUIS LA LISTE DES PAIEMENTS **/
		case "att_mrh_pa":	/* attestation MRH depuis liste des paiements */
		    var page = "genpdf.aspx?b=att_mrh_pa&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_mat_pa":	/* attestation assistance maternelle */
		    var page = "genpdf.aspx?b=att_mat_pa&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_sco_pa":	/* attestation assurance scolaire */
		    var page = "genpdf.aspx?b=att_sco_pa&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "att_pro_pa":	/* attestation assurance pro */
		    var page = "genpdf.aspx?b=att_pro_pa&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;

		/** DEPUIS LES AVENANTS table mrh_avenants **/
		case "av":	/* emission avenant*/
		    var page = "genpdf.aspx?&b=av&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
			
		case "prop_av":	/* edition d'une proposition avenant uniquement depuis session en cours */
			/* ATTENTION, ICI la valeur n represente la formule selectionnée */			
			var F=GetSelectedFormule();						
			var page ="";
			if (F==""){msg="Indiquez la formule";}else{page ="genpdf.aspx?&b=prop_av&n=" + F;}						 	
			break;
						
		case "av_att_mrh":	/* attestation MRH */
		    var page = "genpdf.aspx?b=av_att_mrh&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		 
		case "av_att_mat":	/* attestation assistance maternelle */
		    var page = "genpdf.aspx?b=av_att_mat&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
			
		case "av_att_sco":	/* attestation assurance scolaire */
		    var page = "genpdf.aspx?b=av_att_sco&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
			
		case "av_att_pro":	/* attestation assurance scolaire */
		    var page = "genpdf.aspx?b=av_att_pro&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
			
		case "av_ap":	/* autorisation prelevement */
		    var page = "genpdf.aspx?&b=av_ap&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;	
			
		default:
			var page ="";
			break;
	}
	if (page!==""){
		OpenW(page,"pdf",800,600,1,1);
	}
	else{
		if(msg==""){msg="Service non disponible !";}
		alert(msg);
	}
}

// Capture la formule selectionne sur la page presentation des offres
function GetSelectedFormule(){
	var F="";
	var obj=document.forms[0].selectedformule.length;	
	if (obj){
		for(n=0;n < document.forms[0].selectedformule.length;n++){
			if(document.forms[0].selectedformule[n].checked==true){F=document.forms[0].selectedformule[n].value;}
		}
	}else{F=document.forms[0].selectedformule.value;}
	return F;
}

function Info(Pg) {       
	alert("Afficher la page " + Pg);
}

function InfosAccueil(Id){       
	if (!Id==0){
	var Pg = "infos.aspx?F=haccueil.xml&id="+Id;         
        window.open(Pg, 'info' ,'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,width=300,height=200,screenX=50,screenY=50,left=50,top=50');
	}
}

function InfosDevis(Id){       
	if (!Id==0){
	var Pg = "infos.aspx?F=hdevis.xml&id="+Id;         
        window.open(Pg, 'info' ,'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,width=300,height=200,screenX=50,screenY=50,left=50,top=50');
	}
}

function InfosOffres(Id){       
	if (!Id==0){
	var Pg = "infos.aspx?F=hoffres.xml&id="+Id;         
        window.open(Pg, 'info' ,'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,width=300,height=200,screenX=50,screenY=50,left=50,top=50');
	}
}

function InfosDecPrealable(Id){
	if (!Id==0){
	var Pg = "infos.aspx?F=hdeclarations_prealables.xml&id="+Id;
        window.open(Pg, 'info' ,'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,width=300,height=200,screenX=50,screenY=50,left=50,top=50');
	}
}

function InfosDoc(page){       
	if (!page==""){
	var Pg = "../../../infos/"+page;         
        window.open(Pg, 'infos' ,'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,screenX=50,screenY=50,left=50,top=50');
	}
}

function StatusBar(action){
	var textOver = "Multirisque Habitation Netvox";
	var textOut = "";
	
	switch (action)
	{
		case "over":
			window.status = textOver;
			break;

		case "out":
			window.status = textOut;
			break;

		default:
			window.status = "";
		break;

	}
}
function checkFile(element)
{
    var nom;
        nom = document.getElementById("f_"+element).value;
        if (nom.length<1)
        {     
            return 0;
        }
        else
        {
            return 1;
        }  
}

function Valider_pieces()
{
   if (!checkFile("cp"))
        {
         alert("Pas de pieces selectionnees")   ;
        }
        else
        {
            document.forms[0].action.value="SAVEFILES";
            document.forms[0].submit();
        }
}

// Affichage des pièces jointes liées à un contrat
function ShowPJContrat(id_contrat, police_mere, type_contrat, hash,is) {
	window.open('../../../pages/showPJContrat.aspx?id_contrat=' + id_contrat + '&police_mere=' + police_mere + '&type_contrat=' + type_contrat + '&hash=' + hash + '&is=' + is, 'Affichage', 'toolbar=0,location=0,directories=0,statusBar=0,menuBar=0,scrollbars=1,resizable=1,width=800,height=600,left=50,top=50');
}
