function apareceSubMenu(id) {
	document.getElementById(id).style.display='block';
}
function abre(id) {
	document.getElementById(id).style.display='block';
}
function someSubMenu(id) {
	document.getElementById(id).style.display='none';
}
function fecha(id) {
	document.getElementById(id).style.display='none';
}
function abrePopup(sPagina) {
	window.open(sPagina,null,'width=740,height=445');
}

function displayDiv(id,act){
  div = document.getElementById(id);
  div.style.display=act;
}

function formatar(src, mask)
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida)
  {
	src.value += texto.substring(0,1);
  }
}
function evita_letra(tecla) {
	if (tecla.keyCode < 44 || tecla.keyCode > 57)
		tecla.returnValue = false;
}

function val_cpf(numero2) {
	dig_1 = 0;
	dig_2 = 0;
	controle_1 = 10;
	controle_2 = 11;
	lsucesso = 1;

	var numero = numero2.substr(0,3) + numero2.substr(3,3) + numero2.substr(6,3) + numero2.substr(9,2);
          //alert(numero);
	if (numero == "00000000000" || numero == "11111111111" || numero == "22222222222" || numero == "33333333333" || numero == "44444444444" || numero == "55555555555" || numero == "66666666666" || numero == "77777777777" || numero == "88888888888" || numero == "99999999999") {
		return false;
	}

	if ((numero.length != 11) && (numero.length != 0)) {
		return false;
	}
	else {
		for ( i=0 ; i < 9 ; i++) {
			dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
			controle_1 = controle_1 - 1;
		}

		resto = dig_1 % 11;
		dig_1 = 11 - resto;
		if ((resto == 0) || (resto == 1)) {
			dig_1 = 0;
		}
		for ( i=0 ; i < 9 ; i++) {
			dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
			controle_2 = controle_2 - 1;
		}
		dig_2 = dig_2 + 2 * dig_1;
		resto = dig_2 % 11;
		dig_2 = 11 - resto;
		if ((resto == 0) || (resto == 1)) {
			dig_2 = 0;
		}
		dig_ver = (dig_1 * 10) + dig_2;
		if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
			return false;
		}
	}

	return true;
}

function verifica_mail(email){
	var campo = email;
	//se a "@" não existe e é o primeiro caractere
	if (campo.indexOf("@") < 1) return false
	//se o caracter antes da "@" é "."
	if(campo.charAt(campo.indexOf("@")-1) == ".") return false;
	//se a última incidência de "." está antes da @
	if (campo.lastIndexOf(".") <= campo.indexOf("@")) return false;
	//se o último caracter é ponto,
	if (campo.lastIndexOf(".")  == (campo.length-1)) return false;

	return true;
}

function strlen (string) {
    var str = string+'';
    var i = 0, chr = '', lgth = 0;

    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if (0xD800 <= code && code <= 0xDBFF) {
            if (str.length <= (i+1))  {
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i)+str.charAt(i+1);
        } else if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if (0xD800 > prev || prev > 0xDBFF) { //(could change last hex to 0xDB7F to treat high private surrogates as single characters)
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; // We can pass over low surrogates now as the second component in a pair which we have already processed
        }
        return str.charAt(i);
    };

    for (i=0, lgth=0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {
            continue;
        } // Adapt this line at the top of any loop, passing in the whole string and the current iteration and returning a variable to represent the individual character; purpose is to treat the first part of a surrogate pair as the whole character and then ignore the second part
        lgth++;
    }
    return lgth;
}

function base64_encode( data ) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

    if (!data) {
        return data;
    }

    data = this.utf8_encode(data+'');

    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);

    enc = tmp_arr.join('');

    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}

function trocaImagem(img,texto,width){
	parent.document.getElementById("imgGalGrande").src = img;
    if (width > 540)
        parent.document.getElementById("imgGalGrande").width = '540';
    else if (width > 0)
        parent.document.getElementById("imgGalGrande").width = width;
	parent.document.getElementById("divLegendaFoto").innerHTML = texto;
}
//
var myTime;
function scrollUp(){
	window.frameGal.scrollBy(-5,0);//sobe a barra de rolagem
	myTime = setTimeout('scrollUp()', 5);//myTime objeto q mantém a recursividade
}

function scrollDown(){
	window.frameGal.scrollBy(5,0);//desce a barra de rolagem
	myTime = setTimeout('scrollDown()', 5);//myTime objeto q mantém a recursividade
}
