function handleHttpResponse() { 
	if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos

             results = http.responseText; 
			 document.getElementById("idEjemp").innerHTML = results;
             enProceso = false;
          }
       }
    }
}

function verificaejemplar(thehipo) {
    if (!enProceso && http) {
	   var url = "consulta.php?idhipo="+thehipo;
       http.open("POST", url, true); 
       http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
       http.send(null); 
       http.onreadystatechange = handleHttpResponse;
       enProceso = true;
    }
}

function handleHttpResponse2() { 
	if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos

             results = http.responseText; 
			 document.getElementById("idEjeDi").innerHTML = results;
             enProceso = false;
          }
       }
    }
}

function verificadistejem(thehorse) {
    if (!enProceso && http) {
	   var url = "consulta2.php?idhorse="+thehorse;
       http.open("POST", url, true); 
       http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
       http.send(null); 
       http.onreadystatechange = handleHttpResponse2;
       enProceso = true;
    }
}

function getHTTPObject() {
    var xmlhttp;
	
	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;
}

var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest


function abrirpagina() {
	varhipo = document.forms[0].cmbHipodromos.value;
	varejem = document.forms[0].cmbEjemplares.value;
	vardist = document.forms[0].cmbEjeDis.value;
	window.open('traqueosejemplar.php?idhipodromo='+varhipo+'&idejemplar='+varejem+'&iddistancia='+vardist,'Traqueos','width=800, height=600, scrollbars=yes, toolbar=no, location=no, menubar=no, resizable=no, directories=no');
}

function imprimircomparativo() {
	window.open('traqueoscomparar.php?idhipo='+document.forms[0].cmbHipodromos.value,'Traqueos','width=800, height=600, scrollbars=yes, toolbar=no, location=no, menubar=no, resizable=no, directories=no');
}

function listejemplar(thehipo) {
	if (thehipo!=0) {
		if (!enProceso && http) {
		   var url = "consulta3.php?idhipo="+thehipo;
		   http.open("POST", url, true); 
		   http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		   http.send(null); 
		   http.onreadystatechange = handleHttpResponse3;
		   enProceso = true;
		}
	}
}

function handleHttpResponse3() { 
	if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos

             results = http.responseText.split("|"); 
			 document.getElementById("ejemplares1").innerHTML = results[0];
			 document.getElementById("ejemplares2").innerHTML = results[1];
			 document.getElementById("ejemplares3").innerHTML = "";
			 document.getElementById("ejemplares4").innerHTML = "";
             enProceso = false;
          }
       }
    }
}

function updEjemplar(thehipo,thehorse,theaction) {
	if (thehipo!=0 && thehorse!="") {
		if (!enProceso && http) {
		   var url = "consulta4.php?idhipo="+thehipo+"&idejem="+thehorse+"&idaction="+theaction;
		   http.open("POST", url, true);
		   http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		   http.send(null); 
		   http.onreadystatechange = handleHttpResponse4;
		   enProceso = true;
		}
	}
}

function handleHttpResponse4() { 
	if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos

             results = http.responseText.split("|"); 
			 document.getElementById("ejemplares3").innerHTML = results[0];
			 document.getElementById("ejemplares4").innerHTML = results[1];
             enProceso = false;
          }
       }
    }
}

///////
var sones;

function openpage(idcontrato) {
	sones.desactivar()

	ab = "pronosticador.php?idcont=" + idcontrato;
	window.open(ab,'','width=850,height=550,toolbar=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

function _desactivar(idcontrato)	{
	this.sonido.innerHTML = "";
}

function _activar()	{
	var son = "<embed src='" + this.son[_activar.arguments[0]].src + "' autostart='true' hidden='true' loop='false' style='display: inline'></embed>";
	this.sonido.innerHTML = son;
}

function preSonidos()	{
	this._entradas = preSonidos.arguments;
	this.total = this._entradas.length;
	this.son = new Array(this.total);
	for (var i = 0; i < this.total; i ++)	{
		this.son[i] = document.createElement("embed");
		this.son[i].src = this._entradas[i];
		this.son[i].autostart = false;
		this.son[i].style.display = "none";
		document.body.appendChild(this.son[i]);
	}
	this.sonando = false;
	this.incrustado = false;
	this.activar = _activar;
	this.desactivar = _desactivar;
	this.sonido = document.createElement("div");
	document.body.appendChild(this.sonido);
}

function ini(idfile) {
	//sones = new preSonidos('celtic0.mid', 'celtic1.mid', 'celtic2.mid', 'celtic3.mid', 'Starway_to_Heaven.mp3');
	sones = new preSonidos(idfile);
	sones.activar(0);
}