/***************************************************
	REDIMENSIONA IFRAME
***************************************************/

function resizeIframe() 
{
	try {
	
	 frame = document.getElementById('conteudo');
	 innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	
	 objToResize = (frame.style) ? frame.style : frame;
	
	if(innerDoc=="[object]")
	{
		tamanho = innerDoc.body.scrollHeight;
	}
	else
	{
		tamanho = innerDoc.body.offsetHeight;
	}
		objToResize.height = Number(tamanho);
		document.getElementById('topo').focus();
	}
	
	catch (e) 
	{
		window.status = '';
	}
}


function resizeIframeTwo() {
	try {
	
	 frame = document.getElementById('produtos');
	 innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	
	 objToResize = (frame.style) ? frame.style : frame;
	
	if(innerDoc=="[object]")
	{
		tamanho = innerDoc.body.scrollHeight;
	}
	else
	{
		tamanho = innerDoc.body.offsetHeight;
	}
		objToResize.height = Number(tamanho);
		document.getElementById('topo').focus();
	}
	
	catch (e) 
	{
		window.status = '';
	}
}

/***************************************************
	ABRE POPUP
***************************************************/

function popUp(endereco,nome,largura,altura,rolagem)
{
	var desktop = window.open (endereco,nome, "status=no,scrollbars="+rolagem+",width="+largura+", height="+altura+",left=100,top=100")
	desktop.focus();
}


/***************************************************
	PERMITE DIGITOS
***************************************************/

function IsNumeric(sText,sDigitos)
{
	var ValidChars = sDigitos;
	var IsNumber   =  true;
	var Char;
	
	for (i=0; i<sText.length && IsNumber == true; i++) 
	{ 
	Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}



/***************************************************
	EVENTOS FORM
***************************************************/

function nomeCampos(campo,texto,acao)
{
	with(document.forms[0])
	{
		if (acao == "focus")
		{
			if (campo.value == texto)
			{
				campo.value = "";	
			}
		}
		if (acao == "blur")
		{
			if (campo.value == "")
			{
				campo.value = texto;	
			}
		}
	}
}


/***************************************************
	MASCARA
	* CEP  -> 99.999-999
	* CPF  -> 999.999.999-99
	* CNPJ -> 99.999.999/9999-99
	* Data -> 99/99/9999
	* Tell -> (99) 9999-9999
***************************************************/

function txtBoxFormat(strField, sMask, evtKeyPress) 
{
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

    if(window.event) { // Internet Explorer
      nTecla = evtKeyPress.keyCode; 
	}
    else if(evtKeyPress.which) { // Nestcape / firefox
      nTecla = evtKeyPress.which;
    }
	
    //se for backspace não faz nada
    if (nTecla != 8){
    sValue = document.getElementById(strField).value;
    // alert(sValue);

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i      = 0;
    nCount = 0;
    sCod   = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    document.getElementById(strField).value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
      else { // qualquer caracter...
        return true;
      } }
    else {
      return true;
    }
    }
}


/***************************************************	
	FUNÇÕES PADRÕES DE VALDAÇÃO
***************************************************/

//
//EMAIL
//
function isEmail()
{
	var ok = true;
	var idioma;
	var msg;
	
	msg = "E-mail inválido, formato requerido: seunome@provedor.com.br.";
	
	with(document.formulario)
	{
		if (email.value.indexOf("@",0) < 0 || email.value.indexOf(".")<0 || email.value == "" || email.value == "E-mail"){
			alert(msg);
			email.focus();
			ok = false;
		}
		return ok;
	}
}

//
//NOME
//
function isNome()
{
	var ok = true;
	var msg;
	
	msg = "Preencha seu nome.";
	
	with(document.formulario)
	{
		if (nome.value == "" || nome.value < 4 || nome.value == "Nome"){
			alert(msg);
			nome.focus();
			ok = false;
		}
		return ok;
	}
}

//
//EMPRESA
//
function isEmpresa()
{
	var ok = true;
	var msg;
	
	msg = "Preencha o nome da empresa.";
	
	with(document.formulario)
	{
		if (empresa.value == "" || empresa.value < 4 || empresa.value == "Empresa"){
			alert(msg);
			empresa.focus();
			ok = false;
		}
		return ok;
	}
}

//
//CONTATO
//
function isContato()
{
	var ok = true;
	var msg;
	
	msg = "Informe o nome de uma pessoa para contato.";
	
	with(document.formulario)
	{
		if (contato.value == "" || contato.value < 4 || contato.value == "Contato"){
			alert(msg);
			contato.focus();
			ok = false;
		}
		return ok;
	}
}

//
//CNPJ
//
function isCNPJ()
{
	var ok = true;
	
	with(document.formulario)
	{
		if (cnpj.value == "" || cnpj.value == "CNPJ" || IsNumeric(cnpj.value,"0123456789./-") == false){
			alert("Preencha o cnpj da empresa.");
			cnpj.focus();
			ok = false;
		}
		if (!isCnpj(cnpj.value)){
			alert("O cnpj digitado é inválido.");
			cnpj.focus();
			ok = false;
		}
		return ok;
	}
}

//
//DIA
//
function isDataDia()
{
	var ok = true;
	var msg;
	
	msg = "Selecione o dia de seu nascimento";
	
	with(document.formulario)
	{
		if (dia.value == "" || dia.value == "Dia"){
			alert(msg);
			dia.focus();
			ok = false;
		}
		return ok;
	}
}

//
//MES
//
function isDataMes()
{
	var ok = true;
	var msg;
	
	msg = "Selecione o mês de seu nascimento";
	
	with(document.formulario)
	{
		if (mes.value == "" || mes.value == "Mês"){
			alert(msg);
			mes.focus();
			ok = false;
		}
		return ok;
	}
}

//
//ANO
//
function isDataAno()
{
	var ok = true;
	var msg;
	
	msg = "Selecione o ano de seu nascimento.";
	
	with(document.formulario)
	{
		if (ano.value == "" || ano.value == "Ano"){
			alert(msg);
			ano.focus();
			ok = false;
		}
		return ok;
	}
}

//
//ENDERECO
//
function isEndereco()
{
	var ok = true;
	var msg;
	
	msg = "Preencha seu endereço.";
	
	with(document.formulario)
	{
		if (endereco.value == "" || endereco.value == "Endereço"){
			alert(msg);
			endereco.focus();
			ok = false;
		}
		return ok;
	}
}

//
//NUMERO
//
function isNumero()
{
	var ok = true;
	var msg;
	
	msg = "Preencha o número de sua residência.";
	
	with(document.formulario)
	{
		if (numero.value == "" || IsNumeric(numero.value,"0123456789") == false || numero.value == "Número"){
			alert(msg);
			numero.focus();
			ok = false;
		}
		return ok;
	}
}

//
//CEP
//
function isCEP()
{
	var ok = true;
	var msg;
	
	msg = "Preencha o cep de sua rua.";
	
	with(document.formulario)
	{
		if (cep.value == "" || IsNumeric(cep.value,"0123456789-") == false || cep.value == "CEP"){
			alert(msg);
			cep.focus();
			ok = false;
		}
		return ok;
	}
}

//
//ESTADO
//
function isEstado()
{
	var ok = true;
	var msg;
	
	 msg = "Selecione o estado onde reside.";
	
	with(document.formulario)
	{
		if (estado.value == "" || estado.value == "UF"){
			alert(msg);
			estado.focus();
			ok = false;
		}
		return ok;
	}
}

//
//CIDADE
//
function isCidade()
{
	var ok = true;
	var msg;
	
	msg = "Preencha a cidade onde mora.";
	
	with(document.formulario)
	{
		if (cidade.value == "" || cidade.value == "Cidade"){
			alert(msg);
			cidade.focus();
			ok = false;
		}
		return ok;
	}
}

//
//TELEFONE
//
function isTelefone(campo,txt,tipo)
{
	var ok = true;
	var idioma;
	var msg;
	var campo;
	
	if (tipo == "tel") msg = "Preencha o número de telefone.";
	if (tipo == "cel") msg = "Preencha o número de celular.";
	if (tipo == "fax") msg = "Preencha o número do fax.";
	
	with(document.formulario)
	{
		if (campo.value == "" || IsNumeric(campo.value,"0123456789-.") == false || campo.value == txt){
			alert(msg);
			campo.focus();
			ok = false;
		}
		return ok;
	}
}

//
//DATA
//
function isDataNascimento()
{
	var ok = true;
	var campo = document.getElementById("nascimento").value;
	var array_data = new Array;
	array_data = campo.split("/");
	
	with(document.formulario)
	{
		if (nascimento.value == "" || IsNumeric(nascimento.value,"0123456789/") == false || nascimento.value == "DD/MM/AAAA"){
			alert("Preencha sua data de nascimento.");
			nascimento.focus();
			ok = false;
		}
		if (array_data[0] > 31 || array_data[1] > 12 || array_data[2] > 2008){
			alert("Data de nascimento inválida.");
			nascimento.focus();
			ok = false;
		}
		return ok;
	}
}

//
//TEXTO
//
function isTexto()
{
	var ok = true;
	var msg;
	
	msg = "Preencha a mensagem.";
	
	with(document.formulario)
	{
		if (mensagem.value == "" || mensagem.value == "Mensagem"){
			alert(msg);
			mensagem.focus();
			ok = false;
		}
		return ok;
	}
}

function enviaDuvida()
{
	with (document.forms[0])
	{
		if (isNome() == false) return;
		if (isEmail() == false) return; 
		if (isEndereco() == false) return;
		if (isTelefone(telefone,"Telefone","tel") == false) return;
		if (isTexto() == false) return;
		
		submit();
	}
}

function enviaSac()
{
	with (document.forms[0])
	{
		if (isNome() == false) return;
		if (isEmail() == false) return;
		if (isTelefone(telefone,"Telefone","tel") == false) return;
		if (isEndereco() == false) return;
		if (isNumero() == false) return;
		if (isCEP() == false) return;
		if (isCidade() == false) return;
		if (isEstado() == false) return;
		if (isTexto() == false) return;
		
		submit();
	}
}

function enviaCadastro()
{
	with (document.forms[0])
	{
		if (isNome() == false) return;
		if (isEmail() == false) return;
		if (isDataNascimento() == false) return;
		if (isTelefone(telefone,"Telefone","tel") == false) return;
		if (isEndereco() == false) return;
		if (isCEP() == false) return;
		if (isCidade() == false) return;
		if (isEstado() == false) return;
		
		submit();
	}
}

function enviaConvenio()
{
	with (document.forms[0])
	{
		if (isEmpresa() == false) return;
		if (isCNPJ() == false) return;
		if (isContato() == false) return;
		if (isTelefone(telefone,"Telefone","tel") == false) return;
		if (isEmail() == false) return;
		
		submit();
	}
}

