// 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 ShowCYCLOPDF(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 "cc":	/* contrat */
		    var page = "genpdf.aspx?&b=cc&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;	
		case "att":	/* attestation provisoire */
		    var page = "genpdf.aspx?&b=att&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;				
		case "cv":	/* carte verte en fac simile*/
		    var page = "genpdf.aspx?&b=cv&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "cvp":	/* carte verte provisoire */
		    var page = "genpdf.aspx?&b=cvp&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "cva":	/* carte verte en fac simile depuis avenant*/
		    var page = "genpdf.aspx?&b=cva&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "cvpa":	/* carte verte provisoire  depuis avenant*/
		    var page = "genpdf.aspx?&b=cvpa&n=" + Id + "&hash=" + hash + "&page_precedente=" + document.location.href;
			break;
		case "cvd_p":	/* carte verte definive suite paimeent quittance */
		    var page = "genpdf.aspx?&b=cvd_p&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 "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 + "&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;
		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 = "";
	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("carte_grise") && !checkFile("permis") && !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) {
	window.open('../../../pages/showPJContrat.aspx?id_contrat=' + id_contrat + '&police_mere=' + police_mere + '&type_contrat=' + type_contrat + '&hash=' + hash + '&', 'Affichage', 'toolbar=0,location=0,directories=0,statusBar=0,menuBar=0,scrollbars=1,resizable=1,width=800,height=600,left=50,top=50');
}
