
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function vld_login(){
  msg = "";
  if(document.loginForm.nomeUsuario.value == ""){
	msg  += "\n.: Login"; }
  if(document.loginForm.senhaUsuario.value == ""){
	msg  += "\n.: Senha"; }
  if (msg!="") {
	msg  ="Os campos abaixo não estão preenchidos:" + msg ;
	document.loginForm.nomeUsuario.focus();
	alert(msg);
	return false;
  }
  else return true;
}

function vld_enquete(){
  var ok = false;
  for (i = 0; i < document.enqueteForm.codResposta.length; i++) {
	if (document.enqueteForm.codResposta[i].checked) { ok = true; }
  }
  if (!ok) {
    alert ("Por favor, selecione uma opção.");
    return false;
  }
  else return true;
}

function vld_quiz(){
  var ok = false;
  for (i = 0; i < document.quizForm.codResposta.length; i++) {
	if (document.quizForm.codResposta[i].checked) { ok = true; }
  }
  if (!ok) {
    alert ("Por favor, selecione uma opção.");
    return false;
  }
  else return true;
}

function vld_cadlogin(){
  msg = "";
  if(document.cadLoginForm.nomeEntidade.value == ""){
	msg  += "\n.: Nome"; }
  if(document.cadLoginForm.emailEntidade.value == ""){
	msg  += "\n.: E-mail"; }
  if(document.cadLoginForm.nomeUsuario.value == ""){
	msg  += "\n.: Login"; }
  if(document.cadLoginForm.senhaUsuario.value == ""){
	msg  += "\n.: Senha"; }
  if(document.cadLoginForm.senhaUsuario.value.length < 6){
	msg  += "\n.: Senha deve conter 6 caracteres no mínimo"; }
  if(document.cadLoginForm.senhaUsuario.value != document.cadLoginForm.confirmaSenhaUsuario.value){
	msg  += "\n.: Confirmação de senha"; }
  if (msg!="") {
	msg  ="Os campos abaixo não estão preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}

function vld_altlogin(){
  msg = "";
  if(document.altLoginForm.nomeEntidade.value == ""){
	msg  += "\n.: Nome"; }
  if (msg!="") {
	msg  ="Os campos abaixo não estão preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}

function vld_cadastro(){
  msg = "";
  if(document.FormCadastro.nome.value == ""){
	msg  += "\n.: Nome/Empresa"; }
  if(document.FormCadastro.cpfCnpj.value == ""){
	msg  += "\n.: CPF/CNPJ"; 
  } else {
	cpfCnpj = document.FormCadastro.cpfCnpj.value;
	
	if(cpfCnpj.length > 11){  
  		validacnpj(cpfCnpj);
	} else {
		validacpf(cpfCnpj);
	}
  }
  if(document.FormCadastro.cidade.value == ""){
	msg  += "\n.: Cidade"; }
  if(document.FormCadastro.ddd.value == ""){
	msg  += "\n.: DDD"; 
  } else {
   if(!(/^[0-9]+$/.test(document.FormCadastro.ddd.value))){
    msg += "\n.: DDD só aceita números"; }
  }
  if(document.FormCadastro.fone.value == ""){
	msg  += "\n.: Telefone"; 
  } else {
   if(!(/^[0-9]+$/.test(document.FormCadastro.fone.value))){
    msg += "\n.: Telefone só aceita números"; }
  }
  if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(document.FormCadastro.email.value))) {
	msg  += "\n.: E-mail"; }
  if (msg!="") {
	msg  ="Os campos abaixo estão incorretos ou não preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}

function validacpf(s){
 
var i;
//s = document.FormCadastro.cpfCnpj.value;
var c = s.substr(0,9);
var dv = s.substr(9,2);
var d1 = 0;
for (i = 0; i < 9; i++){
	d1 += c.charAt(i)*(10-i);
}
if (d1 == 0){
msg  += "\n.: CPF Inválido";
return false;
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(0) != d1)
{
msg  += "\n.: CPF Inválido";
return false;
}
d1 *= 2;
for (i = 0; i < 9; i++){
	d1 += c.charAt(i)*(11-i);
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(1) != d1){
msg  += "\n.: CPF Inválido";
return false;
}
return true;
} 


function validacnpj(cnpj)
{
var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
digitos_iguais = 1;

for (i = 0; i < cnpj.length - 1; i++)
	if (cnpj.charAt(i) != cnpj.charAt(i + 1))
		  {
		  digitos_iguais = 0;
		  break;
		  }
if (!digitos_iguais)
	{
	tamanho = cnpj.length - 2
	numeros = cnpj.substring(0,tamanho);
	digitos = cnpj.substring(tamanho);
	soma = 0;
	pos = tamanho - 7;
	for (i = tamanho; i >= 1; i--)
		  {
		  soma += numeros.charAt(tamanho - i) * pos--;
		  if (pos < 2)
				pos = 9;
		  }
	resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	if (resultado != digitos.charAt(0)){
	msg += "\n .: CNPJ Inválido";
	return false;
	}
	tamanho = tamanho + 1;
	numeros = cnpj.substring(0,tamanho);
	soma = 0;
	pos = tamanho - 7;
	for (i = tamanho; i >= 1; i--)
		  {
		  soma += numeros.charAt(tamanho - i) * pos--;
		  if (pos < 2)
				pos = 9;
		  }
	resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	if (resultado != digitos.charAt(1)){
		  msg += "\n .: CNPJ Inválido";
		  return false;
	}
	return true;
	}
else
	 msg += "\n .: CNPJ Inválido";
	return false;
}

function vld_atendimento(){
  msg = "";
  if(document.atendimentoForm.nome.value == ""){
	msg  += "\n.: Nome"; }
  if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(document.atendimentoForm.email.value))) {
	msg  += "\n.: E-mail"; }
  if(document.atendimentoForm.assunto.value == ""){
	msg  += "\n.: Assunto"; }
  if(document.atendimentoForm.assunto.value == ""){
	msg  += "\n.: Comentário"; }
  if (msg!="") {
	msg  ="Os campos abaixo estão incorretos ou não preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}

function vld_envioEmail(){
  msg = "";
  if(document.formEnvia.nome.value == ""){
	msg  += "\n.: Nome"; }
  if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(document.formEnvia.email.value))) {
	msg  += "\n.: E-mail"; }
  if(document.formEnvia.foto.value == ""){
	msg  += "\n.: Foto"; }
  if(document.formEnvia.comentario.value == ""){
	msg  += "\n.: Comentário"; }
  if (msg!="") {
	msg  ="Os campos abaixo estão incorretos ou não preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}


function vld_cadClassificados(){
  msg = "";
  if(document.classificadosForm.descricao.value == ""){
	msg  += "\n.: Título"; }
  if(document.classificadosForm.contato.value == ""){
	msg  += "\n.: Contato"; }
  if(document.classificadosForm.tipo.value == ""){
	msg  += "\n.: Tipo"; }
  if (msg!="") {
	msg  ="Os campos abaixo não estão preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}

function vld_login_campanha(){
  msg = "";
  if(document.loginFormCampanha.nomeUsuario.value == ""){
	msg  += "\n.: Login"; }
  if(document.loginFormCampanha.senhaUsuario.value == ""){
	msg  += "\n.: Senha"; }
  if (msg!="") {
	msg  ="Os campos abaixo não estão preenchidos:" + msg ;
	document.loginFormCampanha.nomeUsuario.focus();
	alert(msg);
	return false;
  }
  else return true;
}


function vld_campanha_navegue(){
	msg = "";
	if(document.campanhaForm.nomeInscrito.value == ""){
		msg  += "\n.: Nome completo"; }
	if(document.campanhaForm.enderecoInscrito.value == ""){
		msg  += "\n.: Endereço"; }
	if(document.campanhaForm.cepInscrito.value == ""){
		msg  += "\n.: CEP"; }
	if(document.campanhaForm.cidadeInscrito.value == ""){
		msg  += "\n.: Cidade"; }
	if(document.campanhaForm.estadoInscrito.value == ""){
		msg  += "\n.: Estado"; }
	if(document.campanhaForm.codTelefoneInscrito.value == ""){
		msg  += "\n.: Código do Telefone"; }
	if(document.campanhaForm.telefoneInscrito.value == ""){
		msg  += "\n.: Telefone"; }
	if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(document.campanhaForm.emailInscrito.value))) {
		msg  += "\n.: E-mail"; }
	if(document.campanhaForm.rgInscrito.value == ""){
		msg  += "\n.: RG"; }

	okSexo = false;
	for (i = 0; i < document.campanhaForm.sexoInscrito.length; i++) {
		if (document.campanhaForm.sexoInscrito[i].checked) { okSexo = true; }
	}
	if(!okSexo){
		msg  += "\n.: Sexo"; }

	okCivil = false;
	for (i = 0; i < document.campanhaForm.estadoCivilInscrito.length; i++) {
		if (document.campanhaForm.estadoCivilInscrito[i].checked) { okCivil = true; }
	}
	if(!okCivil){
		msg  += "\n.: Estado Civil"; }
	if(document.campanhaForm.grauEscolaridadeInscrito.value == ""){
		msg  += "\n.: Grau de Escolaridade"; }
	if(document.campanhaForm.profissaoInscrito.value == ""){
		msg  += "\n.: Profissão"; }
	if(document.campanhaForm.estiloMusicaInscrito.value == ""){
		msg  += "\n.: Estilo de música preferido"; }
	if(!((document.campanhaForm.horarioInscrito1.checked != false) || (document.campanhaForm.horarioInscrito2.checked != false) || (document.campanhaForm.horarioInscrito3.checked != false))){
		msg  += "\n.: Horário em que costuma ouvir a Cidade"; }
	if(document.campanhaForm.programaInscrito.value == ""){
		msg  += "\n.: Programa que mais gosta na Cidade"; }
		
	okCartao = false;
	for (i = 0; i < document.campanhaForm.cartaoInscrito.length; i++) {
		if (document.campanhaForm.cartaoInscrito[i].checked) { okCartao = true; }
	}
	if(!okCartao){
		msg  += "\n.: Cartão de Crédito"; }

	if(document.campanhaForm.motivoInscrito.value == ""){
		msg  += "\n.: Por que você merece viajar de férias num cruzeiro no carnaval?"; }
	if (msg!="") {
		msg  ="Os campos abaixo estão incorretos ou não preenchidos:" + msg ;
		alert(msg);
		return false;
	}
	else return true;
}

function vld_regulamento(){
	if(document.formRegulamento.aceitaRegulamento.checked == false){
		alert("É necessário aceitar o regulamento para continuar.");
		return false;
	}
	return true;
}

function vld_inf(){
  msg = "";
  if(document.formInf.nomeassinar.value == ""){
	msg += "\n.: Nome"; }
  if(!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(document.formInf.emailassinar.value))) {
	msg += "\n.: E-mail"; }
  if (msg != "") {
	msg  ="Os campos abaixo estão incorretos ou não preenchidos:" + msg ;
	alert(msg);
	return false;
  }
  else return true;
}
