// JavaScript Document
function searchProducts(){
	if(document.getElementById("idFam").value == "" && document.getElementById("q").value.length == 0){
		alert("Debes elegir al menos una Familia o escribir un critero de busqueda");
	}else{
		//alert("Buscando...");
		famExist = document.getElementById("checSubValid").value
		subExist = document.getElementById("checLineaValid").value;	
		//alert(famExist+ " " +subExist)
		if(famExist == 0 && subExist == 1 ){
			//VERIFICAMOS SI SE SELECCIONO UNA LINEA
			if(document.getElementById("idL").value == ""){
				//BUSCAMOS SIN LINEA
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value;
				document.form1.submit();
			}else{
				//BUSCAMOS CON LINEA
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&idL="+document.getElementById("idL").value+"&q="+document.getElementById("q").value;
				document.form1.submit();
			}
		}else if(famExist == 1 && subExist == 1){
			//VERIFICAMOS SI SE SELECCIONO UNA LINEA
			if(document.getElementById("idL").value == ""){
				//BUSCAMOS SIN LINEA
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value;
				document.form1.submit();
			}else{
				//BUSCAMOS CON LINEA
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&idL="+document.getElementById("idL").value+"&q="+document.getElementById("q").value;
				document.form1.submit();
			}
		}else if(famExist ==0 && subExist == 0){
			obj = document.getElementById("idSub");
			//alert(obj);
			if(obj != null){
				//alert("entro existe");
				//document.form1.method = "POST";
				//document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value;
				//document.form1.submit();
				obj2 = document.getElementById("idL");
				if(obj2 == null){
					document.form1.method = "POST";
					document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value;
					document.form1.submit();
				}else{
					if(document.getElementById("idL").value == ""){					
						//BUSCAMOS SIN LINEA
						document.form1.method = "POST";
						document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value;
						document.form1.submit();
					}else{
						//BUSCAMOS CON LINEA
						document.form1.method = "POST";
						document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&idL="+document.getElementById("idL").value+"&q="+document.getElementById("q").value;
						document.form1.submit();
					}
				}
			}else{
				//alert("entro NO existe");
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&q="+document.getElementById("q").value;
				document.form1.submit();
			}
		}else if(famExist ==1 && subExist == 0){
			document.form1.method = "POST";
			document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value;
			document.form1.submit();
		}
	}
}
//-->
function validar(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	if(tecla==13){
		if(document.getElementById("idFam").value == "" && document.getElementById("q").value.length == 0){
		alert("Debes elegir al menos una Familia o escribir un critero de busqueda");
		}else{
			//alert("Buscando...");
			famExist = document.getElementById("checSubValid").value
			subExist = document.getElementById("checLineaValid").value;	
			//alert(famExist+ " " +subExist)
			if(famExist == 0 && subExist == 1 ){
				//VERIFICAMOS SI SE SELECCIONO UNA LINEA
				if(document.getElementById("idL").value == ""){
					//BUSCAMOS SIN LINEA
					document.form1.method = "POST";
					document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value
					document.form1.submit();
				}else{
					//BUSCAMOS CON LINEA
					document.form1.method = "POST";
					document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&idL="+document.getElementById("idL").value+"&q="+document.getElementById("q").value
					document.form1.submit();
				}
			}else if(famExist == 1 && subExist == 1){
				//VERIFICAMOS SI SE SELECCIONO UNA LINEA
				if(document.getElementById("idL").value == ""){
					//BUSCAMOS SIN LINEA
					document.form1.method = "POST";
					document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value
					document.form1.submit();
				}else{
					//BUSCAMOS CON LINEA
					document.form1.method = "POST";
					document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&idL="+document.getElementById("idL").value+"&q="+document.getElementById("q").value
					document.form1.submit();
				}
			}else if(famExist ==0 && subExist == 0){
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&q="+document.getElementById("q").value
				document.form1.submit();
			}else if(famExist ==1 && subExist == 0){
				document.form1.method = "POST";
				document.form1.action = "buscar.asp?idFam="+document.getElementById("idFam").value+"&idSub="+document.getElementById("idSub").value+"&q="+document.getElementById("q").value
				document.form1.submit();
			}
		}
	}	
}
//-->
function IsNumber(e) {
tecla = (document.all) ? e.keyCode : e.which;
if (tecla==8) return true;
patron = /\d/; // Solo acepta números
te = String.fromCharCode(tecla);
return patron.test(te);
} 