/*!
\file CPN_windows.js
\brief class to manage window with hidden iFrame
\author jpl
\date 08/09/2008
\par Modification
\li .
*/

var CPN_popframe = {
	
	m_sz_Modal : "modal",
	m_sz_PopUp : "popframe",
	m_sz_ModalSrc : "../js/CPN_window.html",
	m_sz_PopUpSrc : "../js/CPN_window.html",
	
/*!
\fn open : function (the_sz_Url, the_i_Width, the_i_Height)
\brief ouvrir popframe avec creation de 2 IFrames si non existantes (modal et popframe)
\author jpl
\date 08/09/2008
\param the_sz_Url
\param the_i_Width
\param the_i_Height
\return .
\par Modification
\li .
*/
	open : function (the_sz_Url, the_i_Width, the_i_Height) {
		if (!the_i_Width) { the_i_Width = 640; } 
		if (!the_i_Height) { the_i_Height = 480; }
		
		/* Ajout de la frame modale si celle-ci n'éxiste pas */
		if(!top.document.getElementById(this.m_sz_Modal)) {
			this.CPN_popframe_addModalFrame(top.document,this.m_sz_ModalSrc);
		}

		/* Ajout de la frame pop-up si celle-ci n'existe pas */
		if(!top.document.getElementById(this.m_sz_PopUp)) {
			this.CPN_popframe_addPopupFrame(top.document,the_sz_Url);
		} else {
			top.document.getElementById(this.m_sz_PopUp).src=the_sz_Url;
		}
		
		var a_i_LeftPos=(top.document.body.clientWidth-the_i_Width)/2;
		var a_i_TopPos=(top.window.innerHeight-the_i_Height)/2;

		if(isNaN(a_i_TopPos)) {
			a_i_TopPos=parseInt((top.document.documentElement.clientHeight - parseInt(the_i_Height))/2);  
		}
		if(a_i_TopPos<0) {
			a_i_TopPos=0;	
		}
		if(a_i_TopPos==0) {
			a_i_TopPos=(top.document.body.clientHeight - parseInt(the_i_Height))/2;
		}
		if(a_i_TopPos<0) {
			a_i_TopPos=0;
		}

		top.document.getElementById(this.m_sz_Modal).style.zIndex=90;
		top.document.getElementById(this.m_sz_PopUp).style.left=a_i_LeftPos+"px";
		top.document.getElementById(this.m_sz_PopUp).style.top=a_i_TopPos+"px";
		top.document.getElementById(this.m_sz_PopUp).style.height=the_i_Height+"px";
		top.document.getElementById(this.m_sz_PopUp).style.width=the_i_Width+"px";
		top.document.getElementById(this.m_sz_Modal).style.visibility="visible";
		top.document.getElementById(this.m_sz_PopUp).style.visibility="visible";

	} /* open */
	,

/*!
\fn close : function ()
\brief Ferme la pop-up
\author jpl
\date 09/09/2008
\param .
\return .
\par Modification
\li .
*/
	close : function () {
		top.document.getElementById(this.m_sz_Modal).style.visibility="hidden";
		top.document.getElementById(this.m_sz_PopUp).style.visibility="hidden";
	} /* close */
	,

/*!
\fn printCss : function ()
\brief Ecrit la bonne inclusion css (à utiliser dans le <head>)
\author jpl
\date 08/09/2008
\param the_sz_basePath
\return .
\par Modification
\li .
*/	
	printCss : function (the_sz_basePath) {
		if (!the_sz_basePath) { the_sz_basePath = "."; } 
		/* Include css */
		var a_sz_Include="<link rel=\"stylesheet\" href=\""+the_sz_basePath+"/popframe.css\" type=\"text/css\" />";
		a_sz_Include+="<!--[if IE]>";
		a_sz_Include+="<link rel=\"stylesheet\" href=\""+the_sz_basePath+"/popframe_ie.css\" type=\"text/css\" />";
		a_sz_Include+="<![endif]-->";
		document.write(a_sz_Include);
	},

/*!
\fn CPN_popframe_addPopupFrame : function(the_o_Element,the_sz_Src)
\brief ajoute les frames et initialise les proprietes
\author jpl
\date 08/09/2008
\param the_o_Element
\param the_sz_ModalSrc
\return .
\par Modification
\li .
*/
	addFrames : function (the_o_Element,the_sz_ModalSrc) {
		this.m_sz_ModalSrc = this.m_sz_PopUpSrc = the_sz_ModalSrc;
		this.CPN_popframe_addModalFrame(the_o_Element,the_sz_ModalSrc);
		this.CPN_popframe_addPopupFrame(the_o_Element,the_sz_ModalSrc);
	},
	
/*!
\fn CPN_popframe_addModalFrame : function(the_o_Element,src)
\brief Ajoute la frame modale
\author jpl
\date 08/09/2008
\param the_o_Element
\param src
\return .
\par Modification
\li .
*/
	CPN_popframe_addModalFrame : function(the_o_Element,the_sz_Src) {
		the_o_Element.body.innerHTML+='<iframe id="'+this.m_sz_Modal+'" name="'+this.m_sz_Modal+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" style="position:absolute; left:0px; top:0px; width:100%; height:100%;opacity: 0.5; z-index:94; visibility:hidden;" src="'+the_sz_Src+'" allowtransparency="true"></iframe>';
	} /* CPN_popframe_addModalFrame */ 
	,
	
/*!
\fn CPN_popframe_addPopupFrame : function(the_o_Element,the_sz_Src)
\brief ajoute la frame popframe
\author jpl
\date 08/09/2008
\param the_o_Element
\param the_sz_Src
\return .
\par Modification
\li .
*/
	CPN_popframe_addPopupFrame : function(the_o_Element,the_sz_Src) {
		the_o_Element.body.innerHTML+='<iframe id="'+this.m_sz_PopUp+'" name="'+this.m_sz_PopUp+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" style="LEFT: 0px;  POSITION: absolute; TOP: 0px; z-index:95; visibility:hidden;"src="'+the_sz_Src+'" allowtransparency="true"></iframe>';
	} /* CPN_popframe_addPopupFrame */

} /* CPN_popframe */

/**********************************************
	CPN_windows.js
**********************************************/

