
function OpenInfoVille(form) {
	var popup_name = "INFO_VILLE_POPUP";
   	form.target = popup_name;
   	window.name="main";
   	w=window.open("", popup_name, "scrollbars=yes,resizable=no,width=740,height=571");
   	w.focus();
   	form.submit();
}

function OpenInfoVillePJ(form,onglet,acces) {
	var popup_name = "INFO_VILLE_POPUP";
    form.target = popup_name;
	form.ONGLET.value = onglet;
	form.IV_ACTION.value="METEO_LOCALITE";
	form.IV_ACCES.value=acces;
    //w=window.open("", popup_name, "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=640,height=600");
    window.name="main";
    w=window.open("", popup_name, "scrollbars=yes,resizable=no,width=740,height=571");
    w.focus();
    form.submit();
}

function OpenIG( form_name ) {
  w = window.open( "", "PJI_IG", "toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes,width=510,height=400" );
  w.focus(); // Passage en avant-plan
  //Si le div que l'on cherche est dupliqu?, on charge la seconde
  g = document.getElementsByName( form_name );
  var taille = g.length;
  g2 = document.getElementsByName( form_name ).item(taille - 1);
  g2.submit();
}

function OpenEcranImpression(form) {
  w = window.open( "", "RP_ECRAN_PRINT", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=820,height=600");
  w.focus(); // Passage en avant-plan
  //Si le div que l'on cherche est dupliqu?, on charge la seconde
  g = document.getElementsByName( form );
  var taille = g.length;
  g2 = document.getElementsByName( form ).item(taille - 1);
  g2.submit();
}

function OpenEcranImpressionPJ(form, niveauPrecision, nbReponse) {
  w = window.open( "", "PJ_ECRAN_PRINT", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=820,height=600");
  w.focus(); // Passage en avant-plan
  //Si le div que l'on cherche est dupliqu?, on charge la seconde
  g = document.getElementById( form );
  g.niveauPrecision.value=niveauPrecision;
  g.nombreReponseTotal.value=nbReponse;
  g.submit();
}

//------------------------------------
// Ouverture d'une page MMS+

function OpenMMS( theURL ) {
  url = ReEncodeURL(theURL);
  if ( curwinname == "pjipub_inscription" ) {   // page PUB
    if ( url.indexOf( "http://" ) == -1 ) url = DocumentBase() + "../../" + url;
    }
  WOpen(url, "PJI_PLANS", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=640,height=480" );
}

//------------------------------------
function WOpen( url, name, param ) {
  var nv = navigator.appName + navigator.appVersion;
  var MAC = (nv.indexOf( "Mac" ) != -1);
  var MSIE4=((nv.indexOf( "MSIE 7" ) != -1) || (nv.indexOf( "MSIE 6" ) != -1) || (nv.indexOf( "MSIE 5" ) != -1) || (nv.indexOf( "MSIE 4" ) != -1) || (nv.indexOf( "MSIE 3" ) != -1) || (nv.indexOf( "MSIE 2" ) != -1))
  var Opera = (nv.indexOf( "Opera" ) != -1);
  var NETSCAPE = (nv.indexOf( "Netscape" ) != -1);
  if ( !MAC && !MSIE4 && !Opera && !NETSCAPE) {
	w = window.open( "", name, param );
	w.close(); // afin de pouvoir fermer
  }
  if (curwinname == "pjipub_inscription")	
  	if ( (url.indexOf("../../") == -1) && (url.indexOf("http://") == -1))
	  url = "../../" + url; 
  w = window.open( url,name, param );
  if ( !MSIE4 ) w.focus();
}

//------------------------------------
function ReEncodeURL( url_in ) {
  if ( url_in.indexOf( ".." ) != -1 ) {
	url_in = url_in.replace( /\.\./gi, "%252e%252e" )
	}
   
  index = url_in.indexOf( "nom=" )
	if ( index != -1 ) {
		url_start = url_in.slice( 0, index + 4 );
		valueNom = url_in.slice( index + 4 );
		valueNom = valueNom.replace( /&/gi, "%26" );
		url_in = url_start + valueNom;
	}	

  index = url_in.indexOf( "?" )
  if ( index == -1 ) // Pas de param?tre: rien ? faire
	return url_in;
  url = url_in.slice( 0, index + 1 );
  params = url_in.slice( index + 1 );

  param_array = params.split( "&" );
  for ( var i = 0 ; i < param_array.length ; i++ ) {
	param = param_array[i];
	name = param.slice( 0, param.indexOf( "=" ));
	value = param.slice( param.indexOf( "=" ) + 1 );
	url = url + name + "=" + escape( unescape( value )) + "&";
	}
  return url;
}

//------------------------------------
// Ouverture d'une page plan
var URL_PLAN = "";
function OpenPlan( theURL ) {
  url = ReEncodeURL(URL_PLAN + theURL);

  if ( curwinname == "pjipub_inscription" ) {	
	if ( url.indexOf( "http://" ) == -1 ) url = DocumentBase() + "../../" + url;
  }
  WOpen(url, "PJI_PLANS", "toolbar=no,menubar=yes,location=no,scrollbars=no,resizable=yes,width=640,height=480" );
}

//------------------------------------
// Ouverture d'une page photo
function OpenPhoto( theURL ) {
  url = ReEncodeURL(theURL);

  if ( curwinname == "pjipub_inscription" ) {	// page PUB
	if ( url.indexOf( "http://" ) == -1 ) url = DocumentBase() + "../../" + url;
	}

  WOpen(url, "PJI_PLANS", "toolbar=no,menubar=yes,location=no,scrollbars=no,resizable=yes,width=640,height=480" );
}

//------------------------------------
// Ouverture d'un site web externe
function OpenWeb( theURL ) {
  WOpen( ReEncodeURL( theURL ), "PJI_WEB", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=630,height=460" );
}

//------------------------------------
// Ouverture d'un site mairie
function OpenMairie( theURL ) {
  WOpen( ReEncodeURL( theURL ), "PJI_MAIRIE", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=630,height=460" );
}

//------------------------------------
// Lecture de l'URL du document courant et on coupe au dernier "/"
function DocumentBase() {
	cur_url = document.URL;
	document_base = cur_url.substring( 0, cur_url.lastIndexOf( "/" )) + "/";
	return document_base;
}

//------------------------------------
// Ouverture d'une page publicitaire (CIP, DiapoFlash, SpotInfo et prochains objets pub)
var curwinname = ""; // pour que la variable soit toujours disponible
function OpenPub( theURL ) {
  url = ReEncodeURL( theURL );
  params = "toolbar=no,status=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=630,height=600";
  if ( curwinname == "pjipub_inscription" ) {	// page PUB
	if ( url.indexOf( "http://" ) == -1 ) url = DocumentBase() + "../../" + url;
	w = window.open( url, "PJI_PUB", params );
	}
  else if ( curwinname == "inscription" ) {	// page photo/plan
	url = DocumentBase() + "../../" + url;
	WOpen( url, "PJI_PUB", params );
	}
  else WOpen( url, "PJI_PUB", params );
}

//------------------------------------
// Ouverture de la page des tarifs telecom
function OpenTarif( theURL ) {
  WOpen( ReEncodeURL( theURL ), "PJI_TARIF", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=550,height=400" );
}

//------------------------------------
// Ouverture de la page des tarifs exact telecom
function OpenTarifExact( theURL ) {
  WOpen( ReEncodeURL( theURL ), "PJI_TARIF", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=330,height=170" );
}

//------------------------------------
// Ouverture d'une page de mention obligatoire gratuite (MOG) g?n?rique
function OpenMog( template ) {
  theURL = template;
  WOpen( ReEncodeURL( theURL ), "PJI_MOG", "toolbar=no,menubar=no,location=no,scrollbars=auto,resizable=yes,width=225,height=200" );
}

// Ouverture d'une page de mention obligatoire de Domiciliation (MOD) g?n?rique
function OpenMod( theURL ) {
  WOpen( ReEncodeURL( theURL ), "PJI_MOD", "toolbar=no,menubar=no,location=no,scrollbars=auto,resizable=yes,width=550,height=295" );
}



//------------------------------------
// Ouverture d'une page de "dossier" (objet ?ditorial en marge droite des pages r?ponses)
function PJDossier( url ) {
  WOpen( ReEncodeURL( url ), "PJI_DOSSIER", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=550,height=400" );
}

//------------------------------------
// Ouverture de la page d'envoi de mail
function OpenSAM( params ) {
  theURL = params;
  WOpen( ReEncodeURL( theURL ), "PJI_SAM", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=640,height=480" );
}

//------------------------------------
// Choix d'un ?l?ment dans une ambigu?t? g?o ou un guide g?o
function ChoixGeo( code ) {
  document.form1.input_image.value = code;
  document.form1.submit();
  return true;
}

//------------------------------------
// Fonctions pour colorer le fond du libell? de lev?e d'ambigu?t?
var clrOver = "FFED00";
function mOvr( src ) {
  if ( !src.contains( event.fromElement )) {
	src.style.cursor = 'hand';
	src.bgColor = clrOver;
	}
}

function mOut( src ) {
  if ( !src.contains( event.toElement )) {
	src.style.cursor = 'default';
	src.bgColor = "";
	}
}

//------------------------------------
// Les boutons GUIDE sont extraits des <FORM>
// et les guides sont remplac?s par un appel ? cette fonction qui prend en param?tre le
// nom du bouton guide d'origine et optionnellement le FORM ? utiliser
function AppelGuide( id, form ) {
  if ( form == null ) form = document.form;
  form.input_image.value = id;
  form.faire.value = "decode_input_image";
  form.submit();
  return true;
}



//------------------------------------
// Ouverture d'une fen?tre d'alerte avec conseils (pas disponible en mode portail)
function OpenAlerte( form, numero ) {
  lang=form.lang.value;
  if (( lang.toUpperCase() != "FR" ) && ( lang.toUpperCase() != "EN" )) lang = "FR";
  theURL = "pj.cgi?html=commun/popup_alerte.html&num_alerte=" + numero + "&SRV=" + form.srv.value + "&lang=" + lang;
  WOpen( ReEncodeURL( theURL ), "PJI_Alerte", "toolbar=no,menubar=no,location=no,scrollbars=auto,resizable=yes,width=380,height=260" );
}

//------------------------------------
// Ouverture d'une fen?tre d'alerte avec conseils (pas disponible en mode portail)
function OpenAlerte2( form, key, url_alerte,langage, serviceAbbreviation, typeAlerte) {
  var portail = "";
  if (form.portail)
  {
  	portail=form.portail.value;
  }
  if (portail == "") portail="PJ";
  if (langage == "") langage="FR";
  else if (( langage.toUpperCase() != "FR" ) && ( langage.toUpperCase() != "EN" )) langage = "FR";
  theURL = url_alerte + "?key_alerte=" + key + "&serviceAbbreviation=" + serviceAbbreviation + "&langage=" + langage+ "&typeAlerte=" + typeAlerte+ "&portail=" + portail;
  WOpen( ReEncodeURL( theURL ), "PJI_Alerte", "toolbar=no,menubar=no,location=no,scrollbars=auto,resizable=yes,width=380,height=260" );
}


//------------------------------------
// SPECIFIQUE portails: ouverture d'une page "carnet d'adresse"
var URL_CARNET = "";
function OpenCarnet( theURL ) {
  theURL = URL_CARNET + theURL;
  WOpen( ReEncodeURL( theURL ), "PJI_CARNET", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=640,height=480" );
}
function open_aideappel(url_aideappel)
{
	aideappel = open(url_aideappel, 'eStara','width=700,status=no,resizable=yes,toolbar=no,scrollbars=yes,menubar=no,location=no');
	aideappel.focus();
}
//------------------------------------
// Les ?venement sont extraits des <FORM>
function AppelEvent(form, eventActif ) {
    if ("actif" == eventActif)
    {
        document.getElementById(form).submit();
        return true;
    }
    else
    {
		var idEvenement = document.getElementById(form).idEvenementActif.value;
		if (idEvenement == eventActif){
			//L'evenement recupere du SBX est bien active : on affiche la page animation
			document.getElementById(form).submit();
			return true;	
		}
    }
}
