function AjaxRequest() {
	
	var xmlhttp=false;
 	try {
		
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
 	} catch (e) {
		
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (e2) {
 			xmlhttp = false;
 		}
		
  	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;
}

function LoadRefAndFoto() {
	//LoadInputReference("input_ref","load_input.php");
	//LoadResults('results', 'load_reference.php','refer');
	LoadInputReference("imatge","load_imatge.php");
}

function LoadInputReference(opcio) {

	var esquerra = document.getElementById("preview");
	var dreta = document.getElementById("dreta");
	
	
	esquerra.style.display = "inline";
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_fotos.asp", true);
	ajax.onreadystatechange = function() {
	
	 if (ajax.readyState == 4) {
		
			if (ajax.status == 200) {
				
				esquerra.innerHTML = ajax.responseText;
				
				ajax = AjaxRequest();
				ajax.open("POST", "load_textes idioma.asp", true);
				ajax.onreadystatechange = function() {
				
				 if (ajax.readyState == 4) {
					
						if (ajax.status == 200) {
							
							dreta.innerHTML = ajax.responseText;
											
						} else if (ajax.status == 404) {
							preloader.innerHTML = "La página no existe";
							
						} else {
							preloader.innerHTML = "Error:".ajax.status;
							
						}
			
					}
					
				}
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
				ajax.send("numopcio=" + opcio);				
								
			} else if (ajax.status == 404) {
				preloader.innerHTML = "La página no existe";
				
			} else {
				preloader.innerHTML = "Error:".ajax.status;
				
			}

		}
		
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.send("numopcio=" + opcio);
}



function LoadInputReference1(opcio) 
{

	var dreta = document.getElementById("dreta");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_textes.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
	}
   }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
	ajax.send("numopcio=" + opcio);				

}

function LoadInputReference2(opcio) 
{

	var dreta = document.getElementById("dreta");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_textesactor.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
	}
   }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
	ajax.send("numopcio=" + opcio);				

}

function LoadInputReference3(opcio) 
{

	var dreta = document.getElementById("dreta");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_textesnostop.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
	}
   }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
	ajax.send("numopcio=" + opcio);				

}



function LoadInputReferencebook(opcio) {

	var dreta = document.getElementById("preview");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_book.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
								
		
	}
   }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.send("numopcio=" + opcio);
}

function LoadInputReferencecontacte(opcio) {

	var dreta = document.getElementById("dreta");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_contacte.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
								
		
	}
   }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.send("numopcio=" + opcio);
}

function LoadInputReferenceagenda(opcio) {

	var dreta = document.getElementById("dreta");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_agenda.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
								
		
	}
   }
   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
	ajax.send("numopcio=" + opcio);	
}

function LoadInputReferencemenu(opcio) {

	var dreta = document.getElementById("dreta");
	
	dreta.style.display = "inline";
	
	ajax = AjaxRequest();
	ajax.open("POST", "load_menu.asp", true);
	ajax.onreadystatechange = function() 
	{
	
	 if (ajax.readyState == 4) 
	 {
			if (ajax.status == 200) 
			{				
				dreta.innerHTML = ajax.responseText;
								
			} 
			else if (ajax.status == 404) 
			{
				preloader.innerHTML = "La página no existe";
						
			} 
			else 
			{
				preloader.innerHTML = "Error:".ajax.status;
					
			}
			//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				
			//ajax.send("numopcio=" + opcio);				
								
		
	}
   }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.send("numopcio=" + opcio);
}


function LoadResults(id_desti, page, varname) {

	var nom, container;
	
	container = document.getElementById(id_desti);
	container.style.display = "inline";
	
	//alert(id_desti);
	if(varname != null) {	
		nom = document.getElementById(varname).value;
	}
	
	ajax = AjaxRequest();
	ajax.open("POST", page, true);
	ajax.onreadystatechange = function() {
	
	 if (ajax.readyState == 4) {
		
			if (ajax.status == 200) {
				
				container.style.display = "inline";
				container.innerHTML = ajax.responseText;				
								
			} else if (ajax.status == 404) {
				preloader.innerHTML = "La página no existe";
				
			} else {
				preloader.innerHTML = "Error:".ajax.status;
				
			}

		}
		
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	if(varname != null) {
		ajax.send("varname=" + varname + "&" +varname + "=" + nom);
	} else {
		ajax.send("");
	}
}

function LoadResultsModels(id_desti, page, varname) {

	var nom, container;
	
	container = document.getElementById(id_desti);
	container.style.display = "inline";
	
	//alert(id_desti);
	if(varname != null) {	
		nom = document.getElementById(varname).value;
	}
	
	ajax = AjaxRequest();
	ajax.open("POST", page, true);
	ajax.onreadystatechange = function() {
	
	 if (ajax.readyState == 4) {
		
			if (ajax.status == 200) {
				
				container.style.display = "inline";
				container.innerHTML = ajax.responseText;
				
				var seleccion = document.getElementById("modelo");
				var index = seleccion.selectedIndex;
				var modelo = seleccion.options[index].value;
				
				seleccion = document.getElementById("color");
				index = seleccion.selectedIndex;
				var color = seleccion.options[index].value;	
				
				seleccion = document.getElementById("lente");
				index = seleccion.selectedIndex;
				var lente = seleccion.options[index].value;
				
				seleccion = document.getElementById("calibre");
				index = seleccion.selectedIndex;
				var calibre = seleccion.options[index].value;
				
				if(modelo > -2 && color > -2 && lente > -2 && calibre > -2) {				
					LoadRefAndFoto();
				}
								
			} else if (ajax.status == 404) {
				preloader.innerHTML = "La página no existe";
				
			} else {
				preloader.innerHTML = "Error:".ajax.status;
				
			}

		}
		
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	if(varname != null) {
		ajax.send("varname=" + varname + "&" +varname + "=" + nom);
	} else {
		ajax.send("");
	}
}
