/* Variables à initialiser dans la page appelant le javascript 
var CFG_IDSESSION
var IDPAGEWEB_ACCUEIL
var CFG_IDPAGEWEB
*/

var w; //variable popup

// Permet de fermer toutes le fenêtres 
	function fct_fermerAllFenetres()
	{
	window.opener.close();
	window.close();
	}

// ferme les popups en cours 
	function closewinNew(){
	if ((w) && (!w.closed)){
	w.close();}
	}

// Fonction affichant les popUp 
		function fct_popUp(parametresGet, valWidth, valHeight, valLeft, valTop, type)
		{
		var xpage = parseInt((screen.width-valWidth)/2);
		var ypage = parseInt((screen.height-valHeight)/2);
		if (type==1) {
		// popup coin haut/gauche
		w=window.open(parametresGet+'&PHPSESSID='+CFG_IDSESSION, "monPopUp", "top="+valTop+", left="+valLeft+", height="+valHeight+", width="+valWidth+", toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
		}
		else {
		// popup centrée
		w=window.open(parametresGet+'&PHPSESSID='+CFG_IDSESSION, "monPopUp", "top="+ypage+", left="+xpage+", height="+valHeight+", width="+valWidth+", toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
		}		
		w.document.close();
		w.focus();
		}


// Fonction gérant le popUp affichant l'aide
		function popUpAide(langue)
		{	
		var xpage = parseInt((screen.width-800)/2);
		var ypage = parseInt((screen.height-530)/2);
		w=window.open('01_themes/kaaWeb/colorise/04_aide_'+langue+'/aide.html', "aide", "top="+ypage+", left="+xpage+", height=500, width=800, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");	
		w.document.close();
		w.focus();
		}

// Fonction gérant le popUp affichant la recherche avancée 
		   
		function fct_popUpRechercheAvancee(parametresGet, valWidth, valHeight, valLeft, valTop)
		{
		if (screen.width<=1152)  {valHeight = 690;}			
		if (screen.width>1152)  {valHeight = 760;var ypage = (screen.height - valHeight)/2;}
		w=window.open(parametresGet+'&PHPSESSID='+CFG_IDSESSION, "monPopUp", "height="+valHeight+", width="+valWidth+", left="+valLeft+", top="+ypage+", toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
		w.document.close();
		w.focus();
		}


// Fonction gérant le popUp affichant les formulaire pour changer de langue 
		   
		function fct_popUpLangue(idLangue,libLangue,idPageWebParent)
		{
		fct_popUp('?idPageWeb='+IDPAGEWEB_ACCUEIL+'&popUp_langue=1&newIdLangue='+idLangue+'&newLibLangue='+libLangue+'&idPageWebParent='+idPageWebParent, '1', '1', '0', '0','1');
		}


// Fonction gérant le popUp affichant les formulaire de demande de recherche 
		function fct_demandeRecherche()
		{
		fct_popUp('?idPageWeb='+CFG_IDPAGEWEB+'&popUp_demandeRecherche=1', '500', '450', '0', '0');
		}


//  Fonction gérant le popUp affichant les formulaire de téléchargement 
		function fct_telechargerPhoto(parametresGet)
		{
		fct_popUp('?idPageWeb='+CFG_IDPAGEWEB+'&popUp_telecharger=1'+parametresGet, '500', '300', '0', '0');
		}


// Fonction gérant le popUp affichant les formulaire permettant de sélectionner une photo 
		function fct_formSelection(parametresGet)
		{
		fct_popUp('?idPageWeb='+CFG_IDPAGEWEB+'&popUp_selectionner=1'+parametresGet, '250', '250', '0', '0');
		}

// Fonction gérant le popUp affichant les formulaire permettant d'ajouter une photo à une sélection 
		function fct_formAddSelection(parametresGet)
		{
		fct_popUp('?idPageWeb='+CFG_IDPAGEWEB+'&popUp_selectionner=1'+parametresGet, '1', '1', '0', '0','1');
		}


// Fonction gérant le popUp affichant les informations des photos 
		function fct_infosPhotos(parametresGet)
		{
		fct_popUp('?idPageWeb='+CFG_IDPAGEWEB+'&popUp_infosPhoto=1'+parametresGet, 970, 680, 0, 0);
		}


// Fonction gérant le popUp affichant la photo pour impression 
		function fct_imprimerPhoto(parametresGet)
		{
		fct_popUp2('index.php?idPageWeb='+CFG_IDPAGEWEB+'&popUp_imprimerInfosPhoto=1'+parametresGet, '300', '300', '0', '0');
		}


// Fonction affichant les popUp avec status 
		
		function fct_popUp2(parametresGet, valWidth, valHeight, valLeft, valTop)
		{
		var xpage = (screen.width - valWidth)/2, ypage = (screen.height - valHeight)/2;
		w=window.open(parametresGet+'&PHPSESSID='+CFG_IDSESSION, "monPopUp", "top="+ypage+", left="+xpage+", height="+valHeight+", width="+valWidth+", toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=0");
		w.document.close();
		w.focus();
		}

// Fonction affichant les popUp 
		function fct_popUpR(parametresGet, valWidth, valHeight, valLeft, valTop, type)
		{
		var xpage = parseInt((screen.width-valWidth)/2);
		var ypage = parseInt((screen.height-valHeight)/2);
		if (type==1) {
		// popup coin haut/gauche
		w=window.open(parametresGet+'&PHPSESSID='+CFG_IDSESSION, "monPopUp", "top="+valTop+", left="+valLeft+", height="+valHeight+", width="+valWidth+", toolbar=1, location=0, directories=0, status=0, menubar=1, scrollbars=1, resizable=1");
		}
		else {
		// popup centrée
		w=window.open(parametresGet+'&PHPSESSID='+CFG_IDSESSION, "monPopUp", "top="+ypage+", left="+xpage+", height="+valHeight+", width="+valWidth+", toolbar=1, location=0, directories=0, status=0, menubar=1, scrollbars=1, resizable=1");
		}		
		w.document.close();
		w.focus();
		}
		
		// Fonction remplaçant des mots dans le champ fulltext

		function Remplace(expr,a,b) {
      var i=0
      while (i!=-1) {
         i=expr.indexOf(a,i);
         if (i>=0) {
            expr=expr.substring(0,i)+b+expr.substring(i+a.length);
            i+=b.length;
         }
      }
      return expr
   	}
   	
   	
		function fct_word_suggestion(original,suggestion,field_name)
		{
							
				var champ = document.forms['rechercheSimple'].elements['' + field_name];
				
				if(champ.value.indexOf(original,0) == -1)
				{
						if (suggestion.indexOf(' ',0) == -1)
							champ.value =  suggestion + ' '+ champ.value ; 
						else
							champ.value =   '"'+ suggestion + '" ' + champ.value; 	
						
				}
				else
				{
					champ.value = Remplace(champ.value,original,suggestion);
						
				}
		}
