//fpv=3
function fp_plactive_ajax(name,plmod,plcod,idcont,args){
	this.name=name;
	this.id_cont=idcont;
	this.onloadmanagers=new Array;
	this.plmod=plmod;
	this.plcod=plcod;
	this.script="getcontxml";
	this.urlargs=new Object;
	if(args){
		for(var e in args){
			this.urlargs[e]=args[e];	
		}
	}
	this.add_onload_manager_html_elem=function(elemid,xmltagname){
		var man =new fp_plactive_ajax_onload_htmlelem(elemid,xmltagname,this);
		this.onloadmanagers.push(man);	
		return man;
	}
	this.add_onload_manager=function(man){
		this.onloadmanagers.push(man);	
		return man;
	}
	this.urlargs.plcod=this.plcod;
	this.urlargs.jsobjname=this.name;
	this.urlargs.id_cont=this.id_cont;
		
	this.abort_request=function(){
		if(this.req){
			this.req.abort();
			this.req=false;
		}
	}
	this.onAjaxLoad=function(){
		if(!this.req){
			return false;	
		}
		if(this.req.readyState == 4){
			if(this.req.status == 200){
				this.fill_elements_from_req(this.req.responseXML);
			}
		}
	}
	this.fill_elements_from_req=function(response){
		if (typeof(response)=="object"){
			for(var e =0 ;e<this.onloadmanagers.length;e++){
				this.onloadmanagers[e].onresponse(response);	
			}
		}

	}
	this.get_reqparams=function(args){
		var p=new Object;
		for(var e in this.urlargs){
			p[e]=this.urlargs[e];	
		}
		if(args){
			for(e in args){
				p[e]=args[e];	
			}
		}
		return p;
	}
	this.do_request_arg=function(cod,val){
		var args=new Object;
		args[cod]=val;
		this.do_request(args);
	}
	this.do_request=function(args){
		this.abort_request();
		for(var e =0 ;e<this.onloadmanagers.length;e++){
			this.onloadmanagers[e].onsendreq();	
		}
		this.urlreq=fp_get_modoutput_url(this.plmod,this.script,this.get_reqparams(args),"plantillas");
		
		this.req=fp_ajax_crear_Request();
		var _this=this;
		this.req.onreadystatechange = function(){_this.onAjaxLoad()};
		this.req.open("GET", this.urlreq, true);
		this.req.send(null);
		
	}
}

function fp_plactive_ajax_onload_htmlelem(elemid,xmltagname,parent){
	this.elemid=elemid;
	this.xmltagname=xmltagname;
	this.parent=parent;
	
	this.onsendreq=function(){
		if(!this.useloader){
			return false;
		}
		this.set_cont(fp_ajax_loader);
	}
	this.get_html_elem=function(){
		if(this.html_elem){
			return 	this.html_elem;
		}
		var e=fp_get_element_by_id(this.elemid);
		if(e){
			this.html_elem=e;
			return 	this.html_elem;
		}
	}
	this.set_cont=function(c){
		if(!this.get_html_elem()){
			return false;	
		}
		this.html_elem.innerHTML=c;
	}
	this.onresponse=function(response){
		var cont=response.getElementsByTagName(this.xmltagname)
		if(cont.item(0)){
			this.set_cont(cont.item(0).firstChild.data);
			return true;
		}
	}
	


}
