/**
* Paramétrage du composant permettant de construire des aides à la saisie sous forme de popups.
*
* Nom du fichier : $Archive:   O:/Kernel Livraison/archives/kernel/www/scripts/popup-setup.js-arc  $
* Version        : $Revision:   1.1  $
*
* Auteur         : SOPRA Group - $Author:   adessert  $
* Modifié le     : $Date:   May 22 2007 10:14:54  $
*/


var PopupsContext=function(){this.popupOpenedList=new Array();this.addPopup=function(popupId){this.popupOpenedList.push(popupId);}
this.delPopup=function(){var popupToDelete=this.popupOpenedList.pop();}
this.getMainFrame=function(){var currentFrame=null;if(window.name.indexOf("_ifrm")!=-1){currentFrame=parent.window;}else{currentFrame=window;}
return currentFrame;}
this.getPopupNumber=function(){var popupNumber=this.popupOpenedList.length;return popupNumber;}
this.getCurrentPopup=function(){if(!this.isEmpty()){var index=this.popupOpenedList.length-1;return this.popupOpenedList[index];}else{return null;}}
this.getSubPopup=function(){if(!this.isEmpty()){var index=this.popupOpenedList.length-2;return this.popupOpenedList[index];}else{return null;}}
this.getCurrentPopupObject=function(suffix){var eltId=this.getCurrentPopup()+suffix;return document.getElementById(eltId);}
this.getSubPopupObject=function(suffix){var eltId=this.getSubPopup()+suffix;return document.getElementById(eltId);}
this.getCurrentPopupFrame=function(){var eltId=this.getCurrentPopup()+"_ifrm";return document.getElementById(eltId);}
this.getSubPopupFrameName=function(){var popupId=this.getSubPopup();if(popupId){return(popupId+"_ifrm");}else{return null;}}
this.getCurrentPopupFrameContent=function(){var frameId=this.getCurrentPopup()+"_ifrm";return window.frames[frameId];}
this.getSubPopupFrameContent=function(){var frameId=this.getSubPopup()+"_ifrm";return window.frames[frameId];}
this.isContainingSubPopup=function(){if(this.popupOpenedList.length>1){return false;}else{return true;}}
this.isEmpty=function(){if(this.popupOpenedList.length>0){return false;}else{return true;}}}
var popupsContextToInstanciate=new PopupsContext();window["popupsContext"]=popupsContextToInstanciate;var mainFrame=popupsContextToInstanciate.getMainFrame();var popupsContext=mainFrame["popupsContext"];function popupSetup(params){function _defaultParameter(pname,def){if(typeof params[pname]=="undefined"){params[pname]=def;}}
function _computeAbsolutePath(){var deployPath=location.pathname;var secondSlash=deployPath.indexOf('/',1);if(secondSlash>0)
deployPath=deployPath.substring(0,secondSlash);return deployPath;}
function _titleBarInit(){var deployPath=_computeAbsolutePath();var titleCode="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";titleCode+="<tr>";titleCode+="<td id='"+params["popupId"]+"_titleBar"+"' width='100%' class='SCSE'>$title$</td>";titleCode+="<td width='69'><img src='"+deployPath+"/images/imgRightFadingStringCourse69x20.gif' height='20' width='69' border='0'></td>";titleCode+="<td width='30' bgcolor='#339999'><img src='"+deployPath+"/images/img1x1.gif' height='10' width='30' border='0'></td>";titleCode+="</tr>";titleCode+="</table>";if(typeof params["titlebar"]=="undefined"){params["titlebar"]=titleCode.replace("$title$","");}else{params["titlebar"]=titleCode.replace("$title$",params["titlebar"]);}}
function _getScreenWidth(){return document.getElementById&&!document.all?window.innerWidth:document.body.clientWidth;}
function _getScreenHeight(){return document.getElementById&&!document.all?window.innerHeight:document.body.clientHeight;}
function _popupsCaracteristics(){var popupTop=0;var popupLeft=0;var popupWidth=0;var popupHeight=0;coefWidth=coefHeight=85;popupWidth=Math.round((coefWidth*_getScreenWidth())/100);popupHeight=Math.round((coefHeight*_getScreenHeight())/100);popupTop=(popupsContext.getPopupNumber()+1)*25+document.body.scrollTop;popupLeft=(popupsContext.getPopupNumber()+1)*25;return({top:popupTop,left:popupLeft,width:popupWidth,height:popupHeight});}
var popupCarac=_popupsCaracteristics();var deployPath=_computeAbsolutePath();_defaultParameter("left",popupCarac.left);_defaultParameter("top",popupCarac.top);_defaultParameter("width",popupCarac.width);_defaultParameter("height",popupCarac.height);_defaultParameter("content","");_defaultParameter("contentTextColor","white");_defaultParameter("contentBgColor","white");_defaultParameter("fontStyle","10pt sans-serif");_defaultParameter("titlebar",_titleBarInit());_defaultParameter("titlebarBgColor","#003399");_defaultParameter("titlebarTextColor","white");_defaultParameter("borderColor","lightgrey");_defaultParameter("scrollbarColor","#339999");_defaultParameter("shadowColor","");_defaultParameter("hide",true);_defaultParameter("draggable",true);_defaultParameter("resizable",true);_defaultParameter("popupWindows",false);_defaultParameter("external",true);_defaultParameter("popupStay",false);_defaultParameter("imMinimize",deployPath+"/images/btnPopupMax.gif");_defaultParameter("imMaximize",deployPath+"/images/btnPopupMin.gif");_defaultParameter("imClose",deployPath+"/images/btnPopupClose.gif");_defaultParameter("imResize",deployPath+"/images/btnPopupResize.gif");if(document.getElementById(params["popupId"]+"_b")==null){new popUp(params.left,params.top,params.width,params.height,params.popupId,params.content,params.contentTextColor,params.contentBgColor,params.fontStyle,params.titlebar,params.titlebarBgColor,params.titlebarTextColor,params.borderColor,params.scrollbarColor,params.shadowColor,params.hide,params.draggable,params.resizable,params.popupWindows,params.external,params.popupStay,params.imMinimize,params.imMaximize,params.imClose,params.imResize);}else{showbox(params["popupId"]);}
popupsContext.addPopup(params["popupId"]);if(!popupsContext.isContainingSubPopup()){var lastIframeObj=popupsContext.getSubPopupFrameContent();controlForm(lastIframeObj.document,true);var minButton=popupsContext.getSubPopupObject("_min");var closeButton=popupsContext.getSubPopupObject("_cls");minButton.onmousedown=disableEvent;closeButton.onmousedown=disableEvent;addEventHandler(lastIframeObj.document,'mousedown',cancelAndClose);if(!(document.getElementById&&!document.all)){addEventHandler(lastIframeObj.document,'selectstart',disableEvent);}}
if(!(document.getElementById&&!document.all)){addEventHandler(document,'selectstart',disableEvent);}
addEventHandler(document,'mousemove',isEventInpopup);hideShowCovered(popupsContext.getCurrentPopupObject("_b").id);var mainPageObject=document.body.getElementsByTagName("TABLE");if(mainPageObject[0]){mainPageObject[0].className='opaque';}
var currentPopupFrame=popupsContext.getCurrentPopupFrame();if(!(document.getElementById&&!document.all)){currentPopupFrame.attachEvent('onload',replaceTitle);currentPopupFrame.attachEvent('onload',restoreButtonEvents);}else{addEventHandler(currentPopupFrame,'load',replaceTitle);addEventHandler(currentPopupFrame,'load',restoreButtonEvents);}}
function selectElementInPopup(form){if(!popupsContext.isContainingSubPopup()){form.target=popupsContext.getSubPopupFrameName();if(document.all){parent.selectAndClose();}else{parent.setTimeout('selectAndClose();',0);}}else{form.target="_parent";popupsContext.delPopup();}}
function selectAndClose(){var currentFrame=popupsContext.getMainFrame();performFirstCloseActions(currentFrame);performSecondCloseActions(currentFrame);}
function cancelAndClose(){var currentFrame=popupsContext.getMainFrame();performFirstCloseActions(currentFrame);var iframeObj=popupsContext.getCurrentPopupFrameContent();var currentForm=iframeObj.document.forms[0];if(!popupsContext.isContainingSubPopup()){currentForm.target=popupsContext.getSubPopupFrameName();}else{currentForm.target="_parent";}
currentForm.action=composeCancelAction(currentForm);performSecondCloseActions(currentFrame);currentForm.submit();}
function performFirstCloseActions(currentFrame){if(popupsContext.isContainingSubPopup()){var mainPageObject=currentFrame.document.body.getElementsByTagName("TABLE");if(mainPageObject[0]){mainPageObject[0].className='';}
currentFrame.hideShowCovered(popupsContext.getCurrentPopupObject("_b").id);if(!(document.getElementById&&!document.all)){currentFrame.removeEventHandler(currentFrame.document,'selectstart',disableEvent);}}
currentFrame.removeEventHandler(currentFrame.document,'mousemove',isEventInpopup);}
function performSecondCloseActions(currentFrame){if(!popupsContext.isEmpty()){hidebox(popupsContext.getCurrentPopup());}
popupsContext.delPopup();if(!popupsContext.isEmpty()){currentFrame.addEventHandler(currentFrame.document,'mousemove',isEventInpopup);}}
function isEventInpopup(evt){if(!evt)evt=window.event;if(!popupsContext.isEmpty()){e=popupsContext.getCurrentPopupObject("_b");h=eval((e.style.height).substring(0,e.style.height.length-2));w=eval((e.style.width).substring(0,e.style.width.length-2));l=eval((e.style.left).substring(0,e.style.left.length-2));t=eval((e.style.top).substring(0,e.style.top.length-2));mx=(!(document.getElementById&&!document.all))?event.clientX+document.body.scrollLeft:evt.pageX;my=(!(document.getElementById&&!document.all))?event.clientY+document.body.scrollTop:evt.pageY;if((((my)<t)||((my)>(t+h))||((mx)<l)||((mx)>(l+w)))){addEventHandler(document,'mousedown',cancelAndClose);}else{removeEventHandler(document,'mousedown',cancelAndClose);}}}
function replaceTitle(){var iframeObj=popupsContext.getCurrentPopupFrame();if(iframeObj){if(iframeObj.contentWindow){titleToReplace=iframeObj.contentWindow.document.title;}
var elt=popupsContext.getCurrentPopupObject("_titleBar");elt.innerHTML=titleToReplace;}}
function controlForm(oDocument,isDisabled){var aForms=oDocument.forms;for(var i=0;i<aForms.length;i++){var oForm=aForms[i];var aElements=oForm.elements;for(var j=0;j<aElements.length;j++){var oElement=aElements[j];if(oElement.type=="submit"){oElement.disabled=isDisabled;}else if(oElement.type=="button"){oElement.disabled=isDisabled;}else if(oElement.type=="image"){oElement.disabled=isDisabled;}}}
var aImages=oDocument.images;for(var i=0;i<aImages.length;i++){var oImage=aImages[i];isDisabled?addEventHandler(oImage,"click",disableEvent):removeEventHandler(oImage,"click",disableEvent);}
var aLinks=oDocument.links;for(var i=0;i<aLinks.length;i++){var oLink=aLinks[i];isDisabled?addEventHandler(oLink,"click",disableEvent):removeEventHandler(oLink,"click",disableEvent);}
var aSelections=oDocument.getElementsByName("selection");for(var i=0;i<aSelections.length;i++){var oSelection=aSelections[i];var lastAction=oSelection.onclick;oSelection.onclick=function(){disableEvent(e);lastAction;}}
isDisabled?addEventHandler(oDocument,"click",disableEvent):removeEventHandler(oDocument,"click",disableEvent);}
function restoreButtonEvents(){var minButton=popupsContext.getCurrentPopupObject("_min");var closeButton=popupsContext.getCurrentPopupObject("_cls");minButton.onmousedown=minimize;closeButton.onmousedown=new Function("cancelAndClose();");}
function disableEvent(e){return false;}
function composeCancelAction(oForm){var currentURI=null;if(document.baseURI){currentURI=document.baseURI;}else if(document.URL){currentURI=document.URL;}
var splittedUri=currentURI.split("/");var cancelAction=splittedUri[0]+"//"+splittedUri[2]+"/"+splittedUri[3];cancelAction+=oForm.returnActionMapping.value;cancelAction+=".do";cancelAction+="?cancel=true";cancelAction+="&currentActionMapping="+oForm.currentActionMapping.value;cancelAction+="&fastInputProperty="+oForm.fastInputProperty.value;return cancelAction;}
