<!-- Atualizado em 31/01/12 (1) -->
function VerificaNotebook(form){
	if(form.industria.value == ''){
		alert('Selecione a indústria fabricante do Notebook.');
		form.industria.focus();
		return false;
	}
	if(form.cepDestino.value == ''){
		alert('Selecione o CEP de entrega do Notebook.');
		form.cepDestino.focus();
		return false;
	}	
}

/*function buscaFormato (){
	open('http://sac0119/scpr/prazo/formato.cfm','ShowFormato','location=no,resize=no, width=500,height=320,left=18,top=18,maximized=1,scrollbars=1');
}*/
// FIX134 - End - 05/02/2010


function Valida(form)
{
	if(form.servico.value == '')
	{
		alert('Selecione o tipo de serviço desejado.');
		form.servico.focus();
		return false;
	}
	if(form.cepOrigem.value == '' || form.cepDestino.value == '')
	{
		alert('Informe o CEP de Origem e de Destino.');
		form.cepOrigem.focus();
		return false;
	}
	if(form.cepOrigem.value != '')
	{
		if(!validarCep(form.cepOrigem.value))
		{
			alert('Cep de Origem Inválido!!!!');
			form.cepOrigem.focus();
			return false;
		}
	}
	
	if(form.cepDestino.value != '')
	{
		if(!validarCep(form.cepDestino.value))
		{
			alert('Cep de Destino Inválido!');
			form.cepOrigem.focus();
			return false;
		}		
	}
	
	if(form.peso.value != '')
	{		
		if(form.servico.value=="40045") // SEDEX A COBRAR ////////////////////////////////////////////////////////////////////
		{
			if(form.valorD.value == '')
			{
				alert('O Valor Declarado é obrigatório para esse serviço.');
				form.valorD.focus();
				return false;
			}
			
			if(form.Formato.value == '1')
			{
				return validarCaixa(form);
			}
			if(form.Formato.value == '2')
			{
				if(validarPrisma(form)==false)
				{
					return false;
				}
				form.Largura.value = form.Diametro.value;
				form.Altura.value = form.Diametro.value;
			}
			
			/*if(form.avisoRecebimento.value == 'S')
			{
				alert('O serviço SEDEX A COBRAR não aceita Aviso de Recebimento');
				return false;
			}*/
			/*if(form.MaoPropria.value == 'S'){
				alert('O serviço SEDEX A COBRAR não aceita Mão Própria.');
				return false;
			}*/
		}		
		
		if(form.servico.value=="40010" || form.servico.value=="40215" || form.servico.value=="40290" || form.servico.value=="40045") // SEDEX, SEDEX 10 ou SEDEX HOJE///////////////////////
		{
			if(form.Formato.value == '1')
			{
				return validarCaixa(form);
			}
			if(form.Formato.value == '2')
			{
				if(validarPrisma(form)==false)
				{
					return false;
				}
				form.Largura.value = form.Diametro.value;
				form.Altura.value = form.Diametro.value;
			}
			//Wesley em 28/04/2011 - PAP 26718
			if(form.Formato.value == '3')
			{
				return validarEnvelope(form);
			}
		}		
		
		if(form.servico.value=="41106") // PAC ////////////////////////////////////////////////////////////////////////
		{
			if(form.Formato.value == '1')
			{
				return validarCaixa(form);
			}
			if(form.Formato.value == '2')
			{
				if(validarPrisma(form)==false)
				{
					return false;
				}
				form.Largura.value = form.Diametro.value;
				form.Altura.value = form.Diametro.value;
			}
			//Wesley em 28/04/2011 - PAP 26718
			if(form.Formato.value == '3')
			{
				return validarEnvelope(form);
			}
		}
		
		if(form.servico.value=="43010") // REEMBOLSO POSTAL ///////////////////////////////////////////////////////////////////////////////////////////////////
		{
			if(form.valorDeclarado.value == '')
			{
				alert('O Valor Declarado é obrigatório para esse serviço.');
				form.valorDeclarado.focus();
				return false;
			}
			
			if(form.Formato.value == '1')
			{
				return validarCaixa(form);
			}
			if(form.Formato.value == '2')
			{
				if(validarPrisma(form)==false)
				{
					return false;
				}
				form.Largura.value = form.Diametro.value;
				form.Altura.value = form.Diametro.value;
			}
			return true;
		}
		
		//Validações para o campo Valor Declarado
		if(form.valorDeclarado.value != '')
		{
			var vd = form.valorDeclarado.value;
			vd = vd.replace(".","");
			vd = vd.replace(",",".");
			if(isNaN(vd))
			{
				alert('Valor Declarado inválido');
				return false;
			}
			else
			{
				if(vd > 10000)
				{
					alert('O valor declarado não deve ultrapassar R$ 10.000,00');
					return false;
				}
			}
		}
	}
	else
	{
		if((form.MaoPropria.value=="S" || form.valorDeclarado.value!="" || form.avisoRecebimento.value=="S") && form.peso.value=="")
		{
			alert('Infome o peso para o cálculo de preços da sua encomenda.');
			return false;	
		}	
	}	
}

function VerificaServico(form)
{
	// Desabilitar os seviços adicionais Mão Própria e Aviso de recebimento para p/ Servico "Sedex a Cobrar"
	form = document.formulario;
	/*if (!form){
		alert('entrei');
		form = document.formulario;
	}*/
	//FIX133 - End - 02/02/2010
	

	if(form.servico.value == "40045") // SEDEX A COBRAR //////////////////////////////////////////////////////////////////////////////////////////////////////
	{
		form.MaoPropria.value = "N";
		form.avisoRecebimento.value = "N";
		document.all.spanDiametro.style.display="none";
		document.all.spanEmbalagem.style.display="";
		document.all.spanMaoPropria.style.display="";
		// Permitir contratar o serviço opcional AR (Aviso de Recebimento) para o SEDEX A COBRAR.
		// document.all.spanServicoAdicional.style.display="none";
		document.all.spanValorDeclarado.style.display="none";
		document.all.spanServicoAdicional.style.display="";		
		document.all.spanSEDEXCOBRAR.style.display="";
		document.all.spanComprimento.style.display="";
		document.all.spanFormato.style.display="";
		document.all.spanData.style.display="";
	}
	else
	{
		document.all.spanSEDEXCOBRAR.style.display="none";
		document.all.spanServicoAdicional.style.display="";
		document.all.spanValorDeclarado.style.display="";
		document.getElementById('spanEmbalagem').style.display 	= "";
		document.getElementById('spanMaoPropria').style.display = "";
		document.all.spanData.style.display="";
	}
	
	if(form.servico.value == "41106" ||//PAC--------------------------
	   form.servico.value == "40010" ||//SEDEX------------------------
	   form.servico.value == "40045" ||//SEDEX A COBRAR---------------
	   form.servico.value == "40215" ||//SEDEX 10---------------------
	   form.servico.value == "40290")  //SEDEX HOJE-------------------
	{
		// Se Formato igual CAIXA/PACOTE /////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////
		if(form.Formato.value == "1")
		{
			form.Diametro.value == "";
			form.Diametro.disabled = true;
			document.all.spanDiametro.style.display="none";
			document.all.spanLargura.style.display="";
			document.all.spanEmbalagem.style.display="";
			document.all.spanMaoPropria.style.display="";
			//Wesley em 28/04/2011 - PAP 26718
			document.all.spanAltura.style.display="";
			document.all.spanData.style.display="";
		}
		
		// Se Formato igual ROLO/PRISMA //////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////
		if(form.Formato.value == "2")
		{
			document.getElementById('spanLargura').style.display 	= 'none';
			document.getElementById('spanEmbalagem').style.display 	= "";
			document.getElementById('spanMaoPropria').style.display = "";
			//Wesley em 28/04/2011 - PAP 26718
			document.all.spanAltura.style.display="";
		}
				
		// Se Formato igual ENVELOPE /////////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////
		if(form.Formato.value == "3") //Envelope SEDEX
		{
			form.Diametro.value == "";
			form.Diametro.disabled = true;
			document.getElementById('spanDiametro').style.display 	= "none";
			document.getElementById('spanAltura').style.display= "none";
			document.getElementById('spanLargura').style.display 	= "";
		}
		
		document.all.spanFormato.style.display="";
		document.all.spanComprimento.style.display="";
		
		//// se não for SEDEX, não mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value != "40010" && form.Formato.length == 3) 
		{
			if(form.Formato.value == "3") //Envelope SEDEX
			{
				form.Formato.selectedIndex = 0;
				ValidarFormato(form);
			}
			form.Formato.remove(form.Formato.length-1);
		}
		
		//// se não for SEDEX 10, não mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value != "40215" && form.Formato.length == 3) 
		{
			if(form.Formato.value == "3") //Envelope SEDEX
			{
				form.Formato.selectedIndex = 0;
				ValidarFormato(form);
			}
			form.Formato.remove(form.Formato.length-1);
		}
		
		//// se não for SEDEX HOJE, não mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value != "40290" && form.Formato.length == 3) 
		{
			if(form.Formato.value == "3") //Envelope SEDEX
			{
				form.Formato.selectedIndex = 0;
				ValidarFormato(form);
			}
			form.Formato.remove(form.Formato.length-1);
		}
		
		//// se não for SEDEX A COBRAR, não mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value != "40045" && form.Formato.length == 3) 
		{
			if(form.Formato.value == "3") //Envelope SEDEX
			{
				form.Formato.selectedIndex = 0;
				ValidarFormato(form);
			}
			form.Formato.remove(form.Formato.length-1);
		}
		
		// se for SEDEX, mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value == "40010" && form.Formato.length == 2)
		{
			try
			{
			 	form.Formato.add(new Option("Envelope", "3"), null) 
			}
			catch(e)
			{
				form.Formato.add(new Option("Envelope", "3")) 
			}
		}
		
		// se for SEDEX 10, mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value == "40215" && form.Formato.length == 2)
		{
			try
			{
			 	form.Formato.add(new Option("Envelope", "3"), null) 
			}
			catch(e)
			{
				form.Formato.add(new Option("Envelope", "3")) 
			}
		}
		
		// se for SEDEX HOJE, mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value == "40290" && form.Formato.length == 2)
		{
			try
			{
			 	form.Formato.add(new Option("Envelope", "3"), null) 
			}
			catch(e)
			{
				form.Formato.add(new Option("Envelope", "3")) 
			}
		}
		
		// se for SEDEX A COBRAR, mostra o envelope
		////////////////////////////////////////////////////////////////////// - ENVELOPE
		if(form.servico.value == "40045" && form.Formato.length == 2)
		{
			try
			{
			 	form.Formato.add(new Option("Envelope", "3"), null) 
			}
			catch(e)
			{
				form.Formato.add(new Option("Envelope", "3")) 
			}
		}
	}
	else
	{
		document.all.spanFormato.style.display="none";
		document.all.spanComprimento.style.display="none";
		form.Comprimento.value = "";
		form.Largura.value = "";
		form.Altura.value = "";
		form.Diametro.value = "";
	}
	
	if(form.servico.value == "43010") // REEMBOLSO POSTAL ///////////////////////////////////////////////////////////////////
	{
		if(form.Formato.value == "1")
		{
			form.Diametro.value == "";
			form.Diametro.disabled = true;
			//form.embalagem.disabled = true;
			//form.MaoPropria.disabled = true;
			document.all.spanDiametro.style.display="none";
			document.all.spanLargura.style.display="";
			document.all.spanEmbalagem.style.display="none";
			document.all.spanMaoPropria.style.display="none";
			document.all.spanData.style.display="none";
		}		
		else
		{
			document.getElementById('spanLargura').style.display 	= 'none';
			document.getElementById('spanEmbalagem').style.display 	= "";
			document.getElementById('spanMaoPropria').style.display = "";
			document.spanData('spanMaoPropria').style.display = "";
		}		
		document.all.spanFormato.style.display="";
		document.all.spanComprimento.style.display="";		
	}
		
	// 18710 Evolutiva 
	if(form.servico.value == "44105" || // MALOTE-------------------
	   form.servico.value == "85480" || // AEROGRAMA----------------
	   form.servico.value == "10030" || // CARTA SIMPLES------------
	   form.servico.value == "10014" || // CARTA REGISTRADA---------
	   form.servico.value == "16012" || // CARTÃO POSTAL------------
	   form.servico.value == "20010" || // IMPRESSO-----------------
	   form.servico.value == "14010" || // MALA DIRETA--------------
	   form.servico.value == "81019")	// E-SEDEX------------------
	{
		if (form.servico.value != "81019") // E-SEDEX
		{
			document.all.spanServico.style.display="none";
			document.all.spanServicoSelecionado.style.display="none";
			document.all.spanBotao.style.display="none";
			document.all.spanData.style.display="none";
		}
		else
		{
			document.all.spanServico.style.display="none";
			document.all.spanServicoSelecionado.style.display="none";		
			document.all.spanBotao.style.display="none";
			document.all.spanData.style.display="";
		}			
	}
	else
	{
		document.all.spanServico.style.display="";
		document.all.spanServicoSelecionado.style.display="";		
		document.all.spanBotao.style.display="";
		document.all.spanData.style.display="";
	}
}	


function ValidarFormato(form)
{
	if(form.Formato.value=="1")
	{
		form.Largura.disabled=false;
		form.Altura.disabled=false;
		form.Diametro.value="";
		form.Diametro.disabled=true;
		document.all.spanDiametro.style.display="none";
		document.all.spanLargura.style.display="";	
		document.all.spanAltura.style.display=""; //Wesley em 28/04/2011 - PAP 26718
		return false;
	}
	
	if(form.Formato.value=="2")
	{
		form.Largura.value="";
		form.Altura.value="";
		form.Largura.disabled=true;
		form.Altura.disabled=true;
		form.Diametro.disabled=false;
		document.all.spanDiametro.style.display="";
		document.all.spanLargura.style.display="none";	
		//Wesley em 28/04/2011 - PAP 26718
		document.all.spanAltura.style.display="";
		return false;
	}
	//Wesley em 28/04/2011 - PAP 26718
	if(form.Formato.value=="3")
	{
		form.Largura.disabled=false;
		form.Altura.disabled=false;
		form.Diametro.value="";
		form.Diametro.disabled=true;
		document.all.spanDiametro.style.display="none";
		document.all.spanAltura.style.display="none";
		document.all.spanLargura.style.display="";	
		return false;
	}
}


function validarCaixa(form)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////// VALIDAÇÃO CAIXA //////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{	
	if(trim(form.Comprimento.value)=="" || trim(form.Largura.value)=="" || trim(form.Altura.value)=="" )
	{ 
		alert("Para definição do preço desse serviço deverão ser informados, também, o comprimento, a largura e altura do objeto em centímetros (cm).");
		form.Comprimento.focus();
		return false;		
	}
	/*if(trim(form.Comprimento.value)==""){ 
		alert("Informe o comprimento.");
		form.Comprimento.focus();
		return false;
	}*/
	if(trim(form.Comprimento.value)!="")
	{ 
		var vd = form.Comprimento.value;	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Comprimento inválido.");
			form.Comprimento.focus();
			return false;
		}	
		var fComprimento = parseFloat(vd);
	}
	
	/*if(trim(form.Largura.value)==""){
		alert("Informe a largura.");
		form.Largura.focus();
		return false;
	}*/
	if(trim(form.Largura.value)!="")
	{
		var vd = form.Largura.value;	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Largura inválida.");
			form.Largura.focus();
			return false;
		}
		
		var fLargura = parseFloat(vd);
	}
	
	/*if(trim(form.Altura.value)==""){
		alert("Informe a altura.");
		form.Altura.focus();
		return false;
	}*/

	/*if(trim(form.Altura.value)==""){	*/
	if(trim(form.Altura.value)!="")
	{
		/* FIX017 - End - 29/04/2008 */
		var vd = form.Altura.value;
	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Altura inválida.");
			form.Altura.focus();
			return false;
		}
		
		var fAltura = parseFloat(vd);
	}
	
	////////////////////////////////////////////////////////////////////
	// Se serviço = PAC ////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////
	
	if(form.servico.value == "41106")
	{	
		if(fComprimento > 105)
		{
			alert("O comprimento não pode ser maior que 105 cm.");
			form.Comprimento.focus();
			return false;
		}
	
		if(fLargura > 105)
		{
			alert("A largura não pode ser maior que 105 cm.");
			form.Largura.focus();
			return false;
		}
	
		if(fAltura > 105)
		{
			alert("A altura não pode ser maior que 105 cm.");
			form.Altura.focus();
			return false;
		}
	
		if(fAltura < 2)
		{
			alert("A altura não pode ser inferior a 2 cm.");
			form.Altura.focus();
			return false;
		}
		
		if(fLargura < 11)
		{
			alert("A largura não pode ser inferior a 11 cm.");
			form.Largura.focus();
			return false;
		} 
	
		/*if(fLargura < 11)
		{
			if(fComprimento < 25)
			{
				alert("A largura não pode ser menor que 11cm, quando o comprimento for menor que 25cm");
				//alert("O comprimento não pode ser inferior a 25 cm quando a altura for maior ou igual a 5 cm e menor que 11 cm. Para altura a partir de 11 cm o comprimento mínimo é 16 cm.");
				form.Comprimento.focus();
				return false;
			}
		}*/
	
		if(fComprimento < 16)
		{
			alert("O comprimento não pode ser inferior a 16 cm.");
			form.Comprimento.focus();
			return false;
		}
	
		if((fComprimento + fLargura + fAltura) > 200)
		{
			alert("A soma resultante do comprimento + largura + altura não deve superar a 200 cm.");
			form.Comprimento.focus();
			return false;
		}
		return true;
	}
	///////////////////////////////////////////////////////////////////
	/// Se serviço DIFERENTE de PAC ///////////////////////////////////
	///////////////////////////////////////////////////////////////////
	else	
	{		
		if(fComprimento > 105)
		{
			alert("O comprimento não pode ser maior que 105 cm.");
			form.Comprimento.focus();
			return false;
		}
	
		if(fLargura > 105)
		{
			alert("A largura não pode ser maior que 105 cm.");
			form.Largura.focus();
			return false;
		}
	
		if(fAltura > 105)
		{
			alert("A altura não pode ser maior que 105 cm.");
			form.Altura.focus();
			return false;
		}
	
		if(fAltura < 2)
		{
			alert("A altura não pode ser inferior a 2 cm.");
			form.Altura.focus();
			return false;
		}
		
		if(fLargura < 11)
		{
			alert("A largura não pode ser inferior a 11 cm.");
			form.Largura.focus();
			return false;
		} 
	
		/*if(fLargura < 11)
		{
			if(fComprimento < 25)
			{
				alert("A largura não pode ser menor que 11cm, quando o comprimento for menor que 25cm");
				//alert("O comprimento não pode ser inferior a 25 cm quando a altura for maior ou igual a 5 cm e menor que 11 cm. Para altura a partir de 11 cm o comprimento mínimo é 16 cm.");
				form.Comprimento.focus();
				return false;
			}
		}
		*/
		
		if(fComprimento < 16)
		{
			alert("O comprimento não pode ser inferior a 16 cm.");
			form.Comprimento.focus();
			return false;
		}
	
		if((fComprimento + fLargura + fAltura) > 200)
		{
			alert("A soma resultante do comprimento + largura + altura não deve superar a 200 cm.");
			form.Comprimento.focus();
			return false;
		}
		return true;
	}	
}

function validarPrisma(form)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// VALIDAÇÃO ROLO OU PRISMA ///////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
	var iCtd = 0;
	if(trim(form.Comprimento.value)=="" || trim(form.Diametro.value)=="")
	{ 
		alert("Para definição do preço desse serviço deverão ser informados, também, o comprimento, e o diâmetro do objeto em centímetros (cm).");
		form.Comprimento.focus();
		return false;		
	}
	
	if(trim(form.Comprimento.value)!=="")
	{
		var vd = form.Comprimento.value;	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Comprimento inválido.");
			form.Comprimento.focus();
			return false;
		}		
		var fComprimento = parseFloat(vd);		
		iCtd = iCtd + 1;
	}
	
	if(trim(form.Diametro.value)!=="")
	{
		var vd = form.Diametro.value;	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Diâmetro inválido.");
			form.Diametro.focus();
			return false;
		}		
		var fDiametro = parseFloat(vd);
		
		iCtd = iCtd + 1;
	}
	
	if(iCtd > 0 && iCtd < 2)
	{ 
		if(trim(form.Comprimento.value)=="")
		{ 
			alert("Informe o comprimento.");
			form.Comprimento.focus();
			return false;
		}
		
		if(trim(form.Diametro.value)=="")
		{ 
			alert("Informe o diâmetro.");
			form.Diametro.focus();
			return false;
		}
	}	
	
	if(iCtd==2)
	{		
		if((fComprimento + fDiametro) > 0)
		{
			////// Se serviço for PAC ///////////////
			/////////////////////////////////////////
			if(form.servico == "41106")
			{
				if(fComprimento > 105)
				{
					alert("O comprimento não pode ser maior que 105 cm.");
					form.Comprimento.focus();
					return false;
				}
		
				if(fDiametro > 91)
				{
					alert("O diâmetro não pode ser maior que 91 cm.");
					form.Diametro.focus();
					return false;
				}
			}
			////// Se serviço for DIFERENTE de PAC ///////////////
			//////////////////////////////////////////////////////
			else
			{
				if(fComprimento > 105)
				{
					alert("O comprimento não pode ser maior que 105 cm.");
					form.Comprimento.focus();
					return false;
				}
		
				if(fDiametro > 91)
				{
					alert("O diâmetro não pode ser maior que 91 cm.");
					form.Diametro.focus();
					return false;
				}
			}
		}
		
		if(fComprimento < 18)
		{
			alert("O comprimento não pode ser inferior a 18 cm.");
			form.Diametro.focus();
			return false;
		}

		if(fDiametro < 5)
		{
			alert("O diâmetro não pode ser inferior a 5 cm.");
			form.Comprimento.focus();
			return false;
		}

		if((fComprimento + 2 * fDiametro) > 200)
		{
			alert("A soma resultante do comprimento + o dobro do diâmetro não deve superar a 200 cm.");
			form.Comprimento.focus();
			return false;
		}
	}
	return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// VALIDAÇÃO ENVELOPE ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validarEnvelope(form)
{	
	if(trim(form.Largura.value)=="" || trim(form.Comprimento.value)=="" )
	{ 
		alert("Para definição do preço desse serviço deverão ser informados, também, a largura e comprimento do objeto em centímetros (cm).");
		form.Comprimento.focus();
		return false;		
	}
	if(trim(form.Largura.value)!="")
	{
		var vd = form.Largura.value;	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Largura inválida.");
			form.Largura.focus();
			return false;
		}
		
		var fLargura = parseFloat(vd);
	}
	
	if(trim(form.Comprimento.value)!="")
	{
		var vd = form.Comprimento.value;
	
		vd = vd.replace(".","");
		vd = vd.replace(",",".");
	
		if(isNaN(vd))
		{
			alert("Comprimento inválido.");
			form.Comprimento.focus();
			return false;
		}
		
		var fComprimento = parseFloat(vd);
	}
	
	if(fComprimento < 16)
	{
		alert("O comprimento não pode ser inferior a 16 cm.");
		form.Comprimento.focus();
		return false;
	}
	if(fLargura < 11)
	{
		alert("A largura não pode ser inferior a 11 cm.");
		form.Largura.focus();
		return false;
	} 

	if(fLargura > 60)
	{
		alert("A largura não pode ser maior que 60 cm.");
		form.Largura.focus();
		return false;
	}

	if(fComprimento > 60)
	{
		alert("O Comprimento não pode ser maior que 60 cm.");
		form.Comprimento.focus();
		return false;
	}

	return true;
}

////////////////////////////////////////////////////////////////////////////////////////////// NÃO PERMITIR DATAS INVÁLIDAS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Validar data
function validaData(campo)
{
		if (campo.value!="")
		{
				erro=0;
				hoje = new Date();
				anoAtual = hoje.getFullYear();
				barras = campo.value.split("/");
				if (barras.length == 3)
				{
						dia = barras[0];
						mes = barras[1];
						ano = barras[2];
						resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
						if (!resultado)
						{
								alert("Data inválida.");
								campo.focus();
								campo.value = formulario.dataAtual.value;
								return false;
						}
				 } 
				 else
				 {
						 alert("Data inválida.");
						 campo.focus();
						 return false;
				 }
		return true;
		}
}

function formata(val)
{
	var pass = val.value;
	var expr = /[0123456789]/;
		
	for(i=0; i<pass.length; i++){
		// charAt -> retorna o caractere posicionado no índice especificado
		var lchar = val.value.charAt(i);
		var nchar = val.value.charAt(i+1);
	
		if(i==0){
		   // search -> retorna um valor inteiro, indicando a posição do inicio da primeira
		   // ocorrência de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o método retornara -1
		   // instStr.search(expReg);
		   if ((lchar.search(expr) != 0) || (lchar>3)){
			  val.value = "";
		   }
		   
		}else if(i==1){
			   
			   if(lchar.search(expr) != 0){
				  // substring(indice1,indice2)
				  // indice1, indice2 -> será usado para delimitar a string
				  var tst1 = val.value.substring(0,(i));
				  val.value = tst1;				
				  continue;			
			   }
			   
			   if ((nchar != '/') && (nchar != '')){
					var tst1 = val.value.substring(0, (i)+1);
				
					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '/' + tst2;
			   }

		 }else if(i==4){
			
				if(lchar.search(expr) != 0){
					var tst1 = val.value.substring(0, (i));
					val.value = tst1;
					continue;			
				}
		
				if	((nchar != '/') && (nchar != '')){
					var tst1 = val.value.substring(0, (i)+1);

					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '/' + tst2;
				}
		  }
		
		  if(i>=6){
			  if(lchar.search(expr) != 0) {
					var tst1 = val.value.substring(0, (i));
					val.value = tst1;			
			  }
		  }
	 }
	
	 if(pass.length>10)
		val.value = val.value.substring(0, 10);
		return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////// Funçõe para verificar se a data informada abrange um período maior que 365 dias/////////////////////////////////////////////////////////////
function validaData(date)
{
   var err = 0
   string = date
   var valid = "0123456789/"
   var ok = "yes";
   var temp;
   for (var i=0; i< string.length; i++)
   {
     temp = "" + string.substring(i, i+1);
     if (valid.indexOf(temp) == "-1") err = 1;
   }  
   if (string.length != 10) err=1
   b = string.substring(3, 5)        // month
   c = string.substring(2, 3)        // '/'
   d = string.substring(0, 2)        // day 
   e = string.substring(5, 6)        // '/'
   f = string.substring(6, 10)    // year
   if (b<1 || b>12) err = 1
   if (c != '/') err = 1
   if (d<1 || d>31) err = 1
   if (e != '/') err = 1
   if (f<1850 || f>2050) err = 1
   if (b==4 || b==6 || b==9 || b==11){
   if (d==31) err=1
   }
   if (b==2){
     var g=parseInt(f/4)
     if (isNaN(g)) {
         err=1 
     }
     if (d>29) err=1
     if (d==29 && ((f/4)!=parseInt(f/4))) err=1
   }
   if (err==1) {
       alert("Data inválida");
	   document.getElementById('data').value = document.getElementById('dataAtual').value;
	   document.getElementById('data').focus();
	   return false;
   }
   else {      
    return true;
   }
}


function verificaDataFutura()
{
	// Verifica se data2 é maior que data1
	var data2 = formulario.data.value;  
	var data1 = formulario.dataAtual.value;
	
	if ( parseInt( data2.split( "/" )[2].toString() + data2.split( "/" )[1].toString() + data2.split( "/" )[0].toString() ) > parseInt( data1.split( "/" )[2].toString() + data1.split( "/" )[1].toString() + data1.split( "/" )[0].toString() ) )
	{
	  alert( "Não é possível informar data futura." );
	  document.getElementById('data').value = formulario.dataAtual.value;
	  return false;
	}
	return Valida(document.formulario);
}
//-----------------------------------
// Função chamada pelo formulário
function calcPeriodo(dt1,dt2)
{
	dia = toDate(dt1.value);
	diaStr = toDateStr(dateAdd('m',-12, dia));
	diferenca = dias(dt2.value, diaStr);		
	if ( dias(document.getElementById('data').value,  document.getElementById('dataAtual').value ) > 365 )
	{
		alert('Não é possível retroagir mais de um ano em relação à data atual.');
		document.getElementById('data').value = dt2.value;
		document.getElementById('data').focus();
		return false;		
	}				
}


// cria data a partir de uma string (dd/mm/aaaa)
function toDate(data)
{
  if(isDate(data))
  {
	dia = parseInt(data.substr(0, 2), 10);
	mes = parseInt(data.substr(3, 2), 10);
	ano = parseInt(data.substr(6, 4), 10);
	return new Date(ano, mes - 1, dia);
  }
  else
	return new Date();
}

// completa com zeros à esquerda
function Zeros(texto, tamanho)
{
  while(texto.length < tamanho)
	texto = '0' + texto;
  return texto;
}
//---------------------------------------------------
// convert data para string (dd/mm/aaaa)
function toDateStr(data)
{
  dia = Zeros(data.getDate().toString(10), 2);
  mes = Zeros((data.getMonth() + 1).toString(10), 2);
  ano = data.getFullYear();
  return dia + '/' + mes + '/' + ano;
}
//---------------------------------------------------
// retorna tamanho do mes
function monthLen(mes, ano)
{
  switch(mes)
  {
	// meses com 30 dias
	case 4:
	case 6:
	case 9:
	case 11:
	  return 30;
	  break;
	// fevereiro
	case 2:
	  // se ano não for bisexto
	  if(ano % 4)
		return 28;
	  else
		return 29;
	  break;
	// meses com 31 dias
	default:
	  return 31;
  }
}
//-------------------------------------------------------
// adiciona em uma parte da data um número
function dateAdd(parte, numero, data)
{
  dia = data.getDate();
  mes = data.getMonth() + 1;
  ano = data.getFullYear();
  switch(parte)
  {
	// acrescenta dias na data
	case 'd':
	  dia += numero;
	  while(dia > monthLen(mes, ano))
	  {
		dia -= monthLen(mes, ano);
		mes += 1;
		if(mes > 12)
		{
		  mes = 1;
		  ano += 1;
		}
	  }
	  break;
	// acrescenta meses na data
	case 'm':
	  mes += numero;
	  while(mes > 12)
	  {
		mes -= 12;
		ano += 1;
	  }
	  if(dia > monthLen(mes, ano))
		dia = monthLen(mes, ano);
	  break;
	// acrescenta anos na data
	case 'y':
	  ano += numero;
	  if(mes == 2 && dia == 29 && ano % 4)
		dia = 28;
	  break;
	default:
	  // erro de parâmetro (retorna a mesma data)
  }
  return new Date(ano, mes - 1, dia)
}

//----------------------------------------------------------
// verifica se uma string é uma data (dd/mm/aaaa)
function isDate(data)
{
  if(data.length == 10)
  {
	dia = parseInt(data.substr(0, 2), 10);
	mes = parseInt(data.substr(3, 2), 10);
	ano = parseInt(data.substr(6, 4), 10);
	if(dia > 0 && dia < 32 && mes > 0 && mes < 13 && ano > 999 && ano < 10000)
	{
	  if(mes == 2 && dia > 28)
	  {
		if(ano % 4)
		  return false;
		else if(dia > 29)
		  return false;
	  }
	  switch(mes)
	  {
		case 4:
		case 6:
		case 9:
		case 11:
		  if(dia > 30)
			return false;
		  break;
	  }
	}
	else
	  return false;
  }
  else
	return false;
  return true;
}
//-----------------------------------
// Diferença entre dias de duas datas
function dias(data1, data2){
	
	var dataDiff = toDate(data2) - toDate(data1);
	dataDiff = (((dataDiff / 1000) / 60)/60)/24;
	return dataDiff;
}

