function editTextAssoc(idText,lang)
{
var txtassoc = 'textassoc' + idText ;

if (! isSessionActive())
{ 
  redirect("f?p=105:101:0");
  return false;
}

var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=LOAD_TEXT',$v('pFlowStepId'));
get.addParam('x01',idText);
get.addParam('x02',lang);
var htmlContent = get.get();

var content = '<form><input type="hidden" name="textEdited" id="textEdited" value="' + 
txtassoc +'"><textarea cols="110" rows="22" id="txtpopup">' + '</textarea></form>' ;
if ( lang != "en-us")
{
  $.prompt(content,{callback: toggleTextLang, submit: actionTextAssoc, prefix : 'cleanbluefck', zIndex: 3999, /*top: '100px', */buttons: { Anglais : 'en-us', Sauvegarder: 'save-fr', Annuler: 'cancel' } });
  genEditor(htmlContent,"fr");
}
else
{
  $.prompt(content,{callback: toggleTextLang, submit: actionTextAssoc, prefix : 'cleanbluefck', zIndex: 3999, /*top: '100px', */buttons: { French: 'fr-ca', Save: 'save-en', Cancel: 'cancel' } });
  genEditor(htmlContent,"en");
}

}

function actionTextAssoc(v,m)
{
  if (v == "save-fr")
      saveText('fr-ca');
  if (v == "save-en")
      saveText('en-us');
  return true;    
}

function toggleTextLang(v,m,f)
{ 
  if (v == "fr-ca" || v == "en-us" )
      editTextAssoc(f.textEdited.substr(9),v);
}

   function initFCK(pItem,lang) {
 
            var oFCKeditor        = new FCKeditor(pItem) ;
            oFCKeditor.BasePath   = "/ia/javascript/fckeditor/"  ;
            oFCKeditor.Width      = $x(pItem).offsetWidth;
            oFCKeditor.Height     = $x(pItem).offsetHeight;
            oFCKeditor.ToolbarSet = 'Default' ;
            oFCKeditor.Config[ "AutoDetectLanguage" ] = false;
            oFCKeditor.Config[ "DefaultLanguage" ]    = lang;
            oFCKeditor.ReplaceTextarea() ;
            
    }
function genEditor(p_htmlContent,lang) {

  initFCK('txtpopup',lang);
  $s('txtpopup',p_htmlContent);
}
function saveText(lang){

    if (! isSessionActive())
    { 
      redirect("f?p=105:101:0");
      return false;
    }

    var oEditor = FCKeditorAPI.GetInstance('txtpopup') ;
    oEditor.UpdateLinkedField();
    var content = $v('txtpopup');
    //content = content.replace(/<!--\[if !supportEmptyParas\]-->&nbsp;<!--\[endif\]-->/gi,"<br />");
  	var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=SAVE_TEXT',$v('pFlowStepId'));
    get.AddArrayClob(content,1)
    //get.addParam('x01',content);
    get.addParam('x02',$v('textEdited'));
    get.addParam('x03',lang);
    var processedContent = get.get();
    processedContent = processedContent.replace(/<script .*<\/script>/,'');
    processedContent = processedContent.replace(/<script>.*<\/script>/,'');
    $("#" + $v('textEdited')).html(processedContent);
    return true;
}

function showTextEditLinks()
{
  var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=SET_IND_LIENS_EDITION',$v('pFlowStepId'));
  get.addParam('x01','1');
  var pLang = get.get();
  // Mettre a jour l'affichage de la region des textes d'associations
  $(".bouton_textassoc").css({display:""});
  $(".contour_textassoc").css({border:"3px dashed #666"});
  // Mettre a jour l'affichage de la region de lien
  $("#liensIntExt").attr("style","");
  
  if ( pLang != "en-us")
    $s('navBarEditionLiens','Mode standard');
  else
    $s('navBarEditionLiens','Standard Mode');
  $("#navBarEditionLiens").parent().attr("href","javascript:hideTextEditLinks()");
}

function hideTextEditLinks()
{
  var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=SET_IND_LIENS_EDITION',$v('pFlowStepId'));
  get.addParam('x01','');
  var pLang = get.get();
  // Mettre a jour l'affichage de la region des textes d'associations
  $(".bouton_textassoc").css({display:"none"});
  $(".contour_textassoc").css({border:""});
  // Mettre a jour l'affichage de la region de lien
  $("#liensIntExt").attr("style","display:none");
  
  if ( pLang != "en-us")
    $s('navBarEditionLiens','Mode administration');
  else
    $s('navBarEditionLiens','Administration Mode');
  $("#navBarEditionLiens").parent().attr("href","javascript:showTextEditLinks()");
}

function isSessionActive()
{
  var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=IS_SESSION_ACTIVE',$v('pFlowStepId'));
  var status = get.get()
  if (status != "1")
    return false;
  else
    return true;
}