/*** GALERIA DE FOTOS ***/
var intervalo_galeria;
var distancia = 10; //Distancia do movimento em pixels
var velocidade = 50; //Milisegundos
var target;
var fotoAtual = 0;

function montarGaleria(){
	target = document.getElementById('img_galeria');
	target.src = fotos[fotoAtual];
}

function mostrarFoto(indice){
	if(indice >= 0 && indice < fotos.length){
		target.src = fotos[indice];
		fotoAtual = indice;
	}
}

function mostrarSetas(){
	var setaVoltar = document.getElementById('setafoto_voltar');
	var setaAvancar = document.getElementById('setafoto_avancar');
	setaVoltar.style.visibility = 'visible';
	setaAvancar.style.visibility = 'visible';
}

function esconderSetas(){
	var setaVoltar = document.getElementById('setafoto_voltar');
	var setaAvancar = document.getElementById('setafoto_avancar');
	setaVoltar.style.visibility = 'hidden';
	setaAvancar.style.visibility = 'hidden';
}

function mouseOver(sentido){

	var elemento = document.getElementById('content_miniaturas');
	
	function avancar(){
		elemento.scrollLeft += distancia;
	}
	
	function voltar(){
		elemento.scrollLeft -= distancia;
	}
	
	if(sentido == 1) intervalo_galeria = setInterval(avancar,velocidade); else intervalo_galeria = setInterval(voltar,velocidade);
	
}

function mouseOut(){
	clearInterval(intervalo_galeria);
}

/*** abrirFoto ***/
function abrirFoto(foto,width,height) {
	//abrirJanela('foto-maior.php?foto='+foto,'_blank',300,300,'no');
	window.divopen('foto-maior.php?foto='+foto,width,height);
}

/*** abrirFotoPop ***/
function abrirFotoPop(foto,width,height) {
	abrirJanela('foto-maior.php?foto='+foto,'_blank',300,300,'no');
}

function validarEmail(email) {
	email = email.toLowerCase();
	tmpEmail = /^[\w-]+(\.[\w-]+)*@(([0-9a-z\d][0-9a-z\d-]{0,61}[0-9a-z\d]\.)+[0-9a-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	eval("tmpEmail = tmpEmail");
	if (tmpEmail.test(email)) return true;
	else return false;
}

function emitirAlerta(msg,obj) {
	if (msg != '') alert(msg);
	if (obj) obj.focus();
}

function boxMarcados(objForm) {
	qtd = 0;
	for (i = 0;i < objForm.elements.length;i++) {
		if (objForm.elements[i].type == 'checkbox') {
			if (objForm.elements[i].checked) {
				qtd++;
			}
		}
	}
	return qtd;
}

function abrirJanela(url,target,w,h) {
	abrirJanelaScroll(url,target,w,h,'no');
}

function abrirJanelaScroll(url,target,w,h,scrollbar) {
	l = parseInt((screen.width - w) / 2);
	t = parseInt((screen.height - h) / 2);
	window.open(url,target,'width='+w+',height='+h+',left='+l+',top='+t+',scrollbars='+scrollbar);
}

function imprimirAudio(arquivo,w,h) {
	//document.write('<embed src="'+arquivo+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('<object id="MediaPlayer1" width='+w+' height='+h+' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Carregando o Windows Media Player" type="application/x-oleobject" align="middle">');
	document.write('<param name="FileName" value="'+arquivo+'">');
	document.write('<param name="AutoStart" value="True">');
	document.write('<param name="ShowStatusBar" value="True">');
	document.write('<param name="DefaultFrame" value="mainFrame">');
	document.write('<embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" src="'+arquivo+'" align="middle" width='+w+' height='+h+' defaultframe="rightFrame" showstatusbar=false></embed>');
	document.write('</object>');
}

function imprimirFlash(arquivo,w,h,transparente,params,id) {
	document.write('<object'+(((typeof id != 'undefined') && (navigator.appVersion.indexOf('MSIE') > -1))?' id="'+id+'"':'')+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"' + ((typeof w == 'undefined')?'':' width="'+w+'"') + ((typeof h == 'undefined')?'':' height="'+h+'"') + '>');
	document.write('<param name="movie" value="'+arquivo+'">');
	document.write('<param name=quality value=high>');
	document.write('<param name="menu" value="false">');
	if (typeof params != 'undefined') {
		var p = '';

		for (var i in params) {
			p += i + '="' + params[i] + '" ';
			document.write('<param name="'+i+'" value="'+params[i]+'">');
		}
	}
	if (transparente) {
		document.write('<param name="wmode" value="transparent">');
	}
	document.write('<embed'+(((typeof id != 'undefined') && (navigator.appVersion.indexOf('MSIE') < 0))?' id="'+id+'"':'')+' src="'+arquivo+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"' + ((typeof w == 'undefined')?'':' width="'+w+'"') + ((typeof h == 'undefined')?'':' height="'+h+'"') + ' ');
	if (transparente) {
		document.write('wmode="transparent" ');
	}
	document.write(p);
	document.write(' menu="false"></embed>');
	document.write('</object>');
}

function toggleDisplay(id) {
	if (typeof id == 'string') {
		obj = document.getElementById(id);
	} else {
		obj = id;
	}
	if (obj && obj.style) {
		obj.style.display = (obj.style.display == ''?'none':'');
	}
}

function hiddenDisplay(arrId) {
	for (i = 0;i < arrId.length;i++) {
		if (typeof arrId[i] == 'string') {
			obj = document.getElementById(arrId[i]);
		} else {
			obj = arrId[i];
		}
		obj.style.display = 'none';

	}
}

function validaCPF(cpf){
	s = cpf.substring(0,3) + cpf.substring(4,7) + cpf.substring(8,11) + cpf.substring(12,14);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (var i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0){
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}

	if (cpf == '111.111.111-11') return false;
	return true;
}

function verificarMascara(tecla,m) {
	if (m == '?') {
		return ('0123456789ABCDEFGHIJKLMNOPQRSTUVXWYZÇÁÀÉÈÃÕÏÖÜÄ'.toLowerCase().indexOf(tecla.toLowerCase()) > -1);
	} else if (m == '#') {
		return ('0123456789'.indexOf(tecla) > -1);
	} else if (m == '$') {
		return ('ABCDEFGHIJKLMNOPQRSTUVXWYZÇÁÀÉÈÃÕÏÖÜÄ'.toLowerCase().indexOf(tecla.toLowerCase()) > -1);
	} else return false;
}

function mascaraCampo(elemento, mascara, event){
	if (navigator.appName.toLowerCase().indexOf("netscape") > -1){
		ntecla=event.which;
	} else {
		ntecla=event.keyCode;
	}

	tecla = String.fromCharCode(ntecla);

	var m = mascara.charAt(elemento.value.length);

	var teclas = new Array(0, 8, 9, 13, 16, 17, 18, 20, 27, 28, 29, 30, 31, 37, 38, 39, 40, 46, 116);

	for (var i = 0; i < teclas.length; i ++) {
		if (teclas[i] == ntecla) {
			return true;
		}
	}

	if ((m == '?') || (m == '#') || (m == '$')) return verificarMascara(tecla,m);
	else {
		elemento.value += mascara.charAt(elemento.value.length);
		m = mascara.charAt(elemento.value.length);
		if (mascara.charAt(elemento.value.length-1) == tecla){
			return false;
		}
		else{
			return verificarMascara(tecla,m);
		}
	}
}

function abrirRadio() {

}

function exibirHitMedia(id) {
	obj = document.getElementById(id);
	if (obj) {
		obj.style.visibility='visible';
		obj.style.position = 'absolute';
	}
}

function esconderHitMedia(id) {
	obj = document.getElementById(id);
	if (obj) {
		obj.style.visibility = 'hidden';
		obj.style.position = 'absolute';
	}
}

function jsQuery(src) {
	var h = document.getElementsByTagName('script')[0];
	var s = document.createElement('script');
	s.setAttribute('type', 'text/javascript');
	s.setAttribute('src', src);
	h.appendChild(s);
}

function inputOnFocus(obj,padrao) {
	if (obj.value == padrao) {
		obj.value = '';
	}
}

function inputOnBlur(obj,padrao) {
	if (obj.value == '') {
		obj.value = padrao;
	}
}


function nextFocusOnFull(obj, event) {
	var teclas = new Array(0, 8, 9, 13, 16, 17, 18, 20, 27, 28, 29, 30, 31, 37, 38, 39, 40, 36, 35);
	if ((obj.value.length == obj.maxLength) && (teclas.indexOf(event.keyCode || event.which) < 0)) {
		for (var i = 0; i < obj.form.elements.length; i++) {
			if (obj.form.elements[i] == obj) {
				var el = obj.form.elements[(i+1) % obj.form.elements.length];
				el.focus();
				event.returnValue = false;
				event.cancelBubble = true;
				if (event.preventDefault) {
					event.preventDefault();
				}
				return true;
			}
		}
	}
}

function nextTab(obj, event, next, brother){
	if(event.keyCode == 9){
		if(brother != 1){
			for(var x=0;x < obj.form.elements.length;x++){
				if(obj.form.elements[x].name == next){
					obj.form.elements[x].focus();
					return false;
				}
			}
		} else {
			document.getElementById(next).focus();
			return false;
		}
	}
}

tmpEnqueteparcial = false;

function toggleParcial(total){
	var tempEle;
	for(var x=0; x<total; x++){
		tempEle = document.getElementById('parcial_'+x).style;
		tempEle.visibility = (tempEle.visibility=="hidden")?"visible":"hidden";
	}
}

function checkFormEnquete() {
	obj = document.enquete;
	if (!tmpEnqueteparcial) {
		if (isOneChecked(document,'enquete','radio')) {
			return true;
		} else alert('Selecione alguma opção');
	//Em caso de resultado parcial, a enquete deve ser submetida
	} else return true;
	return false;
}

function fechar(){
    document.getElementById('hitmidia').style.display = 'none';
}
