/*********FUNCION QUE HACE OBLIGATORIOS ALGUNOS CAMPOS**********************/

function validar(formulario)
{
	var val=true; //esta bandera sirve para verficar si manda los datos o no los manda
	var flag=false;
	
	with(formulario)
	{
		 // condiccion para los campos obligatorios
		for(i=0;i<elements.length;i++)
		{
			if(elements[i].name == "ALTO" || elements[i].name == "ANCHO" || elements[i].name == "FUELLE")  
			{
				if(elements[i].value == "")
				{
					alert("El campo "+elements[i].name+" es obligatorio");
					val=false;
				}	
			}
			if (elements[i].name == "ID" && elements[i].checked == true)
				flag=true;
		}
		if(flag==false)	
		{
			alert("Debe elegir un precio de los mostrados en el tablero");
			val=false;
		}	
		//No permitir que los valores sean nulos o letras
		if(isNaN(new Number(ANCHO.value)))
		{
			alert("El valor del ANCHO debe ser numérico");
			val=false;
		}
		if(isNaN(new Number(FUELLE.value)))
		{	
			alert("El valor del FUELLE debe ser numérico");
			val=false;
		}
		
		if(isNaN(new Number(ALTO.value)))
		{
			alert("El valor del ALTO debe ser numérico");
			val=false;
		}
		
		if(isNaN(new Number(Cliche_Uno_Alto.value)) || isNaN(new Number(Cliche_Dos_Alto.value)) || isNaN(new Number(Cliche_Tres_Alto.value)) || isNaN(new Number(Cliche_Cuatro_Alto.value)))
		{
			alert("El valor de todos los campos ALTO debe ser numérico");
			val=false;
		}
		if(isNaN(new Number(Cliche_Uno_Ancho.value)) || isNaN(new Number(Cliche_Dos_Ancho.value)) || isNaN(new Number(Cliche_Tres_Ancho.value)) || isNaN(new Number(Cliche_Cuatro_Ancho.value)))
		{
			alert("El valor de los todos lo campos ANCHO debe ser numérico");
			val=false;
		}				
		//condiccion de que el ancho debe ser mayor en 2 cm al fuelle
		if(ANCHO.value != "" && FUELLE.value != "")
		{
			if(ANCHO.value-FUELLE.value < 2)
			{
				alert("El ANCHO debe ser MAYOR EN 2 CM al FUELLE");
				val=false
			}
		}
	}
	return val;	
}

/*********FUNCION QUE HACE OBLIGATORIOS ALGUNOS CAMPOS**********************/
function validarPrivado(formulario)
{
	var val=true; //esta bandera sirve para verficar si manda los datos o no los manda
	var flag=false;
	
	with(formulario)
	{
		for(i=0;i<elements.length;i++)
		{
			if(elements[i].name == "ALTO" || elements[i].name == "ANCHO" || elements[i].name == "FUELLE")  
			{
				if(elements[i].value == "")
				{
					alert("El campo "+elements[i].name+" es obligatorio");
					val=false;
				}	
			}
			if (elements[i].name == "ID" && elements[i].checked == true)
				flag=true;
		}
		if(flag==false)	
		{
			alert("Debe elegir un papel de los mostrados en el tablero");
			val=false;
		}	
		//No permitir que los valores sean nulos o letras
		if(isNaN(new Number(ANCHO.value)))
		{
			alert("El valor del ANCHO debe ser numérico");
			val=false;
		}
		if(isNaN(new Number(FUELLE.value)))
		{	
			alert("El valor del FUELLE debe ser numérico");
			val=false;
		}
		
		if(isNaN(new Number(ALTO.value)))
		{
			alert("El valor del ALTO debe ser numérico");
			val=false;
		}	
		//condiccion de que el ancho debe ser mayor en 2 cm al fuelle
		if(ANCHO.value != "" && FUELLE.value != "")
		{
			if(ANCHO.value-FUELLE.value < 2)
			{
				alert("El ANCHO debe ser MAYOR EN 2 CM al FUELLE");
				val=false
			}
		}
	}
	return val;	
}


//Funcion que muestra los colores al comienso si tiene datos
function ColoresAlCargar()
{
	if(document.formulario.Cliche_Uno_Alto.value != "" ||  document.formulario.Cliche_Uno_Ancho.value != "")
	{
		Capa=document.getElementById("Color1");
		Capa.style.visibility="visible";
	}
	if(document.formulario.Cliche_Dos_Alto.value != "" ||  document.formulario.Cliche_Dos_Ancho.value != "")
	{
		Capa=document.getElementById("Color2");
		Capa.style.visibility="visible";
	}
	if(document.formulario.Cliche_Tres_Alto.value != "" ||  document.formulario.Cliche_Tres_Ancho.value != "")
	{
		Capa=document.getElementById("Color3");
		Capa.style.visibility="visible";
	}
	if(document.formulario.Cliche_Cuatro_Alto.value != "" ||  document.formulario.Cliche_Tres_Ancho.value != "")
	{
		Capa=document.getElementById("Color4");
		Capa.style.visibility="visible";
	}
}

//Funcion que muestra los colores y pone gramaje al pinchar
function MuestraColores(NumColores,Gramaje)
{
	with (document.formulario)
	{	
		for(i=1;i<=NumColores;i++)
		{
			Capa=document.getElementById("Color"+i);
			Capa.style.visibility="visible";
		}
		for(i=4;i>NumColores;i--)
		{
			Capa=document.getElementById("Color"+i);
			Capa.style.visibility="hidden";
		}
		for(i=0;i<=GRAMAJE.options.length-1;i++)
		{
			if(GRAMAJE.options[i].value < Gramaje )
			{
				GRAMAJE.options[i].text='-';
			}
			if(GRAMAJE.options[i].value == Gramaje )
			{
				GRAMAJE.options[i].selected=true;
				GRAMAJE.options[i].text=GRAMAJE.options[i].value;
			}
			if(GRAMAJE.options[i].value > Gramaje )
			{
				GRAMAJE.options[i].text=GRAMAJE.options[i].value;
			}
		}

	}
}
