/*---------------------------------------------------------
 * a general baseclass for ajax based 
 * toc displays
 * 
 * basice structure of container-element
 * <div id="xBox">
 *   <form class="zack_toc_controls">
 *    input fields 
 *    <input type=hidden name="zack_toc_pn"
 *   <div class="zack_toc"
 *    where to put dynamic parts hd+bd+ft
 *   <div class="zack_toc_pagination
 * ------------------------------------------------------*/

ZACK.ObjWidget=function(containerID, template, params){

  this.template=template || null;
  // timeout for ajax requests
  this.timeout=4000;
  // the containing div element  
  this.containerID=containerID;

  this.params={method:'zack.obj.getvalues', appKey:ZACK.appKey, mkey:ZACK.mKey,
               ownerID:ZACK.ownerID, groupID:ZACK.groupID, rspm: 'json'  };
  for(p in params)
    this.params[p]=params[p];  
}

ZACK.ObjWidget.prototype= {

/*---------------------------------------------------------
 * the CORE function
 * getting infos and applying templates
 * ------------------------------------------------------*/
handleSuccessGetObj: function(o){
  var obj=eval('('+o.responseText+')');
  if(obj.stat=='fail'){
    alert('getObj failed!');
  }
  if(this.template){
    arguments=obj.result;
    var tpl=TrimPath.parseDOMTemplate(this.template);
    $(this.containerID).innerHTML=tpl.process(arguments);
     
  }
  
  /*
  var toc=obj.toc;
  var str=this.template.hd;
  var tpl=new Template(this.template.bd);
  for(i=0;i<toc.length;i++){
  	var item=this.handleItem(toc[i],i );
    str +=tpl.evaluate(item);
  }
  this.container.toc.innerHTML=str;
  if(this.container.pagination){
  	this.container.pagination.innerHTML=
  	  this.pagination(obj.numItems, o.argument.pn, o.argument.rpp, '');
  }*/
},


makePostString: function(params){
    var rv='';
	for (var p in params) {
	  rv+= p+'='+ /*escape_utf8*/(params[p])+'&';
	}	
  return rv;
},


/*---------------------------------------------------------
 * getObj
 * ------------------------------------------------------*/
getObj: function(id) {
/*
  if(!this.container.toc)
    this._getTargets();

  
  this.container.toc.innerHTML=
  //this.container.pagination.innerHTML=
  '<b>loading!</b>&nbsp;&nbsp;&nbsp;<img src="/gif/loading-small.gif" width="12" height="12" />';
*/
  this.params['ID']=id;
  var request = YAHOO.util.Connect.asyncRequest('POST', ZACK.RESTURL,
     {success:this.handleSuccessGetObj, 
	  failure: function(o){alert('error: got no information');},
	  timeout: this.timeout, 
	  scope: this} , this.makePostString(this.params)); 
}


} // -------------------------- end ZACK.toc




