// JavaScript Document

function mudastatus() {
	window.status = "JBP - Jornal Brasileiro de Pneumologia";
}

var loginacess = 0;                
var senhaacess = 0;

function limpalogin() {
	if(loginacess == 0) {
		document.getElementById("login").value = "";
		loginacess = 1;
	}
}

function limpasenha() {
	if(senhaacess == 0) {
		document.getElementById("senha").value = "";
		senhaacess = 1;
	}
}

function restituicampo(campo) {
	if(!document.getElementById(campo).value && campo == "login") {
		document.getElementById(campo).value = "Login"
		loginacess = 0;
	}
	if(!document.getElementById(campo).value && campo == "senha") {
		document.getElementById(campo).value = "Senha"
		//document.getElementById("senha").type = "text";
		senhaacess = 0;
	}
}
//Mensagem do botão direitp
var message="® Copyright JBP Jornal Brasileiro de Pneumologia - Todos os direitos reservados"; // Message for the alert box
function click(e) {
if (document.all) {
if (event.button == 2) {
//alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
//Funcões para Troca de fundo da tabela
function mover(local){
	//local.style.backgroundImage = "../images/back_menu_over.gif";
	local.bgColor = "#D80A0A";
	//local.background = "../images/back_menu_over.gif";
}
function mout(local){
	local.bgColor = "";
	//local.background = "";
	//local.style.backgroundImage = "";
}
function valida_email(campoform)
{
	email = campoform.value;
    if (email)
		{
		p=email.indexOf('@');
		pont=email.indexOf('.');
		if (p<1 || p==(email.length-1) || pont<1 || pont==(email.length-1))
			{
				alert ('O e-mail deve ser um endereço de e-mail válido.');
	    		campoform.value = '';
	    		campoform.focus();
				return false;
			}
		} else {
			alert ('O e-mail deve ser um endereço de e-mail válido.');
  		campoform.value = '';
	    campoform.focus();
		return false;
		}
}
function valida_tel(campo) {
   var valor='';
   var digito = false;
   a = campo.value;
   if (a) {
   num = a.length;
   for (f=0;f<num;f++)
     {
     if (parseInt(a.substr(f,1)) || a.substr(f,1)=='0') 
        if ((a.substr(f,1) != '0') || digito) valor = valor + '' + a.substr(f,1);
        if (parseInt(a.substr(f,1)) && a.substr(f,1) != '0') digito = true;
     };
   num = valor.length;
   if (num < 9 || num > 10)
      {
      alert ('- Número de telefone inválido. \nEntre com o DDD e o número do telefone.\nExemplo: (11) 1234-5678');
      campo.value = '';
      campo.focus();
      }
	  else
	  {
	  if (num == 9) valor = '(' + valor.substr(0, 2) + ') ' + valor.substr(num-7, 3) + '-' + valor.substr(num-4, 4);
	  if (num == 10) valor = '(' + valor.substr(0, 2) + ') ' + valor.substr(num-8, 4) + '-' + valor.substr(num-4, 4);
	  campo.value = valor;
	  }
   }
}
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 eDigito(pStr){				//função usada no form1 para validação de telefone
	var reDigits = /[0-9]+/;
	if (reDigits.test(pStr)) {
		return true; // é dígito
		} else if (pStr != null && pStr != "") {
			return false; // não é dígito
		}
}
		
		function ValidaTelefone(tel){
        exp = /\(\d{2}\)\ \d{4}\-\d{4}/
        if(!exp.test(tel.value)){
                alert("Número de telefone inválido,\npreencha corretamente!");
				return (false);
}
		}
		
		function validaNumero( campo ){
         var numero = document.getElementById( campo );
         var numeroValor = numero.value/*.replace( ",",".")*/;
         
         if ( isNaN( numeroValor )){
                   //alert( "O campo " + numero.name.toUpperCase() + " deve conter apenas números" );
                  // numero.focus();
                   return false;
         }
         return true;
}

// Validação de campo vazio sem exibir alert
function validaBranco2( campo ){
         campo = document.getElementById( campo );

         if( trim( campo.value ) == "" ) {
                   return false;
		 }
		 return true;
}

function trim(txt){  
         var retirar = ' ';
         var retorno = '';

         for(i=0;i<txt.length;i++){  
                   if(retirar.indexOf(txt.substr(i,1)) == -1){  
                            retorno += txt.substr(i,1);
                   }
         }  
         return retorno;
}


