// JavaScript Document

// Alterar classe com mouseover de um elemento.
// id = id do elemento
function over(id){
  document.getElementById(id).className = 'mouseOver1';
}

// Alterar classe com mouseout de um elemento.
// id = id do elemento
function out(id){
  document.getElementById(id).className = 'mouseOut';
}

// Abre popup
// ex: abrir('arquivo.html', 'he100', 'wi100', 'scno');
function abrir() {
	var windowFeatures = "", nomeArquivo = "", nomeJanela = "", erro = null
	Argumentos = abrir.arguments; noArgumentos = Argumentos.length; nomeArquivo = Argumentos[0]
	for (i = 1; i < noArgumentos; i++) {
		valor = Argumentos[i].substring(2,Argumentos[i].length)
		switch(Argumentos[i].substring(0,2)) {
			case "nj" : nomeJanela = valor; break
			case "to" : windowFeatures += "top=" + valor + ", "; break
			case "le" : windowFeatures += "left=" + valor + ", "; break
			case "he" : windowFeatures += "height=" + valor + ", "; break
			case "wi" : windowFeatures += "width=" + valor + ", "; break
			case "lb" : windowFeatures += "location=" + valor + ", "; break
			case "mb" : windowFeatures += "menubar=" + valor + ", "; break
			case "sc" : windowFeatures += "scrollbars=" + valor + ", "; break
			case "st" : windowFeatures += "status=" + valor + ", "; break
			case "tb" : windowFeatures += "toolbar=" + valor + ", "; break
			case "tt" : windowFeatures += "titlebar=" + valor + ", "; break
			case "re" : windowFeatures += "resizable=" + valor + ", "; break
			default : erro = '"Código de atributo não informado no '+(i+1)+' º argumento (' +Argumentos[i]+ ')"'
		}
	}
	windowFeatures = windowFeatures.substring(0,windowFeatures.lastIndexOf(","))
	if (erro) { alert(erro) } else { novaJanela = window.open(nomeArquivo, nomeJanela, windowFeatures) }
}


// Conta caracteres de um campo texto
// textareaID = id do elemento texto
// spanId = id do elemento que aparece a contagem regressiva
// maxSize = número máxim de caracteres permitidos.
function contaCaracteres(textareaId, spanId, maxSize) 
{
  textarea = document.getElementById(textareaId);
  if (textarea == null) {
	return;
  }
  if (textarea.value.length > maxSize) {
	  textarea.value = textarea.value.substring(0, maxSize);
  }
  document.getElementById(spanId).innerHTML = maxSize - textarea.value.length;
}


// Formata campos textos passando uma máscara
// src = elemento que possuirá a máscara
// mask = tipo da máscara. 
// 0 = numérico
// # = não escreve nada
// A = letra
function formatar(src, mask) {
	var i = src.value.length;
	var saida = mask.substring(i,i+1);
	var ascii = event.keyCode;
	if (saida == "A") {
		if ((ascii >=97) && (ascii <= 122)) { 
			event.keyCode -= 32;
		} else {
			event.keyCode = 0;
		}
	} else if (saida == "0") {
		if ((ascii >= 48) && (ascii <= 57)) {
			return
		} else {
			event.keyCode = 0
		}
	} else if (saida == "#") {
		return;
	} else {
		src.value += saida;
		i += 1
		saida = mask.substring(i,i+1);
		if (saida == "A") {
			if ((ascii >=97) && (ascii <= 122)) {
				event.keyCode -= 32;
			} else {
				event.keyCode = 0; 
			}
		} else if (saida == "0") {
			if ((ascii >= 48) && (ascii <= 57)) {
				return
			} else {
				event.keyCode = 0 
			}
		} else {
			return;
		}
	}
}

