// JavaScript Document
if(!gtiFwk)             var gtiFwk      = new Object();
if(!gtiFwk.gtiJsLib)    gtiFwk.gtiJsLib = new Object();

gtiFwk.gtiJsLib = {
    setHelpLinks:function() {
        dojo.query("a.stepHelp").forEach(
            function(item, index, array){
                dojo.connect(item, 'onclick', gtiFwk.gtiJsLib.showHelp);
            }
            );
    },
    showHelp:function () {
        var arHelp = new Array();
        arHelp['metaData'] = 'metaData Help';
        arHelp['siteColors'] = 'Site Colors Help';
        arHelp['introText'] = 'Intro Text Help';

        dojo.byId('help').innerHTML = arHelp[this.title];
        return false;
    },
    test:function(){
    },
    getImgUrl:function(imgUrl){
        cntId='imgURL';
        document.getElementById(cntId).value=imgUrl;
    },
    setToWaitStatus : function(divId) {
        document.getElementById(divId).innerHTML = "<p align=center><img id='indicator' \n\
                     src='sys_resources/images/sys_icons/indicator.gif' ></p>\n\
                 <p align='center' class='dbMsg'>Chargement en cours ...</p>";
    },
    //-------------------------------------------------------
    //	actionExportDocument 
    //-------------------------------------------------------	
    actionExportDocument: function (url,id){
        var urlComlpet="";
        if(url.indexOf("?") != -1)  urlComlpet=url+"&idElemToPrin="+id;
        else                        urlComlpet=url+"?idElemToPrin="+id;
        gtiFwk.gtiJsLib.openDoc(urlComlpet);
    }//function 
    ,
    //------------------------------------------------------
    // verifierGroupe
    //------------------------------------------------------
    verifierGroupe: function (){
        var idGroupeSelected=document.getElementById("h_goupe_select").value;
        var hLink ="sys_admin_default/srv_changing_groupe_in_header.php?idGroupe="+idGroupeSelected+"&showLeftMenu=1";
        gtiFwk.gtiAjaxLib.updateDOMCnt(hLink, "tdLeftMenu");      
    }//function
    ,	
    //------------------------------------------------------
    // loadAlert
    //------------------------------------------------------
    loadAlert: function (){
        idGroupeSelected="";
        if(document.getElementById("h_goupe_select")) idGroupeSelected=document.getElementById("h_goupe_select").value;
        var xhr = gtiFwk.gtiAjaxLib.util_getXhr();
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                var response=xhr.responseText; 
                obj=document.getElementById("mainCnt");
                if(document.getElementById("mainCnt")) gtiFwk.gtiAjaxLib.util_innerHTMLJS(obj,response); 
            }
            else gtiFwk.gtiAjaxLib.util_setToWaitStatus("mainCnt");
        }
        xhr.open("POST","sys_admin/mesAlertes.php",true);
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send("idGroupe="+idGroupeSelected);
    }//function	
    ,
    //------------------------------------------------------
    // openPopUp
    //------------------------------------------------------
    openPopUp: function (url,width,height){
        var opt = "width="+width+",height="+height+",status=yes";
        window.open(url,"Chargement_fichiers",opt);
    }//function	
    ,
    //------------------------------------------------------
    // chgImgSection
    //------------------------------------------------------
    chgImgSection: function (idSection){
        var img="imgSection_"+idSection;
        if(document.getElementById(img).src.indexOf("show")!=-1){
            document.getElementById(img).src="sys_resources/images/sys_icons/hide.PNG";
            document.getElementById(idSection).style.display="";
        }
        else{
            document.getElementById(img).src="sys_resources/images/sys_icons/show.PNG";
            document.getElementById(idSection).style.display="none";
        }
    }//function
    ,
    //------------------------------------------------------
    // confirm_out
    //------------------------------------------------------
    confirm_out: function (){	
        var confirmMsg='Etes-vous certain de vouloir vous déconnecter ?';
        var styleTbl = document.getElementsByTagName("table")[0];
        var styleAvant=styleTbl.style.filter;
        styleTbl.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(opacity=0.4)";
	
        if(confirm(confirmMsg)){
            document.getElementById('frmlogOut').submit();
            return true;
        }//if
        else
        {
            styleTbl.style.filter = styleAvant;
            return false;
        }//else
    }//function
    ,
    //------------------------------------------------------
    // activeChild
    //------------------------------------------------------
    showHideEnfTd: function (idEnfTd){
        //alert("idEnfTd:"+idEnfTd);
        var idEnfTdImg = idEnfTd+"_img";
        curObj = document.getElementById(idEnfTd);
        curObjImg = document.getElementById(idEnfTdImg);
        if(curObj.style.display==""){
            curObj.style.display="none";	
            curObjImg.src="sys_resources/images/sys_icons/listPuceClosed.gif";		
        }//if affiche
        else {
            curObj.style.display="";	
            curObjImg.src="sys_resources/images/sys_icons/listPuceOpened.gif";		
        }
    }//function
    ,
    //------------------------------------------------------
    // item_clicked
    //------------------------------------------------------
    item_clicked: function (prefix,i){
        try{
            var nbr_mLink; 
            idDiv=prefix+i;  
            backg='#FEE5D3';//'#BDDB45';
            border='#54B423 1px solid';
            if(prefix=='s_head_'){
                backg='#2E871C';
                border='#2E871C 1px solid';
            }//if  
            if(document.getElementById(idDiv)){
                var divObj = document.getElementById(idDiv);  
                divObj.style.background=backg;
                divObj.style.border	   =border; 
            }//if
            //-----------------------------NETOYAGE MENU LINK
            if(document.getElementById('nbr_mLink'))  nbr_mLink= document.getElementById('nbr_mLink').value;  
            for(var j=0; j<nbr_mLink; j++){
                idDivM='trMenuLink_'+j;  
                if(idDivM!=idDiv){
                    if(document.getElementById(idDivM)){
                        var divMObj = document.getElementById(idDivM);
                        divMObj.style.background=''; 
                        divMObj.style.border='';
                    }//if
                }//if
            }//for 
            //---------------------------------NETOYAGE HEADER-----------
            if(document.getElementById('nbrLink'))  nbr_header= document.getElementById('nbrLink').value;  
            for(var j=0; j<nbr_header; j++){
                idDivM='s_head_'+j;  
                if(idDivM!=idDiv){
                    if(document.getElementById(idDivM)){
                        var divMObj = document.getElementById(idDivM);
                        divMObj.style.background=''; 
                        divMObj.style.border='';
                    }//if
                }//if
            }//for
        }catch(ex){
            alert("Erreur sur la page"+ex);
        }//catch
    }//function
    ,
    //------------------------------------------------------
    // updateDivsStyles
    //------------------------------------------------------
    updateDivsStyles: function(currInd,nbrDivs,prefixDivs){ 
        idDiv=prefixDivs+currInd;
        backg='#FEE5D3';
        if(document.getElementById(idDiv)){
            var divObj = document.getElementById(idDiv);  
            divObj.style.background=backg;
            divObj.style.border	   =border;
        }//if
        for(var j=0; j<nbrDivs; j++){
            idDivM=prefixDivs+j;  
            if(j!=currInd){
                if(document.getElementById(idDivM)){
                    var divMObj = document.getElementById(idDivM);
                    divMObj.style.background=''; 
                    divMObj.style.border='';
                }//if
            }//if
        }//for
    }//function
    ,
    //-------------------------------------------------------
    //	openDoc 
    //-------------------------------------------------------	
    openDoc: function (href){ 
        location.href=href;
    }//function 
    ,
    //-------------------------------------------------------------------------------------
    // 								FONCTIONS DE GESTION DES DOCUMENTS					  //
    //-------------------------------------------------------------------------------------
    //-----------------------------------------------------------------
    //	docs_activeDiv_newDoc
    //-----------------------------------------------------------------
    docs_activeDiv_newDoc: function (divNewDoc,idParentElem,idVariableToPosted,urlServer){
        var divMinCnt=divNewDoc+"_mainCnt";
        idElem=document.getElementById(idParentElem).value;
        if(document.getElementById(divNewDoc).innerHTML=="")	gtiFwk.gtiAjaxLib.util_setToWaitStatus(divNewDoc);
        gtiFwk.gtiAjaxLib.activeDiv_standardDoc(divNewDoc);
        var xhr = gtiFwk.gtiAjaxLib.util_getXhr();
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                var response=xhr.responseText;
                var obj=document.getElementById(divMinCnt);
                gtiFwk.gtiAjaxLib.util_innerHTMLJS(obj,response);
            }
        }
        xhr.open("POST",urlServer,true);
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send(idVariableToPosted+"="+idElem);
    }//function
    ,
    //-----------------------------------------------------------------
    //	docs_deleteDoc
    //-----------------------------------------------------------------
    docs_deleteDoc: function (idDoc,divNewDoc,divCnt,idParentElem,idVariableToPosted,urlServer,currFilePath){ 
        strMsg= document.getElementById("deleteConfirm").value;
        if(confirm(strMsg)){
            var xhr = gtiFwk.gtiAjaxLib.util_getXhr();
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){
                    var response=xhr.responseText;
                    if(response.indexOf("Erreur") != -1){
                        if(document.getElementById(divCnt))	document.getElementById(divCnt).innerHTML=response;
                    }//if
                    else									gtiFwk.gtiJsLib.docs_colsePopUp(divNewDoc,idParentElem,divCnt,currFilePath);
                }
            }	
            xhr.open("POST",urlServer,true);
            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xhr.send(idVariableToPosted+"="+idDoc);
        }//if confirm
    }//function
    ,
    //-----------------------------------------------------------------
    //	docs_colsePopUp
    //-----------------------------------------------------------------
    docs_colsePopUp: function (div,idParentElem,divCnt,currFilePath){
        idElem=document.getElementById(idParentElem).value;
        var xhr = gtiFwk.gtiAjaxLib.util_getXhr();
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                var response=xhr.responseText;
                if(document.getElementById(divCnt))	document.getElementById(divCnt).innerHTML=response;
            }
        }
        xhr.open("POST",currFilePath+"?idElem="+idElem,true);
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send(null);
        document.getElementById(div).style.display="none";
    }//funtion
    ,
    //-----------------------------------------------------------------
    //	activeDiv_reconnexion
    //-----------------------------------------------------------------
    activeDiv_reconnexion: function (idUsr,newTime){
        try{
            var div='div_reconnexion_'+newTime;
            var divMinCnt=div+"_mainCnt"; 
            if(document.getElementById(div).innerHTML=="")	gtiFwk.gtiAjaxLib.util_setToWaitStatus(div);		
            gtiFwk.gtiAjaxLib.activeDiv_standard(div);
            var xhr = gtiFwk.gtiAjaxLib.util_getXhr();
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){
                    var response=xhr.responseText;
                    var obj=document.getElementById(divMinCnt); 
                    obj.innerHTML=response;
                //gtiFwk.gtiAjaxLib.util_innerHTMLJS(obj,response);
                }
            }	
            xhr.open("POST","sys_includes/loginFrmPopup.inc.php",true);
            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xhr.send('idUsr='+idUsr+'&newTime='+newTime);
        }catch(ex){
            alert('une erreur s\'est produite sur la page');
        }//catch
    }//function
    ,
    //-----------------------------------------------------------------
    //	sendRequest_popupConnexion
    //-----------------------------------------------------------------
    sendRequest_popupConnexion: function (bean,newTime){
        var xhr = gtiFwk.gtiAjaxLib.util_getXhr();
        var elemToSend="";
        var divWaitMsg		  ="div_responsePopup_"+newTime;
        var passwdPop		  ="passwdPop_"+newTime;
        var btn_sendPopup	  ="btn_sendPopup_"+newTime;
        var div_popup 		 ="div_popup_"+newTime;
        var password=document.getElementById(passwdPop).value;
        var idUser=document.getElementById('idUser').value;
        elemToSend='passwdPop='+password+'&idUser='+idUser;
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                document.getElementById(btn_sendPopup).disabled=false;
                document.getElementById(div_popup).disabled=false;
                var response=xhr.responseText;  
                var obj=document.getElementById(divWaitMsg); 
                if(response.indexOf("Erreur!!!!") != -1){
                    var resultat=xhr.responseText.split("Erreur!!!!"); 
                    gtiFwk.gtiAjaxLib.util_innerHTMLJS(obj,resultat[1]); 
                }//if
                else{  
                    var div_reconnexion		 ='div_reconnexion_'+newTime;
                    var idDivTime			 ='errorTimeSessionForPage_'+newTime;
                    gtiFwk.gtiFwk_divPopUp.closeDivPopUp(div_reconnexion);
                    document.getElementById(idDivTime).innerHTML="<p class='infoBold'>Accès validé</p>";
                }//else 
            }//if
            else if(xhr.readyState == 4 && xhr.status != 200) {
                alert('Fichier non trouvable ou erreur \r\n. Status :'+xhr.status);
            }
            else{
                gtiFwk.gtiAjaxLib.util_setToWaitStatus(divWaitMsg);
                document.getElementById(div_popup).disabled=true;
                document.getElementById(btn_sendPopup).disabled=true; 
            }//else
        }//if
	 
        xhr.open('POST',bean,true);
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send(elemToSend);
    }//function
    ,
    leftMenuView_hide :	function (elemIndex){
		var elemId= "lm_tbl_"+elemIndex;
		var iconId = "lm_icon_"+elemIndex;
		if(document.getElementById(elemId).style.display==""){
			document.getElementById(elemId).style.display="none";
			document.getElementById(iconId).src="sys_resources/images/theme/lm_show.gif";
		}
		else{
			document.getElementById(elemId).style.display="";
			document.getElementById(iconId).src="sys_resources/images/theme/lm_hide.gif";
		}
	}
}//class
 
