// JavaScript Document
function verifica_radio(campo){
	frm = campo; var opcao = 0;
	for (var i = 0; i < frm.length; i++) {if (frm[i].checked) {opcao = frm[i].value;}}
	if (opcao == "0"){return false;}else {return true;}
}

function verifica_faca_seu_anuncio(f){
	if(f.nome.value==''){alert('Por favor informe o nome');f.nome.focus();return false;}
	if(isEmail(f.email,'E-mail')==false){f.email.focus();f.email.select();return false;}
	if(f.ddd.value==''){alert('Por favor informe o DDD');f.ddd.focus();return false;}
	if(f.telefone.value==''){alert('Por favor informe o telefone');f.telefone.focus();return false;}
	if(f.codAssinante.value==''){alert('Por favor informe o código de assinante');f.codAssinante.focus();return false;}
	if(f.codAssinante.value!=''){
		if(f.codAssinante.value.lenght > 5){alert('Código de assinante incorreto');f.codAssinante.focus();return false;}
		if(f.codAssinante.value=='0' || f.codAssinante.value=='00' || f.codAssinante.value=='000' || f.codAssinante.value=='0000' || f.codAssinante.value=='00000' ){
			alert('Código de assinante incorreto');f.codAssinante.focus();return false;}
	}
	if(f.area.value==''){alert('Por favor informe a área de atuação');f.area.focus();return false;}
	if(f.idTipoClassificado.value==''){alert('Por favor informe a categoria');f.idTipoClassificado.focus();return false;}
	if(f.titulo.value==''){alert('Por favor informe o título');f.titulo.focus();return false;}
	if(f.texto.value==''){alert('Por favor informe o texto do anúncio');f.texto.focus();return false;}
}

function verifica_concursos(f){
	if(f.Nome.value==''){alert('Por favor informe o nome');f.Nome.focus();f.Nome.select();return false;}
	if(f.Endereco.value==''){alert('Por favor informe o endereço');f.Endereco.focus();f.Endereco.select();return false;}
	if(f.Complemento.value==''){alert('Por favor informe o complemento');f.Complemento.focus();f.Complemento.select();return false;}
	if(f.Bairro.value==''){alert('Por favor informe o bairro');f.Bairro.focus();f.Bairro.select();return false;}
	if(f.Cidade.value==''){alert('Por favor informe a cidade');f.Cidade.focus();f.Cidade.select();return false;}
	if(f.Estado.value==''){alert('Por favor informe o estado');f.Estado.focus();f.Estado.select();return false;}
	if(f.Dia.value==''){alert('Por favor informe o dia de nascimento');f.Dia.focus();f.Dia.select();return false;}
	if(f.Mes.value==''){alert('Por favor informe o mês de nascimento');f.Mes.focus();f.Mes.select();return false;}
	if(f.Ano.value==''){alert('Por favor informe o ano de nascimento');f.Ano.focus();f.Ano.select();return false;}
	if(f.Sexo.value==''){alert('Por favor informe o sexo');f.Sexo.focus();return false;}
	if(f.DDD.value==''){alert('Por favor informe o DDD');f.DDD.focus();f.DDD.select();return false;}
	if(f.Telefone.value==''){alert('Por favor informe o telefone');f.Telefone.focus();f.Telefone.select();return false;}
	if(f.DDDCel.value==''){alert('Por favor informe o DDD do celular');f.DDDCel.focus();f.DDDCel.select();return false;}
	if(f.Celular.value==''){alert('Por favor informe o telefone celular');f.Celular.focus();f.Celular.select();return false;}
	if(isEmail(f.Email,'E-mail')==false){f.Email.focus();f.Email.select();return false;}
	if(!verifica_radio(document.form1.AreaAtuacao)){alert("Selecione a área de atuação");return false;}
	if(f.Descricao.value==''){alert('Por favor responda a pergunta');f.Descricao.focus();f.Descricao.select();return false;}
	if(f.Ciente.value=='' || f.Ciente.value=='Nao'){alert('Por favor selecione estar ciente do regulamento');f.Ciente.focus();return false;}
}

function verifica_indique(f) {
	if(f.NomeAmigo.value==''){alert('Informe o nome do seu amigo');f.NomeAmigo.focus();f.NomeAmigo.select();return false;}
	if(isEmail(f.EmailAmigo,'E-mail')==false){f.EmailAmigo.focus();f.EmailAmigo.select();return false;}
	
	if(f.Nome.value==''){alert('Informe seu nome');f.Nome.focus();f.Nome.select();return false;}
	if(isEmail(f.Email,'E-mail')==false){f.Email.focus();f.Email.select();return false;}
}

function verifica_contato(f){
	if(f.Nome.value==''){alert('Por favor informe o nome');f.Nome.focus();return false;}
	if(!isEmail(f.Email, 'E-mail')){f.Email.focus();return false;}	
	if(f.Texto.value==''){alert('Por favor informe a mensagem');f.Texto.focus();return false;}
}

function verifica_cadastre(f){
	if(f.Nome.value==''){alert('Por favor informe o nome');f.Nome.focus();return false;}
	if(!isEmail(f.Email, 'E-mail')){f.Email.focus();return false;}
	if(f.Cidade.value==''){alert('Por favor informe a cidade');f.Cidade.focus();return false;}
	if(f.Estado.value==''){alert('Por favor informe o estado');f.Estado.focus();return false;}
	var opcao = '';
	var frm = f.getElementsByTagName('input');
	for (var i = 0; i < frm.length; i++) {if (frm[i].checked){opcao = frm[i].value;}}
	if(opcao==''){alert('Selecione ao menos um assunto de interesse!');return false;}
}


function verifica_assine(formulario)
{
	
	if(!(formulario.aceite.checked)){
		alert("Se você quer assinar ou renovar a Revista FHOX marque a opção \n\n'Sim, quero receber a Revista FHOX no meu endereço abaixo'");
		formulario.aceite.focus();
		return false;
	}
	
	if(!verifica_radio(document.form1.Pessoa)){
		alert("Selecione o tipo de Pessoa: 'Física' ou 'Jurídica'");
		window.location.hash = "hash_tipopessoa";
		return false;
	}
	
	campo_form = Array(formulario.Nome, formulario.Endereco, formulario.Numero, formulario.Bairro,  formulario.Cidade, formulario.Estado, formulario.CEP, formulario.DDD, formulario.Telefone, formulario.Celular, formulario.Email);
	msg_campo_form = Array("o Nome", "o Endereço", "o Número", "o Bairro", "a Cidade", "o Estado", "o CEP", "o DDD", "o Telefone", "o Celular", "o E-mail");
	for(var cont = 0; cont < campo_form.length; cont ++){
		if(campo_form[cont].value.length == 0){
			alert("Digite " + msg_campo_form[cont] );
			campo_form[cont].focus();
			return false;
		}
	}

	//verifica se o email é valido
	if(!isEmail(formulario.Email, 'E-mail')){formulario.Email.focus(); formulario.Email.select(); return false;}	

	if(verifica_radio(document.form1.Pessoa)){
		if(formulario.Pessoa[0].checked){
			if(formulario.CPF.value.length == 0){
				alert("Digite o CPF");
				formulario.CPF.focus();
				return false;
			}
		}
		if(formulario.Pessoa[1].checked){
			if(formulario.CNPJ.value.length == 0){
				alert("Digite o CNPJ");
				formulario.CNPJ.focus();
				return false;
			}
		}
	}	
	
	if(!verifica_radio(document.form1.AssinRenov)){
		alert("Selecione uma das opções 'Assinatura' ou 'Renovação' ou 'Renovação Dupla'");
		return false;
	}else{
		if(formulario.AssinRenov[0].checked){
			if(!verifica_radio(document.form1.AssinPagto)){
				alert("Selecione uma das opções de pagamento 'Boleto' ou 'Cartão'");
				return false;
			}else{
				if(formulario.AssinPagto[0].checked){
					if(formulario.AssinT_boleto.value.length == 0){
						alert("Selecione o tipo de envio do Boleto Bancário");
						formulario.AssinT_boleto.focus();
						return false;
					}
				}
				
				if(formulario.AssinPagto[1].checked){
					if(formulario.AssinT_cartao.value.length == 0){
						alert("Selecione o cartão");
						formulario.AssinT_cartao.focus();
						return false;

					}
				}
			}
		}
		
		
		if(formulario.AssinRenov[1].checked){
			if(!verifica_radio(document.form1.RenovPagto)){
				alert("Selecione uma das opções de pagamento 'Boleto' ou 'Cartão'");
				return false;
			}else{

				if(formulario.RenovPagto[0].checked){
					if(formulario.RenovT_boleto.value.length == 0){
						alert("Selecione o tipo de envio do Boleto Bancário");
						formulario.RenovT_boleto.focus();
						return false;
					}
				}

				if(formulario.RenovPagto[1].checked){
					if(formulario.RenovT_cartao.value.length == 0){
						alert("Selecione o cartão");
						formulario.RenovT_cartao.focus();
						return false;

					}
				}
			}
		}
		
		if(formulario.AssinRenov[2].checked){
			if(!verifica_radio(document.form1.RenovDuplaPagto)){
				alert("Selecione uma das opções de pagamento 'Boleto' ou 'Cartão'");
				return false;
			}else{

				if(formulario.RenovDuplaPagto[0].checked){
					if(formulario.RenovDuplaT_boleto.value.length == 0){
						alert("Selecione o tipo de envio do Boleto Bancário");
						formulario.RenovDuplaT_boleto.focus();
						return false;
					}
				}

				if(formulario.RenovDuplaPagto[1].checked){
					if(formulario.RenovDuplaT_cartao.value.length == 0){
						alert("Selecione o cartão");
						formulario.RenovDuplaT_cartao.focus();
						return false;

					}
				}
			}
		}
	}
}

var isEmail = function(iCampo, iNomeCampo) {
	var str = iCampo.value;
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if ( (!r1.test(str) && r2.test(str)) ) {
		return true;
	} else {
		alert(iNomeCampo + ' inválido.'); return false;
	}
	return true;
}

function maxCarac(txarea, total){
	tam = txarea.value.length;
	str="";
	str=str+tam;
	if (tam > total){
	  aux = txarea.value;
	  txarea.value = aux.substring(0,total);
	}
}