<!--

/*******************************/
/*** BLOQUEIO DE CARACTERES ****/
/*******************************/

function mostrarDiv(div){
	if(document.getElementById(div).style.display == "none")
		document.getElementById(div).style.display = "block";
	else
		document.getElementById(div).style.display = "none";		
}

//Permite digitao de nmeros apenas com aviso
function permitirNumero(e,div){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)){
		document.getElementById(div).innerHTML = "";
		return true;
	}else{
		//return(tecla != 8 && tecla !=13 && tecla != 0)?false:true;
    	if (tecla != 8 && tecla !=13 && tecla != 0){ 
			document.getElementById(div).innerHTML = "digite somente n&uacute;meros";
			return false;
		}else{ 
			document.getElementById(div).innerHTML = "";
			return true;
		}
	} 
}

//Permite digitao de nmeros e vrgulas
function permitirNumeroVirgula(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)){
		document.getElementById("aviso").innerHTML = "";
		return true;
	}else{
		//return(tecla != 8 && tecla !=13 && tecla != 0)?false:true;
    	if (tecla != 8 && tecla !=13 && tecla != 0 && tecla != 44){ 
			document.getElementById("aviso").innerHTML = "digite somente n&uacute;meros";
			return false;
		}else{ 
			document.getElementById("aviso").innerHTML = "";
			return true;
		}
	} 
}

function valida(form) {
	var elementos = form.elements;
	
	for (var i=0; i< elementos.length; i++)
	{
		if (elementos[i].getAttribute("type")=="text" || elementos[i].type == "textarea")
		{
			if (trim(elementos[i].value)=="") {
				alert("O campo "+elementos[i].getAttribute("name")+" e obrigatorio.");
				return false;
			}
		}
	}
	return true;
}

function validaFormBusca(form) {
	var tipo = form.tipo.value;
	var marca = form.marca.value;
	
	if(tipo == "" && marca == "")
	{	
		alert("Escolha um item");
		return false;
	}
	else
	{
		return true;
	}
}

function maxLength(obj, limit) {
	if (obj.value.length >= limit) {
		obj.value = obj.value.substring(0, limit-1);
	}
}

function validaFormEvento(form){
	var titulo   = trim(form.titulo.value);
	var dtinicio = trim(form.dtinicio.value);
	var dtfim    = trim(form.dtfim.value);
	var cidade   = trim(form.cidade.value);
	
	if(titulo == "" || dtinicio == "" || dtfim == "" || cidade == "")
	{
		alert("Preencha todos os campos")
		return false;
	}
	else
		if(validarData(dtinicio) != "" || validarData(dtfim) != "")
		{
			alert("Data incorreta")
			return false;
		}
		else
		{
			return true;
		}
}

/*******************************/
/***** VALIDAES INTERNAS *****/
/*******************************/

//Valida E-mail
function validarEmail(email){
	var erro = "";
	var bolReturn = false;
	var oRegEmail = /^[a-z0-9\._\-]+\@[a-z0-9\._\-]+\.[a-z]{2,3}$/i;
	bolReturn = oRegEmail.test(email);
	
	if(!bolReturn){
		erro += " Digite um e-mail vlido";
        return erro;
	}
	return erro;
}

//Valida CPF
function validarCPF(cpf){
      var erro = "";
	  
      if (cpf.length < 11){
        erro += "- CPF invlido";
		return erro;
	  }

      if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555"
          || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
        erro += "- CPF invlido";
		return erro;
      }
      var a = [];
      var b = new Number;
      var c = 11;

      for (i=0; i<11; i++){        
        a[i] = cpf.charAt(i);
        if (i < 9) b += (a[i] * --c);
      }

      if ((x = b % 11) < 2){
        a[9] = 0
      }
      else{
      a[9] = 11-x
      }
      b = 0;
      c = 11;
      for (y=0; y<10; y++) b += (a[y] * c--);
        if ((x = b % 11) < 2){
          a[10] = 0;
        }
        else{
          a[10] = 11-x;
        }
        if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
	      erro += "- CPF invlido";
		  return erro;
        }
	return erro;
}

//Valida Data
function validarData(data){

	var dia  = data.substring(0,2);
	var mes  = data.substring(3,5); 
	var ano  = data.substring(6,10);
	var bar1 = data.substring (2,3);
	var bar2 = data.substring (5,6);
	var erro = "";
	
	if ((isNaN(parseInt(dia)) || isNaN(parseInt(mes)) || isNaN(parseInt(ano))) ||(ano < 1900 || ano > 9999) ||(mes < 1 || mes > 12) ||(dia < 1 || dia > 31) ||(mes == 2 && dia > 28 && (ano % 4 != 0)) ||(mes == 2 && dia > 29 && (ano % 4 == 0)) ||(dia > 30 && (mes == 4 || mes == 6 || mes == 9 || mes== 11))){		
		if ((bar1 != '/') || (bar2 != '/')){		
			erro += "- Digite uma data válida";
			return erro;
		}else{
			erro += "- Digite uma data válida";
			return erro;
		}
	}
	return erro;
}

//Limpa contedo de um elemento
function limparAviso(div){
	document.getElementById(div).innerHTML = "";
}

function exibirQuestao(msg){
	return (confirm(msg) ? true : false);
}

function exibirPopup(pagina){
	window.open(pagina, "popup", "width=330 , height=300, top=180, left=225, status=yes ");
}

//Funo para retirar espaos TRIM
function trim(campo){
	var i = 0;

	while (campo.charCodeAt(0) == '32'){
	   campo = campo.substring(i,campo.length);
	  i++;}
	while(campo.charCodeAt(campo.length-1) == "32"){
	   campo = campo.substring(0,campo.length-1);
	  }
	
	return campo
}

// JavaScript Document


/* Permite inserir um caracter em uma string em uma posição especifica */
function InsChar( str, char, pos ) {
	var aux = '';
	var tmp = new String( str );
	var auxstr = tmp.split('');
	for( i=0; i < auxstr.length; i++ ) {
		if( (pos == i) && ( auxstr[i] != char ) ) {
			aux = aux + char;
		}
		aux = aux + auxstr[i];
	}
	return aux;
}

/* Retorna apenas os digitos numericos de uma string */
function GetNum( str ) {
	var aux = '';
	var tmp = new String( str );
	var arr = tmp.split('');
	for( i=0; i < arr.length; i++ ) {
		if( !isNaN( arr[i] ) && (arr[i] != ' ')) {
			aux = aux + arr[i];
		}
	}
	return aux;
}

function InverteString( str ) {
	var aux = new String( str );
	var tmp = '';
	for( i=0; i < aux.length; i++ ) {
		tmp = aux[i] + tmp;
	}
	return tmp;
}

/* Coloca a data no formato DD/MM/AAAA e verifica se é uma data válida */
function mskData( input ) {
	var aux = new String( InsChar( GetNum( input.value ), '/', 2 ) );
	var erro = 0;
	aux = aux.substring( 0, 10 );
	aux = InsChar( aux, '/', 5 );
	if( aux.length == 10 ) {
		dt = aux.split("/");
		var dia = parseInt( dt[0] );
		if( (dia > 31) || (dia < 1)) {
			erro = 1
		} else {
			var mes = parseInt( dt[1] );
			if( (mes>12) || (mes<1) ) {
				erro = 2;
			} else {
				var ano = parseInt( dt[2] );
				switch ( mes ) {
					case 4:
					case 6:
					case 9:
					case 11:
						if( dia > 30 ) {
							erro = 1;
						}
					break;
					case 2:
						if( (ano % 4) == 0 ) {
							if( dia > 29 ) {
								erro = 1;
							}
						} else {
							if( dia > 28 ) {
								erro = 1;
							}
						}
					break;
				} // end switch
			} // end else
		} // end else
	} // end else
	if( erro > 0 ) {
		alert( aux + ' é não é uma data válida!');
		aux = '';
	}
	input.value = aux.substring( 0, 10 );
}

function mskTelefone( input ) {
	var aux = new String( InsChar( GetNum( input.value ), '(', 0 ) );
	aux = InsChar( aux, ')', 3 );
	aux = InsChar( aux, ' ', 4 );
	aux = InsChar( aux, '.', 9 );
	input.value = aux.substring( 0, 14 );
}

/* ------------------------------------------------------------------------------------
	Formata numero na seguinte forma: 1.000.000,00 
	Obs.: o paramerto 'cd' é o número de casa decimais */
function mskNumero( input, cd ) {
	if( typeof( input ) == 'object' ) {
		var aux = new String( input.value );
		input.style.textAlign = 'right';
	} else {
		var aux = new String( input );
	}
	var tmp = aux.split('');
	var sinal = '';
	if( tmp[0] == '-' ) {
		sinal = '-';
	}
	var aux = new String( InverteString( GetNum( aux ) ) );
	if( cd > 0 ) {
		aux = InsChar( aux, ',', cd );
		cd = cd + 1;
	}
	var t = 2;
	var tmp = aux.split('');
	for( i=1; t < tmp.length; i++ ) {
		aux = InsChar( aux, '.', t + cd + 1 );
		tmp = aux.split('');
		t = t + 4;
	}
	if( typeof( input ) == 'object' ) {
		input.value = sinal + '' + InverteString( aux );
	} else {
		return sinal + '' + InverteString( aux );
	}
}


function unmskNumero( str ) {
	var aux = new String( str );
	var tmp = aux.split('');
	var novo = '';
	for( i=0; i < tmp.length; i++ ) {
		if( tmp[i] != '.' ) {
			if( tmp[i] == ',' ) {
				novo += '.';
			} else {
				novo += tmp[i];
			}
		}
	}
	return novo;
}
-->