
function Template()
{
  this.tplLoadFuncs=new Array();
  this.tplsToLoad='';

  this.loadTpl=function(tpl,func)
  {

    
    if(content[tpl])
      return content[tpl];
    else
    {
 
      if(typeof dojo!='undefined' &&dojo && dojo.storage && !debug&&(content[tpl]=dojo.storage.get('tpl'+tpl.replaceAll('\/',""))))
      {
      	   // console.info("Load Tpl from Cache:"+tpl);
      
        return content[tpl];
	  }      this.tplsToLoad+=tpl+',';
      if(!this.tplLoadFuncs[tpl])
        this.tplLoadFuncs[tpl]=new Array();
      this.tplLoadFuncs[tpl][this.tplLoadFuncs[tpl].length]=(func);
      return false;
    }  
  }
  this.loadTpls=function(cat) //erst sammeln dann laden
  {
  	
  	if(this.tplsToLoad.length)
  	{
        var script=document.createElement('script');
        if(log)
        script.src="/ajax.php?f="+(cat?cat:tplCategory)+"/moduleTpl&tpl="+this.tplsToLoad;
        else
        script.src="/ajan.php?f="+(cat?cat:tplCategory)+"/moduleTpl&tpl="+this.tplsToLoad;       
        script.type='text/javascript';
        document.getElementsByTagName('head')[0].appendChild(script);
       // var tpls=this.tplsToLoad.split(',');
        
  	}
        this.tplsToLoad='';  
       
  }
  this.finishedLoadTpl=function(data)
  {   
      if(typeof dojo!='undefined' &&dojo && dojo.storage)
        dojo.storage.put('tpl'+data.replaceAll('\/',""),content[data]);
   if(this.tplLoadFuncs[data])
   {
    for(var i=0;i<this.tplLoadFuncs[data].length;i++)
    {
    
     this.tplLoadFuncs[data][i]();
    }
   }
     this.tplLoadFuncs[data]=new Array();
  }
  this.part=function(str,name)
  {
    var beginn=str.indexOf("<!--"+name+"-->");
    var end   =str.indexOf("<!--/"+name+"-->"); 
    
    return str.substr(beginn,end); 
  }
}
