// Funcions

///////////////////////////////// 	xml i ajax ///////////////////////////////////////////////////////////


function CrearXmlHttp()
{        
    // Probamos con IE
    try
    {
        // Funcionará para JavaScript 5.0
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {  
            xmlHttp = null;
        }
    }

    // Si no se trataba de un IE, probamos con esto
    if(!xmlHttp && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp = new XMLHttpRequest();    
    }

    return xmlHttp;

}


function Obtener_Fecha() 
{

 		var miFecha = new Date();		
		var tiempo_url = miFecha.getYear().toString() + '-' + miFecha.getMonth().toString() + '-' + miFecha.getDate().toString() + '-' + miFecha.getHours().toString() +'-'+ miFecha.getMinutes().toString()+ '-' + miFecha.getSeconds().toString();		
		return tiempo_url;

}

function RecargarDatos(dir, div) 
{
	if (document.getElementById(div))
	{
            var oXmlHttp = CrearXmlHttp();		

			var tiempo_url = Obtener_Fecha();
	
            oXmlHttp.open("POST", dir +"&TT=" + tiempo_url, false);

            oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-1"); 
			
		    oXmlHttp.send(12);    			
			
            document.getElementById(div).innerHTML = oXmlHttp.responseText;			
			
	}
}


//////////////////////////////////// fi funcions XML i Ajax  /////////////////////////////////////////////////////

function buscadorAjax(tipo, idioma) {
			
	if(tipo == 1) { // buscador avançat	
		if (document.getElementById("div-busca")) // div on ho pintaré
		{
			
			var dir = 'includes/buscadorAvansat.asp?idIdioma=' + idioma;
			//alert('envio: ' + dir);
			RecargarDatos(dir, "div-busca");
		} 
	} 
	
	if(tipo == 2) { // buscador simple	
		if (document.getElementById("div-busca")) // div on ho pintaré
		{
			
			var dir = 'includes/buscadorSimple.asp?idIdioma=' + idioma;
			//alert('envio: ' + dir);
			RecargarDatos(dir, "div-busca");
		} 
	} 
}

function actualizarListado(seccio, idMenu) {  // ajax combo ListadoPianos i ListadoPianos-ajax.asp
			
		
		if (document.getElementById("contenidoPrincipal")) // div on ho pintaré
		{
			
			//controlo quina pagina haig de cridar
			var nomPagina;
			nomPagina = '';
			if(seccio == 'NV') { //piano nou vertical
				nomPagina = 'LlistaPianosNousV-ajax';
			}
			else if(seccio == 'NC') { //piano nou cua
				nomPagina = 'LlistaPianosNousC-ajax';
			}
			else if(seccio == 'OV') { //piano ocasio vertical
				nomPagina = 'LlistaPianosOcasioV-ajax';
			}
			else if(seccio == 'OC') { //piano ocasio cua
				nomPagina = 'LlistaPianosOcasioC-ajax';
			}
			else if(seccio == 'KV') { //piano km0 vertical
				nomPagina = 'LlistaPianosKM0V-ajax';
			}
			else if(seccio == 'KC') { //piano km0 vertical
				nomPagina = 'LlistaPianosKM0C-ajax';
			}
			
			var dir = "includes/" + nomPagina + ".asp?ordre=" + document.getElementById('ordre').options[document.getElementById('ordre').selectedIndex].value + "&idMenu=" + idMenu; 
			//alert('envio: ' + dir);
			RecargarDatos(dir, "contenidoPrincipal");	
		} 
	
}

function canviarFoto(foto) {
	
		//funció que carrega la imatge seleccionada a la imatge gran
		document.getElementById('imatgeGran').src = foto;
		
}
