/*
 * Fonctions associées aux popups
 *
 * - PopupScroll( sUrl, sNom, iWidth, iHeight, sMessageNoPopup)
 * - PopupPrint(sUrl,sMessageNoPopup)
 * - PopupNoScroll( sUrl, sNom, iWidth, iHeight, sMessageNoPopup)
 * - PopupFullScreen( sUrl, sNom, sMessageNoPopup)
 * - Msg(strTitre,strMessage)
 * - VerifAction( strAction, strResult, bJavascript)
 * - ConfirmAction( strAction, strResult1, bJavascript1, strResult2, bJavascript2)
 */

function PopupFermer() {
	window.close();
}

// Function d'ouverture de Popup avec scroll
function PopupScroll(sUrl,sNom,iWidth,iHeight,sMessageNoPopup) {
	var oPopup = null;
	
	oPopup = window.open(sUrl, sNom,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + iWidth + ",height=" + iHeight);
	if (sMessageNoPopup == "") sMessageNoPopup = "Les Popups sont bloquees sur votre navigateur !";
	if (oPopup != null) oPopup.focus();
}

// Function d'ouverture de Popup pour impression
function PopupPrint(sUrl,sMessageNoPopup) {
	var oPopup = window.open(sUrl, "print","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=30,height=30");
	if (sMessageNoPopup == "") sMessageNoPopup = "Les Popups sont bloquees sur votre navigateur !";
	if (oPopup != null) oPopup.focus();
	
	return oPopup;
}

// Function d'ouverture de Popup sans scroll
function PopupNoScroll(sUrl,sNom,iWidth,iHeight,sMessageNoPopup) {
	var oPopup = window.open(sUrl, sNom,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + iWidth + ",height=" + iHeight);
	if (sMessageNoPopup == "") sMessageNoPopup = "Les Popups sont bloquees sur votre navigateur !";
	if (oPopup != null) oPopup.focus();
}

// Function d'ouverture de Popup en plein ecran
function PopupFullScreen(sUrl,sNom,sMessageNoPopup) {
	var oPopup = window.open(sUrl, sNom, "fullscreen,scrollbars");
	if (sMessageNoPopup == "") sMessageNoPopup = "Les Popups sont bloquees sur votre navigateur !";
	if (oPopup == null) document.location = sUrl;
	else oPopup.focus();
}

// Function d'affichage des messages
function PopupJS(strDisplay,strPopup) {

	if (strDisplay == "inline") {
		var objDivPopup = document.getElementById("popup");
		var objDivMsg = document.getElementById(strPopup);
		
		var iHeight = 0;
		var iScrollHeight = 0;
		var iClientHeight = 0;
		var iClientWidth = 0;
		var iScrollTop = 0;
		if (document.all) {
			iScrollHeight = document.body.scrollHeight;
			iClientHeight = document.body.clientHeight;
			iClientWidth = document.body.clientWidth;
			iScrollTop = document.body.scrollTop;
		} else {
			iScrollHeight = document.body.scrollHeight;
			iClientHeight = document.body.clientHeight;
			iClientWidth = document.body.clientWidth;
			iScrollTop = document.body.scrollTop;
		}
		if (iClientHeight > iScrollHeight) iHeight = iClientHeight;
		else iHeight = iScrollHeight;
		
		objDivPopup.style.height = iHeight + 'px';
		objDivMsg.style.top = eval(250 + iScrollTop) + 'px';
		objDivMsg.style.left = eval((iClientWidth - 300) / 2) + 'px';
	}

	DisplayId("popup", strDisplay);
	DisplayId(strPopup, strDisplay);
}

// Function d'affichage des messages
function LoadingJS(strDisplay) {
	if (strDisplay == "inline") {
		var objDivPopup = document.getElementById("popup");
		var objDivLoading = document.getElementById("loading");
		
		var iHeight = 0;
		var iScrollHeight = 0;
		var iClientHeight = 0;
		var iClientWidth = 0;
		var iScrollTop = 0;
		if (document.all) {
			iScrollHeight = document.body.scrollHeight;
			iClientHeight = document.body.clientHeight;
			iClientWidth = document.body.clientWidth;
			iScrollTop = document.body.scrollTop;
		} else {
			iScrollHeight = document.body.scrollHeight;
			iClientHeight = document.body.clientHeight;
			iClientWidth = document.body.clientWidth;
			iScrollTop = document.body.scrollTop;
		}
		alert(iScrollHeight);
		if (iClientHeight > iScrollHeight) iHeight = iClientHeight;
		else iHeight = iScrollHeight;
		
		objDivPopup.style.height = iHeight;
		objDivLoading.style.top = 250 + iScrollTop;
		objDivLoading.style.left = (iClientWidth - 300) / 2;
	}

	DisplayId("popup", strDisplay);
	DisplayId("loading", strDisplay);
}

// Function d'affichage des messages
function Msg(strTitre,tabMessages) {
	var objDivMsg = document.getElementById("msg");
	
	ClearElement(objDivMsg);
	
	var h3Msg = document.createElement("h3");
	h3Msg.setAttribute("id","titInfo");
	var divH3Msg = document.createElement("div");
	divH3Msg.setAttribute("id","fermer");
	var aDivH3Msg = document.createElement("a");
	aDivH3Msg.onclick = function () { PopupJS("none","msg"); }
	var textADivH3Msg = document.createTextNode("X");
	aDivH3Msg.appendChild(textADivH3Msg);
	divH3Msg.appendChild(aDivH3Msg);
	h3Msg.appendChild(divH3Msg);
	objDivMsg.appendChild(h3Msg);
	
	var divMsg = document.createElement("div");
	divMsg.setAttribute("id","msgInfo");
	var ulMsg = document.createElement("ul");
	for (var i = 0; i < tabMessages.length; i++) {
		var liUlMsg = document.createElement("li");
		var textPMsg = document.createTextNode(tabMessages[i]);
		liUlMsg.appendChild(textPMsg);
		ulMsg.appendChild(liUlMsg);
	}
	divMsg.appendChild(ulMsg);
	objDivMsg.appendChild(divMsg);
	
	var textH3Msg = document.createTextNode(strTitre);
	h3Msg.appendChild(textH3Msg);
		
	PopupJS("inline","msg");
}

// Function de message de confirmation
function VerifAction(strAction,strResult,bJavascript) {
	var objDivMsg = document.getElementById("msg");
	
	ClearElement(objDivMsg);
	
	var h3Msg = document.createElement("h3");
	h3Msg.setAttribute("id","titVerif");
	var textH3Msg = document.createTextNode(strTitre);
	h3Msg.appendChild(textH3Msg);
	var divH3Msg = document.createElement("div");
	divH3Msg.setAttribute("id","fermer");
	var aDivH3Msg = document.createElement("a");
	aDivH3Msg.onclick = function () { PopupJS("none","msg"); }
	var textADivH3Msg = document.createTextNode("X");
	aDivH3Msg.appendChild(textADivH3Msg);
	divH3Msg.appendChild(aDivH3Msg);
	h3Msg.appendChild(divH3Msg);
	objDivMsg.appendChild(h3Msg);
	
	var divMsg = document.createElement("div");
	divMsg.setAttribute("id","msgVerif");
	var form = document.createElement("form");
	form.onsubmit = function () { return false; };
	divMsg.appendChild(form);
	objDivMsg.appendChild(divMsg);
	
	var pTextAction = document.createElement("p");
	if (strAction.indexOf("**") > -1) {
		var strAction1 = strAction.substring(0,strAction.indexOf("**"));
		var strAction2 = strAction.substring(strAction.indexOf("**")+2,strAction.lastIndexOf("**"));
		var strAction3 = strAction.substring(strAction.lastIndexOf("**")+2,strAction.length);
		
		var spanAction1 = document.createElement("span");
		var textAction1 = document.createTextNode(strAction1);
		spanAction1.appendChild(textAction1);
		pTextAction.appendChild(spanAction1);
		
		var spanAction2 = document.createElement("span");
		var textAction2 = document.createTextNode(strAction2);
		spanAction2.appendChild(textAction2);
		pTextAction.appendChild(spanAction2);
		spanAction2.className = "bold";
		
		var spanAction3 = document.createElement("span");
		var textAction3 = document.createTextNode(strAction3);
		spanAction3.appendChild(textAction3);
		pTextAction.appendChild(spanAction3);
	} else {
		var textAction = document.createTextNode(strAction);
		pTextAction.appendChild(textAction);
	}
	form.appendChild(pTextAction);
	
	var divBt = document.createElement("div");
	divBt.setAttribute("id","button");
	form.appendChild(divBt);
	
	var btOui = document.createElement("input");
	btOui.setAttribute("type","button");
	btOui.setAttribute("value","Oui");
	if (bJavascript) {
		btOui.onclick = function () { Msg("confirm","none"); eval(strResult); };
	} else {
		btOui.onclick = function () { Msg("confirm","none"); window.location = strResult; };
	}
	divBt.appendChild(btOui);
	btOui.className = "w_60";
	
	var btNon = document.createElement("input");
	btNon.setAttribute("type","button");
	btNon.setAttribute("value","Non");
	btNon.onclick = function () { Msg("confirm","none"); };
	divBt.appendChild(btNon);
	btNon.className = "w_60";
	
	PopupJS("inline","msg");
}

// Function de demande de confirmation
function ConfirmAction(strAction,strResult1,bJavascript1,strResult2,bJavascript2) {
	var objDivMsg = document.getElementById("msg");
	
	ClearElement(objDivMsg);
	
	var h3Msg = document.createElement("h3");
	h3Msg.setAttribute("id","titConfirm");
	var textH3Msg = document.createTextNode(strTitre);
	h3Msg.appendChild(textH3Msg);
	var divH3Msg = document.createElement("div");
	divH3Msg.setAttribute("id","fermer");
	var aDivH3Msg = document.createElement("a");
	aDivH3Msg.onclick = function () { PopupJS("none","msg"); }
	var textADivH3Msg = document.createTextNode("X");
	aDivH3Msg.appendChild(textADivH3Msg);
	divH3Msg.appendChild(aDivH3Msg);
	h3Msg.appendChild(divH3Msg);
	objDivMsg.appendChild(h3Msg);
	
	var divMsg = document.createElement("div");
	divMsg.setAttribute("id","msgConfirm");
	var form = document.createElement("form");
	form.onsubmit = function () { return false; };
	divMsg.appendChild(form);
	objDivMsg.appendChild(divMsg);
	
	var pTextAction = document.createElement("p");
	if (strAction.indexOf("**") > -1) {
		var strAction1 = strAction.substring(0,strAction.indexOf("**"));
		var strAction2 = strAction.substring(strAction.indexOf("**")+2,strAction.lastIndexOf("**"));
		var strAction3 = strAction.substring(strAction.lastIndexOf("**")+2,strAction.length);
		
		var spanAction1 = document.createElement("span");
		var textAction1 = document.createTextNode(strAction1);
		spanAction1.appendChild(textAction1);
		pTextAction.appendChild(spanAction1);
		
		var spanAction2 = document.createElement("span");
		var textAction2 = document.createTextNode(strAction2);
		spanAction2.appendChild(textAction2);
		pTextAction.appendChild(spanAction2);
		spanAction2.className = "bold";
		
		var spanAction3 = document.createElement("span");
		var textAction3 = document.createTextNode(strAction3);
		spanAction3.appendChild(textAction3);
		pTextAction.appendChild(spanAction3);
	} else {
		var textAction = document.createTextNode(strAction);
		pTextAction.appendChild(textAction);
	}
	form.appendChild(pTextAction);
	
	var divBt = document.createElement("div");
	divBt.setAttribute("id","button");
	form.appendChild(divBt);
	
	var btOui = document.createElement("input");
	btOui.setAttribute("type","button");
	btOui.setAttribute("value","Oui");
	if (bJavascript1) {
		btOui.onclick = function () { Msg("confirm","none"); eval(strResult1); };
	} else {
		btOui.onclick = function () { Msg("confirm","none"); window.location = strResult1; };
	}
	divBt.appendChild(btOui);
	btOui.className = "w_60";
	
	var btNon = document.createElement("input");
	btNon.setAttribute("type","button");
	btNon.setAttribute("value","Non");
	if (bJavascript2) {
		btNon.onclick = function () { Msg("confirm","none"); eval(strResult2); };
	} else {
		btNon.onclick = function () { Msg("confirm","none"); window.location = strResult2; };
	}
	divBt.appendChild(btNon);
	btNon.className = "w_60";
	
	PopupJS("inline","msg");
}

var bZoomVisuel = false;
function zoomVisuel(oImg,bDisplay) {
	var oAImg = oImg.parentNode;
	if (bDisplay) {
		var divMsg = document.createElement("div");

		divMsg.setAttribute("id","zoomVisuel");
		var imgDivMsg = document.createElement("img");
		imgDivMsg.setAttribute("id","filtre");
		imgDivMsg.onmousedown = function () { clickDroit() };
		imgDivMsg.onmouseout = function () { zoomVisuel(oImg,false) };
		imgDivMsg.onclick = function () { PopupScroll( contextPath + "/zoomVisuel.do;jsessionid=" + sessionId + "?src=" + oAImg.href.substring(oAImg.href.indexOf("src=") + 4, oAImg.href.length), 'zoom_visuel', 476, 450,''); return false; }
		imgDivMsg.onmouseover = function () { eval("bZoomVisuel = true;"); }
		imgDivMsg.setAttribute("src", oAImg.href.substring(oAImg.href.indexOf("src=") + 4, oAImg.href.indexOf("p.jpg")) + "m.jpg");
		divMsg.appendChild(imgDivMsg);
		oAImg.appendChild(divMsg);
		filtreImage(eval(imgDivMsg),'');
	} else {
		if (bZoomVisuel) oAImg.removeChild(oAImg.childNodes[1]);
	}
}
