
//version du 6 mars 2010
 
var DlgMessageBox = function() {


		this.btn_del_src='bouton_supprimer.jpg';
		this.btn_ok_src='bouton_ok.jpg';
		this.btn_valid_src='bouton_valider.jpg';
		this.btn_cancel_src='bouton_annuler.jpg';
		this.btn_corr_src='bouton_corriger.jpg';
		this.btn_close_src='bouton_fermer.jpg';
		this.btn_confirm_src='bouton_confirmer.jpg';		
		this.icon_question_src='interrogation.gif';
		this.icon_ok_src='ok.gif';
		this.icon_info_src='';		
		this.icon_warning_src='exclamation.gif';	
		
			
		this.mode = 0; 		// 0=manuel 1=information 2=confirmation 3=erreur/correction 2 boutons 4=erreur 1 bouton 5=erreur sans correction possible
		this.title1='Information: ';
		this.title2='';		
		this.text='';	
		this.question='';
		this.btn1='';//spécifie le bouton avec le type de bouton prédéfinie
		this.btn2='';//spécifie le bouton avec le type de bouton prédéfinie
		this.button1='bouton_valider.jpg'; //spécifie le bouton avec le fichier
		this.button2='bouton_annuler.jpg'; //spécifie le bouton avec le fichier
		this.link1='';		//spécifie l'url ou le code javascript à appliquer à button1
		this.link2='';		//spécifie l'url ou le code javascript à appliquer à button2
		this.nobutton=0;
		this.uniqu_button=0;
		this.manual_content=''; 	//le fait de rentrer ici un code html affiche ce code à l'intérieur de la boîte de dialogue tout en conservant la présentation autour
		this.layer_content = '';	//permet d'insérer du code html brut directement dans le layeren enlevant la présentation

		this.layer_border = '';		//indiquer une couleur hexadecimale. si vide pas de bordure
		this.layer_color = '';		//indiquer une couleur de fond au layer. si vide = transparent

		this.frame = 0;			//met le contenu dans une iframe au niveau du layer
		this.frame_width = 0;		//largeur de l'iframe si = 0 la largeur ne sera pas indiquée
		this.frame_height = 550;	//hauteur du iframe si = 0 la longueur ne sera pas indiquée
		this.frame_url	='';		//url du document à afficher dans l'iframe
		this.frame_autoscroll = 1;	//affiche les barres de scroll en cas de nécessité
		this.frame_button =0;		//permet d'afficher le bouton de fermeture de fenêtre
		this.frame_button_link = '';
		this.photo =''; 	//mettre une url de photo. la photo sera affichée en grand. 
					//ne pas oublier de renseigner this.link1 qui servira pour transmettre le code servant à fermer la boite
                this.preload_photo =''; 	//tableau contenant des photos à précharger.
                				//chaque élément est composé du chemin aboslue de la photo. ls sont séparés par le caractère |
                                                

		this.url_querystring = '';	//chaine contenant les variables à passer dans l'url sous la forme var=myvar&
		this.use_icon=1;
		this.icon=''; //spécifie l'icone avec le type d'icone prédéfinie
		this.icon_glyph='';//spécifie l'icone avec un fichier d'icone
		this.use_title=0;		//met un message automatique à gauche dans le titre
		this.manual_button='';		//mettre le code html pour passer manuellement des boutons ou lien (inclure aussi les url)
		this.bgcolor='#FFFFE8';		//couleur de fond de la boîte dialogue
		this.top_color='#73A7CE';	//couleur claire de l'encadrement
		this.bottom_color='#3C7FAF';	//couleur foncée de l'encadrement 
		this.image_path='http://'+SYS_INFO.web_site_name+'/images/dialog_box/';//image des images sur le serveur url absolue (http://)
		this.hidebackground=1; 		//cache la page web par opacité
		this.background_color='#333333';//indique la couleur de cache opaque  DEPRECATED
		this.background_opacity=95; 	//opacité du background  DEPRECATED
		this.autoscroll = 1;		//des barres de scroll sont installés à la création de l'objet si le contenu dépasse la boîte
		this.force_autoscroll = 0;	//des barres de scroll sont installés à l'execution de l'objet si le contenu dépasse la boîte

		this.width = 610;		//largeur de la boîte en pixel. si égal 0: pas d'indication de largeur
		this.height = 500;		//hauteur de la boîte en pixel. si égal 0: pas d'indication de hauteur
		


                


                var my_object = this;

		//méthodes
	
		//show montre la boite de dialogue et cache le fond par opcacité
		//close cache la boite de dialogue et cache le fond par opcacité
		//show_dlg affiche uniquement la boite de dialogue
		//close_dlg cache uniquement la boite dialogue
		//close_background cache le background opaque uniquement
		//show_background affiche le background opaque uniquement
                //preload_img 


		
                //écriture des calques à la création de la page
		
		document.write('<style>');
		document.write('.hidden { display: none;}'); 
		document.write('.visible {display: inline;}');	
		document.write('.dlgborder{border: 1px #999999 solid}');
		document.write('</style>');		
		var style1 = 'top:0;left:0;width:100%;height:100%;position:fixed;background-image: url('+my_object.image_path+'background.png);';
                var margintop = my_object.height / 2;var marginleft = my_object.width / 2;
		var style2 = 'width: '+my_object.width+'px;height: '+my_object.height+'px;display: block;position:absolute;top: 50%;left: 50%;margin-top: -'+margintop+'px;margin-left: -'+marginleft+'px;'; 
		if(my_object.autoscroll>0){style2+='overflow:auto;';}
		//if(my_object.layer_border!=''){style2+='border: 1px '+my_object.layer_border+' solid';}		
		document.write('<div id="dlgbackground" style="z-index:900;'+style1+'" class="hidden">');
		document.write('<div id="dlgbox"  style="z-index:1000;'+ style2 +'" class="hidden"></div>');
		document.write('</div>')
	
                
                
                //creation du contenu

		this.create_content= function()
		{
			
	                 //préchargement de photos
	                 
	                 if(my_object.preload_photo!='')
	                 	{
	                 		
	              		i=0;var tab =  my_object.preload_photo;
	              		var element = tab.split("|");var preload = new Array;   		
	                 	while(i<element.length)
	                 		{
	                 		preload[i] = new Image;
	                 		preload[i].src = element[i];
	                 		i++;	
	                 		}
	                 		
	                 	}
	                
	                
	                //ajustement des propriétés des calques
	                
                	var el =  document.getElementById("dlgbox");
		
			var margintop = my_object.height / 2;
			el.style.marginTop = - margintop + 30 +'px' ;
			var marginleft = my_object.width / 2;
			el.style.marginLeft = - marginleft+'px';
			el.style.width=my_object.width+'px';
			el.style.height=my_object.height+'px';               
			if( my_object.layer_border!='') {el.style.border = '1px solid '+ my_object.layer_border;}
			if( my_object.force_autoscroll>0) {el.style.overflow="scroll";}
			if( my_object.layer_color !='' ) {el.style.backgroundColor=my_object.layer_color;}
			
			switch(my_object.btn1)
				{		
				case 'ok' : my_object.button1=my_object.btn_ok_src; break;
				case 'del' : my_object.button1=my_object.btn_del_src; break;
				case 'valid' : my_object.button1=my_object.btn_valid_src; break;
				case 'cancel' : my_object.button1=my_object.btn_cancel_src; break;
				case 'corr' : my_object.button1=my_object.btn_corr_src; break;
				case 'close' : my_object.button1=my_object.btn_close_src; break;
				case 'confirm' : my_object.button1=my_object.btn_confirm_src; break;								
				}

			switch(my_object.btn2)
				{
		
				case 'ok' : my_object.button2=my_object.btn_ok_src; break;
				case 'del' : my_object.button2=my_object.btn_del_src; break;
				case 'valid' : my_object.button2=my_object.btn_valid_src; break;
				case 'cancel' : my_object.button2=my_object.btn_cancel_src; break;
				case 'corr' : my_object.button2=my_object.btn_corr_src; break;
				case 'close' : my_object.button2=my_object.btn_close_src; break;
				case 'confirm' : my_object.button1=my_object.btn_confirm_src; break;								
				}

			switch(my_object.icon)
				{			
				case 'ok' : my_object.icon_glyph=my_object.icon_ok_glyph; break;
				case 'question' : my_object.icon_glyph=my_object.icon_question_glyph; break;
				case 'warning' : my_object.icon_glyph=my_object.icon_warning_glyph; break;
				case 'info' : my_object.icon_glyph=my_object.icon_info_glyph_src; break;
				}


				
			switch(my_object.mode)
				{		
				case 1 : { my_object.title1='Information:';my_object.icon_glyph=my_object.icon_ok_src;my_object.button1=my_object.btn_ok_src;my_object.uniqu_button=1;break;}	
				case 2 : { my_object.title1='Question:';my_object.icon_glyph=my_object.icon_question_src;my_object.button1=my_object.btn_valid_src;my_object.button2=my_object.btn_cancel_src;my_object.uniqu_button=0;break;}	
				case 3 : { my_object.title1='Erreur:';my_object.icon_glyph=my_object.icon_warning_src;my_object.button1=my_object.btn_corr_src;my_object.button2=my_object.btn_cancel_src;my_object.uniqu_button=0;break; }				
				case 4 : { my_object.title1='Erreur:';my_object.icon_glyph=my_object.icon_warning_src;my_object.button1=my_object.btn_corr_src;my_object.uniqu_button=1;break; }				
				case 5 : { my_object.title1='Erreur:';my_object.icon_glyph=my_object.icon_warning_src;my_object.button1=my_object.btn_close_src;my_object.uniqu_button=1;break; }				
				}

	
			
			

			dialog_content='<table width="600" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="'+my_object.bgcolor+'">';
			dialog_content+='<tr>'; 
			dialog_content+='<td bgcolor="'+my_object.top_color+'" width="1" height="1"><img src="'+my_object.image_path+'transparent.gif" width="1" height="1"><img src="'+my_object.image_path+'transparent.gif" width="2" height="2"></td>';
			dialog_content+='<td bgcolor="'+my_object.top_color+'" height="1"><img src="'+my_object.image_path+'transparent.gif" width="2" height="1"></td>';
			dialog_content+='<td bgcolor="'+my_object.bottom_color+'" width="1" height="1"><img src="'+my_object.image_path+'transparent.gif" width="1" height="1"></td>';
			dialog_content+='</tr><tr><td bgcolor="'+my_object.top_color+'" width="2"><img src="'+my_object.image_path+'transparent.gif" width="2" height="2"></td>';

			
			dialog_content+='<td bgcolor="'+my_object.bgcolor+'">';		
			dialog_content+='<table width="596" border="0" cellspacing="0" cellpadding="8" bgcolor="#DDE9F4" background="'+my_object.image_path+'dialog_box_title.jpg">';
			dialog_content+='<tr><td width="123"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#FFFFFF" size="3"><i>';
		
			if(my_object.use_title){dialog_content+='<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#FFFFFF" size="3"><i>'+my_object.title1+'</i></font>';} 

			dialog_content+='</td><td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">'+my_object.title2+'</font></b></font></td></tr></table>';
						

			

			if(my_object.manual_content)
				{
				dialog_content+='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>'+my_object.manual_content+'</td></tr></table>';
				} 
			else 
				{			
						
				dialog_content+='<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#2F5E8C"><tr>';
				dialog_content+='<td><img src="'+my_object.image_path+'images/transparent.gif" width="1" height="1"></td></tr></table><table width="596" border="0" cellspacing="2" cellpadding="6">';
				dialog_content+='<tr><td width="95">';
		
				if(my_object.use_icon){dialog_content+='<img src="'+my_object.image_path+my_object.icon_glyph+'">';}
		
				dialog_content+='</td><td width="499"><table width="100%" border="0" cellspacing="0" cellpadding="2">';

				if(my_object.text){dialog_content+='<tr><td><font size="2" face="Arial, Helvetica, sans-serif" color="#333333">'+my_object.text+'</font></td></tr>';}

				dialog_content+='<tr><td>&nbsp;</td></tr>'; 
		
				if(my_object.question){dialog_content+='<tr><td><b><font face="Arial, Helvetica, sans-serif" color="#333333">'+my_object.question+'</font></b></td></tr>';}
		
				dialog_content+='<tr><td>&nbsp;</td></tr><tr><td>';


				if(!my_object.nobutton)
					{
				
					if(!my_object.manual_button)
						{		
						
						if(my_object.uniqu_button>0)		
		
								{
								dialog_content+='<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"><tr>'; 
								dialog_content+='<td align="center" width="100%"><a href="'+my_object.link1+'"><img src="'+my_object.image_path+my_object.button1+'" border="0"></a></td>';
								dialog_content+='</tr></table>';				
								}
							else
								{
								dialog_content+='<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"><tr>'; 
								dialog_content+='<td align="center" width="50%"><a href="'+my_object.link1+'"><img src="'+my_object.image_path+my_object.button1+'" border="0"></a></td>';
								dialog_content+='<td width="50%"><a href="'+my_object.link2+'"><img src="'+my_object.image_path+my_object.button2+'" border="0"></a></td>';
								dialog_content+='</tr></table>';
								}
			
						}
					else
						{
						dialog_content+='<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td width="100%" >'+my_object.manual_button+'</td></tr></table>'; 				
						}//end manual_button
					}//end nobutton
			
			
				dialog_content+='</td></tr></table></td></tr></table>';
		
				} // end else manual_content


			dialog_content+='</td>';

		
			dialog_content+='<td bgcolor="'+my_object.bottom_color+'" width="2"><img src="'+my_object.image_path+'transparent.gif" width="2" height="2"></td></tr>';
			dialog_content+='<tr><td bgcolor="'+my_object.bottom_color+'" width="2" height="2"><img src="'+my_object.image_path+'transparent.gif" width="2" height="2"></td><td bgcolor="'+my_object.bottom_color+'" height="2"><img src="'+my_object.image_path+'transparent.gif" width="2" height="2"></td>';
			dialog_content+='<td bgcolor="'+my_object.bottom_color+'" width="2" height="2"><img src="'+my_object.image_path+'transparent.gif" width="2" height="2"></td></tr></table>';

			if(my_object.photo !='')
				{
				var 	mycode ='<table cellpadding="0" cellspacing="5" border="0" bgcolor="#FFFFFF"  align="center" class="dlgborder"><tr><td align="center">';
				mycode+='<a href="'+my_object.link1+'"><img src ="'+ my_object.photo +'" border="0" class="dlgborder"></a>';
				mycode+='</td></tr><tr><td align="center">';
				mycode+='<a href="'+my_object.link1+'"><div style="color:#333333"><b>Fermer cette fenêtre</b></div></a>';				
				mycode+='</td></tr></table>';
			
				document.getElementById("dlgbox").innerHTML=mycode;						
				}

	
			 else
				{				
				document.getElementById("dlgbox").innerHTML=dialog_content;
				}  


			if(my_object.layer_content!='')
				{
				document.getElementById("dlgbox").innerHTML=my_object.layer_content;
				}

			if(my_object.frame>0)
				{
				content ='<center><table cellpadding="0" cellspacing="0" border="0"  width="100%" align="center" bgcolor="#FFFFFF" class="dlgborder"><tr><td align="center">';
				
				content = '<iframe id="myiframe" name="myiframe" src="'+my_object.frame_url+'" ';
				if(my_object.frame_width>0) {content+=' width="'+my_object.frame_width+'" ';}else{content+=' width="100%" ';}
				if(my_object.frame_height>0){content+=' height="'+my_object.frame_height+'" ';}
				if(my_object.frame_autoscroll>0){content+=' scrolling="yes"  ';}else{content+=' scrolling="no"  ';}
				content+=' frameborder="0"></iframe>';				
				content+='</td></tr><tr><td>&nbsp;</td></tr>';				
				if(my_object.frame_button>0){content+='<tr><td align="center" width="100%"><center><a href="'+my_object.frame_button_link+'"><img src="'+my_object.image_path+my_object.btn_close_src+'" border="0"></a></center>';}
				content+='</table></center>';
				document.getElementById("dlgbox").innerHTML=content;
				}


			
		}   //end create_content













		function hidedlg(status){
			if(status){document.getElementById('dlgbackground').className = "hidden";}	
			document.getElementById('dlgbox').className = "hidden";	
		}
		
		function showdlg(status)
		{
				
			if((status)&&(my_object.hidebackground>0)){document.getElementById('dlgbackground').className = "visible";}	
			document.getElementById('dlgbox').className = "visible";	
		}


		this.show = function()
		{
			showdlg(1);
		
		}

		this.close = function()
		{
			hidedlg(1);
		
		}

		this.show_dlg = function()
		{
			showdlg(0);
		
		}
	
		this.close_dlg = function()
		{
			hidedlg(0);
		
		}	


		this.close_background = function()
		{
			document.getElementById('dlgbackground').className = "hidden";	
		}
		
		this.show_background = function()
		{
				
			document.getElementById('dlgbackground').className = "visible";	
		}





}