function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
} 
function checkBoxValue(nomeCampo, obj){
	if (obj.checked == true){
		document.getElementById(nomeCampo).value = 'S';
	} else {
		document.getElementById(nomeCampo).value = 'N';	
	}
	//alert(document.getElementById(nomeCampo).value);
}
function selectionaPrimeiroCampo() {
	var campo = document.body.getElementsByTagName("INPUT");
	var campo = campo[0];	
	if (campo != null) {
		campo.focus();	
	}
}
function pegaCookie(obj){
	var email = getCookie("email");
	document.getElementById(obj).value = email;
	if (email != "" && email != null)
		document.getElementById('Salvar').checked = true
}
function focusLogin() {
	email = document.getElementById('email');
	senha = document.getElementById('senha');
	if (email.value == "")
		email.focus();
	else
		senha.focus();
}
function validaResolucao(){
	var largura = window.screen.availWidth;
	var altura = window.screen.availHeight;
	if (largura < 800 && altura < 600) {
		alert("É recomendado uma resolução de no mínimo de 800x600 para que o sistema seja visualizado corretamente!");
	}
}
function salvarEmail(email) {	
	if (document.getElementById('Salvar').checked == true) {
		setCookie("email", email);	
	} else {
		setCookie("email", "");	
	}
}
function setCookie( name, value ) {
	var expDays = 30;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	var expires = exp; 
	var bla = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
	document.cookie = bla;
}
function getCookie( name ) {
	var search = name + "=";
	if (document.cookie.length > 0) { // Existem cookies
			offset = document.cookie.indexOf(search)
			if (offset != -1) { // Existe o cookie "name"
					offset += search.length // inicio do conteudo do cookie
					end = document.cookie.indexOf(";", offset) // fim do conteudo
					if (end == -1) end = document.cookie.length;
					return unescape(document.cookie.substring(offset, end));
			} else {
					return "";
			}
	} else {
			return "";
	}
}
function url(obj){
	//alert(obj.value);
	var valor = obj.value;
	if (valor != null && valor != "") {
		if(valor.indexOf('http://') == -1) {
			obj.value = "http://" + obj.value;
		}
	}
}
MyWindow=null; 
function abrirJanela(theURL,winName,features) { 
	if(MyWindow != null) {   
		if(!MyWindow.closed) {                                  
			MyWindow.close();                               
			MyWindow = window.open(theURL,winName,features);                           
		} else {                             
			MyWindow = window.open(theURL,winName,features);                           
		}   
	} else {          
		MyWindow = window.open(theURL,winName,features); 
	}
}
function excluiRegistro(id) {	
	if(confirm("Você realmente deseja excluir este registro?\nAo deletar ele outros registro poderão ser afetados!")){
		document.location.href="?action=delete&did="+id;
	}	
}
function excluiRegistroConsulta(id, idModulo) {	
	if(confirm("Você realmente deseja excluir este registro?\nAo deletar ele outros registro poderão ser afetados!")){
		document.location.href="?action=delete&modulo="+idModulo+"&did="+id;
	}	
}
function excluiArquivo(id, idPai) {	
	if(confirm("Você realmente deseja excluir este arquivo?")){
		document.location.href="?action=deleteArq&didImg="+id+"&id="+idPai;
	}	
}
function logOut() {	
	if(confirm("Você realmente deseja sair?")){
		document.location.href="?logout";
	}	
}
function numbers_only(objeto, evt){
	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		//alert(ntecla);
		if (ntecla > 47 && ntecla<58 || ntecla==46 || ntecla==44 || ntecla==8 || ntecla==9|| ntecla==37|| ntecla==39) 
			return true;
		else 
			return false;
	}
}
function mostrarOcultar(obj) {
	if (obj.style.display == 'none') { 
		obj.style.display ='inline'; 
	} else {  
		obj.style.display ='none'; 
	} 
}
function mostrarOcultarMenuPub(nmObj, boo) {
	obj = document.getElementById(nmObj);
	if (boo) {
		obj.style.display ='inline'; 
	} else {  
		obj.style.display ='none'; 
	} 
}
function mostrarOcultarMenuPub(nmObj, boo) {
	obj = document.getElementById(nmObj);
	if (boo) {
		obj.style.display ='inline'; 
	} else {  
		obj.style.display ='none'; 
	} 
}
function lowerCase(obj) {
	obj.value = obj.value.toLowerCase();
}
function hideTagSelect(hidSho){
	var tags = document.getElementsByTagName("select");
	for (i = 0; i < tags.length; i++) {
		if (hidSho) {
			tags[i].style.visibility = 'visible';
		} else {
			tags[i].style.visibility = 'hidden';			
		}
	}
}
function verificaCheckBox(procura, msg, obriga){
	var tags = document.getElementsByTagName("input");
	var nameCheck = '';
	var valido = false;
	for (i = 0; i < tags.length; i++) {
		if (tags[i].type == "checkbox") {
			nameCheck = tags[i].id;
			if(nameCheck.indexOf(procura) != -1) {
				if (tags[i].checked == true) {
					valido = true;
				}
			}
		}
	}
	if (obriga) {
		if (valido == false){
			alert(msg);
			return false;
		} else {
			return true;
		}	
	} else {
		if (valido == false){
			if(confirm(msg)){
				return true;
			} else {
				return false;	
			}		
		}
	}
}
function msg(txt){
	alert(txt);
}
function openCloseDiv(tit, obj, pag, boo){
	var obj = document.getElementById(obj);
	if (boo) {
		obj.style.display = 'inline';
	} else {
		obj.style.display = 'none';
	}
	if (pag != "") {
		document.getElementById('iframeMainSuper').src = pag;	
	} else {
		document.getElementById('iframeMainSuper').src = 'branco.html';			
	}
	document.getElementById('tituloDiv').innerHTML = tit;	
}
function swapClassName(obj, mode, cName) {

//alert(obj.className);

	if (mode == 1) {
	   obj.className = cName;
	   obj.setAttribute("class",cName)
	   return true;
	} else if (mode == 0) {
	   obj.className = cName;
	   return true;
	}
	return true;
}
function marcaDia(d,m,a)
{
	try
	{
		html = "";
		request = createXMLHTTP();
		request.open("post", "detalheAgenda.php", false);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.send("dia=" + d + "&mes=" + m + "&ano="+a);
		obj = eval(request.responseText);
		for(i=0;i<obj.length;i++)
		{
			//html += "<dl>";
			html += "<div class=\"titulo_evento\"><strong><a href=\"evento.php?nid="+obj[i].nid+"\">"+URLDecode(obj[i].titulo)+"</a></strong><br />";
			html += URLDecode(obj[i].subtitulo)+"<br />";
			//html += "<p>"+URLDecode(obj[i].descricao)+"</p></dd>";
			//html += "</dl>";
		}
		document.getElementById('detalheCalendario').innerHTML = html;
	} catch(e){alert(e);}
}
function trocaCalendario(m,a)
{
	document.location.href='?pag=12&m='+m+'&a='+a;
}