if(!window.DHTMLSuite)var DHTMLSuite = new Object();
DHTMLSuite.dynamicContent = function()
{
var enableCache;	// Cache enabled.
var jsCache;
var dynamicContent_ajaxObjects;
var waitMessage;
this.enableCache = true;
this.jsCache = new Array();
this.dynamicContent_ajaxObjects = new Array();
this.waitMessage = 'Loading content - please wait...';
this.waitImage = 'ajax-loader-darkblue.gif';
try{
if(!standardObjectsCreated)DHTMLSuite.createStandardObjects();	// This line starts all the init methods
}catch(e){
alert('You need to include the dhtmlSuite-common.js file');
}
var objectIndex;
this.objectIndex = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects.length;
DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[this.objectIndex] = this;
}
DHTMLSuite.dynamicContent.prototype = {

loadContent:function(divId,url,functionToCallOnLoaded, vars)
{
  var ind = this.objectIndex;
  if(this.enableCache && this.jsCache[url]){
    document.getElementById(divId).innerHTML = this.jsCache[url];
    this.__evaluateJs(document.getElementById(divId));	// Call private method which evaluates JS content
    this.__evaluateCss(document.getElementById(divId));	// Call private method which evaluates JS content
    if(functionToCallOnLoaded) {
	  setTimeout(functionToCallOnLoaded, 500);
      //eval(functionToCallOnLoaded);
    }
    return;
  }
  var ajaxIndex = 0;
  var waitMessageToShow = '';
  if(this.waitImage){	// Wait image exists ?
    waitMessageToShow = waitMessageToShow + '<div style="text-align:center;padding:10px"><img src="' + DHTMLSuite.configObj.imagePath + this.waitImage + '" border="0" alt=""></div>';
  }
  if(this.waitMessage){	// Wait message exists ?
    waitMessageToShow = waitMessageToShow + '<div style="text-align:center">' + this.waitMessage + '</div>';
  }
  try{
    document.getElementById(divId).innerHTML = waitMessageToShow ;
  }catch(e){
  }
  var ajaxIndex = this.dynamicContent_ajaxObjects.length;
  
  try{
    this.dynamicContent_ajaxObjects[ajaxIndex] = new sack();
  }catch(e){
    alert('Could not create ajax object. Please make sure that ajax.js is included');
  }
  if(vars) {
    for(var n = 0; n < vars.length; n++)
	  this.dynamicContent_ajaxObjects[ajaxIndex].setVar(vars[n].name, vars[n].value);
  }
  this.dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
  this.dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[ind].__ajax_showContent(divId,ajaxIndex,url,functionToCallOnLoaded); };	// Specify function that will be executed after file has been found
  this.dynamicContent_ajaxObjects[ajaxIndex].onError = function(){ DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[ind].__ajax_displayError(divId,ajaxIndex,url,functionToCallOnLoaded); };	// Specify function that will be executed after file has been found
  this.dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function
}
,
setWaitMessage:function(newWaitMessage)
{
this.waitMessage = newWaitMessage;
}
,
setWaitImage:function(newWaitImage)
{
this.waitImage = newWaitImage;
}
,
setCache:function(enableCache)
{
this.enableCache = enableCache;
}
,
__ajax_showContent :function(divId,ajaxIndex,url,functionToCallOnLoaded)
{
var obj = document.getElementById(divId);
obj.innerHTML = this.dynamicContent_ajaxObjects[ajaxIndex].response;
//document.getElementById("tareaDEBUG").value = this.dynamicContent_ajaxObjects[ajaxIndex].response;
if(this.enableCache){	// Cache is enabled
this.jsCache[url] = this.dynamicContent_ajaxObjects[ajaxIndex].response;	// Put content into cache
}
this.__evaluateJs(obj);	// Call private method which evaluates JS content
this.__evaluateCss(obj);	// Call private method which evaluates CSS content

if(functionToCallOnLoaded) {
  setTimeout(functionToCallOnLoaded, 500);
    //eval(functionToCallOnLoaded);
}
this.dynamicContent_ajaxObjects[ajaxIndex] = null;	// Clear sack object
}
,
__ajax_displayError:function(divId,ajaxIndex,url,functionToCallOnLoaded)
{
document.getElementById(divId).innerHTML = '<h2>Message from DHTMLSuite.dynamicContent</h2><p>The ajax request for ' + url + ' failed</p>';
}
,
__evaluateJs:function(obj)
{
var scriptTags = obj.getElementsByTagName('SCRIPT');
var string = '';
var jsCode = '';
for(var no=0;no < scriptTags.length;no++){
if(scriptTags[no].src){
var head = document.getElementsByTagName("head")[0];
var scriptObj = document.createElement("script");
scriptObj.setAttribute("type", "text/javascript");
scriptObj.setAttribute("src", scriptTags[no].src);
}else{
if(DHTMLSuite.clientInfoObj.isOpera){
jsCode = jsCode + scriptTags[no].text + '\n';
}
else
jsCode = jsCode + scriptTags[no].innerHTML;
}
}

if(jsCode)this.__installScript(jsCode);
}
,
__installScript:function ( script )
{

try{
if (!script)
return;
if (window.execScript){
window.execScript(script)
}else if(window.jQuery && jQuery.browser.safari){ // safari detection in jQuery
window.setTimeout(script,0);
}else{
window.setTimeout( script, 0 );
}
}catch(e){
}
}
,
__evaluateCss:function(obj)
{
var cssTags = obj.getElementsByTagName('STYLE');
var head = document.getElementsByTagName('HEAD')[0];
for(var no=0;no<cssTags.length;no++){
head.appendChild(cssTags[no]);
}
}
}
