//fpv=28
function fp_ajax_xml2obj_data(parent,tagname){
	var n=parent.getElementsByTagName(tagname).item(0);
	if(!n){
		return false;	
	}
	var dnode=n.getElementsByTagName("data").item(0);
	
	if(dnode){
		return 	fp_ajax_xml2obj_item(dnode);
	}
			

}
function fp_ajax_xml2obj_item(xmlNode){
	if(!xmlNode){
		return false;	
	}
	
	var dtype=xmlNode.getAttribute('dataType');
	if (dtype==("Object")){
		var r=new Object;
		var itemkey="";
		if(xmlNode.childNodes.length>0){
 			for(var i=0;i<xmlNode.childNodes.length;i++){
				if (xmlNode.childNodes[i].nodeType == 1){
					itemkey=xmlNode.childNodes[i].getAttribute('id');
					r[itemkey]=fp_ajax_xml2obj_item(xmlNode.childNodes[i]);
				}
			}
    	}
		return r;	
	}else{
		if(xmlNode.firstChild){
			var r;
			if (dtype==("Bool")){
				if(xmlNode.firstChild.data){
					return true;	
				}else{
					return false;		
				}
			}
			if (dtype==("Int")){
				r=parseInt(xmlNode.firstChild.data);
				if(isNaN(r)){
					return 0;	
				}
				return r;
			}
			if (dtype==("Numeric")){
				r=parseFloat(xmlNode.firstChild.data);
				if(isNaN(r)){
					return 0;	
				}
				return r;
			}
			if (dtype==("String")){
				if(typeof(xmlNode.firstChild.data=="string")){
					return xmlNode.firstChild.data;
				}
				return "";
			}
			return 	xmlNode.firstChild.data;
		}else{
			if (dtype==("Bool")){
				return false;	
			}
			if (dtype==("Int")){
				return 0;	
			}
			if (dtype==("Numeric")){
				return 0;	
			}
			if (dtype==("String")){
				return "";	
			}
		}
	}
	return false;
}

function fp_ajax_xml2objdebug_requrl(url) {
	fp_get_output_get_debugbox("Loading XML from "+url);
	var fp_ajax;
	if (fp_ajax=fp_ajax_crear_Request()){
		fp_ajax.onreadystatechange = function (){
			if (fp_ajax.readyState == 4) {
				if (fp_ajax.status == 200) {
					var data;
					fp_get_output_get_debugbox("Data XML from "+url+" loaded");
					if(data=fp_ajax_xml2obj(fp_ajax)){
						fp_get_output_get_debugbox(fp_ajax_xml2objdebug(data));
					}
					fp_get_output_get_debugbox(fp_ajax.responseText);
				}
			}
		}
		fp_ajax.open("GET", url, true);
		fp_ajax.send(null);	
	}
}


function fp_ajax_xml2obj(http_request){
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (typeof(http_request.responseXML)!="object"){
				return false;
			}
			if (http_request.responseXML==null){
				return false;	
			}
			var xmlNode=http_request.responseXML.getElementsByTagName('data').item(0);
			if (typeof(xmlNode)!="object"){
				return false;
			}
			if (xmlNode==null){
				return false;	
			}
			return fp_ajax_xml2obj_item(xmlNode)
		}
    }
}
function fp_ajax_xml2objdebug(objdata,showtype){
	var output="";
	if (typeof(objdata)=="object"){
		output=output+"<div style='margin-left:5px; border:1px solid #000000'>";
		for (var k in objdata){
			output=output+"<div>"+k+" =&gt; "+fp_ajax_xml2objdebug(objdata[k],showtype)+"</div>";
		}
		output=output+"</div>";
	}else{
		output=	objdata;
		if(showtype){
			output=output+" <i>("+typeof(objdata)+")</i>";	
		}
	}
	return output;
	
}
function fp_get_modoutput_url(mod,script,params,tp) {
	if(!tp){
		tp="funciones";	
	}
	if(!params){
		params=new Object;	
	}
	params.fpmodoutputget_tp=tp;
	params.fpmodoutputget_mod=mod;
	params.fpmodoutputget_script=script;
	return fp_get_output_url("modoutput",params);
	
}

function fp_get_output_url(script,params) {
	var urla=fp_url_get()+"output/"+script+".php";
	if(params){
		var q=fp_url_args2query(params);
		if(q){
			urla+=q;
		}
	}
	return urla;
}

function fp_get_output(url,destino,metodo,sinloader,onload) {
	var urla=fp_url_get()+"output/"+url;
	fp_ajax_cargaURL(urla,destino,metodo,onload,sinloader);
}

function fp_get_output_loop(url,destino,metodo,sinloader,intervalo) {
	if (sinloader){
		var sinloadertxt="true";
	}else{
		var sinloadertxt="false";
	}
	fp_get_output(url,destino,metodo,sinloader);
	var str="fp_get_output_loop('"+ url + "','" +destino + "','" +metodo+ "'," + sinloadertxt + ","+ intervalo +")";
	
	setTimeout(str,intervalo);
}
var fp_output_debugbox=false;
var fp_output_debugbox_ctr=false;
var fp_output_debugbox_num=0;
function fp_get_output_get_debugbox_textarea(cont){
	
	//var c="<textarea cols='100' rows='20'>"+cont+"</textarea>";
	return fp_get_output_get_debugbox(cont,false,false,false,true);
}
function fp_get_output_get_debugbox(cont,showtype,title,asurl,intextarea){
	if (!title){
		title=false;	
	}
	if (!fp_output_debugbox){
		fp_output_debugbox=  document.createElement('div');
		fp_output_debugbox.style.backgroundColor="#ffffff";
		fp_output_debugbox.style.border="2px solid #000000";
		fp_output_debugbox.style.position="absolute";
		fp_output_debugbox.style.fontSize="10px";
		fp_output_debugbox.style.zIndex=990000;
		fp_output_debugbox.style.top="5px";
		fp_output_debugbox.style.left="5px";
		fp_output_debugbox.style.padding="2px";
		fp_output_debugbox.style.margin="2px";
		fp_output_debugbox.style.display="none";
		
		fp_output_debugbox_ctr=  document.createElement('div');
		fp_output_debugbox_ctr.style.backgroundColor="#ffffff";
		fp_output_debugbox_ctr.style.border="2px solid #000000";
		fp_output_debugbox_ctr.style.position="absolute";
		fp_output_debugbox_ctr.style.fontSize="8px";
		fp_output_debugbox_ctr.style.zIndex=990001;
		fp_output_debugbox_ctr.style.top="5px";
		fp_output_debugbox_ctr.style.right="5px";
		fp_output_debugbox_ctr.style.padding="2px";
		fp_output_debugbox_ctr.style.margin="2px";
		fp_output_debugbox_ctr.style.cursor="pointer";
		fp_output_debugbox_ctr.innerHTML="JS Debug";
		fp_output_debugbox_ctr.onclick=function(){fp_hide_show_obj(fp_output_debugbox)};
		
		
		document.body.appendChild(fp_output_debugbox);
		document.body.appendChild(fp_output_debugbox_ctr);
	}
	if(typeof(cont)=="object"){
		cont=fp_ajax_xml2objdebug(cont,showtype);	
	}
	if(asurl){
		if(intextarea){
			cont="<a href='"+cont+"' target='_blank'>"+cont+"</a><br><textarea cols='100' rows='2'>"+cont+"</textarea>";
		}else{
			cont="<a href='"+cont+"' target='_blank'>"+cont+"</a>";
		}
	}else if(intextarea){
		cont="<textarea cols='100' rows='20'>"+cont+"</textarea>";
	}
	
	var box=  document.createElement('div');
	box.style.backgroundColor="#ffffff";
	box.style.border="1px solid #000000";
	box.style.padding="1px";
	box.style.margin="1px";
	var divtit=document.createElement('div');
	var divtitin=document.createElement('div');
	var divclose=document.createElement('div');
	var divcont=document.createElement('div');
	divtitin.style.display="inline-block";
	divtitin.style.fontSize="8px";
	divclose.style.fontSize="8px";
	divclose.style.display="inline-block";
	divclose.style.color="#FF0000";
	divclose.style.cursor="pointer";
	divclose.style.border="1px solid #cccccc";
	
	fp_output_debugbox_num++;
	if (title){
		divtitin.innerHTML=title+" ("+fp_output_debugbox_num+")";
	}else{
		divtitin.innerHTML=fp_output_debugbox_num;
	}
	divclose.innerHTML="[-]";
	fp_output_debugbox_ctr.innerHTML="JS Debug ("+fp_output_debugbox_num+")";
	divclose.onclick=function(){
		var ne=fp_hide_show_obj(divcont);
		if(ne=="show"){
			this.innerHTML="[-]";	
		}else{
			this.innerHTML="[+]";		
		}
		
	};
	divtit.appendChild(divclose);
	divtit.appendChild(divtitin);
	
	box.appendChild(divtit);
	divcont.style.border="1px solid #cccccc";
	divcont.style.top="5px";
	divcont.style.left="5px";
	divcont.style.padding="2px";
	divcont.style.margin="2px";
	divcont.innerHTML=cont;
	box.appendChild(divcont);
	fp_output_debugbox.appendChild(box);
	
	
	return divcont;
	
}

