//Vars de configuration
deltaH=20; //decalage horizontal au resize
deltaV=35; //decalage vertical au resize

function MM_openBrWindow(theURL,winName,features) { //v2.0
  //window.open(theURL,winName,features);

	//separe les différents params des features
	var tabFeatures = features.split(",");
	
	//y cherche les params width et height
	var winWidth = "";
	var winHeight = "";
	
	for ( i = 0 ; i < tabFeatures.length ; i ++ ){
		if ( tabFeatures[i].substring ( 0 , 5 ) == "width"  ) { 
			//recupère la valeur de width
			var z = tabFeatures[i].split("=");
			winWidth = parseInt ( z[1] );
		}
		if ( tabFeatures[i].substring ( 0 , 6 ) == "height" ) {
			//recupère la valeur de height
			z = tabFeatures[i].split("=");
			winHeight = parseInt ( z[1] );
		}
	}
	
	
	//calcule les nouvelles positions en tenant compte du nb de fenetres ouvertes
	posX = new String ( Math.round ( screen.width -  winWidth )/2  ) ;
	posY = new String ( Math.round ( screen.height - winHeight )/2  ) ;
	
	//reconstruit la chaine des parametres
	var newFeatures = "" ;
	var modLeft=false;
	var modTop=false;
	for ( i = 0 ; i < tabFeatures.length ; i ++ ){
	
		//si le param est gauche ou haut on le modifie en accord avec les nouvelles positions
		if ( tabFeatures[i].substring ( 0 , 4 ) == "left" ) {
			tabFeatures[i] = "left=" + posX ;
			modLeft=true;
		}
		if ( tabFeatures[i].substring ( 0 , 3 ) == "top"  ) {
			tabFeatures[i] = "top="  + posY ;
			modTop=true;
		}
		
		//rajoute le param dans la chaine des new Params
		newFeatures += "," + tabFeatures[i] ;
	}
	
	//rajoute les params a la fin si pas déjà fait
	if( !modLeft ){
		newFeatures +=",left=" + posX ;
	}
	if( !modTop ){
		newFeatures +=",top=" + posY;
	}


	//supprime la premiere virgule
	newFeatures = newFeatures.substring ( 1 ) ;
	
	//ouvre la popup dans la categorie séléctionnée
	popup=window.open(theURL,winName,newFeatures);
	//resize
	popup.resizeTo(winWidth+deltaH, winHeight+deltaV);
	//et la remet devant
	popup.focus();
}


//Vars de config
decalH=10; //decalage horizontal par rapport au bord de l'ecran (en pixels)
decalV=10; //decalage vertical par rapport au bord de l'ecran (en pixels)

//*******VERSION BASIQUE*****************/

//fonction qui ouvre unpopup
function openPopup(theURL,winName,features){

	//separe les différents params des features
	var tabFeatures = features.split(",");
	
	//y cherche les params width et height
	var winWidth = "";
	var winHeight = "";
	
	for ( i = 0 ; i < tabFeatures.length ; i ++ ){
		if ( tabFeatures[i].substring ( 0 , 5 ) == "width"  ) { 
			//recupère la valeur de width
			var z = tabFeatures[i].split("=");
			winWidth = parseInt ( z[1] );
		}
		if ( tabFeatures[i].substring ( 0 , 6 ) == "height" ) {
			//recupère la valeur de height
			z = tabFeatures[i].split("=");
			winHeight = parseInt ( z[1] );
		}
	}
	
	
	//calcule les nouvelles positions en tenant compte du nb de fenetres ouvertes
	posX = new String ( Math.round ( screen.width -  winWidth )/2  ) ;
	posY = new String ( Math.round ( screen.height - winHeight )/2  ) ;
	
	//reconstruit la chaine des parametres
	var newFeatures = "" ;
	for ( i = 0 ; i < tabFeatures.length ; i ++ ){
	
		//si le param est gauche ou haut on le modifie en accord avec les nouvelles positions
		if ( tabFeatures[i].substring ( 0 , 4 ) == "left" ) {
			tabFeatures[i] = "left=" + posX ;
		}
		if ( tabFeatures[i].substring ( 0 , 3 ) == "top"  ) {
			tabFeatures[i] = "top="  + posY ;
		}
		
		//rajoute le param dans la chaine des new Params
		newFeatures += "," + tabFeatures[i] ;
	}
	
	//supprime la premiere virgule
	newFeatures = newFeatures.substring ( 1 ) ;
	
	/*ajout du shunt pour popups de fiches pays*/
	if (winName == "pays") {
		winWidth = 350;
		winHeight = 455;
	}
	/*fin ajout du shunt*/
	
	//met le meme nom a totue les popups
	winName="firstPop";

	//popup.close();
	//ouvre la popup dans la categorie séléctionnée
	popup=window.open(theURL,winName,newFeatures);

	popup.resizeTo(winWidth+deltaH, winHeight+deltaV);
	//et la remet devant
	popup.focus();
}
	
//*******FIN VERSION BASIQUE******************/
