﻿//ELA
var sListDescIdVisible = '';
var sListDescIdHidden = '';
var bAutomaticReload = true;
var bAdminRefresh = false;

function MsgBox( strMsg, nType, strTitle, strDesc, nShowDetail, oDescContent, nTypeDetail, oReturn )	
{
	if( strMsg == null )
		strMsg = "";
	if( nType == null )
		nType = 0;
	if( strTitle == null )
		strTitle = "";
	if( strDesc == null )
		strDesc = "";
	if( nShowDetail == null )
		nShowDetail = 0;
	if( nTypeDetail == null )
		nTypeDetail = 0;
	var strReturn = window.showModalDialog( 'MsgBox.asp?msg='+encode( strMsg )+'&type='+nType+'&Detail='+nShowDetail+'&title='+encode( strTitle )+'&desc='+encode( strDesc )+'&typedetail='+nTypeDetail, oDescContent, 'dialogHeight:210px;dialogWidth:400px;edge:Raised;center:1;help:0;resizable:0;status:0' );
	if( nTypeDetail > 0 && strReturn != null )
	{
		var aDatas = strReturn.split( '&' );
		oReturn.value = aDatas[1];
		return parseInt( aDatas[0], 10 );
	}
	else
		return strReturn;
	
}

function MsgErr( strTitle )	
{
	if( strTitle == null )
		strTitle = "";
	window.showModalDialog( 'MsgErr.asp?title='+encode( strTitle ), '', 'dialogHeight:150px;dialogWidth:400px;edge:Raised;center:1;help:0;resizable:0;status:0');
}

function InputBox( strTitle, strLabel, strDefaultValue  )	
{
	if( strTitle == null )
		strTitle = "";
	if( strLabel == null )
		strLabel = "";
	if( strDefaultValue == null )
		strDefaultValue = "";
	return window.showModalDialog( 'InputBox.asp?Title='+ encode( strTitle )+'&Label='+ encode( strLabel )+'&Value='+ encode( strDefaultValue ),'','dialogHeight:140px;dialogWidth:350px;edge:Raised;center:1;help:0;resizable:0;status:0' );

}

function showColor( strColor )
{
	return window.showModalDialog( 'SelectColor.asp?color='+encode( strColor ), '', 'dialogHeight:200px;dialogWidth:171px;edge:Raised;center:1;help:0;resizable:0;status:0');
}

function ShowWaitDialog( nType )	
{
	var hWindow;
	try
	{
		hWindow = window.showModelessDialog( 'DialogWait.asp?type='+nType, self, 'dialogHeight:130px;dialogWidth:300px;edge:Raised;center:1;help:0;resizable:0;status:0' );
	}
	catch(e)
	{
		var nTop = Math.round( (screen.availHeight-130) / 2 );
		var nLeft = Math.round( (screen.availWidth-300) / 2 );
		hWindow = window.open( 'DialogWait.asp?type='+nType, '', 'height=130px,width=300px,top='+nTop+'px,left='+nLeft+'px,dependent=yes,titlebar=yes' );
	}
	return hWindow;
}

function OpenWaitDialog(strType, strCallBack)
{
	try
	{
		top.frames['FraWait'].location = "DialogWaitParent.asp?type="+strType+"&callback="+encode( strCallBack );
	}
	catch(e){}
}

function SetCustomMsg(strMsg)
{
	try
	{
		top.frames['FraWait'].SetCustomMsg(strMsg);
	}
	catch(e){}
}

function CloseWaitDialog()
{
	try
	{
		top.frames['FraWait'].CloseWaitDialog();
	}
	catch(e){}
}

function showFileDialog( nTab, nFileId, nTabFrom, oDialogArgument, nPpId, nPmId, nEvtId, nAdrId, strOptionalParam, nDialogHeight, nDialogWidth )
{
	if( !nFileId )				nFileId = 0;
	if( !nPpId )				nPpId = 0;
	if( !nPmId )				nPmId = 0;
	if( !nEvtId )				nEvtId = 0;
	if( !nAdrId )				nAdrId = 0;
	if( !nTabFrom )				nTabFrom = 0;
	if( !oDialogArgument )		oDialogArgument = top.frames;
	if( !strOptionalParam )		strOptionalParam = "";
	if( strOptionalParam.substr( 0, 1 ) != "&" )	
		strOptionalParam = "&"+ strOptionalParam;

	if( !nDialogHeight )		nDialogHeight = 0;
	if( nDialogHeight < 100 )	nDialogHeight = 300;
	if( !nDialogWidth )			nDialogWidth = 0;
	if( nDialogWidth < 100 )	nDialogWidth = 800;

	return window.showModalDialog( 'FileDialogParent.asp?Tab='+nTab+'&FileId='+nFileId+'&TabFrom='+nTabFrom+'&PpId='+nPpId+'&PmId='+nPmId+'&EvtId='+nEvtId+'&AdrId='+nAdrId+strOptionalParam, oDialogArgument, 'edge:Raised;center:1;help:0;resizable:0;status:0;dialogHeight:'+ nDialogHeight +'px;dialogWidth:'+ nDialogWidth +'px;' );
}

function showFile( nTab, nFileId, nTabFrom )
{
    var nScrollPos = 0;
	var strFieldId = "";
	if( nTab == 100 )
		strFieldId = 'EVTId';
	else if( nTab == 200 )
		strFieldId = 'PPId';
	else if( nTab == 300 )
		strFieldId = 'PMId';
	else
		strFieldId = 'TPLId_'+ nTab;

    if ( nTabFrom == null ) nTabFrom = 0;
    if ( nTabFrom > 0 )
        nScrollPos = document.body.scrollTop;

	if( top.frames['FraParam'].document.getElementById( strFieldId ) && top.frames['FraParam'].document.getElementById("Rows") )
	{
		top.frames['FraParam'].document.getElementById( strFieldId ).value = nFileId;
        if ( nTabFrom > 0 && top.frames['FraParam'].document.getElementById( 'Scroll_' + nTabFrom ))
    		top.frames['FraParam'].document.getElementById( 'Scroll_' + nTabFrom ).value = nScrollPos;
		top.frames['FraTop'].SetTab( nTab );
	}
	else if( top.opener.top.frames['FraParam'].document.getElementById( strFieldId ) )
	{		
		top.opener.top.frames['FraParam'].document.getElementById( strFieldId ).value = nFileId;
		top.opener.top.frames['FraTop'].SetTab( nTab );
        if ( nTabFrom > 0 && top.opener.top.frames['FraParam'].document.getElementById( 'Scroll_' + nTabFrom ) )
    		top.opener.top.frames['FraParam'].document.getElementById( 'Scroll_' + nTabFrom ).value = nScrollPos;
		top.close();		
	}
}

function showFilePlanning(nTab, strMode, strUserId, strDate)
{
/*
alert(nTab);
alert(strMode);
alert(strUserId);
alert(strDate);
*/
var nRefresh = 9;
if (bAdminRefresh)
	{
	nRefresh = 10;
	bAdminRefresh = false;
	}
	if( !strDate )
		strDate = '';
	    top.frames['FraTmp'].location = 'PrefTreatment.asp?Refresh='+nRefresh+'&PrefTab='+nTab+'&PrefField=viewmode&Value='+encode(strMode)+'&Menu=1&UserId='+strUserId+'&Date='+encode(strDate);
}

function showFileTemplate(nTab, nType)
{
    document.location = 'NavBar.asp?tab='+nTab;
}

function FilterRec(nTab)	
{
	var nTop = (screen.availHeight-380) / 2;
	var nLeft = (screen.availWidth-650) / 2;
	window.open( 'FilterList.asp?Tab='+nTab, '', 'width=650,height=380,top='+nTop+',left='+nLeft+',dependent=yes,titlebar=yes' );
}

function FilterCancel(nTab)	
{
	top.frames['FraTmp'].location = 'FilterCancel.asp?Tab='+nTab;
	//top.frames['FraTmp'].location = 'PrefTreatment.asp?Refresh=8&CancelAllFilter=1&PrefTab='+nTab;
}
function SearchRecMRU( nTab )	
{
	SearchRec('?type=0&tab='+nTab+'&tabfrom='+nTab);
}

function SearchRec( strParam )	
{
	var	nTop = ( screen.availHeight - 300 ) / 2; 
	var nLeft = ( screen.availWidth - 700 ) / 2;
	var nHeight = 275;
	var bWithSelection = ( strParam.indexOf( 'WithSelection=1', 1 ) > - 1 )
	if( bWithSelection )
		nHeight = 400;
	
	window.open( 'Search.asp'+strParam, null, 'width=700,height='+nHeight+',top='+nTop+',left='+nLeft+',dependent=yes,titlebar=yes,resizable=yes,status=no' );
}

function SearchRecAdv( strParam )
{
	var	nTop = ( screen.availHeight - 300 ) / 2; 
	var nLeft = ( screen.availWidth - 700 ) / 2;
	var strData = window.showModalDialog( 'FileSearchParent.asp'+strParam, top.frames, 'dialogHeight:420px;dialogWidth:700px;edge:Raised;center:1;help:0;resizable:1;status:0' );
	var strReload = '';
	if( strData )
	{
	
		aData = parseQueryString( strData );
		
		nPpId =	getArrayValue( aData, 'PPID' );
		nPmId = getArrayValue( aData, 'PMID' );
		nEvtId = getArrayValue( aData, 'EVTID' );
		nAdrId = getArrayValue( aData, 'ADRID' );
		nTab = getArrayValue( aData, 'TAB' );
		nType = getArrayValue( aData, 'TYPE' );
		strAction = getArrayValue( aData, 'ACTION' );
		strFile = getArrayValue( aData, 'FILE' );
		strDefault = getArrayValue( aData, 'DEFAULT' );
		strReload = getArrayValue( aData, 'RELOAD' );
		nAdrAuto = getArrayValue( aData, 'ADRAUTO' );
		nAutoBuildName = getArrayValue( aData, 'AUTOBUILDNAME' );
		
		if( top.frames['FraTmp'] )
			var oTmp = top.frames['FraTmp'];
		else if( top.opener.top.frames['FraTmp'] )
			var oTmp = top.opener.top.frames['FraTmp'];
		else
			var oTmp = top.opener.top.opener.top.frames['FraTmp'];
			
		if( strAction == 'ADDTPL')
		{
			strData = AddTpl( nTab );
		}
		else if( strAction == 'SHOWTPL')
		{
			strData = ShTpl( nTab, nEvtId );
		}
		else if( strAction == 'SHOWMAIN')
		{	
			SPV( 'PPId', nPpId, true );
			SPV( 'PMId', nPmId, true );
			if( nTab >= 1000 )
				SPV( 'TPLId_'+nTab, nEvtId, true );
			else
				SPV( 'EVTId', nEvtId, true );
			top.frames['FraTop'].SetTab( nTab );
		}
			
		else if( strAction == 'ADDMAIN' )
		{
			oTmp.location = 'AddNewRecord.asp?Type='+nType+'&File='+encode(strFile)+'&Default='+encode(strDefault)+'&PmId='+nPmId+'&PpId='+nPpId;
		}
		else if ( strAction == 'ADDEVT' )
		{
			//Nom event en construction auto
			if( nAutoBuildName == 1 )
				AddEvt( nTab );
			else
				AddEvt( nTab, true, '', 0, 0, strDefault );
		}
		else if( strAction == 'ADDADR' )
		{
			if(  nAdrAuto == 1 )
				AddAdr( nPpId, nPmId, true, 0, false);
			else
				AddAdr( nPpId, nPmId, false, 0, false);
		}
	}
	if( strReload == '1')
	{
		top.frames['FraDetail'].location.reload();
	}
}


function FindRec( strParam )	
{
	return window.showModalDialog( 'Finder.asp'+strParam, self, 'dialogHeight:250px;dialogWidth:650px;edge:Raised;center:1;help:0;resizable:1;status:0' );
}

function AddEvt( nEventTab, bDialog, strFile, nFileId, nType, strDefault, strTargetField, nMulti ,nRandom)
{
	if( !strFile )
		strFile = "";
	if( !strDefault )
		strDefault = "";
	if( !strTargetField )
		strTargetField = "";
	if( !nFileId )
		nFileId = 0;
	if( !nType )
		nType = 0;
	if ( !nMulti )
		nMulti = 0;
    if ( !bDialog ) 
        bDialog = false
	if(!nRandom)
		nRandom = '';
    var nDialog = 0;
    if ( bDialog ) nDialog = 1;

	
	
	if( top.frames['FraTmp'] )
	{
		var oTmp = top.frames['FraTmp'];
	}
	else if( top.opener.top.frames['FraTmp'] )
	{
		var oTmp = top.opener.top.frames['FraTmp'];
	}
	else
	{
		var oTmp = top.opener.top.opener.top.frames['FraTmp'];
	}

	if( top.frames['FraTop'] )
	{
		var oTop = top.frames['FraTop'];
	}
	/*else if( top.opener.top.frames['FraTop'] )
	{
		var oTop = top.opener.top.frames['FraTop'];
	}
	else
	{
	    alert( "else");
		var oTop = top.opener.top.opener.top.frames['FraTop'];
	}*/
	
    
    if ( !bDialog )
    {
        try
        {
            if ( !oTop.TabExist( nEventTab ) ) 
            {
                bDialog = true;
                nDialog = 1;
            }
        }
        catch(e){}
    }
    
	if( bDialog )
	{
		var strEvent = window.showModalDialog( 'EvtFiche.asp?tab='+nEventTab+'&new=1&file='+encode(strFile)+'&fileid='+nFileId+'&def='+encode(strDefault)+'&Multi='+nMulti, '', 'dialogHeight:200px;dialogWidth:710px;edge:Raised;center:1;help:0;resizable:0;status:0' );
		if( strEvent )
		{
			// JLA #9358
			if(nMulti != 0)
				OpenWaitDialog('0', '');
			var strFunction = "LaunchTreatment(" + nEventTab + ", " + nDialog + ", '" + strFile + "', " + nFileId + ", " + nType + ", '" + strDefault +"', '" + strTargetField + "', " + nMulti + ", '" + nRandom + "', '" + strEvent + "');";
			setTimeout(strFunction , 500);
			
			//oTmp.location = 'EvtCreate.asp?tab='+nEventTab+'&file='+encode(strFile)+'&fileid='+nFileId+'&'+strEvent+'&type='+nType+'&targetfield='+encode(strTargetField)+'&Multi='+nMulti+'&Dialog='+nDialog+'&strRandom='+nRandom;
		}
	}
	else
	{
		oTmp.location = 'EvtCreate.asp?tab='+nEventTab+'&targetfield='+encode(strTargetField)+'&Multi='+nMulti+'&new=1&file='+encode(strFile)+'&fileid='+nFileId+'&Dialog='+nDialog+'&strRandom='+nRandom;
	}
}

// JLA #9358
function LaunchTreatment(nEventTab, nDialog, strFile, nFileId, nType, strDefault, strTargetField, nMulti ,nRandom, strEvent) {
	if( top.frames['FraTmp'] )
	{
		var oTmp = top.frames['FraTmp'];
	}
	else if( top.opener.top.frames['FraTmp'] )
	{
		var oTmp = top.opener.top.frames['FraTmp'];
	}
	else
	{
		var oTmp = top.opener.top.opener.top.frames['FraTmp'];
	}
	
	oTmp.location = 'EvtCreate.asp?tab='+nEventTab+'&file='+encode(strFile)+'&fileid='+nFileId+'&'+strEvent+'&type='+nType+'&targetfield='+encode(strTargetField)+'&Multi='+nMulti+'&Dialog='+nDialog+'&strRandom='+nRandom;
}

function showFileDialogClone( nTab, nFileId, nMulti )
{
	if( !nFileId )
		nFileId = 0;
	if ( !nMulti )
		nMulti = 0;
	
	var strDuplicate = window.showModalDialog( 'FileDialogClone.asp?tab='+nTab+'&fileid='+nFileId+'&Multi='+nMulti, top.frames, 'dialogHeight:380px;dialogWidth:850px;edge:Raised;center:1;help:0;resizable:0;status:0' );
}

function ShEvt( nEventTab, nEvtId )	{

	var strEvent = window.showModalDialog( 'EvtFiche.asp?tab='+nEventTab+'&new=0&evtid='+nEvtId, '', 'dialogHeight:200px;dialogWidth:700px;edge:Raised;center:1;help:0;resizable:0;status:0' );

	if( strEvent )	{
		if( strEvent == '-1' )
			top.frames['FraTmp'].location = 'Delete.asp?tab='+nEventTab+'&FileId='+nEvtId;
		else	
			top.frames['FraTmp'].location = 'EvtUpdate.asp?tab='+nEventTab+'&evtid='+nEvtId+'&'+strEvent;
	}
}

function AddTpl( nTab, nEvtId, nPpId, nPmId, nTabFrom, nMulti, nType, nParentEvtId, nParentTplTab, strDefDate, nDialogHeight, nDialogWidth, strDefOwner, strDefRecipients, nFileIdFrom, nMasterMailId , nRandom,bAdvancedEmailingEnabled)
{
	if( !nDialogHeight )		nDialogHeight = 0;
	if( nDialogHeight < 100 )	nDialogHeight = 300;
	if( !nDialogWidth )			nDialogWidth = 0;
	if( nDialogWidth < 100 )	nDialogWidth = 710;

	if( !nMasterMailId )
		nMasterMailId = 0;
	if( !nMulti )
		nMulti = 0;
	if( !nFileIdFrom )
		nFileIdFrom = 0;
	if (!nRandom)
		nRandom = 0;
	if( !strDefOwner )
		strDefOwner = "";
	if( !strDefRecipients )
		strDefRecipients = "";
		
	//JBE - Nouveau module d'emailing
	
	if (!bAdvancedEmailingEnabled)
	{
		var bAdvancedEmailingEnabled = false;
	}
	if (nMulti > 0 && nType ==3 && bAdvancedEmailingEnabled )
	{
		window.showModalDialog( 'TplMailing.asp?new=1&Type='+nType+'&multi='+nMulti+'&tabfrom='+nTabFrom+'&fileidfrom='+nFileIdFrom+'&tab='+nTab+'&evtid='+nEvtId+'&ppid='+nPpId+'&pmid='+nPmId+'&parentevtid='+nParentEvtId+'&parenttpltab='+nParentTplTab+'&defdate='+encode(strDefDate)+'&defowner='+encode(strDefOwner)+'&defrecipients='+encode(strDefRecipients), top.frames, 'edge:Raised;center:1;help:0;resizable:0;status:0;dialogHeight:'+ nDialogHeight +'px;dialogWidth:'+ nDialogWidth +'px;' );
		return;
	}
		
		
		
	var strDatas = window.showModalDialog( 'TplFiche.asp?new=1&Type='+nType+'&multi='+nMulti+'&tabfrom='+nTabFrom+'&fileidfrom='+nFileIdFrom+'&tab='+nTab+'&evtid='+nEvtId+'&ppid='+nPpId+'&pmid='+nPmId+'&parentevtid='+nParentEvtId+'&parenttpltab='+nParentTplTab+'&defdate='+encode(strDefDate)+'&defowner='+encode(strDefOwner)+'&defrecipients='+encode(strDefRecipients)+'&MasterMailId='+nMasterMailId, top.frames, 'edge:Raised;center:1;help:0;resizable:0;status:0;dialogHeight:'+ nDialogHeight +'px;dialogWidth:'+ nDialogWidth +'px;' );

	
	
	if( strDatas )	
	{

        var aDatas = parseQueryString( strDatas );
		var nFileId = getArrayValue( aDatas , 'FileId' );	
		if( nFileId == null )
		    nFileId = 0;
		if( isNaN( nFileId ) )
		    nFileId = 0;
	
		if( strDatas.substring(0,2) == '-1' )
		{
			top.frames['FraTmp'].location.replace( 'TplDelete.asp?'+strDatas.substring(3,strDatas.length) );
		}
		else if( strDatas.substring(0,2) == '-2' )
		{
				var aDatas = strDatas.split( '&' );
				var nTabToShow = parseInt( aDatas[1] );
				top.frames['FraTop'].SetTab( nTabToShow );
		}
		else if( nFileId != 0 )
		{
			var oFrm = document.getElementById('frmDlg'+nTab);
			if( oFrm.DialogValue )
			{
				oFrm.DialogValue.value = 'asp=TplUpdate.asp&'+strDatas; 
			}
			oFrm.submit();
		}
		else 
		{
			var oFrm = document.getElementById('frmDlg'+nTab);
			
			if( oFrm.DialogValue ) {
				// HLA - Ajout de la wait dialog pour avoir le compteur des enregistrements fait en temps réel
				if(nMulti != 0)
					OpenWaitDialog('0', '');
				
				var strFunction = "LaunchTreatmentTpl(" + nTab + ", " + nMulti + ", " + nRandom + ", '" + strDatas + "');";
				// HLA - Permet d'attendre que la WaitDialog s'ouvre avant le lancement du traitement
				setTimeout(strFunction, 500);
				
				/*if( nMulti == 3  ) {
					oFrm.DialogValue.value = 'target=FraSelectTmp2&asp=TplCreate.asp&nRandom='+ nRandom +'&'+strDatas;
				}
				else {
					oFrm.DialogValue.value = 'asp=TplCreate.asp&nRandom='+ nRandom +'&'+strDatas;
				}
				
				oFrm.submit();*/
			}
			else
				oFrm.submit();
			
			if( nMulti != 0 )
			{
				return 1;
			}
		}
		if( strDatas.indexOf('&TabLink=') > 0 )
		{
			GoToLink( strDatas );
		}
	}
	else
	{
		if( nMulti != 0 )
		{
			return 0;
		}
	}
}

function LaunchTreatmentTpl(nTab, nMulti, nRandom, strDatas) {
	var oFrm = document.getElementById('frmDlg'+nTab);
	
	if( nMulti == 3  ) {
		oFrm.DialogValue.value = 'target=FraSelectTmp2&asp=TplCreate.asp&nRandom='+ nRandom +'&'+strDatas;
	}
	else {
		oFrm.DialogValue.value = 'asp=TplCreate.asp&nRandom='+ nRandom +'&'+strDatas;
	}
	
	oFrm.submit();
}

function ShTpl( nTab, nFileId, nTabFrom, nAutoOpenPj, nDialogHeight, nDialogWidth, nScheduleId, bAskScheduleSelect )	
{
	if( !nDialogHeight )		nDialogHeight = 0;
	if( nDialogHeight < 100 )	nDialogHeight = 300;
	if( !nDialogWidth )			nDialogWidth = 0;
	if( nDialogWidth < 100 )	nDialogWidth = 710;
	if( !nScheduleId )			nScheduleId = 0;
	if( bAskScheduleSelect == null )	bAskScheduleSelect = true;

	if( nTab == 100000 ) // TAB_HISTO
	{
		var strDatas = showFileDialog( nTab, nFileId );
		if( strDatas )	
		{
			if( strDatas.substring(0,2) == '-1' )
				top.frames['FraTmp'].location = 'TplDelete.asp?tab='+nTab+'&FileId='+nFileId;
		}
	}
	else
	{
		if( !nAutoOpenPj )
			nAutoOpenPj = 0;
			
		var strSerie = '0';
		
		if( nScheduleId != 0 && bAskScheduleSelect )
		{
			strSerie = window.showModalDialog( 'ScheduleSelect.asp', '', 'dialogHeight:170px;dialogWidth:350px;edge:Raised;center:1;help:0;resizable:0;status:0' );
			if( strSerie == null )
				return;
		}
		else
			strSerie = '1';
			
		var strDatas = window.showModalDialog( 'TplFiche.asp?new=0&tabfrom='+nTabFrom+'&tab='+nTab+'&FileId='+nFileId+'&AutoOpenPj='+nAutoOpenPj+'&OpenSerie='+strSerie+'&ScheduleId='+nScheduleId, top.frames, 'edge:Raised;center:1;help:0;resizable:0;status:0;dialogHeight:'+ nDialogHeight +'px;dialogWidth:'+ nDialogWidth +'px;' );
		if( strDatas )	
		{
			var strDatasTemp = strDatas;
			if( strDatas.indexOf('MasterMailId=') >= 0 && strDatas.indexOf('MasterMailId=0') == -1 )
			{
				var aDatas = parseQueryString ( strDatas );
				var nMasterMailId = getArrayValue ( aDatas , 'MasterMailId' );
				var nEvtId = getArrayValue ( aDatas , 'EvtId' );
				var nPpId = getArrayValue ( aDatas , 'PpId' );
				var nPmId = getArrayValue ( aDatas , 'PmId' );
				var nMulti = getArrayValue ( aDatas , 'Multi' );
				var nType = getArrayValue ( aDatas , 'Type' );
				var nFileIdFrom = getArrayValue ( aDatas , 'FileIdFrom' );
				AddTpl( nTab, nEvtId, nPpId, nPmId, nTabFrom, nMulti, nType, 0, 0,0 ,nDialogHeight, nDialogWidth,0 ,'' ,nFileIdFrom , nMasterMailId );
			}			
			else if( strDatas.substring(0,2) == '-1' )
			{
				top.frames['FraTmp'].location = 'TplDelete.asp?tab='+nTab+'&FileId='+nFileId+'&ScheduleId='+nScheduleId+'&OpenSerie='+strSerie;
			}
			else	
			{			
				var oFrm = document.getElementById('frmDlg'+nTab);
				if( oFrm.DialogValue )					
					oFrm.DialogValue.value = 'asp=TplUpdate.asp&'+strDatas+'&ScheduleId='+nScheduleId+'&OpenSerie='+strSerie;				
				oFrm.submit();
			}
			if( strDatas.indexOf('&TabLink=') > 0 )
			{
				GoToLink( strDatas );			
			}
		}
	}
}

function GoToLink( strDatas )
{
	var aReturn = parseQueryString( strDatas );
	var nTabToShow = getArrayValue( aReturn, "TabLink" );
	var nFileIdLink = getArrayValue( aReturn, "FileLink" );
	
	showFile( nTabToShow, nFileIdLink );
}

function AddTplSelect( nTab, nEvtId, nPpId, nPmId, nTabFrom, nMulti )
{
	if( !nMulti )
		nMulti = 0;
	var strDatas = window.showModalDialog( 'TplSelect.asp?new=1&multi='+nMulti+'&tabfrom='+nTabFrom+'&tab='+nTab+'&evtid='+nEvtId+'&ppid='+nPpId+'&pmid='+nPmId, '', 'dialogHeight:170px;dialogWidth:350px;edge:Raised;center:1;help:0;resizable:0;status:0' );
	if( strDatas )
	{
		AddTpl( nTab, nEvtId, nPpId, nPmId, nTabFrom, nMulti, strDatas );
	}
}

function AddExTpl( nTab, nEvtId, nTabFrom )
{
	var	nTop = ( screen.availHeight - 400 ) / 2; 
	var nLeft = ( screen.availWidth - 720 ) / 2;
	window.open( 'SelectQuery.asp?delete=0&tabfrom='+nTabFrom+'&tab='+nTab+'&evtid='+nEvtId, '', 'width=720,height=400,top='+nTop+',left='+nLeft+',dependent=yes,titlebar=yes,resizable=yes' );
}

function DelExTpl( nTab, nEvtId, nTabFrom )
{
	var	nTop = ( screen.availHeight - 400 ) / 2; 
	var nLeft = ( screen.availWidth - 720 ) / 2;
	window.open( 'SelectQuery.asp?delete=1&tabfrom='+nTabFrom+'&tab='+nTab+'&evtid='+nEvtId, '', 'width=720,height=400,top='+nTop+',left='+nLeft+',dependent=yes,titlebar=yes,resizable=yes' );
}

function Report( nMode, nTypeReport, nTab, nFromBkm, nFileId )	
{
	
	if( isNaN( nTypeReport ) )
		nTypeReport = 0;

	if( nMode == 1 && nTypeReport == 0  )
	{
		var nLeft = ( screen.availWidth - 550 ) / 2;
		var nTop = ( screen.availHeight - 260 ) / 2;
		window.open( 'ReportWizardFiche.asp?FileId='+nFileId+'&Tab='+nTab,'','top='+nTop+',left='+nLeft+',dependent=yes,width=550,height=260,titlebar=yes' );
	}
	else
	{
		var strReturn = window.showModalDialog( 'ReportList.asp?TypeReport='+nTypeReport+'&TabFrom='+nTab+'&FromBkm='+nFromBkm+'&FileId='+nFileId, '', 'dialogHeight:325px;dialogWidth:640px;edge:Raised;center:1;help:0;resizable:0;status:0' );
		if( strReturn != null )
		{
			var qs = "";
			aReturn = strReturn.split( "&" );
			for( var i = 0 ; i < aReturn.length ; i++ )
			{
				strItems = aReturn[i];
				aItems = strItems.split( "=" );
				
				strField = decode( aItems[0] );
				strValue = decode( aItems[1] );
				strField = strField.toLowerCase();

				if( strField == "param" )
				{
					top.frames['FraParam'].document.getElementById("Report").value = strValue;
				}
				if( strField == "qs" )
				{
					qs = strValue;
				}
			}
			top.frames['FraTmp'].location.replace( 'Report.asp?'+qs );
		}
	}
}

function AddAdr( nPpId, nPmId, bAutoBuilt, nRefreshWindow, bCloseWindow, nTabFrom, bUpdateAdrId )
{
	if( !bAutoBuilt ) 
	{
		if (!nTabFrom )
			nTabFrom = 0;
		strReturn = showFileDialog( 400, 0, nTabFrom, null, nPpId, nPmId );
		if( strReturn )
		{
			if( nRefreshWindow == 1 )
				if( top.opener.top.frames['FraDetail'] )
					top.opener.top.frames['FraDetail'].location.reload();
			else if( nRefreshWindow != 0 )
			{
				if( top.frames['FraDetail'] )
					top.frames['FraDetail'].location.reload();
			}

			if( bUpdateAdrId )
			{
				var strAdrId = GetUrlValue(strReturn, "ADRId");
				if ( document.getElementById("ADRId") )
					document.getElementById("ADRId").value = strAdrId;
			}

		}
		if( bCloseWindow )
			top.close();
	}
	else
	{
		var nCloseWindow = 0;
		var nUpdateAdrId = 0;
		var nNoRefresh = 1;
		if ( bCloseWindow ) nCloseWindow = 1;
		if ( bUpdateAdrId ) nUpdateAdrId = 1;
		if ( nRefreshWindow == 0 ) nNoRefresh = 1;

		var oFrm = document.getElementById( 'frmDlg400' );
		if( oFrm.DialogValue )	
		{
			oFrm.DialogValue.value = 'asp=AdrCreate.asp&autobuilt=1&target=_self&closewindow='+nCloseWindow+'&updateadrid='+nUpdateAdrId+'&Refresh='+nRefreshWindow+'&NoRefresh='+nNoRefresh+'&pmid='+nPmId+'&ppid='+nPpId;
		}
		oFrm.submit();
	}
}

function GetUrlValue(strUrl, strTag)
{
	var strReturnValue = "";
	var aFields = strUrl.split("&");
	var aData;
	for ( i=0 ; i<aFields.length ; i++)
	{
		aData = aFields[i].split("=");
		if ( aData.length >= 2 )
		{
			if ( aData[0] = strTag )
			{
				strReturnValue = aData[1];
				break;
			}
		}
	}
	return strReturnValue;
}

function SelectItem( cboTarget, strValue )	
{
	if( !cboTarget )
		return;
	
	for( var j = 0 ; j < cboTarget.length ; j++ )	
	{
		if( cboTarget.options(j).value == strValue )	
		{
			cboTarget.selectedIndex = j;
			break;
		} 
	}
	if( j > (cboTarget.length - 1) )
	{
		cboTarget.selectedIndex = -1;
	}
}

function CreateAddress( strParam )	{
	return window.showModalDialog( 'Finder.asp'+strParam, '', 'dialogHeight:250px;dialogWidth:650px;edge:Raised;center:1;help:0;resizable:1;status:0' );
}

function SelectTab( strTabs, nLabelResId )
{
	return window.showModalDialog( 'FileSelect.asp?LabelResId='+nLabelResId+'&Tabs='+strTabs, '', 'dialogHeight:200px;dialogWidth:450px;edge:Raised;center:1;help:0;resizable:0;status:0' );
}

function SendMultiVoicing( nTabFrom, strMailTabs, nMultiType, nParentEvtId, nParentTplTab  )
{

	var nMailTab = 0;
        
        	
	if( isNaN( strMailTabs ) )
	{
		nMailTab = SelectTab( strMailTabs, 1164 );
		if( nMailTab == null )
			return;
		if( isNaN( nMailTab ) )
			return;
	}
	else
	{
		nMailTab = parseInt( strMailTabs );
	}	
	
	    AddTpl( nMailTab, 0, 0, 0, nTabFrom, nMultiType, 7, nParentEvtId, nParentTplTab );
	
}


function SendMultiMail( nTabFrom, strMailTabs, nMultiType, nParentEvtId, nParentTplTab, bSmsEnabled, bAdvancedEmailingEnabled )
{
	var nMailTab = 0;
	
	if( isNaN( strMailTabs ) )
	{
		nMailTab = SelectTab( strMailTabs, 801 );
		if( nMailTab == null )
			return;
		if( isNaN( nMailTab ) )
			return;
	}
	else
	{
		nMailTab = parseInt( strMailTabs );
	}	

    //bSmsEnabled = false;
    if( bSmsEnabled )
	{
		/* MAB V7 - 20080717 - URL absolue nécessaire afin de pouvoir afficher la popup depuis le menu contextuel du planning */
		var baseURL = window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1);
	    var strDatas = window.showModalDialog( baseURL + 'TplSelect.asp?new=1&multi='+nMultiType+'&tabfrom='+nTabFrom+'&tab='+nMailTab+'&evtid='+nParentEvtId, '', 'dialogHeight:170px;dialogWidth:350px;edge:Raised;center:1;help:0;resizable:0;status:0' );
    	if( strDatas )
    	{
			if (strDatas == "3")
				{
					if (!bAdvancedEmailingEnabled)
						var bAdvancedEmailingEnabled = false;
					AddTpl( nMailTab, 0,0, 0, nTabFrom, nMultiType, 3, nParentEvtId, nParentTplTab,null,null,null,null,null,null,null,null, bAdvancedEmailingEnabled);
				}
			else
				AddTpl( nMailTab, 0, 0, 0, nTabFrom, nMultiType, strDatas ,nParentEvtId, nParentTplTab );
	    }
	}
	else
	{
		if (!bAdvancedEmailingEnabled)
			var bAdvancedEmailingEnabled = false;
	    AddTpl( nMailTab, 0,0, 0, nTabFrom, nMultiType, 3, nParentEvtId, nParentTplTab,null,null,null,null,null,null,null,null, bAdvancedEmailingEnabled);
	}

}

function SetAccelerator( nTab )
{
	try
	{
		top.frames['FraTop'].SetMainAccelerator( document.parentWindow.event, nTab );
	}
	catch(e){}
}

function showPermission( nPermId )
{
	var strValue = window.showModalDialog( 'Permission.asp?PermId='+nPermId, '', 'dialogHeight:160px;dialogWidth:460px;edge:Raised;center:1;help:0;resizable:0;status:0' );
	return strValue;
}

// MRU
function showMRU( nTab, strMru, nType, bSearchLink, nAction, bShowTextBox, bAdminLink, nMode )
{
	var nMaxItemVisible = 7;	//Nombre max de MRU
    //alert(strMru);
	oItemPopup = createMenu();
	beginMenu( oItemPopup );

	if( bShowTextBox )
	{
		addMenuTextBox( oItemPopup, "",  " value='' ednTab='"+ nTab +"' ednTabFrom='0' ednDescId='"+ (nTab + 1) +"' ednType='0' ", strImgSearch )
		beginScrollArea( oItemPopup, "SCROLLVALUES" )
	}
	
	if (nType!=2 && nMode==0 ) // ELA 
	{
	    var aMru = strMru.split( "|" );
	    for( var i=0 ; i < aMru.length ; i++ )
	    {
		    var strTmp = aMru[i];
		    if ( strTmp != "" )
		    {
			    var aTmp = strTmp.split( ";" );
			    var strAction = getMenuAction( aTmp, nAction );
                
			    if( aTmp[4] != null )
			        //alert(strAction);
				    addMenuLabel( oItemPopup, decode( aTmp[4] ), " onclick=\""+ strAction +"self.parent.hideMenu(self.parent.oItemPopup);\" ", getMenuIcon( decode( aTmp[1] ) ) );
				    //IA 22/02/05 : Unicode -> decode (encode dans GetMruHTML() dans Function.asp)
		    }
	    }
	}
	
	if (nType==2 && nMode==0 )// && (bAdminLink==false)) // Retour au mode liste du template 'ELA le 20/02/2007
	{
	    var aMru = strMru.split( "|" );
	    var strTmp = aMru[0];
	    var strAction = aMru[1];
	    strAction = "self.parent.showFileTemplate("+nTab+", "+nType+");";
	    //alert (strAction);
	    //alert (strAction);
	    
	    addMenuLabel( oItemPopup, decode( strTmp ), " onclick=\"" + strAction + "self.parent.hideMenu(self.parent.oItemPopup);\" ", getMenuIcon( 0 ) );
	}
	
	if (nMode==2) // Retour à la fiche de provenance 'ELA le 03/04/2007
	{
		//var aMruFiles = strMru.split( "|" );
		var aMru = strMru.split( ";" );
	    var nTabSource = aMru[3];
	    var nIdSource = aMru[4];
	    var strLabelSource = aMru[0]+' '+aMru[5];
	    strAction = "self.parent.ShApp("+nTabSource+", "+nIdSource+");";
	    addMenuLabel( oItemPopup, decode( strLabelSource ), " onclick=\"" + strAction + "self.parent.hideMenu(self.parent.oItemPopup);\" ", getMenuIcon( 0 ) );
	}
	
	if( bShowTextBox )
	{
		if( i < nMaxItemVisible )
		{
			for( j = i; j < nMaxItemVisible; j++ )
			{
				addMenuLabel( oItemPopup, "", "", null );
			}
		}
		endScrollArea( oItemPopup, "SCROLLVALUES", nMaxItemVisible );
	}

	if( bSearchLink )
	{
		addMenuSeparator( oItemPopup );
		// Rechercher
		addMenuLabel( oItemPopup, strResSearch, " onclick=\"self.parent.SearchRecMRU("+ nTab +");self.parent.hideMenu(self.parent.oItemPopup);\" ", strImgSearch );
	}
	if( bAdminLink )
	{
	    if (nType!=2 && nMode==0) // ELA 
	       {
		    addMenuSeparator( oItemPopup );
		   }
		// Administrer
		if (nMode == 1)
		    {
	        addMenuLabel( oItemPopup, strResAdmin, " onclick=\"self.parent.ShAdmin("+ nTab +", 1, '"+strMru+"');self.parent.hideMenu(self.parent.oItemPopup);\" ", strImgAdmin );
	        }
	    else
	        {
	        addMenuLabel( oItemPopup, strResAdmin, " onclick=\"self.parent.ShAdmin("+ nTab +", 0, '');self.parent.hideMenu(self.parent.oItemPopup);\" ", strImgAdmin );
	        }
	}
	endMenu( oItemPopup );
	showMenu( oItemPopup ); 

	window.event.returnValue = false;
}

function getMenuIcon( nIconIndex )
{
	switch( parseInt( nIconIndex, 10 ) )
	{
	case 1:		return strImgAgenda;
	case 2:		return strImgTask;
	default:	return strImgRecord;
	}
}

function getMenuAction( aActionArray, nAction )
{
	var strAction = "";
	
	switch( parseInt( decode( aActionArray[0] ), 10 ) )									//ajout decode IA 25/02/05 (encode dans GetMruHTML() dans Function.asp)
	{
	case 1:			// Lien présent dans le menu
			strAction = decode( aActionArray[2] );										//decode
			break;
			
	default:
		switch( nAction )
		{
		case 1:			// Association
			strAction = "self.parent.AttachPersFromMru($tab$,$fileid$,'$filename$');";
			break;
		case 2:			// Lien sur la fiche depuis admin
			strAction = "self.parent.ShApp($tab$,$fileid$);";
			break;
		default:		// Lien sur la fiche
			strAction = "self.parent.showFile($tab$,$fileid$);";
		}
		strAction = strAction.replace( "$tab$", decode( aActionArray[2] ) );				//decode
		strAction = strAction.replace( "$fileid$", decode( aActionArray[3] ) );				//decode
		strFileName = decode( aActionArray[4] );											//decode
		strAction = strAction.replace( "$filename$", strFileName.replace( "'", "\'" ) );
	}
	return strAction;
}
function onExpand ( nDispOrder, nTab, nUserId, nExpand )
{
	var aElements = null;
	var aSubElements = null;
	var aDivElements = null;
	var nId = null;
	var strTrId = null;
	var strImgId = 'ImgTree_'+nDispOrder;
	var strImgSrc = document.getElementById(strImgId).src;
	var nTag = document.getElementById(strImgId).ednTag;
	var bExpand = ( nTag == 0 );
	var bExpandLoad = (nExpand == 1);
	var strVisibility;
	var strPosition;
	var strDisplay;
	
	if ( bExpand || bExpandLoad )
	{
		strVisibility = 'visible';
		strPosition = 'relative';
		strDisplay = 'block';
		//Modifie l'image
		document.getElementById(strImgId).src = strImgSrc.replace( "Plus.gif","Minus.gif");
		//Modifie le Tag
		document.getElementById(strImgId).ednTag = 1;
		//Enregistre l'ouverture
		loadPage('Process.asp?Type=1&Tab='+nTab+'&Userid='+nUserId+'&DispOrder='+nDispOrder+'&Open=1');
	}
	else
	{
		strVisibility = 'hidden';
		strPosition = 'absolute';
		strDisplay = 'none';
		//Modifie l'image
		document.getElementById(strImgId).src = strImgSrc.replace( "Minus.gif","Plus.gif");
		//Modifie le Tag
		document.getElementById(strImgId).ednTag = 0;
		//Enregistre la fermeture
		loadPage('Process.asp?Type=1&Tab='+nTab+'&Userid='+nUserId+'&DispOrder='+nDispOrder+'&Open=0');
	}
	var aElements = document.getElementsByTagName("TR");
	for( var i=0 ; i < aElements.length ; i++ )
	{
		if( aElements[i].name == nDispOrder+'_TR_SEP')
		{	
			aElements[i].style.visibility = strVisibility;
			// HLA - Champs notes sous un séparateur inaccessible (mise en commentaire de la mdification de la position de l'objet) - Bug #8585
			//aElements[i].style.position = strPosition;
			aElements[i].style.display = strDisplay;
			aSubElements = aElements[i].childNodes;
			z=0;
			for( j = 0 ; j < aSubElements.length ; j++ )
			{
				if ( aSubElements[j].tagName == 'TD' )
				{
					if (aSubElements[j].ednHidden != 1)
					{
			        aSubElements[j].style.visibility = strVisibility;
					// HLA - Champs notes sous un séparateur inaccessible (mise en commentaire de la mdification de la position de l'objet) - Bug #8585
                    //aSubElements[j].style.position = strPosition;
                    aSubElements[j].style.display = strDisplay;
					}
					else
					{
					z=z+1;
					}
					
				}
			}
			if (z==j) aElements[i].style.display = 'none';
		}
	}

	//Redimensionne la fiche
	Resize();
}

function onExpandClose ( nDispOrder, nTab, nUserId )
{
	var aElements = null;
	var aSubElements = null;
	var aDivElements = null;
	var nId = null;
	var strTrId = null;
	var strImgId = 'ImgTree_'+nDispOrder;
	var strImgSrc = document.getElementById(strImgId).src;
	var nTag = document.getElementById(strImgId).ednTag;
	var strVisibility;
	var strPosition;
	var strDisplay;
	
	strVisibility = 'hidden';
	strPosition = 'absolute';
	strDisplay = 'none';
	//Modifie l'image
	document.getElementById(strImgId).src = strImgSrc.replace( "Minus.gif","Plus.gif");
	//Modifie le Tag
	document.getElementById(strImgId).ednTag = 0;
	//Enregistre la fermeture
	loadPage('Process.asp?Type=1&Tab='+nTab+'&Userid='+nUserId+'&DispOrder='+nDispOrder+'&Open=0');

	var aElements = document.getElementsByTagName("TR");
	for( var i=0 ; i < aElements.length ; i++ )
	{
		if( aElements[i].name == nDispOrder+'_TR_SEP')
		{	
			aElements[i].style.visibility = strVisibility;
			// HLA - Champs notes sous un séparateur inaccessible (mise en commentaire de la mdification de la position de l'objet) - Bug #8585
			//aElements[i].style.position = strPosition;
			aElements[i].style.display = strDisplay;
			aSubElements = aElements[i].childNodes;
			for( j = 0 ; j < aSubElements.length ; j++ )
			{
				if ( aSubElements[j].tagName == 'TD' )
				{
			        aSubElements[j].style.visibility = strVisibility;
					// HLA - Champs notes sous un séparateur inaccessible (mise en commentaire de la mdification de la position de l'objet) - Bug #8585
                    //aSubElements[j].style.position = strPosition;
                    aSubElements[j].style.display = strDisplay;
				}
			}
		}
	}
	//Redimensionne la fiche
	Resize();
}

function IsFieldObligatEmpty( bSave, strDescId, nTab )
{


	var COL_FLD_OBLIGAT = '#FFCCCC';
	var COL_FLD_BLANK = '#FFFFFF';
	var COL_FLD_READONLY = '#E6E6E6';
	
	var bNotEmpty = true;
	var bFieldObligatRules = false;
	if( !strDescId )
		strDescId = '0';
		
	// sph
	// 04/11/2007 
	// variable globale externe a tt.js
	if (!strListDescIdObligatRules)		
		strListDescIdObligatRules='';
		
	var strListObligatField = ';'+strListDescIdObligatRules+';';

	
	if( strDescId != '0')
		bFieldObligatRules = ( strListObligatField.indexOf(';' + strDescId +';', 0) > - 1 );

	//Démarrage
	if( strDescId == -1 )
		bFieldObligatRules = true;
			
	//Si la rubrique fait partie d'une régle de saisie obligatoire ou enregistrement de la fiche
	bFieldObligatRules = ( bFieldObligatRules || bSave )

	var strListObligatFieldEmpty ='';
	if( strListObligatField != ';;' && bFieldObligatRules )
	{	
		var strReturn = window.showModalDialog( 'DialogWaitRules.asp?Tab='+nTab+'&ObligatDescId='+strListObligatField, self, 'dialogHeight:130px;dialogWidth=300px;edge:Raised;center:1;help:0;resizable:0;status:0' );
		if( strReturn != '' )
		{
			var aList = strReturn.split ("&");
			for( var i=0;i<aList.length;i++)
			{
				aDescIdObligat = aList[i].split ( "=" );
				var strDescIdObligat = aDescIdObligat[0];
				aObligat = aDescIdObligat[1].split ( ";" );
				var strLabel = aObligat[0];
				var nObligat = parseInt( aObligat[1], 10 );
				var bObligat = ( nObligat == 1);
				if( document.getElementById( strDescIdObligat ) )	
				{
					if( document.getElementById( strDescIdObligat+'A' ) )
						strDescIdObligat = strDescIdObligat +'A';
					
					//Mise à jour du tag pour la saisie obligatoire
					document.getElementById( strDescIdObligat ).ednObligat = nObligat;
					
					//Changement de la couleur de fond
					if( !bObligat )
					{
						if( document.getElementById( strDescIdObligat ).readOnly )
							document.getElementById( strDescIdObligat ).style.backgroundColor = COL_FLD_READONLY;
						else
							document.getElementById( strDescIdObligat ).style.backgroundColor = COL_FLD_BLANK;
					}
					else
					{
						document.getElementById( strDescIdObligat ).style.backgroundColor = COL_FLD_OBLIGAT;
						if( trim( document.getElementById(strDescIdObligat).value ) == "" && bSave )	
						{
							if( strListObligatFieldEmpty != '' ) 
								strListObligatFieldEmpty = strListObligatFieldEmpty + ";";
							strListObligatFieldEmpty = 	strListObligatFieldEmpty + strLabel;
							G_bApply = false;
							bNotEmpty = false;
						}
					}
				}
			}
		}
	}
	if( strListObligatFieldEmpty != '')
	{
		var aListObligat = strListObligatFieldEmpty.split( ';' );
		strListObligatFieldEmpty ='';
		for( var i=0;i<aListObligat.length;i++)
		{
			var strLabel = '- ' + aListObligat[i];
			if( strListObligatFieldEmpty != '' )
				strListObligatFieldEmpty = strListObligatFieldEmpty + "\n";
			
			strListObligatFieldEmpty = strListObligatFieldEmpty + strLabel;
		}
		var strMsg = strRes1268;
		alert( strMsg + strListObligatFieldEmpty ); //JBE
		//DisableEnableLinks(1);
		//return bNotEmpty
	}
	//DisableEnableLinks(0);
	return bNotEmpty;
}

//TODO - 
//JBE - 31/03/2008 - Saisie obligatoire	
// Cette fonction active/désactive les divs sur les liens des pages affichées 
// pour obliger la saisie sur les champs obligatoires
/* function DisableEnableLinks(vAction)
{
	var divObligTop = top.frames['FraTop'].document.getElementById('DivOblig');
	var divObligBottom = top.frames['FraBottom'].document.getElementById('DivOblig');
	var divObligLeft = top.frames['FraLeft'].document.getElementById('DivOblig');
	var divObligDetail = top.frames['FraDetail'].document.getElementById('DivOblig');

	var strDivStyle;
	if (vAction = 0)
		strDivStyle = "none";
	else
		strDivStyle = "block";

	divObligTop.style.visibility = strDivStyle;
	divObligBottom.style.visibility = strDivStyle;
	divObligLeft.style.visibility = strDivStyle;
	divObligDetail.style.visibility = strDivStyle;
} */

function UpdateDefaultCatValue( nTab )
{
	for( i = nTab + 1 ; i < nTab + 100 ; i++ )	
	{
		if( document.getElementById('CAT_'+ i ) )
		{
			if( document.getElementById(i) )
				document.getElementById('CAT_'+ i ).value = document.getElementById(i).value;
		}
	}
}



function CollapseAllInlineTpl(nTab, strInlineFileIds)
{

	var aTmpInlineTpl = strInlineFileIds.split(";");
	var i;
	var nMaxExpandedTpl = aTmpInlineTpl.length;
	var InlineDiv;
	var InlineTr;
	for (i=0;i< nMaxExpandedTpl;i++)
	{
		InlineDiv = top.frames["FraDetail"].document.getElementById("DivInlineTpl_"+ nTab + "_" + aTmpInlineTpl[i]);
		InlineTr = top.frames["FraDetail"].document.getElementById("TrInlineTpl_"+ nTab + "_" + aTmpInlineTpl[i]);
		InlineTr.style.display = 'none';
	}
}


function ExpandAllInlineTpl(nExpandedTmp, nTab,strInlineFileIds,nTabFrom, nAutoOpenPj, nDialogHeight, nDialogWidth, nScheduleId, bAskScheduleSelect, vAction )
{

	var aTmpInlineTpl = strInlineFileIds.split(";");
	var i;
	var nMaxExpandedTpl = aTmpInlineTpl.length;
	if (nExpandedTmp == -1)
		nMaxExpandedTpl = aTmpInlineTpl.length;
	else
		if (nExpandedTmp < nMaxExpandedTpl)
			nMaxExpandedTpl = nExpandedTmp ;
	//ouvrir n fiches max
	if (nMaxExpandedTpl > 5)
		nMaxExpandedTpl = 5;
	for (i=0;i< nMaxExpandedTpl;i++)
	{
		ShInlineTpl (nTab,aTmpInlineTpl[i], nTabFrom, nAutoOpenPj, nDialogHeight, nDialogWidth, nScheduleId, bAskScheduleSelect, vAction );
	}
}
function ShInlineTpl( nTab, nFileId,        nTabFrom, nAutoOpenPj, nDialogHeight, nDialogWidth, nScheduleId, bAskScheduleSelect, vAction )	
{

	if( !nDialogHeight )		nDialogHeight = 0;
	if( nDialogHeight < 100 )	nDialogHeight = 300;
	if( !nDialogWidth )			nDialogWidth = 0;
	if( nDialogWidth < 100 )	nDialogWidth = 710;
	if( !nScheduleId )			nScheduleId = 0;
	if( bAskScheduleSelect == null )	bAskScheduleSelect = true;
	

	if (vAction == 0){
	
		var InlineDiv = top.frames["FraDetail"].document.getElementById("DivInlineTpl_"+ nTab + "_" + nFileId);
		var InlineTr = top.frames["FraDetail"].document.getElementById("TrInlineTpl_"+ nTab + "_" + nFileId);
		InlineTr.style.display='none';
		try{
		var MainTr = top.frames["FraDetail"].document.getElementById("Tr_Main_" + nTab + "_" + nFileId);
		MainTr.style.backgroundColor = "";}
		catch(e){}
		return;
	}
	
	if( nTab == 100000 ) // TAB_HISTO
	{
		var strDatas = showFileDialog( nTab, nFileId );
		if( strDatas )	
		{
			if( strDatas.substring(0,2) == '-1' )
				top.frames['FraTmp'].location = 'TplDelete.asp?tab='+nTab+'&FileId='+nFileId;
		}
	}
	else
	{
		if( !nAutoOpenPj )
			nAutoOpenPj = 0;
			
		var strSerie = '0';
		
		if( nScheduleId != 0 && bAskScheduleSelect )
		{
			//strSerie = window.showModalDialog( 'ScheduleSelect.asp', '', 'dialogHeight:170px;dialogWidth:350px;edge:Raised;center:1;help:0;resizable:0;status:0' );
			//if( strSerie == null )
			//alert('Impossible d\'ouvrir une fiche récurrente ici..');
			//return;
		}
	
		try{
		var MainTr = top.frames["FraDetail"].document.getElementById("Tr_Main_" + nTab + "_" + nFileId);
		MainTr.style.backgroundColor = "#D9ECFF";
		}
		catch(e){}
		var InlineTr  = top.frames["FraDetail"].document.getElementById("TrInlineTpl_"+ nTab + "_" + nFileId);
		var InlineDiv = top.frames["FraDetail"].document.getElementById("DivInlineTpl_"+ nTab + "_" + nFileId);

		InlineTr.style.display='block';
		InlineDiv.innerHTML = "<img align=center id='IMG_"+nTab + "_" + nFileId +"' src='"+ strImgLoading +"'>";
		var strOnload = "this.style.visibility = 'visible';this.document.getElementById('IMG_"+nTab + "_" + nFileId+"').style.display = 'none';";
		InlineDiv.innerHTML += "<iframe border=0 scrolling=\"no\" onload=\""+ strOnload +"\" style='visibility:hidden' id='frm_"+ nTab + "_" + nFileId +"' width=100% height=100% src=\""  + "TplFiche.asp?new=0&tabfrom="+nTabFrom+"&tab="+nTab+"&FileId="+nFileId+"&AutoOpenPj="+nAutoOpenPj+"&OpenSerie="+strSerie+"&ScheduleId="+nScheduleId + "&InlineMode=1\"><br><hr>";

	}
}

//ELA le 13/05/2008
function SubmitMemoHtml(strValue, nDescId, nFileId, nFrom)
{
//Fichier Principal
if (nFrom == '1') top.frames['FraTmp'].location = 'Update.asp?fileid='+nFileId+'&descid='+nDescId+'&value='+encode(strValue);
//Fichier Principal (boîte de dialogue)
//if (nFrom == '3') top.frames['FraTmp'].location = 'Update.asp?fileid='+nFileId+'&descid='+nDescId+'&value='+encode(strValue);
//Sous-Fichier (boîte de dialogue)
if (nFrom == '2') top.frames['FraTplFicheTmp'].location = 'Update.asp?fileid='+nFileId+'&descid='+nDescId+'&value='+encode(strValue);
}

/*function sleep(nMs) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < nMs);
} 
*/

