// JavaScript Document
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function getVetEvReclaSegui(id_r_s,off_id_r_s,idmrs){
	var fecha_tem=new Date();
	var VarTem = fecha_tem.getHours() + fecha_tem.getMinutes() + fecha_tem.getSeconds();
	document.getElementById('wNOtaM').style.display='block';
	document.getElementById('transW').style.display='block';
	
    divFormulario = document.getElementById('wNOtaM');
	ajax=objetoAjax();
	ajax.open("POST", "w_segui_recla_suge.php");
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divFormulario.innerHTML = ajax.responseText;
			document.getElementById('precaLoadW').style.display='none';
			
		}else{
			document.getElementById('precaLoadW').style.display='block';			
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("VarTem="+VarTem+"&id_r_s="+id_r_s+"&off_id_r_s="+off_id_r_s+"&idmrs="+idmrs+"#cadere");
}

function getVetAgenteComun(id_agc,off_id_agc,idmrs){
	var fecha_tem=new Date();
	var VarTem = fecha_tem.getHours() + fecha_tem.getMinutes() + fecha_tem.getSeconds();
	document.getElementById('wNOtaM').style.display='block';
	document.getElementById('transW').style.display='block';
	
    divFormulario = document.getElementById('wNOtaM');
	ajax=objetoAjax();
	ajax.open("POST", "w_datos_agc.php");
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divFormulario.innerHTML = ajax.responseText;
			document.getElementById('precaLoadW').style.display='none';
			
		}else{
			document.getElementById('precaLoadW').style.display='block';			
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("VarTem="+VarTem+"&id_agc="+id_agc+"&off_id_agc="+off_id_agc+"&idmrs="+idmrs+"#cadere");
}

 function CeSuVDi(){
    document.getElementById('transW').style.display='none';
    document.getElementById('wNOtaM').style.display='none'; 
 }
 
/**/
/***/
/****/
/*****/
/******/
/*******/
/*PARA EL BUSCADOR SUPERIOR*/
function redirecURL(urldi){
	 document.location.href=urldi;
	 return;
}
	var IE = navigator.appName.toLowerCase().indexOf("microsoft") > -1;
	var Mozilla = navigator.appName.toLowerCase().indexOf("netscape") > -1;
	var textoAnt = "";
	var posicionListaFilling = 0;
	var datos = new Array();
   function cargaLista(evt, obj, txt,idMrs) {      
		ajax = objetoAjax();
		ajax.open("GET", "fileproject/xml/xmlListUsuaMRS.php?texto="+txt+"&idMrsV="+idMrs, true);			
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				var datos = ajax.responseXML;
				var listXML = datos.getElementsByTagName("usuario");				
				var listUsut = new Array();
				if (listXML) {
					for (var i=0; i<listXML.length; i++) {
						listUsut[listUsut.length] = listXML[i].firstChild.data;
					}
				}			
				escribeLista(obj, listUsut);
				document.getElementById('wPrecarLisBUs').style.display='none';
		  }else{			    
			    document.getElementById('wPrecarLisBUs').style.display='block';			
		   }
		}
		ajax.send(null);
	}
	
	function escribeLista(obj, lista) {
		var html = "";
		var fill = document.getElementById('listaMRS');		
		if (lista.length == 0) {			
			fill.style.display = "none";// Si la lista es vacia no la mostramos
			LimiTablCre();
		} else {
			// Creamos una tabla con // todos los elementos encontrados
			LimiTablCre();
			fill.style.display = "block";
            this.canFilas=lista.length /*CANTIDAD DE FILAS*/			
			var divFongb = document.createElement("div");/*div de fondo*/
			var tablaFongb = document.createElement("table");/*tabla de fondo*/
			var tblBody = document.createElement("tbody");		
			/*ATRIBUTOS PARA EL DIV*/
		       divFongb.setAttribute("id","wIdResuTabG");
			/********* FIN DIV *********/			
			/*ATRIBUTOS PARA LA TABLA*/
		       tablaFongb.setAttribute("border","0");
			   tablaFongb.setAttribute("cellspacing","0");
			   tablaFongb.setAttribute("cellpadding","0");
			   tablaFongb.setAttribute("width","100%");			   
			   tblBody.setAttribute("id","wIdTableGeneBusC");/**/
			/********* FIN DIV *********/		
			/*CREAMOS LA TABLA PARA LOS RESULTADOS*/
			for (var i=0; i<lista.length; i++) {/*CANTIDAD DE FILAS*/
              /*VARIABLES PARA LOS USUARIO*/
				var DatoMRS=lista[i].split(',/');
				var fotot=DatoMRS[1];
				var idwt=DatoMRS[2];
				var idEessV=DatoMRS[3];
				var idMrsV=DatoMRS[4];				
				var rutafotot=DatoMRS[5];
				var tipo=DatoMRS[6];
				var idComV=DatoMRS[7];				
				var tipV='';
				var urlV='';				
				if(tipo=='trabajadores'){
				   tipV='PERSONAL DE SALUD';
				   urlV='../trabajamrs/index.php?pg=l_body_v&pgcb=l_top_v&spg=w_inicio_v&id_w_v='+idwt;
				   rutFotUAC='../trabajamrs/fileproject/'+rutafotot+'/filestraba/'+fotot;
				}else if(tipo=='comunidad'){
				   tipV='COMUNIDAD';
				   urlV='../iniweb/inicio.php?pagin=w_entrada_co&ac=c&id_p='+idComV+'&idmrs='+idMrsV;
				   rutFotUAC='../adminmrs/fileproject/'+rutafotot+'/file_comu/'+fotot;
				}else if(tipo=='eess'){
				   tipV='EE.SS';
				   urlV='../iniweb/inicio.php?pagin=w_entrada_es&ac=e&id_p='+idEessV+'&idmrs='+idMrsV;
				   rutFotUAC='../adminmrs/fileproject/'+rutafotot+'/files_eess/'+fotot;
				}
               /*FIN VARIABLES PARA LOS USUARIO*/
			   var trFongb=document.createElement("tr");/*SE CREA EL TR*/			  
				   trFongb.setAttribute("id",'trTiC'+i);
				   //trFongb.onmouseover = function() {alert(''+i+'');}				  
				  /* var flotrTo=document.getElementById('trTiC'+i);
					if (flotrTo.addEventListener){
		    			flotrTo.addEventListener('onmousedown',function(event){redirecURL(''+urlV+'');}, false);
					} else if (flotrTo.attachEvent){
					    flotrTo.attachEvent('onmousedown', function(event){;});
					}*/					
			     var tdFongb1=document.createElement("td");
				      tdFongb1.setAttribute("width",'50');
					  tdFongb1.setAttribute("align",'center');
				 var divFot=document.createElement("div");
				     divFot.setAttribute("id","wIdFotFormCorU");					 
					 var LinkUrlUFoto=document.createElement("a");
				     LinkUrlUFoto.href=urlV;				
				 /****************/
				 if(fotot!=""){
				 var imgFotoUsuMr=document.createElement("img");
				     imgFotoUsuMr.setAttribute("src",'l_ver_imagenes.php?ruta_i='+rutFotUAC+'&al=50&calid=100');
					 imgFotoUsuMr.setAttribute("border",'0');
				     LinkUrlUFoto.appendChild(imgFotoUsuMr);
				 }
				 divFot.appendChild(LinkUrlUFoto);
				 /****************/
				 tdFongb1.appendChild(divFot);
				 var tdFongb2=document.createElement("td");
			         var LinkUrlU=document.createElement("a");
				     LinkUrlU.href=urlV;				  
				 var Nomb = document.createTextNode(''+DatoMRS[0]+'');				 
				 LinkUrlU.appendChild(Nomb);
				 var brbr=document.createElement('br');
				 LinkUrlU.appendChild(brbr);				 
				 var spanspan=document.createElement('span');				 
				 var NombTipo = document.createTextNode(''+tipV+'');				 
				 var brbrBORRAR=document.createElement('br');/***/				 
				 spanspan.appendChild(NombTipo);
				 LinkUrlU.appendChild(spanspan);				 
				 tdFongb2.appendChild(LinkUrlU);				 
				trFongb.appendChild(tdFongb1);trFongb.appendChild(tdFongb2);
				tblBody.appendChild(trFongb);
			}
			/**/			
			tablaFongb.appendChild(tblBody);
			divFongb.appendChild(tablaFongb);			
			fill.appendChild(divFongb);			
		}
		//var texto = document.createTextNode(html);
		//fill.appendChild(texto); //agrego el texto al nuevo div
		 //var cinnerHTML = ''+html+'';
	}

function LimiTablCre(){
	if(document.getElementById('wIdResuTabG')){
			document.getElementById('listaMRS').removeChild(document.getElementById('wIdResuTabG'));
	}
}
	function inputFilling(evt, obj,idMrs) {// Muestra las coincidencias en la lista
		var fill = document.getElementById('listaMRS');
		LimiTablCre()
		fill.style.display = "block";
		var elems = datos;		
		var tecla = "";
		var lista = new Array();
		var res = obj.value;
		var borrar = false;
		// Almaceno la tecla pulsada
		if (!IE) {tecla = evt.which;} else {tecla = evt.keyCode;}		
		var texto;		
		// Si la tecla que pulso es una // letra o un espacio, o el intro// o la tecla borrar, almaceno lo // que debo buscar 		
		if (!String.fromCharCode(tecla).match(/(\w|\s)/) && tecla != 8 && tecla != 13) {
			texto = textoAnt;
		} else {
			texto = obj.value;
		}		
		textoAnt = texto;		
		// Si el texto es distinto de vacio//o se pulsa ARRIBA o ABAJO//hago llamada AJAX para que// me devuelva la lista de palabras//que coinciden con lo que hay
		// escrito en la caja
		//if ((texto != null && texto != "") || (tecla == 40 || tecla == 38)) {cargaLista(evt, obj, texto);}
		if (texto != null && texto != "") {cargaLista(evt, obj, texto,idMrs);}		
		// Según la letra que se pulse
		if (tecla == 37) { // Izquierda// No hago nada			
		} else if (tecla == 38) { // Arriba
			// Subo la posicion en la // lista desplegable una posición			
			if (posicionListaFilling > 0) {
				posicionListaFilling--;
			}
			// Corrijo la posición del scroll
			fill.scrollTop = posicionListaFilling*14;
		} else if (tecla == 39) { // Derecha
			// No hago nada
		} else if (tecla == 40) { // Abajo
			if (obj.value != "") {
				// Si no es la última palabra // de la lista
			  if(posicionListaFilling < this.canFilas - 1){	
				 posicionListaFilling++;
			  }
			}
		} else if (tecla == 8) { // Borrar <-
			// Se sube la lista del todo
			posicionListaFilling = 0;
			// Se permite borrar
			borrar = true;			
		} else if (tecla == 13) { // Intro
		    /*	
				  // Deseleccionamos el texto
						if (obj.createTextRange) {
							var r = obj.createTextRange();
							r.moveStart("character",obj.value.length+1);
							r.moveEnd("character",obj.value.length+1);
							r.select();
						} else if (obj.setSelectionRange) {
							obj.setSelectionRange(
							obj.value.length+1, 
							obj.value.length+1);
						}
						// Ocultamos la lista
						fill.style.display = "none";
						// Ponemos el puntero de // la lista arriba del todo			
						posicionListaFilling = 0;
						// Controlamos el scroll
						fill.scrollTop = 0;
						return true;
				*/
		} else {
			// En otro caso que siga// escribiendo			
			posicionListaFilling = 0;
			fill.scrollTop = 0;
		}		
		// Si no se ha borrado
  if(obj.value==""){LimiTablCre();fill.style.display = "none";}//SI NO HAY  TEXTO 	
	 /*
	 if (!borrar) {
		  LimiTablCre();
			if (lista.length != 0) {
				// Seleccionamos la parte del texto// que corresponde a lo que aparece// en la primera posición de la lista// menos el texto que realmente hemos// escrito
				obj.value = lista[posicionListaFilling];
				if (obj.createTextRange) {
					var r = obj.createTextRange();
					r.moveStart("character",texto.length);
					r.moveEnd("character",lista[posicionListaFilling].length);
					r.select();
				} else if (obj.setSelectionRange) {
					obj.setSelectionRange(texto.length,lista[posicionListaFilling].length);
				}
			}
		}
	*/	 
		return true;
	}  
	// Introduce el texto seleccionado
	function setInput() {
	   setTimeout("document.getElementById('txt_busca_mr').value=textoAnt;document.getElementById('listaMRS').style.display = 'none';posicionListaFilling= 0;",5000);  
	} 
	// Cambia el estilo de// la palabra seleccionada// de la lista
	function seleccionaFilling(id, n) {
		document.getElementById(id + n).className = "brilloBTMRS";
		document.getElementById(id + posicionListaFilling).className = "";  	
		posicionListaFilling = n;
	}  
	// Pasa el texto del filling a la caja
	function seleccionaTextoFilling (id, n) {
		//textoAnt = document.getElementById(id + n).firstChild.innerHTML;
		//posicionListaFilling = 0;
	}
/* FIN BUSCADOR SUPERIOR MRS */
/*******/
/******/
/*****/
/****/
/***/
/**/
/*PARA BSUCAR RECURSOS BIBLIOTECA*/
function loadBusRecuBiBl(idAre){
	var fecha_tem=new Date();
	var VarTem= fecha_tem.getHours() + fecha_tem.getMinutes() + fecha_tem.getSeconds();
	var nuCanTo=4/*cuatro o cinco*/;
    var body 	= document.getElementsByTagName('body').item(0); 
	var divFon = document.createElement("div");/*div de fondo*/
	    divFon.id="wAlertGFond";
		if (divFon.addEventListener){
		    divFon.addEventListener('click',function(event){ CerrWPedCle();}, false);
		} else if (divFon.attachEvent){
			divFon.attachEvent('onclick', function(event){ CerrWPedCle();});
		}		
		
    var divAviso = document.createElement("div");	/*div aviso*/
		divAviso.id="wAlertG";
	body.appendChild(divFon);
	body.appendChild(divAviso);
    var divFormulario = document.getElementById('wAlertG');
    ajax=objetoAjax();
	ajax.open("POST", "../trabajamrs/wLisRecusosBiTodVist.php");
	ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
			divFormulario.innerHTML = ajax.responseText;
		 }else{
			divFormulario.innerHTML = '<div align="center"><br><img src="fileproject/img/precarga_g.gif"/></div>';
		}
	
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("VarTem="+VarTem+"&idAre="+idAre);
}

function CerrWPedCle(){	
	if(document.getElementById("wAlertGFond")){
		var body 	= document.getElementsByTagName('body').item(0);
		body.removeChild(document.getElementById("wAlertG"));
		body.removeChild(document.getElementById("wAlertGFond"));		
	}
}
function buscResuBi(){
	var fecha_tem=new Date();
	var VarTem= fecha_tem.getHours() + fecha_tem.getMinutes() + fecha_tem.getSeconds();
	var txtIdAre=document.getElementById('txtIdAreRes');
	var txtbusca=document.getElementById('txtbusctitub');
	if(!txtIdAre.value){alert('LOS SENTIMOS PERO NO SE PUEDE SEGUIR');return false;}
	var divFormularioR = document.getElementById('IdReulBusBib');
    ajax=objetoAjax();
	ajax.open("POST", "../trabajamrs/wResulBiblBus.php");
	ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
			divFormularioR.innerHTML = ajax.responseText;
		 }else{
			divFormularioR.innerHTML = '<div align="center"><br><img src="fileproject/img/precarga_g.gif"/></div>';
		}
	
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("VarTem="+VarTem+"&idAreT="+txtIdAre.value+'&txtbusbi='+txtbusca.value);
}
/*FIN PARA BSUCAR RECURSOS BIBLIOTECA*/
