var opActiva="";

function EsconderTabla(Num,Total)
{	//alert(opActiva);
	//alert(Num);

	for (i=0;i<Total;i++)
	{	document.getElementById(i).style.display='none';	}
		
	//alert(document.getElementById(Num).style.display);	
	
	if (document.getElementById(Num).style.display=='block') 
	{ 	document.getElementById(Num).style.display='none';
		document.getElementById(opActiva).style.display='block';
	}
	else
	{	document.getElementById(Num).style.display='block';	
		if ((opActiva!="") && (opActiva!=Num))		
			document.getElementById(opActiva).style.display='none';			
	}
	
	opActiva=Num;
}

function Tecla(Campo,funcion)
{	if (self.event.keyCode == 13 )
	{	self.event.keyCode = 9;
		if (self.event.srcElement.name == Campo)
		{	if (funcion=='FormularioPC')
			{	EnviarFormularioPC();
				//AbrirVentana();
			}	
			if (funcion=='FormularioBuscador')
			{	EnviarFormularioBuscador();	
				//AbrirVentana();
			}	
			if (funcion=='FormularioPedido3')
			{	EnviarFormularioPedido3();	}	
		}
		
	}	
}

function EnviarFormularioPC()
{	if (document.getElementById('PC').value=='')
	{	alert("Informe la palabra clave.");
		document.getElementById('PC').focus();
		return false;
	}
	document.FormularioPC.submit();
}

function AbrirVentana()
{	WindowOpenCentrado("loading.asp", 'animacion','resizable=no,statusbar=no,scrollbars=no', 250, 250, 50);	}

function Cargando()
{	if (document.readyState=="complete")
	{	document.getElementById('Loading').style.display='none';	}
	else
	{	setTimeout("Cargando()",100)		}
}

function WindowOpenCentrado(url, name, param,w, h, perc) 
{ 	var winX = (screen.availWidth - w)*perc*.01;
	var winY = (screen.availHeight - h)*perc*.01;
	popupWin = window.open(url, name, 'width=' + w + ',height=' + h +',left=' + winX + ',top=' + winY + ','+param);
}

function EnviarFormularioBuscador()
{	if ((document.getElementById("Descripcion").value=="") && (document.getElementById("CodigoArticulo").value=="") && (document.getElementById("DescripcionLinea").value=="") && (document.getElementById("Normativa").value==""))
	{	alert("Informe al menos uno de los campos de búsqueda.");
		document.getElementById("Descripcion").focus();
		return false;
	}
	document.FormularioBuscador.submit();
}

function RevisarCantidad(obj)
{	if (obj.value!="")
	{	var number = parseFloat(obj.value);
		if (isNaN(number)==true)
		{	alert("Sólo valores numéricos ..."); 
			obj.focus();
		}
		else
		{	if(number==0)
			{	alert("Informar un valor mayor o menor de 0."); 
				obj.focus();
			}
		}
	}	
}

function EnviarFormularioPedido3()
{	
	if (document.getElementById("empresa").value=="")
	{	alert("Informe su Empresa");
		document.getElementById("empresa").focus();
		return false;
	}
	if (document.getElementById("nif").value=="")
	{	alert("Informe su NIF");
		document.getElementById("nif").focus();
		return false;
	}
	if (document.getElementById("contacto2").value=="")
	{	alert("Informe la persona de contacto");
		document.getElementById("contacto2").focus();
		return false;
	}
	if (document.getElementById("direccion").value=="")
	{	alert("Informe la dirección completa de envío");
		document.getElementById("direccion").focus();
		return false;
	}
	if (document.getElementById("codigopostal").value=="")
	{	alert("Informe el código postal");
		document.getElementById("codigopostal").focus();
		return false;
	}
	if (document.getElementById("poblacion").value=="")
	{	alert("Informe la población");
		document.getElementById("poblacion").focus();
		return false;
	}
	if (document.getElementById("provincia").value=="")
	{	alert("Informe la provincia");
		document.getElementById("provincia").focus();
		return false;
	}
	if (document.getElementById("telefono").value=="")
	{	alert("Informe el teléfono");
		document.getElementById("telefono").focus();
		return false;
	}
	if (document.getElementById("fax").value=="")
	{	alert("Informe el fax");
		document.getElementById("fax").focus();
		return false;
	}
	if (document.getElementById("email").value=="")
	{	alert("Informe su email");
		document.getElementById("email").focus();
		return false;
	}
	else (document.getElementById("email").value!="")
	{	arroba=document.getElementById("email").value.indexOf("@");
		punto=document.getElementById("email").value.indexOf(".",arroba);
		if (arroba<1 || (punto-arroba)<2 || punto==(document.getElementById("email").value.length-1))
		{	alert("Introducir una dirección de correo electrónico correcta.")
			document.getElementById("email").focus();
			return (false);
		}
	}
	if (document.getElementById("observaciones").value=="")
	{	alert("Informe sus Observaciones");
		document.getElementById("observaciones").focus();
		return false;
	}
	
	document.FormularioPedido3.submit();
}

function EnviarFormularioPedido4()
{	
	if (!(document.getElementById("Condiciones").checked))
	{	alert("Debe leer y aceptar las condiciones generales.");
		document.getElementById("Condiciones").focus();
		return false;
	}
	document.FormularioPedido4.submit();
}

