function link(qual) {
	window.open(qual, '_blank');
}

window.onload = function() {
  var links = document.links;
  for (var i = 0, s = links.length; i < s; i++) {
    if (links[i].rel == 'external') {
      links[i].target = '_blank';
    }
  }
};

function marcar(tipo) {
	if(tipo == "in") {
		document.getElementById("responsabilidade").checked = false;	
		document.getElementById("riscos").checked = false;	
		document.getElementById("residencial").checked = false;	
		document.getElementById("empresarial").checked = false;
	}
	if (tipo == "out") {
		document.getElementById("responsabilidade").checked = false;	
	}
}

function doIt(what, who) {
	if (what == "habilitar") {
		document.getElementById(who).disabled = false;
		document.getElementById(who).focus();		
	}
	if (what == "desabilitar") {
		document.getElementById(who).disabled = true;
		document.getElementById(who).value = "";
	}
}

function doIt2(who, where) {
	if (document.getElementById(who).checked == true) {
		document.getElementById(where).disabled = false;	
		document.getElementById(where).focus();	
	}
	if (document.getElementById(who).checked == false) {
		document.getElementById(where).disabled = true;
	}
}

function goTo(destiny) {
	window.location.href = destiny;	
}

function enviar(destiny) {
	if(document.getElementById("assunto").value == "Orçamento") {
		goTo(destiny);
	}
}

function validarFormulario() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email");

  // validações dos campos gerais
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!checkMail(email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("ddd").value == "" || document.getElementById("telefone").value == "") {
	 passou = false; alerta += "- Telefone preenchido incorretamente. Utilize a forma: 00 00000000\n";
  }
  if (document.getElementById("cnpj_cpf").value == "") {
	 passou = false; alerta += "- CNPJ / CPF preenchido incorretamente.\n";
  }
  if (document.getElementById("cidade").value == "") {
	 passou = false; alerta += "- Cidade preenchido incorretamente.\n";
  }
  if (document.getElementById("estado").value == "") {
	 passou = false; alerta += "- Estado preenchido incorretamente.\n";
  }
  interesse = false;
  for(i=0; i < document.getElementById("form_contato").length; i++) {
		if(document.getElementById("form_contato")[i].name == "servico") {
			if(document.getElementById("form_contato")[i].checked) {
				interesse = true;
			}
		}
  }
  if(!interesse && document.getElementById("outros").value == ""){
	 passou = false; alerta += "- Escolha um serviço.\n";
  }
  /*if (document.getElementById("captcha").value == "") {
	 passou = false; alerta += "- Digite o código que aparece na imagem.\n";
  }*/

  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarFichaProspecPJ() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email2");

  // validações dos campos gerais
  if (document.getElementById("fantasia").value == "") {
	 passou = false; alerta += "- Nome Fantasia preenchido incorretamente.\n";
  }
  if (document.getElementById("cnpj").value == "") {
	 passou = false; alerta += "- CNPJ preenchido incorretamente.\n";
  }
  if (document.getElementById("razao").value == "") {
	 passou = false; alerta += "- Razão Social preenchido incorretamente.\n";
  }
  if (document.getElementById("endereco").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("funcionarios").value == "") {
	 passou = false; alerta += "- Funcionários preenchido incorretamente.\n";
  }
  if (document.getElementById("bairro").value == "") {
	 passou = false; alerta += "- Bairro preenchido incorretamente.\n";
  }
  if (document.getElementById("cep").value == "") {
	 passou = false; alerta += "- CEP preenchido incorretamente.\n";
  }
  if (document.getElementById("cidade2").value == "") {
	 passou = false; alerta += "- Cidade preenchido incorretamente.\n";
  }
  if (document.getElementById("uf").value == "") {
	 passou = false; alerta += "- UF incorretamente.\n";
  }
  if (document.getElementById("site").value == "") {
	 passou = false; alerta += "- Site preenchido incorretamente.\n";
  }
  if (document.getElementById("nome2").value == "") {
	 passou = false; alerta += "- Nome do Contato preenchido incorretamente.\n";
  }
  if (document.getElementById("cargo").value == "") {
	 passou = false; alerta += "- Cargo do Contato preenchido incorretamente.\n";
  }
  if (email.value == "") {
     passou = false; alerta += "- E-mail do Contato preenchido incorretamente.\n";
  }else{
      if (!checkMail(email.value)) {
           passou = false; alerta += "- E-mail do Contato preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("telefone2").value == "") {
	 passou = false; alerta += "- Telefone do Contato preenchido incorretamente. Utilize a forma: 00 00000000\n";
  }
  /*if (document.getElementById("captcha").value == "") {
	 passou = false; alerta += "- Digite o código que aparece na imagem.\n";
  }*/

  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarFichaProspecPF() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email2");

  // validações dos campos gerais
  if (document.getElementById("nome4").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("cpf").value == "") {
	 passou = false; alerta += "- CPF preenchido incorretamente.\n";
  }
  if (document.getElementById("rg").value == "") {
	 passou = false; alerta += "- RG preenchido incorretamente.\n";
  }
  if (document.getElementById("enderecoPf").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("numero").value == "") {
	 passou = false; alerta += "- Número preenchido incorretamente.\n";
  }
  if (document.getElementById("bairro").value == "") {
	 passou = false; alerta += "- Bairro preenchido incorretamente.\n";
  }
  if (document.getElementById("cep").value == "") {
	 passou = false; alerta += "- CEP preenchido incorretamente.\n";
  }
  if (document.getElementById("cidade2").value == "") {
	 passou = false; alerta += "- Cidade preenchido incorretamente.\n";
  }
  if (document.getElementById("uf").value == "") {
	 passou = false; alerta += "- UF preenchido incorretamente.\n";
  }
  if (document.getElementById("nome5").value == "") {
	 passou = false; alerta += "- Nome do Contato preenchido incorretamente.\n";
  }
  if (email.value == "") {
     passou = false; alerta += "- E-mail do Contato preenchido incorretamente.\n";
  }else{
      if (!checkMail(email.value)) {
           passou = false; alerta += "- E-mail do Contato preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("telefone2").value == "") {
	 passou = false; alerta += "- Telefone do Contato preenchido incorretamente. Utilize a forma: 00 00000000\n";
  }
  /*if (document.getElementById("captcha").value == "") {
	 passou = false; alerta += "- Digite o código que aparece na imagem.\n";
  }*/

  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarFormularioResidencia() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email");

  // validações dos campos gerais
  if (document.getElementById("nome3").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("seguro").value == "") {
	 passou = false; alerta += "- Seguro preenchido incorretamente.\n";
  }
  if (document.getElementById("enderecoLocal").value == "") {
	 passou = false; alerta += "- Endereço do Local preenchido incorretamente.\n";
  }
  if (document.getElementById("cepLocal").value == "") {
	 passou = false; alerta += "- CEP preenchido incorretamente. Utilize a forma: 00000-000\n";
  }
  if (document.getElementById("valor").value == "") {
	 passou = false; alerta += "- Valor do Imóvel preenchida incorretamente.\n";
  }
  /*if (document.getElementById("captcha").value == "") {
	 passou = false; alerta += "- Digite o código que aparece na imagem.\n";
  }*/

  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarSeguroAuto1() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email3");
  
  if (document.getElementById("data").value == "") {
	 passou = false; alerta += "- Data preenchida incorretamente.\n";
  }
  if (document.getElementById("vigencia").value == "") {
	 passou = false; alerta += "- Vigência preenchida incorretamente.\n";
  }
  if (document.getElementById("segurado").value == "") {
	 passou = false; alerta += "- Segurado preenchido incorretamente.\n";
  }
  if (document.getElementById("telefone3").value == "") {
	 passou = false; alerta += "- Telefone preenchido incorretamente. Utilize a forma: 00 00000000\n";
  }
  if (email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!checkMail(email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("cpf2").value == "") {
	 passou = false; alerta += "- CPF preenchido incorretamente.\n";
  }
  if (document.getElementById("cel").value == "") {
	 passou = false; alerta += "- Celular preenchido incorretamente. Utilize a forma: 00 00000000\n";
  }
  if (document.getElementById("dataNasc").value == "") {
	 passou = false; alerta += "- Data de Nascimento preenchido incorretamente.\n";
  }
  if (document.getElementById("habilitacao").value == "") {
	 passou = false; alerta += "- Número de Habilitação preenchido incorretamente.\n";
  }
  if (document.getElementById("rg2").value == "") {
	 passou = false; alerta += "- RG preenchido incorretamente.\n";
  }
  if (document.getElementById("marca").value == "") {
	 passou = false; alerta += "- Marca preenchida incorretamente.\n";
  }
  if (document.getElementById("modelo").value == "") {
	 passou = false; alerta += "- Modelo preenchido incorretamente.\n";
  }
  
  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarSeguroAuto2() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email3");
  
  if (document.getElementById("nome6").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.getElementById("estadoCivil").value == "") {
	 passou = false; alerta += "- Estado Civil preenchido incorretamente.\n";
  }
  if (document.getElementById("cpf3").value == "") {
	 passou = false; alerta += "- CPF preenchido incorretamente.\n";
  }
  if (document.getElementById("dataNasc2").value == "") {
	 passou = false; alerta += "- Data de Nascimento preenchido incorretamente.\n";
  }
  if (document.getElementById("profissao").value == "") {
	 passou = false; alerta += "- Profissão/Ocupação preenchido incorretamente.\n";
  }
  if (document.getElementById("tempohab").value == "") {
	 passou = false; alerta += "- Tempo de habilitação preenchido incorretamente.\n";
  }
  
  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarContato() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email");

  // validações dos campos gerais
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!checkMail(email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("empresa").value == "") {
	 passou = false; alerta += "- Empresa preenchido incorretamente.\n";
  }
  if (document.getElementById("ddd").value == "" || document.getElementById("telefone").value == "") {
	 passou = false; alerta += "- Telefone preenchido incorretamente. Utilize a forma: 00 00000000\n";
  }
  if (document.getElementById("assunto").value == "") {
	 passou = false; alerta += "- CEP preenchido incorretamente. Utilize a forma: 00000-000\n";
  }
  if (document.getElementById("mensagem").value == "") {
	 passou = false; alerta += "- Mensagem preenchida incorretamente.\n";
  }
  /*if (document.getElementById("captcha").value == "") {
	 passou = false; alerta += "- Digite o código que aparece na imagem.\n";
  }*/

  if (passou == true) { document.getElementById("form_contato").submit(); }
  else { alert(alerta); return false; }
}

function validarNewsletter() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";
  
  email = document.getElementById("email");

  // validações dos campos gerais
  if (email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!checkMail(email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }

  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}

function validarEmail(email)
{
	var s = email;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
	return true;
	else
	return false;
}

function checkMail(mail){
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        if(typeof(mail) == "string"){
                if(er.test(mail)){ return true; }
        }else if(typeof(mail) == "object"){
                if(er.test(mail.value)){ 
                                        return true; 
                                }
        }else{
                return false;
                }
}

function chnum( caractere ){ 
	var strValidos = "0123456789" 
	if ( strValidos.indexOf( caractere ) == -1 ) 
		return false; 
	return true;  
}

function validanum(campo, event) { 
	var BACKSPACE = 8;
	var key;
	var tecla; 
	CheckTAB=true; 
	if(navigator.appName.indexOf("Netscape")!= -1) 
		tecla= event.which; 
	else 
		tecla= event.keyCode; 
	key = String.fromCharCode(tecla);   
	if ( tecla == 13 ) 
		return true;
	if ( tecla == 9 ) 
		return true; 
	if ( tecla == 32 ) 
		return true;
	if ( tecla == BACKSPACE ) 
		return true; 
	return ( chnum(key) ); 
}

//mascara data onkeyup="mdata(this)" onkeypress="return validanum(this, event)"
 function mdata(campo){
     if (campo.value.length > 2)
     	if (campo.value.charAt(campo.value.length - 1) == '/' && campo.value.charAt(campo.value.length - 2) == '/')
        	campo.value = campo.value.substr(0,campo.value.length - 2);
	 if (event.keyCode != 8)			   
     	if (campo.value.length == 2 || campo.value.length == 5)
    		campo.value += '/';
  }
//mascara cep onkeyup="mcep(this)" onkeypress="return validanum(this, event)"
 function mcep(campo){
	 if (campo.value.length == 5)
   	 	campo.value += "-";
  }
//mascara hora onkeyup="mhora(this)" onkeypress="return validanum(this, event)"
 function mhora(campo){
     if (campo.value.length > 2)
       if(campo.value.charAt(campo.value.length - 1) == ':' && campo.value.charAt(campo.value.length - 2) == ':')
          campo.value = campo.value.substr(0,campo.value.length - 2);
	 if (event.keyCode != 8)
   	  if (campo.value.length == 2 || campo.value.length == 5) 
	  	campo.value += ':';
  }
//mascara validade onkeyup="mdata(this)" onkeypress="return validanum(this, event)"
 function mvalidade(campo){
     if (campo.value.length == 2)
    	campo.value += '/';
  }
  
function validaNome(evento){
	(evento.keyCode) ? key = evento.keyCode : key = evento.which;
	//alert(key);
	var er = new RegExp(/^[a-z\u00C0-\u00ff A-Z]+$/);
	if(String.fromCharCode(key).match(/^[a-z\u00C0-\u00ff A-Z]+$/) || key==8 || key==9 || key==46 || key==37 || key==39){
		return true;
	}
	else {
		return false;
	}
}

function validaNumero(evento){
	(evento.keyCode) ? key = evento.keyCode : key = evento.which;
	//alert(key);
	var er = new RegExp(/^[a-z\u00C0-\u00ff A-Z]+$/);
	if(String.fromCharCode(key).match(/^[a-z\u00C0-\u00ffA-Z]+$/)){
		return false;
	}
	else {
		return true;
	}
}


function formataData(campo, event){

	var codigo 	= 	event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var palavra = String.fromCharCode(codigo);
	if(codigo == 32){
		return false;
	}
	if(palavra >= 0 || palavra <= 9){
		if(campo.value.length == 2){
			campo.value += "/";
		}
		if(campo.value.length == 5){
			campo.value += "/";
		}
		return true;
	}else if(codigo == 8 || codigo == 46 || codigo == 116){
		return true;
	}else if(codigo == 37 || codigo == 39){
		return true;
		/*}else if(campo.value.length == 10 && codigo == 97){
		return true;*/
	}else{
		return false;
	}
}
