var browserVersion = parseInt(navigator.appVersion);
var isNetscape = navigator.appName.indexOf("Netscape") != -1;
var isIE = navigator.appName.indexOf("Microsoft") != -1;

function wPopUp(page,  _w, _h, opc ){
	if (_w == null)
        _w = '400';
	if (_h == null) 
		_h = '500';
	if (opc == null)
		opc = 'resizable=no,status=no';
	else opc = opc + ',resizable=no,status=no';
	
	var top = (window.screen.height - _h)/2;
	var left = (window.screen.width - _w)/2;

	if (document.all) { // se for I.E.
		var result = window.showModalDialog(page, "",  "help:no; scroll:no; status:no;" + "dialogHeight:" +_h + "px; " + "dialogWidth:" + _w + "px;");
	} else {
		window.open(page, 'width=' + _w + ',height= ' + _h + ',scrollbars=no,top=' + top + ',left=' + left + ',' + opc);
	}
}

	function abrirPopUp(URL, target, aWidth, aHeight) {
		var left = 375;
		var top = 250;
		
		window.open(URL,target, 'width='+aWidth+', height='+aHeight+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
	}
	
	//permite apenas a inserção de número no campo texto
	function validaNumero(form) {

		var digits="0123456789"
		var temp 
		var ok = true;
	
		for (var i = 0; i < form.value.length; i++) {
  			temp = form.value.substring(i,i+1)
	
	  		if (digits.indexOf(temp)==-1) {
			    alert("O campo deve ser preenchido apenas com numeros!")
			    form.focus();
			    ok = false;
			    return(false);
			    break;
	   		}
  		}
	}	
	
	function submitForm(form){
		form.submit();
	}
	
	
	function habilitarDesabilitarCampo(checkBox,campo){

		if(checkBox.checked == true){
			campo.disabled = false;
		}
		else{
			campo.value = '';
			campo.disabled = true;
		}
	}
	
	function submitFormProminpSelecionaCurso(form,origem){
		form.origem.value = origem;
		form.submit();
	}

	function submitFormInstituicaoEnsino(form, acao){
		form.acao.value = acao;
		form.submit();
	}
	
	function chamarPagina( pagina ){
		window.location.href = pagina;
	}
	
	function atualizaCombo( action ){
		document.forms[0].action = action;
		document.forms[0].submit();		
	}

	function atualizaComboInstituicaoEnsino(form, action, acao ){
		form.acao.value = acao;
		form.action = action;
		form.submit();
	}
		
	//copia o valor do campo origem para o campo destino
	function copiarForm(formOrigem, formDestino){
		
		for(var i=0; i<formOrigem.elements.length; i++){
			for(var j=0; j<formDestino.elements.length; j++){
				if(formOrigem.elements[i].type == 'hidden' && formDestino.elements[j].type == 'hidden' ){
					if(formOrigem.elements[i].name == formDestino.elements[j].name){
						formDestino.elements[j].value = formOrigem.elements[i].value;
					}
				}
			}			
		}		
	}

	function winPopUp(page, _w, _h, campos, tamanhos, tabela, opc)
	{
		if (_w == null)
	        _w = '400';
		if (_h == null) 
			_h = '500';
		if (opc == null)
			opc = 'resizable=no,status=no';
		else opc = opc + ',resizable=no,status=no';
		
		var top = (window.screen.height - _h)/2;
		var left = (window.screen.width - _w)/2;

		if (page.indexOf("?") > -1) // verifica se já existe parâmetro no url para continuar concatenando com o nome dos campos de retorno
			page = page + "&";
		else page = page + "?";
	
		if (document.all) { // se for I.E.
			var result = window.showModalDialog(page, "",  "help:no; scroll:no; status:no;" + "dialogHeight:" +_h + "px; " + "dialogWidth:" + _w + "px;");
			
			if (result != null) {// testa se há algum retorno.						
				if (tabela != null)
				{
					adicionarLinha( tabela, campos, result, tamanhos );
				}
				else
				{
					escreverValores( campos, result );
				}
			}
		} else {
			window.open(page, '_new', 'width=' + _w + ',height= ' + _h + ',scrollbars=no,top=' + top + ',left=' + left + ',' + opc);			
			
		}	
	}

	function escreverValores( campos, valores )
	{

		for (i = 0; i < campos.length; i++)
		{		
			campo  = document.getElementById(campos[i])
			campo.value = valores[i];
			//campos[i].value = valores[i];
		}				
	}	
	
	function definirEstilo( tabela )
	{
		var estilo = new Object();
		estilo.background = "../../pixelBranco.jpg";
		estilo.width = "1";
		estilo.padding = "4px";
		estilo.bgColor = "#DDDDDD";	
		if( (tabela.rows.length % 2) == 0 ) estilo.bgColor = "#EEEEEE";
		
		return estilo;
	}
	
	function adicionarColunaCaixa( linhas, linhaNova, estilo )
	{
	    var coluna = linhas( linhaNova.rowIndex ).insertCell();    
	    coluna.bgColor = estilo.bgColor;    
		coluna.align = "center";
		coluna.style.width = "27";
		coluna.style.height = "20";	
		coluna.style.padding = estilo.padding;	
	    coluna.innerHTML = "<input type='checkbox' id='chaves' name='chaves' onclick='javascript:controlarBotoes(chaves, btExcluir)'>";
	}
	
	function adicionarColunaSeparadora( linhas, linhaNova, estilo )
	{
	    var coluna = linhas( linhaNova.rowIndex ).insertCell();        
	    coluna.background = estilo.background;
	    coluna.style.width = estilo.width; 
	}
	
	function adicionarColunaValor( linhas, linhaNova, estilo, campo, valor, tamanho  )
	{
	    var coluna = linhas( linhaNova.rowIndex ).insertCell();
	    coluna.bgColor = estilo.bgColor;
		coluna.style.padding = estilo.padding;    
	    coluna.style.width = tamanho;    
	    coluna.innerHTML = "<input type='hidden' name='" + campo + "' value=" + valor + ">" + valor;
	}
	
	function adicionarLinha( tabela, campos, valores, tamanhos )
	{
	    var linhaNova = tabela.insertRow( tabela.rows.length );
	    var linhas = tabela.rows;
	    var colunas = linhaNova.cells;
		var estilo = definirEstilo( tabela );	   

		adicionarColunaCaixa( linhas, linhaNova, estilo );
		
		for (i = 0; i < valores.length; i++)
		{		
			adicionarColunaSeparadora( linhas, linhaNova, estilo );
			adicionarColunaValor( linhas, linhaNova, estilo, campos[i], valores[i], tamanhos[i] );
		}
	}
	
	function colorirLinhas( linhas )
	{
	   for ( var i=0; i < linhas.length; i++ ) 
	    {
			colunas = linhas( i ).cells;
	
			for ( var j=0; j < colunas.length; j++ )
			{
				if ( colunas(j).style.width != "1px" )
				{
					if ( (i % 2) == 0 ) {
				    	cor = "#DDDDDD";    
				    } else {
				    	cor = "#EEEEEE";     
				    }
		
					colunas(j).bgColor = cor;
				}
			}      
	    } 
	}
	
	function removerLinhas( tabela, indices ) 
	{
	    for( var i=indices.length - 1; i >= 0; i-- )
	    { 
			tabela.deleteRow( indices[ i ] ); 
	    }
	
	    linhas = tabela.rows;
	    colorirLinhas( linhas );
	}
	
	function confirmarRemocao( tabela, caixasSelecao )
	{
	    var indices = new Array();
	
	    if ( !caixasSelecao.length )
	    {    		
			indices[0] = 0;
	    }
	    else
	    {       	     
	        for (i=0; i < caixasSelecao.length; i++)
	        {
				if ( caixasSelecao[i].checked )
				{ 
					indices[ indices.length ] = i;
				}
	        }
	    }
	    
		if ( confirm("Deseja realmente excluir o(s) iten(s) selecionado(s)?") )
		{
			removerLinhas( tabela, indices );
	    }
	}	
 
	function retornarValores( valores )
	{		
		if( valores[0] != "" )
		{
			window.returnValue = valores;						
		}
		window.close();
	}		
	
	function limparCampos( campos )
	{
		for(var i=0; i<campos.length; i++)
		{
			campos[i].value = '';
		}
	}	
	
	function controlarBotoes( caixasSelecao, botaoExcluir, botaoAlterar ) 
	{		
		if ( !caixasSelecao.length ) {
			if ( caixasSelecao.checked ) {
				botaoExcluir.style.visibility = "visible";
				if ( eval( botaoAlterar ) ) botaoAlterar.style.visibility = "visible";									
			} else {
				botaoExcluir.style.visibility = "hidden";
				if ( eval( botaoAlterar ) ) botaoAlterar.style.visibility = "hidden";												
			}
		} else {
			var contador = 0;
			for(var i=0; i<caixasSelecao.length; i++) {
				if ( caixasSelecao[i].checked ) {
					contador++;
					if ( contador == 2 ) {
						botaoExcluir.style.visibility = "visible";
						if ( eval( botaoAlterar ) ) botaoAlterar.style.visibility = "hidden";																	
						break;
					}
				}
			}						
			if ( contador == 0 ) {
				botaoExcluir.style.visibility = "hidden";
				if ( eval( botaoAlterar ) ) botaoAlterar.style.visibility = "hidden";																	
			} else if ( contador == 1 ) {
				botaoExcluir.style.visibility = "visible";
				if ( eval( botaoAlterar ) ) botaoAlterar.style.visibility = "visible";																	
			}
		}
	}		

function confirmaGeracao()
{
	return confirm("Deseja realmente gerar arquivo?");
}
	
function confirmaExclusao()
{
	return confirm("Deseja realmente excluir?");
}

/**
 * Implementa a seleção e a anulação da seleção de todos os checkboxes
 * do formulário
 * @author Ricardo Rezende
 */
function marcarDesmarcarTodos(campo) {
	var formulario = campo.form, i = 0;
	for(i=0; i<formulario.length;i++){
		if(formulario[i].type == 'checkbox' && formulario[i].name != 'marcarTodas'){
			formulario[i].checked = campo.checked;
		}
	}
}
/**
 * Implementa a verificação da seleção de pelo menos um checkbox
 * do formulário
 * @author eolf
 */
function peloMenosUmMarcado(campo) {
	var formulario = campo, i = 0;
	for(i=0; i<formulario.length;i++){
		if(formulario[i].type == 'checkbox' && formulario[i].name != 'marcarTodas'){
			if(formulario[i].checked)
			 return formulario[i].checked;
		}
	}
}

/**
 * Implementa a seleção de pelo todos um checkbox do formulário
 * @author eolf
 */
function selecionar_tudo(form){ 
   for (i=0;i<form.elements.length;i++) 
      if(form.elements[i].type == "checkbox" && !form.elements[i].disable) 
         form.elements[i].checked=1 
}

String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

function verifyDate(campo)
{ 
	token1 = campo.value.indexOf("/");
	token2 = token1 + 1 + campo.value.substring(token1+1, 10).indexOf("/");

	dia = parseInt(campo.value.substring(0,token1), 10);
	mes = parseInt(campo.value.substring(token1 + 1,token2), 10);
	ano = parseInt(campo.value.substring(token2 + 1,10), 10);
	
	diaString = campo.value.substring(0,token1);
	mesString = campo.value.substring(token1 + 1,token2);
	anoString = campo.value.substring(token2 + 1,10);

	if (anoString.trim().length < 4)
		return (false);
		
	if (isNaN(dia) || isNaN(mes) || isNaN(ano))
		return (false);

	// verify the day for each month 
	if ((dia < 01) || ((dia > 30) && (mes == 04 || mes == 06 || mes == 09 || mes == 11)) || (dia > 31) || ano == 0000)
		return (false);

	// verify if the month is valid 
	if ((mes < 01) || (mes > 12))
		return (false);

	// verify if it is a leap year
	if ((mes == 2) && ((dia > 29) || ((dia > 28) && (parseInt(ano / 4) != ano / 4))))
		return (false);

	return (true); 
}

function somenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    
    if((tecla > 47 && tecla < 58)) return true;
    else{
    	if (tecla != 8  && tecla != 13 && tecla != 0) // backspace, enter e setas.
    		return false;
    	else 
    		return true;
	}
}

function SomenteNumerosELetras(e)
{
	
		var tecla=(window.event)?event.keyCode:e.which;
	 	
		if(tecla >= 65 && tecla <= 90){ // LETRAS MAIUSCULAS
			return true;
		}else if(tecla >= 97 && tecla <= 122){ // LETRAS MINUSCULAS			
			return true;
		}else if(tecla > 47 && tecla < 58){ // numeros de 0 a 9
			return true;
		}else if(tecla == 32){ //espaço
			return true;
		} else if(tecla == 44 || tecla == 45 || tecla == 46){ // , - .
			return true;
		}else if(tecla == 231 //ç 
				|| tecla == 199 // Ç
				|| tecla == 225 //á
				|| tecla == 192 //À 
				|| tecla == 193 //Á 
				|| tecla == 194 //Â 
				|| tecla == 195 //Ã 
				|| tecla == 196 //Ä
				|| tecla == 197 //Å 
				|| tecla == 195 //ã
				|| tecla == 227 //Ã
				|| tecla == 226 //â
				|| tecla == 182 //Â
				|| tecla == 233 //é 
				|| tecla == 201 //É
				|| tecla == 234 //ê  
				|| tecla == 202 //Ê
				|| tecla == 237 //í 
				|| tecla == 205 //Í  
				|| tecla == 243 //ó 
				|| tecla == 211 //Ó 
				|| tecla == 245 //õ
				|| tecla == 213 //Õ
				|| tecla == 244 //ô 
				|| tecla == 212 //Ô 
				|| tecla == 250 //ú 
				|| tecla == 218 //Ú  
				|| tecla == 252 //ü
				|| tecla == 220 //Ü
	
		){  
			return true;
		}else{
			if (tecla != 8 && tecla != 13 && tecla != 0){ // backspace, enter e setas.
				return false;
			}else{
				return true;
			}
		}
}

function SomenteNumerosELetrasComCaracteresEspeciais(e)
{
	
		var tecla=(window.event)?event.keyCode:e.which;
	 	
		if(tecla >= 65 && tecla <= 90){ // LETRAS MAIUSCULAS
			return true;
		}else if(tecla >= 97 && tecla <= 122){ // LETRAS MINUSCULAS			
			return true;
		}else if(tecla > 47 && tecla < 58){ // numeros de 0 a 9
			return true;
		}else if(tecla == 32){ //espaço
			return true;
		} else if(tecla == 40 || tecla == 41){ // ( )
			return true;
		} else if(tecla == 44 || tecla == 45 || tecla == 46){ // , - .
			return true;
		} else if(tecla == 94){ // _ 
			return true;
		}else if(tecla == 231 //ç 
				|| tecla == 133 // à
				|| tecla == 183 // À
				|| tecla == 199 // Ç
				|| tecla == 225 //á
				|| tecla == 192 //À 
				|| tecla == 193 //Á 
				|| tecla == 194 //Â 
				|| tecla == 195 //Ã 
				|| tecla == 196 //Ä
				|| tecla == 197 //Å 
				|| tecla == 227 //Ã
				|| tecla == 226 //â
				|| tecla == 233 //é 
				|| tecla == 201 //É
				|| tecla == 234 //ê  
				|| tecla == 202 //Ê
				|| tecla == 237 //í 
				|| tecla == 205 //Í  
				|| tecla == 243 //ó 
				|| tecla == 211 //Ó 
				|| tecla == 245 //õ
				|| tecla == 213 //Õ
				|| tecla == 244 //ô 
				|| tecla == 212 //Ô 
				|| tecla == 250 //ú 
				|| tecla == 218 //Ú  
				|| tecla == 252 //ü
				|| tecla == 220 //Ü
				|| tecla == 136 //Ü

		){  
			return true;
		}else{
			if (tecla != 8 && tecla != 13 && tecla != 0){ // backspace, enter e setas.
				return false;
			}else{
				return true;
			}
		}
}


function SomenteNumerosELetrasParaEmail(e)
{
  	    
		var tecla=(window.event)?event.keyCode:e.which;
 
		if(tecla >= 65 && tecla <= 90){ // LETRAS MAIUSCULAS
			return true;
		}else if(tecla >= 97 && tecla <= 122){ // LETRAS MINUSCULAS			
			return true;
		}else if(tecla > 47 && tecla <= 58){ // numeros de 0 a 9
			return true;
		}else if(tecla == 64){ // @ e espaço
			return true;
		} else if(tecla == 44 || tecla == 45 || tecla == 46){ // , - .
			return true;		
		}else if(tecla == 95){ // _
			return true;
		}else if(tecla == 231 //ç 
				|| tecla == 199 // Ç
				|| tecla == 225 //á
				|| tecla == 193 //Á
				|| tecla == 195 //ã
				|| tecla == 227 //Ã
				|| tecla == 226 //â
				|| tecla == 182 //Â
				|| tecla == 233 //é 
				|| tecla == 201 //É
				|| tecla == 234 //ê  
				|| tecla == 202 //Ê
				|| tecla == 237 //í 
				|| tecla == 205 //Í  
				|| tecla == 243 //ó 
				|| tecla == 211 //Ó 
				|| tecla == 245 //õ
				|| tecla == 213 //Õ
				|| tecla == 244 //ô 
				|| tecla == 212 //Ô 
				|| tecla == 250 //ú 
				|| tecla == 218 //Ú  
				|| tecla == 252 //ü
				|| tecla == 220 //Ü
		){
		 	
			return true;
		}else{
		 
			if (tecla != 8 && tecla != 13 && tecla != 0){ // backspace, enter e setas			 	
				return false;
			}else{			 	
				return true;
				}
		}
}

// Verify if only numbers were inserted into a field
function numbersOnly(myfield, e, nextField)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);

	var regex = /^(\d|\/)+$/;
	
	if (regex.test(keychar)) {
		return true;
	} else if (nextField && ((keychar == '.')||(keychar == ','))) {
		nextField.focus();
		return false;
	} else if (key == 17 || key == 86 || key == 118) {
		if (regex.test(myfield.value)) {
			return true; 
		} else {
			myfield.value = "";
		}
	}

	return false;	
}

var r={'special':/[^a-zA-Z0-9\sçÇáÁãÃéÉêÊíÍóÓôÔõÕúÚüÜ_]/g}
function valid(o,w)
{
  o.value = o.value.replace(r[w],'');
}

var r1={'special':/[^a-zA-Z0-9çÇáÁãÃéÉêÊíÍóÓôÔõÕúÚüÜ@._-]/g}
function validEmail(o,w)
{
	
	o.value = o.value.replace(r1[w],'');
}

var r2={'special':/[a-zA-Z\s\\çÇáÁãÃéÉêÊíÍóÓôÔõÕúÚüÜ@.!#$%¨&*()_]/g}
function validTelefoneFax(o,w)
{
	o.value = o.value.replace(r2[w],'');
}

var r3={'special':/[a-zA-Z\s\\çÇáÁãÃéÉêÊíÍóÓôÔõÕúÚüÜ@.!#$%¨&*()_]/g}
function validLetter(o,w)
{
	o.value = o.value.replace(r3[w],'');
}

var r4={'special':/[^a-zA-Z0-9\sçÇáÁãÃéÉêÊíÍóÓôÔõÕúÚüÜÀàÂâ()\-.,_]/g}
function validComCaracterEspecial(o,w)
{
  o.value = o.value.replace(r4[w],'');
}


function verTipoB(event,e)
{
 if(isIE){ 	   
 alert('ie');	 
		if (event == "SomenteNumerosELetras"){	
		 	     
		 	var sne = SomenteNumerosELetrasIE(e);		 	 
		}
		if (event == "SomenteNumerosELetrasParaEmail"){						    
		 	var sne = SomenteNumerosELetrasParaEmailIE(e);	
		 	 	 
		}		
		 		
}else if(isNetscape){
		    
		if (event == "SomenteNumerosELetras"){		
			var sne = SomenteNumerosELetrasNS(e);
		}
		if (event == "SomenteNumerosELetrasParaEmail"){
		 	var sne = SomenteNumerosELetrasParaEmailNS(e);
		}	
	}
	return sne;
}

function validaCpf(f,campo,cpf,erro) {
	 
	
	// Aqui começa a checagem do cpf
	var posicao, i, soma, dv, dvInformado;
	var digito = new Array(10);
	dvInformado = cpf.substr(9, 2); // Retira os dois últimos dígitos do número informado
	
	// Desemembra o número do cpf na array digito
	for (i=0; i<=8; i++) {
	  digito[i] = cpf.substr( i, 1);
	}
	
	// Calcula o valor do 10º dígito da verificação
	posicao = 10;
	soma = 0;
	   for (i=0; i<=8; i++) {
	      soma = soma + digito[i] * posicao;
	      posicao = posicao - 1;
	   }
	digito[9] = soma % 11;
	   if (digito[9] < 2) {
	        digito[9] = 0;
	}
	   else{
	       digito[9] = 11 - digito[9];
	}
	
	// Calcula o valor do 11º dígito da verificação
	posicao = 11;
	soma = 0;
	   for (i=0; i<=9; i++) {
	      soma = soma + digito[i] * posicao;
	      posicao = posicao - 1;
	   }
	digito[10] = soma % 11;
	   if (digito[10] < 2) {
	        digito[10] = 0;
	   }
	   else {
	        digito[10] = 11 - digito[10];
	   }
	
	// Verifica se os valores dos dígitos verificadores conferem
	dv = digito[9] * 10 + digito[10];
	   if (dv != dvInformado) {
	      erro+='Campo cpf é inválido';
	       
	   } 
}


function validaCNPJ(f,cnpj) {
 
                   erro = new String;
 				   
 				   if(document.layers && parseInt(navigator.appVersion) == 4){
                       x = cnpj.substring(0,2);
                       x += cnpj. substring (3,6);
                       x += cnpj. substring (7,10);
                       x += cnpj. substring (11,15);
                       x += cnpj. substring (16,18);
                       cnpj = x; 
	               } else {
	                       cnpj = cnpj. replace (".","");
	                       cnpj = cnpj. replace (".","");
	                       cnpj = cnpj. replace ("-","");
	                       cnpj = cnpj. replace ("/","");
	               }
 				  
 				   	
	 			   var a = [];
	               var b = new Number;
	               var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	               for (i=0; i<12; i++){
	                       a[i] = cnpj.charAt(i);
	                       b += a[i] * c[i+1];
	 	       	   
	 	       	   }
	               if ((x = b % 11) < 2) { 
	               	   a[12] = 0 
	               } else {
	               	   a[12] = 11-x 
	               }
	               
	               b = 0;
	               for (y=0; y<13; y++) {
	                       b += (a[y] * c[y]);
	               }
	               
	               if ((x = b % 11) < 2) {
	               	 a[13] = 0; 
	               } else {
	               	 a[13] = 11-x; 
	               }
 				 
 				 	
                 if (cnpj.length == 0){ 
                 	erro += "O campo CNPJ é obrigatório.\n ";
                 	
				 }else if (cnpj.length < 14 ){
                	erro += "O campo CNPJ inválido.\n ";
                 }else if (cnpj.length == 14 ){
                 	if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13])){
                       erro +="Dígito verificador do campo CNPJ é inválido.\n";
               	 	}
                 } 
                 //substituir os caracteres que não são números
               
               /*var nonNumbers = /\D/;
               if (nonNumbers.test(cnpj)){
               		 erro += "A verificação de cnpj suporta apenas números! ";
               }*/		 
            
               if (erro.length > 0){
                       alert(erro);
                       return false;               
	       	   } else {	       	   
                      return eval("document."+f+".submit()");
               }
                
       }
       
       
 function SomenteNumerosELetrasParaLogin(e)
{
  	    
		var tecla=(window.event)?event.keyCode:e.which;
 
		if(tecla >= 65 && tecla <= 90){ // LETRAS MAIUSCULAS
			return true;
		}else if(tecla >= 97 && tecla <= 122){ // LETRAS MINUSCULAS			
			return true;
		}else if(tecla > 47 && tecla <= 58){ // numeros de 0 a 9
			return true;
		}else if(tecla == 46){ // .
			return true;	
		}else if(tecla == 45){ // -
			return true;			
		}else if(tecla == 95){ // _
			return true;
		}else if(tecla == 231 //ç 
				|| tecla == 199 // Ç
				|| tecla == 225 //á
				|| tecla == 193 //Á
				|| tecla == 195 //ã
				|| tecla == 227 //Ã
				|| tecla == 233 //é 
				|| tecla == 201 //É
				|| tecla == 234 //ê  
				|| tecla == 202 //Ê
				|| tecla == 237 //í 
				|| tecla == 205 //Í  
				|| tecla == 243 //ó 
				|| tecla == 211 //Ó 
				|| tecla == 245 //õ
				|| tecla == 213 //Õ
				|| tecla == 244 //ô 
				|| tecla == 212 //Ô 
				|| tecla == 250 //ú 
				|| tecla == 218 //Ú  
				|| tecla == 252 //ü
				|| tecla == 220 //Ü
		){  
		 	
			return true;
		}else{
		 
			if (tecla != 8 && tecla != 13 && tecla != 0){ // backspace, enter e setas		 	
				return false;
			}else{			 	
				return true;
				}
		}
}      
       
//MÁSCARA DE VALORES


//Data:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99/99/9999', event);">
//RG:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99.999.999-9', event);">
//Telefone:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '(99)9999-9999', event);">
//Código:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99-999', event);">
 
function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8 || nTecla == 0) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
      	if (sMask.charAt(i-1) == '' && nTecla != 13 && nTecla != 0 && nTecla != 11) 
      		return false;
      	else
        	return true;
      } 
    }
    else {
      return true;
    }
  }


function trimJS(objeto){

	String = document.forms[0].elements[objeto].value;
	 
	resultado = String;

	//Retira os espaços do inicio
	//Enquanto o primeiro caracter for igual à "Espaço" 
	//1 caracter do inicio é removido

	var i;
	i = 0;
	 

	if (resultado.charCodeAt(2-1) == '32'){
	}

	while (resultado.charCodeAt(0) == '32'){
	   resultado = String.substring(i,String.length);
	  i++;}

	//Pega a string já formatada e agora retira os espaços do final
	//mesmo esquema, enquanto o ultimo caracter for um espaço, 
	//ele retira 1 caracter do final...

	while(resultado.charCodeAt(resultado.length-1) == "32"){
	   resultado = resultado.substring(0,resultado.length-1);
	  }
	  
	document.forms[0].elements[objeto].value = resultado;

	String = "";

	}

function SomenteNumerosELetrasParaSite(e)
{
  	    
		var tecla=(window.event)?event.keyCode:e.which;
 
		if(tecla >= 65 && tecla <= 90){ // LETRAS MAIUSCULAS
			return true;
		}else if(tecla >= 97 && tecla <= 122){ // LETRAS MINUSCULAS			
			return true;
		}else if(tecla >= 47 && tecla <= 58){ // numeros de / 0 a 9
			return true;
		}else if(tecla == 64){ // @ e espaço
			return true;
		} else if(tecla == 45 || tecla == 46){ //  - .
			return true;		
		}else if(tecla == 95){ // _
			return true;
		}else if(tecla == 231 //ç 
				|| tecla == 199 // Ç
				|| tecla == 225 //á
				|| tecla == 193 //Á
				|| tecla == 195 //ã
				|| tecla == 227 //Ã
				|| tecla == 226 //â
				|| tecla == 182 //Â
				|| tecla == 233 //é 
				|| tecla == 201 //É
				|| tecla == 234 //ê  
				|| tecla == 202 //Ê
				|| tecla == 237 //í 
				|| tecla == 205 //Í  
				|| tecla == 243 //ó 
				|| tecla == 211 //Ó 
				|| tecla == 245 //õ
				|| tecla == 213 //Õ
				|| tecla == 244 //ô 
				|| tecla == 212 //Ô 
				|| tecla == 250 //ú 
				|| tecla == 218 //Ú  
				|| tecla == 252 //ü
				|| tecla == 220 //Ü
		){
		 	
			return true;
		}else{
		 
			if (tecla != 8 && tecla != 13 && tecla != 0){ // backspace, enter e setas			 	
				return false;
			}else{			 	
				return true;
				}
		}
}

/*
* Lert v1.0
* by Jeffrey Sambells - http://JeffreySambells.com
* For more information on this script, visit http://JeffreySambells.com/openprojects/lert/
* Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
* Icons from Tango Desktop Project http://tango.freedesktop.org/Tango_Desktop_Project
*/
function Lert(message, buttons, options) {
	this.message_ = message;
	this.buttons_ = buttons;
	this.defaultButton_ = options.defaultButton || this.buttons_[0];
	this.icon_ = options.icon || null;
}

Lert.prototype.display = function() {
	var body = document.getElementsByTagName ('BODY')[0];
	var pageScroll = getPageScroll();
	var pageSize = getPageSize();

	//create the overlay if necessary
	var overlay = document.getElementById('lertOverlay');
	if(!overlay) {
		var overlay = document.createElement("div");
		overlay.setAttribute('id','lertOverlay');
		overlay.style.display = 'none';
		body.appendChild(overlay);
	}

	//position and show the overlay
	overlay.style.height=pageSize[1]+'px';
	overlay.style.display='block';

	//create the container if necessary
	var container = document.getElementById('lertContainer');
	if(!container) {
		var container = document.createElement("div");
		container.setAttribute('id','lertContainer');
		container.style.display = 'none';
		body.appendChild(container);
	}

	//position and show the container
	container.style.top = ( pageScroll[1] + (pageSize[3] / 15) ) + 'px';
	container.style.display = 'block';

	//create the window
	var win = document.createElement('div');
	win.setAttribute('id','lertWindow');

	//create the optional icon
	if(this.icon_ != null) {
		var icon = document.createElement('img');
		icon.setAttribute('src',this.icon_);
		icon.setAttribute('id','lertIcon');
		icon.setAttribute('alt','');
		win.appendChild(icon);
	}

	//create the message space
	var message = document.createElement('p');
	message.setAttribute('id','lertMessage');
	message.innerHTML = this.message_;
	win.appendChild(message);

	//create the button space
	var buttons = document.createElement('div');
	buttons.setAttribute('id','lertButtons');

	var oldKeyDown = document.onkeydown;

	//add each button
	for(i in this.buttons_) {
		var button = this.buttons_[i];
		if(button.getDom) {
			var domButton = button.getDom(function() {
				container.style.display = 'none';
				overlay.style.display = 'none';
				document.onkeydown=oldKeyDown;
				container.innerHTML = '';
				button.onclick_;
			},this.defaultButton_);
			buttons.appendChild(domButton);
		}
	}
	win.appendChild(buttons);

	document.onkeydown = this.keyboardControls;

	//append the window
	container.appendChild(win);
}

Lert.prototype.keyboardControls = function(e) {
	if (e == null) { keycode = event.keyCode; } // ie
	else { keycode = e.which; } // mozilla
	if(keycode==13) { document.getElementById('lertDefaultButton').onclick(); }
}

function LertButton(label, event, options) {
	this.label_ = label;
	this.onclick_ = event;
	this.eventClick = function() {};
}

LertButton.prototype.getDom = function(eventCleanup,defaultButton) {
	var button = document.createElement('a');
	button.setAttribute('href','javascript:void(0);');
	button.className = 'lertButton';
	if(this == defaultButton) button.setAttribute('id','lertDefaultButton');
	button.innerHTML = this.label_;

	var eventOnclick =  this.onclick_;
	button.onclick = function() {
		eventCleanup();
		eventOnclick();
	}
	this.eventClick = button.onclick;
	return button;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

