// $Id: iCaptions.js 60868 2010-08-25 14:39:08Z johnarne $
/*
-Ajax requests return corrupted characters for captions that were added directly on templates when calling addCaption(...),
so now we force the parser to produce entities for captions in the template which will be unescaped inside function addCaption (See SOTI-155)

addCaption( caption_logical_name, caption_from_template_containing_html_entities)
getCaption( caption_logical_name) -> caption_with_entities_already_unescaped
*/

jscaptions = [];

getCaption = function(str_logicalName){
    if(jscaptions[str_logicalName]){
        return jscaptions[str_logicalName];
    }
    // todo: might try fetch by ajax
    return '*'+str_logicalName+'*';
}

addCaption = function(str_logicalName, str_value){
    if(typeof jscaptions[str_logicalName] == 'undefined'){// ACOQTI-128 not overwriting
        try{str_value=unescapeHTMLHelper(str_value);}catch(ex){}//SOTI-155: Restoring after forcing parser to produce entities

        jscaptions[str_logicalName] = str_value;
    }
}

_unescapeHTMLHelperTemp=document.createElement("DIV");
unescapeHTMLHelper= function(string)
{
   _unescapeHTMLHelperTemp.innerHTML = string;
   if(_unescapeHTMLHelperTemp.innerText)
      return _unescapeHTMLHelperTemp.innerText; // IE
   return _unescapeHTMLHelperTemp.textContent; // FF
}
