
ifrLoaded = 0;
var queryGenerale = '';
    
function ouvre_popup(page, largeur, hauteur, resizable, status, nompopup)
{
	if (nompopup == null) {nompopup = 'Popup';}
	msg=window.open(page, nompopup, 'scrollbars=no,status=' + status + ',toolbar=no,directories=no,menubar=no,location=no,resizable=' + 
	resizable + ',width=' + largeur + ',height=' + hauteur +
	',left=' + ((screen.width - largeur)/2) + ',top=' + ((screen.height - hauteur)/2) );
	msg.focus();
} 
      
function gId(id, level){
    var w ;
    if ( level == 1 ) w = parent.window ; else { if ( level == 2 ) w = parent.parent.window ; else w = window ; }
    return w.document.getElementById(id) ;
}

function HoverSnap(who) {
    if (gId(who,0) != null)
        gId(who,0).className = 'imgHover';
}
function OutSnap(who) {
    if (gId(who,0) != null)
        gId(who,0).className = 'imgNormal';
}

//fonction niveau 1
function redim(len,ifrName) {
    var thisIF = gId(ifrName,0);
    if(thisIF) {
        thisIF.style.height = Math.max(0,len+50)+ 'px';
    }
    var thisIF2 = gId("IFGestion",1);
    if(thisIF2) {
        thisIF2.style.height = Math.max(450,len +200) + 'px';
    }
}

function initF() {
    //redim(0);
    window.parent.iamLoaded();
}

function menu() {
    gId('ifrAide',0).style.display='none';
    gId('ifrGestion',0).style.display='block';
    gId('ifrGestion',0).src='configuration.aspx';
    gId("retourMenu",0).style.display="none";
    selectNode('',false)
    
    affichOnglets(0);
}

//function minimize du menu
masque = false;


//Fonction niveau 1
function mini() {
	var img = gId("maskGestion",0);
    var ligne=gId("LigneToMinimize",0);
    
	if( ! masque) {
		gId("mask",0).src=ServeurImage + 'Calendrier/masquer2.gif';
		ligne.style.display = 'none'
		masque = true;
	}
	else {
		gId("mask",0).src=ServeurImage + 'Calendrier/masquer1.gif';
		ligne.style.display = ''
   		masque = false;
	}
}

function CreateTopicFromTreeViewFromDDL(IdNode)
{
    var Node = window.TMenuConf.FindNodeById(IdNode) ;
    affichOnglets(IdNode);
    CreateTopic(StringParent(Node), Node.ToolTip, Node.Value) ;
}

//Fonction niveau 1: charge une page à partir du treeview
function CreateTopicFromTreeView(idA,iC)
{
    if (idA == '6_2' || idA == '5_2') {
        var my_idA = '';
        //if (idA == '6_2') my_idA = '1_6';
        if (idA == '6_2') my_idA = '1_4';
        if (idA == '5_2') my_idA = '1_4';
        selectAnalyseMenu(my_idA,true);
    }
    else {
        var param=gId('hid_' + idA,0).value;

        OngletConfFonctionLoaded =0;
        OngletConfAideLoaded =0;
        OngletsConfBlocked =0;
        gId('ifrAide',0).style.display = 'none';
        gId('ifrGestion',0).style.display = 'block';
        
        CreateTopic(libelle[iC], tooltip[iC], icone[iC]);

        /* Fonction actuIfrgestion */
        affichOnglets(idA);
        showOnglet('Gestion',idA,iC);   
        gId("retourMenu",0).style.display="block";
    }
    
        
}   

function CreateTopicFirstTime()
{
    CreateTopic(gId('hiddenTitreTopic',0).value,gId('hiddenSousTitreTopic',0).value,gId('hiddenImageTopic',0).value);
}

function CreateTopic(TitreGestion, SousTitreGestion, Image)
{
    if(!SousTitreGestion) SousTitreGestion='';
    
    gId('TitreGestion',0).innerHTML = TitreGestion;
    gId('SousTitreGestion',0).innerHTML = SousTitreGestion;
    gId('imgTitre',0).src = ServeurImage + 'gestion/menu/grand/fond_bleu/' + Image;
}

function StringParent(Node)
{
	var Parent = Node.GetParentNode();
	if (Parent == null)
	{ return Node.Text; }
	else
	{
		var GrandParent = Parent.GetParentNode();
		if ( GrandParent == null ) {
		    if ( Parent.Text == Node.Text ) { return (Parent.Text); }
		    else { return (Parent.Text + " > " + Node.Text); }
		}
		else { 
		    if ( GrandParent.Text == Parent.Text ) { return (GrandParent.Text + " > " + Node.Text); }
		    else { 
		        var gp = GrandParent.Text ;
		        var p = Parent.Text ;
		        var n = Node.Text ;
		        if ( gp.length + p.length + n.length >= 45 ) {
		            return (GrandParent.Text + " > ... > " + Node.Text); }
		        else { return (GrandParent.Text + " > " + Parent.Text + " > " + Node.Text); }
		    }
		}
	}
}



function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
   //Fonction niveau 1: met à jour le treeview  en fonction d'un lien dans une page
 function ChangerMenuConfigurationFromLinkDDL(idMenu) {
    affichOnglets(idMenu);
    //OngletsConfBlocked =1;
    OngletConfFonctionLoaded =0;
    OngletConfAideLoaded =0;
    if (String(idMenu).indexOf('_') != -1) parent.selectAnalyseMenu(idMenu,true);
    else parent.mShowGrp(idMenu,0) ;
    gId("retourMenu",0).style.display="block";
    
}
 
 //Fonction niveau 2: met à jour le treeview en fonction d'un lien dans une page
 function ChangerMenuConfiguration(idMenu) {
    var idNode;
    window.parent.affichOnglets(idMenu);
    //OngletsConfBlocked =1;
    OngletConfFonctionLoaded =0;
    OngletConfAideLoaded =0;
    if (String(idMenu).indexOf('_') != -1) 
    {
        parent.selectAnalyseMenu(idMenu,true);
    }
    else {
        window.location='sommaire.aspx?' + parent.queryGenerale + '&id1='+idMenu;
    }
    gId("retourMenu",1).style.display="block";    
    
}
//fonction niveau 1:Affiche les onglets Fonction et Aide
function affichOnglets(idMenu) {

    gId('aGestion',0).className = 'AideOngletSelected';
    gId('aAide',0).className = 'AideOnglet';
    
    //ajouter ici les noeuds ou il ne faut pas afficher d'onglets
    if ((IsNumeric(idMenu) || idMenu=='1_1' || idMenu=='13_1') && idMenu!="11") {
        gId("tabOngletsConf",0).style.display="none";
    }
    else {
        gId("tabOngletsConf",0).style.display="block";
    }
    
}

function epure(src){
    var str = src
    if ( src.indexOf('.aspx') != -1 ) {
        str = src.substr(0, eval(src.indexOf('.aspx')) + 5) ;
        if ( str.indexOf('javascript:location=')!= -1 ) str = str.substr(21, str.length) ;
    }
    return(str)
}

function actuIfr(ifr,url) {
    if(ifr) {
       var newsrc = epure(ifr.src) ;
        if(parent.browser.isSafari || parent.browser.isNS || parent.browser.isOpera) {
            url = (url == '') ? epure(ifr.src) : url;
            ifr.src = '';
            ifr.src = url;
            //QUE POUR LA verion < à la 9.02
            if ( parent.browser.isOpera && parent.browser.versionMajor < 9) {ifr.src='javascript:location.reload()';}
        }
        else {
            if(url == '') {
                if ( newsrc == "" ) ifr.src='javascript:location.reload()';
                else ifr.src='javascript:location=\''+ newsrc +'\'';
            }
            else {
                ifr.src='javascript:location=\''+ url+'\'';
            }
        }
    }
}

//Fonction niveau 1: Affiche l'onglet clique
function showOnglet(param) {
    var idA=idAnalyse[iC];
    if (OngletsConfBlocked == 0) { 
          var rep=getRep();
          
          switch (param) {
            case 'Gestion' :
                    gId('aGestion',0).className = 'AideOngletSelected';
                    gId('aAide',0).className = 'AideOnglet';
                    gId('ifrAide',0).style.display = 'none';
                    gId('ifrGestion',0).style.display = 'block';
                    if (OngletConfFonctionLoaded == 0 ) {
                        OngletConfFonctionLoaded=1;
                        if (tabUrl[iC].indexOf("?") ==-1)
                            tabUrl[iC] += "?";
                        actuIfr(gId("ifrGestion",0) , rep+"gestion/" + tabUrl[iC] + queryGenerale + '&gestion=1'); 
                    }
                    else {
                        initIfrGestion();
                    }
            break ;
            case 'Aide' :
                    gId('aGestion',0).className = 'AideOnglet';
                    gId('aAide',0).className = 'AideOngletSelected';
                    gId('ifrAide',0).style.display = 'block';
                    gId('ifrGestion',0).style.display = 'none'; 
                    if (OngletConfAideLoaded == 0 ) {
                        OngletConfAideLoaded=1;
                        actuIfr(gId("ifrAide",0) , rep+"gestion/aide.aspx?id=" + String(idA) + queryGenerale);
                    }
                    else {
                        initIfrAide();
                    }
            break ;
          }
    }
}

function getOffsetPos(refObj, inTYPE) {
    var iVal = 0;
    var oObj = refObj;
    var sType = 'oObj.offset' + inTYPE;
    while (oObj) {
        iVal += eval(sType);
        oObj = oObj.offsetParent;
    }
    return iVal;
}

//Fonction niveau 1: redimensionnement Frame Gestion
function initIfrGestion() {
    var IF=gId("ifrGestion",0);
    if (IF) {
        redim(getOffsetPos(IF.contentWindow.document.getElementById("fin"),'Top'),'ifrGestion');
    }
}

//Fonction niveau 1: redimensionnement Frame Aide
function initIfrAide() {

    try{
        if (document.getElementById('frameP'))
            var IF = document.getElementById('frameP');
        else
            var IF = document.getElementById('ifrAide');
            
        var the_height=IF.contentWindow.document.body.scrollHeight;
        IF.height=the_height;
        parent.resizeFrAna();
    } catch(e){ }
}


//fonction niveau 1
function getRep() {
    return (SERVER_NAME);
}

//fonction niveau 2
function frameLoaded() {
    initIfrGestion();
    setTimeout("parent.initIfrGestion()", 1000);
    OngletConfFonctionLoaded=1;
    OngletsConfBlocked =0;
}

//fonction niveau 1
function frameLoaded1() {
    initIfrGestion1();
    setTimeout("initIfrGestion1()", 1000);
    OngletConfFonctionLoaded=1;
    OngletsConfBlocked =0;
}

//Fonction niveau 1: redimensionnement Frame Gestion
function initIfrGestion1() {
    var IF=gId("ifrGestion",1);
    if (IF) {
        parent.redim(getOffsetPos(document.getElementById("fin"),'Top'),'ifrGestion');
    }
}

function reload(idContrat, namePage, idPage, idAutrePage)
{
    var urlPage = window.location.href.substring(0, window.location.href.indexOf("?"));
    window.location.href = urlPage + '?idPage' + namePage + '=' + idPage + '&idContrat=' + idContrat + '&idAutrePage=' + idAutrePage;
}


// Fonction de hide d'un <div> dans la page Gestion/contrats_factures/paiements_coordonnes.aspx avec le user control ModePaiement.ascx
//function hideCB()
//{
//    var divCB = document.getElementById('UCModes_divCB');
//    divCB.style.display = 'none';
//    frameLoaded();
//}

// Fonction d'affichage d'un <div> dans la page Gestion/contrats_factures/paiements_coordonnes.aspx avec le user control ModePaiement.ascx
function changeCB(idcontratcrypt)
{
    ouvre_popup('https://secure.xiti.com/inscription/rens_cb.aspx?ccb=' + idcontratcrypt, 300, 250, 'no','no');
}

function ouvre_popup(page, largeur, hauteur, resizable, status, nompopup)
{
	if (nompopup == null) {nompopup = 'Popup';}
	msg=window.open(page, nompopup, 'scrollbars=no,status=' + status + ',toolbar=no,directories=no,menubar=no,location=no,resizable=' + 
	resizable + ',width=' + largeur + ',height=' + hauteur +
	',left=' + ((screen.width - largeur)/2) + ',top=' + ((screen.height - hauteur)/2) );
	msg.focus();
}
