function buscarDatos(url, callback_function, id){
		var return_xml=false;
		var http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
		 } else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
		}
		}
		if (!http_request) {
			alert('Este sistema requiere una version mas nueva de navegador.');
		return false;
		}
		http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
		 		} else {
					eval(callback_function + '(http_request.responseText, \''+id+'\')');									
				}
		} else {
		alert('La solicitud de información produjo un error.(Code: ' + http_request.status + ')');
		}
		}
		}
		http_request.open('GET', url, true);
		http_request.send(null);
}


function buscarDatosDirectos(url,division, id, nomCampo){
		var return_xml=false;
		var http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
		 } else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
		}
		}
		if (!http_request) {
			alert('Este sistema requiere una version mas nueva de navegador.');
		return false;
		}
		http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
		 		} else {
					eval('desplegarCampoCombo' + '(http_request.responseText, \''+division+'\',\''+id+'\',\''+nomCampo+'\')');									
				}
		} else {
		alert('La solicitud de información produjo un error.(Code: ' + http_request.status + ')');
		}
		}
		}
		http_request.open('GET', url, true);
		http_request.send(null);
}

function Trim(s){
if((s==null)||(typeof(s)!='string')||!s.length)return'';
return s.replace(/^\s+/,'').replace(/\s+$/,'');
}

function actualizarCampoTxt(id, nomCampo){
	if(!document.getElementById(id+nomCampo)){
  	var valor = document.getElementById(nomCampo+id).innerHTML;
  	valor = Trim(valor);
  	if(valor==" " || valor=="&nbsp;"){
  		valor="";
  	}
  	document.getElementById(nomCampo+id).innerHTML="<input type=\"text\" id=\""+id+nomCampo+"\" value=\""+valor+"\" size=\""+valor.length+"\"><img src=\"../../imagenes/save.gif\" align=\"absolutemiddle\" onClick=\"grabarObjeto('"+id+"\', \'"+nomCampo+"\', \'texto\');\" style=\"cursor:hand; cursor:pointer\">";
	}
}

function actualizarCampoTextArea(id, nomCampo){
	if(!document.getElementById(id+nomCampo)){
  	var valor = document.getElementById(nomCampo+id).innerHTML;
  	valor = Trim(valor);
  	valor = valor.replace(/<BR>/g,"\n");
  	document.getElementById(nomCampo+id).innerHTML="<textarea id=\""+id+nomCampo+"\" rows=\"5\" cols=\"40\">"+valor+"</textarea><img src=\"../../imagenes/save.gif\" align=\"absolutemiddle\" onClick=\"grabarObjeto('"+id+"\', \'"+nomCampo+"\', \'texto\');\" style=\"cursor:hand; cursor:pointer\">";
	}
}

function actualizarCampoFecha(id, nomCampo){
	if(!document.getElementById(id+nomCampo)){
  	var valor =document.getElementById(nomCampo+id).innerHTML;
  	valor = Trim(valor);
  	var campo = id+nomCampo;
  	var divCal = campo+"Div";
  	document.getElementById(nomCampo+id).innerHTML="<input type=\"text\" name=\""+campo+"\"  id=\""+campo+"\" value=\""+valor+"\" size=\""+valor.length+"\"><img src=\"../../imagenes/iconos16/cal_3.png\"  border=\"0\" align=\"absmiddle\" onClick=\"CalendarInit('"+campo+"','"+divCal+"')\" id=\"img"+campo+"\" style=\"cursor:hand; cursor:pointer\"><img src=\"../../imagenes/save.gif\" align=\"absolutemiddle\" onClick=\"grabarObjeto('"+id+"\', \'"+nomCampo+"\', \'texto\');\" style=\"cursor:hand; cursor:pointer\">";
	}
}

function actualizarCampoCombo(id, nomCampo, combo){
  	if(!document.getElementById(id+nomCampo)){
	var valor = document.getElementById(nomCampo+id).innerHTML;
  	valor = Trim(valor);
  	document.getElementById(nomCampo+id).innerHTML="<center><img src=\"../../imagenes/cargando.gif\" height=\"16\" width=\"16\">Cargando</center>";
  	var divid = nomCampo+id;
  	var url = 'AdmAjax.php?accion='+combo+'&pk='+id+'&nomCampo='+nomCampo;
  	buscarDatosDirectos(url,divid,id, nomCampo);
  	}
}

function desplegarCampoCombo(combo,divid, id, nomCampo){
		document.getElementById(divid).innerHTML="<select id=\""+id+nomCampo+"\">"+combo+"</select><img src=\"../../imagenes/save.gif\" align=\"absolutemiddle\" onClick=\"grabarObjeto('"+id+"\', \'"+nomCampo+"\', \'combo\');\" style=\"cursor:hand; cursor:pointer\">";
}

function desplegarInfo(respuesta, id){
	respuesta = respuesta.replace(/\n/g,"<br>");
	document.getElementById(id).innerHTML=respuesta;
}

function borrarRegistro(accionAjax, pk, callback, otrasVariables, campoMensaje){
 document.getElementById(campoMensaje).innerHTML= "<center><img src=\"../../imagenes/cargando.gif\" height=\"16\" width=\"16\">Borrando</center>";
 var url = 'AdmAjax.php?accion='+accionAjax+'&pk='+pk+otrasVariables;
 buscarDatos(url, callback, null);	
}
  
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
} 

function abrirPopUp(url) {
    x = (640 - 800)/2, y = (480 - 600)/2;
    if (screen) {
        y = (screen.availHeight - 600)/2;
        x = (screen.availWidth - 800)/2;
    }
OpenWin = window.open(url, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=800,height=600,screenX="+x+",screenY="+y+",top="+y+",left="+x);
}
function alertBorrar(){
	if(confirm("Esta operación borrará el registro, ¿desea continuar?")){
		return true;
	}else{
		return false;
	}
	
}

function formateaMoneda(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$us  ' + num + '.' + cents);
}
function formateaNumero(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}