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

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 isOneChecked(doc,form,type) {
	if (type == '') type = 'checkbox';
	for (i = 0;i < doc.forms[form].elements.length;i++) {
		if (doc.forms[form].elements[i].type == type) {
			if (doc.forms[form].elements[i].checked) {
				return true;
			}
		}
	}
	return false;
}

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;
			}
		}
	}
}

var NULL_KEYS = [0, 8, 9, 13, 16, 17, 18, 20, 27, 28, 29, 30, 31, 37, 38, 39, 40, 36, 35];

function fechaPopUp(){
	document.getElementById('popup').style.display = "none";
}

/**
 *  String.pad(length: Integer, [substring: String = " "], [type: Integer = 0]): String
 *  
 *  Retorna a string padificada a esquerda, direita ou ambos os lados.
 *  length: quantidade de caracteres que a string deverá ter após executar a funçã
 *  substring: string que será concatenada
 *  type: especifica em o lado em que deverá ocorrer a concatenação, onde: 0 = esquerda, 1 = direita e 2 = ambos os lados
 */
String.prototype.pad = function(l, s, t){
  return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
      + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
      + this + s.substr(0, l - t) : this;
};

function tempo(hora,minuto,segundo) {
	var tmphora=""+hora, tmpminuto=""+minuto, tmpsegundo=""+segundo;
	tmphora=(hora<10)?tmphora.pad(2,"0",0):tmphora;
	tmpminuto=(minuto<10)?tmpminuto.pad(2,"0",0):tmpminuto;
	tmpsegundo=(segundo<10)?tmpsegundo.pad(2,"0",0):tmpsegundo;

	$(".hora").find('strong').text(tmphora+":"+tmpminuto);

	segundo++;

	if (segundo > 59) {
		segundo = 0;
		minuto++;
	}

	if (minuto > 59) {
		minuto = 0;
		hora++;
	}

	if (hora > 24) {
		hora == 0;
	}

	var intervalo = window.setTimeout(function() { tempo(hora,minuto,segundo) },1000);
}
