// 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');
}

/* affichage devis moto en PDF */
/* Id=identifiant, Dst=type de PDF, hash=Code hashage */
function ShowMOTOPDF(Id, Dst, hash) {
	var msg = "";
	var page = "genpdf.aspx?";

	switch (Dst) {
		case "dc": 	/* devis */
		case "cc": /* contrat */
		case "att": /* attestation provisoire */
		case "cv": /* carte verte en fac simile*/
		case "cvp": /* carte verte provisoire */
		case "cva": /* carte verte en fac simile depuis avenant*/
		case "cvpa": /* carte verte provisoire  depuis avenant*/
		case "cvd_p": /* carte verte definive suite paimeent quittance */
		case "ap": /* autorisation prelevement */
		case "av": /* emission avenant*/
		case "mew": /* demande d'expertise */
			page += "b=" + Dst + "&n=" + Id + "&hash=" + hash;
			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();
//			if (F == "") {
//				page = "";
//				msg = "Indiquez la formule";
//			} else {
//				page += "b=" + Dst + "&n=" + F;
//			}
//			break;

		default:
			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 ShowCG(Prd) {
	var page = "../../../pages/showCG.aspx?PRD=" + Prd;
	window.open(page, 'info', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,width=800,height=600,screenX=50,screenY=50,left=50,top=50');
}

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 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');
	}
}

// sinistres
function InfosSinistre(Id) {
	if (!Id == 0) {
		var Pg = "infos.aspx?F=hsinistres.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 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("releve_incident") && !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,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');
}
