// Document JavaScript

var objXML;
var indicador = false;

function CreaXHR()
{
	var ref = false;
	
	try
	  	{ // Procediment per a crear un objecte XMLHttpRequest compatible entre diversos
		ref = new ActiveXObject('Msxml2.XMLHTTP');
		}
	catch (e1) // navegadore Web
		{
		try {ref = 	new ActiveXObject('Microsoft.XMLHTTP');}
		catch (e2) {objXML = false;}
		}

	if (!ref && (typeof XMLHttpRequest != 'undefined' || window.XMLHttpRequest)) ref = new XMLHttpRequest();  
	return ref;
}

// Aquesta funciķ carregarā les pāgines
function llamarasincrono_cantaires(corda, numero, id_contenedor)
{
	var URL='cantaires.php' + '?corda=' + corda + '&numero=' + numero;

	objXML = CreaXHR();
	objXML.onreadystatechange = function(){cargarpagina(objXML, id_contenedor)}
	objXML.open('GET', URL, true); // assignem els mčtodes open i send
	objXML.send(null);
}

// tot és correcte i ha arribat el moment de posar la informaciķ requerida
// en el seu lloc a la pāgina xhtml
function cargarpagina(objXML, id_contenedor)
{
	if (objXML.readyState == 4 && (objXML.status==200 || window.location.href.indexOf("http")==-1))
		{
			document.getElementById(id_contenedor).innerHTML = objXML.responseText;
			document.getElementsByTagName('body')[0].removeChild(indicador);
			indicador = false; // variables nulˇles
		}
	else // si comencem a rebre resposta
		if(objXML.readyState == 3)
			{
				document.getElementById(id_contenedor).innerHTML = '';
	
				// Creem una secciķ dināmica
				indicador = document.createElement('div');
				// y l'afegim al document
				document.getElementById(id_contenedor).appendChild(indicador);
			
				// Mostrem una indicaciķ en forma de finestra flotant
				indicador.style.width = '200px';
				indicador.style.height= "50px";
				indicador.style.margin = '50px';
				indicador.style.backgroundColor = 'ffffcc';
				indicador.style.color = 'black';
				indicador.style.border = '1px solid #a51133';
				indicador.style.padding = '5px';
				indicador.innerHTML = '<p>Carregant la informaciķ</p>';
			}

}
