// Inicializaci—n de funci—n de AJAX
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;
}

// Almacenamiento de datos de Rooming
function guarda_room(id_invitado, cadena, espera){
	//instanciamos el objetoAjax
	ajax=objetoAjax();
	//uso del medotod GET
	divFormulario=document.getElementById(espera);
	ajax.open("POST", "guarda_room.php");
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			resp =  ajax.responseText;
			if (resp != "OK") {
				divFormulario.innerHTML = resp;
				alert('No Guardado, avise a soporte@colmexreuma.org.mx p.f.');
			}
			document.body.style.cursor='default';
		}
		else {
			//divFormulario.innerHTML = 'Espere, procesando...';
		}
	}
	//como hacemos uso del metodo GET
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	cad = "r="+id_invitado;
	cad += cadena;
	ajax.send(cad);
}

function agregar(id, forma)
{
   var opciones="left=100, top=100, width=550, height=350, toolbar=0, directories=0, menubar=0, scrollbars=1";
   window.open("entrada_historia_2.php?idusr=" + id + "&opera=agrega&tipocert=" + forma, "entrada_historia 2", opciones);
}

function actualiza_fecha(forma, campo) 
{
	cdia = "dia" + campo;
	cmes = "mes"  + campo;
	canio = "anio" + campo;
	for (i=0; i<document.forms[0].elements.length; ++i) {
	   if (campo == document.forms[0].elements[i].name) {
		  document.forms[0].elements[i].value=document.forms[0].elements[canio].value + "-" +document.forms[0].elements[cmes].value + "-" + document.forms[0].elements[cdia].value;
	   }
	}   
}

function muestra(cual)
{
   if (cual == 'upload') {
      alert('<?php print $G_INSTRUCCIONES["upload"];?>');
   }
}

function guarda(forma, quien)
{
//   alert("Aqui se valida" + forma);
   forma.submit();
}

function lookup(inputString, cCampo, cQuery) {
//   alert(cQuery + cCampo + cQuery);
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $("#suggestions").hide();
    } else {
        $.post("rpc_real.php", {queryString: ""+inputString+"", campo: ""+cCampo+"", query: ""+cQuery+""}, function(data){
            if(data.length >0) {
                $("#suggestions").show();
                $("#autoSuggestionsList").html(data);
            }
        });
    }
} // lookup

function fill(thisValue,cCampo) {
   $("#" + cCampo).val(thisValue);
//   $("#inputString").val(thisValue);
   $("#suggestions").hide();
}

function vista(forma, id) {
   forma.submit();
}

function agregar(id, forma)
{
   var opciones="left=100, top=100, width=550, height=350, toolbar=0, directories=0, menubar=0, scrollbars=1";
   alert (forma);
   if (forma == 'adh') {
      window.open("edita_hotel.php?idusr=" + id + "&opera=agrega&tipocert=" + forma, "entrada_historia_2", opciones);
   }
}

function cambia_orden(orden, forma)
{
	forma.submit();
}

function cambia_estado(estado, forma)
{
	forma.submit();
}

