/****************************************************************
/ Nombre: getHTTPObject
/ Implentacion: 
/ Revision: 301106
/ Descripcion: Manejo del AJAX
'***************************************************************/
function getHTTPObject() {
	var xmlhttp;      
  
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {  
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	}
	return xmlhttp;
}
    
//--
var http = getHTTPObject(); 

function cambiarProducto(){
	

	marca=document.getElementById("formularioBusqueda").marca.value;
	familia=document.getElementById("formularioBusqueda").familia.value;
	subfamilia=document.getElementById("formularioBusqueda").subfamilia.value;
	if (marca!="x" && marca!="xx"){
		url = "cambiar-productos.asp?marca=" + marca + "&familia=" + familia + "&subfamilia=" + subfamilia;
		http.open("GET", url , true);
		http.onreadystatechange = handleHttpResponseCambiarProducto;
		http.send(null);		
	}

}


function handleHttpResponseCambiarProducto() {
	if (http.readyState == 4) {    
		respuesta=http.responseText
		document.getElementById("capaGlobal").innerHTML = respuesta;
	}    
}

function cambiarCategoria(){
	
	marca=document.getElementById("formularioBusqueda").marca.value;
	familia=document.getElementById("formularioBusqueda").familia.value;
	if (familia!="x" && familia!="xx"){
		url = "cambiar-categorias.asp?familia=" + familia + "&marca=" + marca;
		http.open("GET", url , true);
		http.onreadystatechange = handleHttpResponseCambiarCategoria;
		http.send(null);		
	}

}


function handleHttpResponseCambiarCategoria() {
	if (http.readyState == 4) {    
		respuesta=http.responseText
		document.getElementById("capaCategorias").innerHTML = respuesta;
	}    
}

function buscar(){
	var texto1="";
	var texto2="";
	var texto3="";
	if(document.getElementById("formularioBusqueda").marca.value=="x" || document.getElementById("formularioBusqueda").marca.value=="xx"){
		texto1="* Debe seleccionar una marca para buscar.\n"
	}
	if(document.getElementById("formularioBusqueda").familia.value=="x" || document.getElementById("formularioBusqueda").familia.value=="xx"){
		texto2="* Debe seleccionar un producto para buscar.\n"
	}
	if(document.getElementById("formularioBusqueda").subfamilia.value=="x" || document.getElementById("formularioBusqueda").subfamilia.value=="xx"){
		texto3="* Debe seleccionar una categoria para buscar.\n"
	}
	
	if (texto1!="" && texto2!="" && texto3!=""){
		 var texto=""
		 texto=texto1 + texto2 + texto3;
		alert(texto);	
	}else{
		document.getElementById("formularioBusqueda").submit();	
	}
}


function handleHttpResponseComprobarDatos() {
	if (http.readyState == 4) {    
		respuesta=http.responseText
		if (respuesta=="si"){
			document.getElementById("formulario").submit();
		}else{
			alert("* Email o clave incorrectas.")	
		}
	}    
}

function cambiaColor(){
	var color=document.getElementById("colores").value	;
	
	url = "cambiar-color.asp?id=" + color;
	http.open("GET", url , true);
	http.onreadystatechange = handleHttpResponseCambiarColor;
	http.send(null);
	
}

function handleHttpResponseCambiarColor() {
	if (http.readyState == 4) {    
		var respuesta=http.responseText
		document.getElementById("capaColor").style.backgroundColor="#" + respuesta;
	}    
}