// JavaScript Document

//mudar cor ao posicionar o mouse
function MudaCorBgd(id, act) {
  if (act == 'over') {
  document.getElementById(id).style.backgroundColor = '#DDDDDD';
  }
  if (act == 'out') {
  document.getElementById(id).style.backgroundColor = '#EEEEEE';
  }
}

/*envia o internauta para um novo local*/
function NewLocation(url) {
  window.location=url;
}

/*abrir nova janela*/
function OpenWindowA(url) {
  window.open(url,"_blank");
}

/*abrir nova janela com parâmetros*/
function OpenWindowB(url) {
  window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=530, height=500");
}

/*retira os espaços do início e fim de uma string*/
function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

/*verifica se é um e-mail válido*/
function ValidaEmail(email) {
  var padrao = '^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([a-z,A-Z]){2,3}([0-9,a-z,A-Z])?$';
  var reg = new RegExp(padrao);
  var result = reg.exec(email);
	if(result != null)
	  return true;
	else
	  return false;
}

/*validação dos campos do formulário*/
function ValidaForm(form) {
  var erros = Array();
  var foco = null;
  var nomeform = form;


    if (nomeform.nome) {
	  nomeform.nome.value = trim(nomeform.nome.value);
	    if(nomeform.nome.value == "") {
		  erros.push('Nombre: Dato obligatorio.');
		if (foco == null)
		  foco = nomeform.nome;
		}
	}

    if (nomeform.cidade) {
	  nomeform.cidade.value = trim(nomeform.cidade.value);
	    if(nomeform.cidade.value == "") {
		  erros.push('Ciudad: Dato obligatorio.');
		if (foco == null)
		  foco = nomeform.cidade;
		}
	}

	
	if (nomeform.email) {
	  nomeform.email.value = trim(nomeform.email.value);
	    if (!ValidaEmail(nomeform.email.value)) {
		  erros.push('E-mail: Dato obligatorio.');
		if (foco == null)
		  foco = nomeform.email;
		}	
	}
	

	if (nomeform.mensagem) {
	  nomeform.mensagem.value = trim(nomeform.mensagem.value);
	    if (nomeform.mensagem.value == "") {
		  erros.push('Mensaje: Dato obligatorio.');
		if (foco == null)
		  foco = nomeform.mensagem;
		}
	}

	numErros = erros.length;	
	if (numErros > 0) {
	  msg = 'Atención:';
	  for (i = 0; i < numErros; i++) {
	    msg += '\n » ' + erros[i];
	  }
	  alert(msg);
	  foco.focus();
	  return false;
	} else {
	  nomeform.submit();
	  return true;
	}
}
