// JavaScript Document
function getxmlhttp() {
	// Criar variavel booleana para verificar a exsitência de uma instancia Microsoft ActiveX
	var xmlhttp = false;
	
	//Verificar se estamos usando IE
	
	try {
		//Se a versão JS for maior que 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		// S enão, então usar o objeto ActiveX mais antigo.
		try {
			//Se estamos usando IE
			xmlhttp = new ActiveXOjbect("Microsoft.XMLHTTP");
		} catch (E) {
			//Ou devemos estar usando um navegador diferente do IE
			xmlhttp = false;
		}
	}
	// Se não estivermos usando o IE, criar uma instancia JS do objeto
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

//Função para processar um XMLHttpRequest.
function processajax(obj, serverPage) {
	//Achar um objeto XMLHttpRequest para uso.
	var theimg;
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

// Função para determinar quando o arquivoi process_upload.php acabou de executar
function doneloading(theframe,thefile){
	var theloc = "showimg.php?thefile=" + thefile
	theframe.processajax("showimg",theloc);
}

function updateStatus() {
	document.getElementById("errordiv").innerHTML = "";
	document.getElementById("middiv").innerHTML = "<b> Carregando...</b>";
	
}

function refreshView() {
	//Carregar a imagem em tamanho total.
	setTimeout('processajax("middiv","midpic.php")',refreshrate);
	//Carregar a navegação
	setTimeout('processajax("picdiv","picnav.php")',refreshrate);

}
function uploadimg (theform) {
	
	//Atualizar mensagem de status do usuário
	updateStatus();
	// Enviar o formulário.
	theform.submit();
	// Em seguida atualiza o display
	refreshView();
}

function removeimg(theimg) {
	processajax("errordiv","delpic.php?pic=" + theimg);
	refreshview();
}

function imageClick(img) {
	
	updateStatus();
	processajax("middiv" , "midpic.php?curimage=" + img);
	processajax("picdiv" , "picnav.php?curimage=" + img);
}
	

//Função para definir um status de carga.
function setStatus (theStatus, theObj) {
	obj = document.getElementById(theObj);
	if (obj) {
		obj.innerHTML = "<div class=\"bold\">" + theStatus + "</div>";
	}
}

function logoff() {
	
	window.location.href = "acesso_restrito.php?acao=logoff";
	
}



// Google Analytics

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-664231-5");
pageTracker._trackPageview();
} 
catch(err) {}



function retira_acentos(texto) {
	var chrEspeciais = new Array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë",
				     "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö",
				     "ú", "ù", "û", "ü", "ç",
				     "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë",
				     "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö",
				     "Ú", "Ù", "Û", "Ü", "Ç");
	var chrNormais = new Array("a", "a", "a", "a", "a", "e", "e", "e", "e",
				   "i", "i", "i", "i", "o", "o", "o", "o", "o",
				   "u", "u", "u", "u", "c",
				   "A", "A", "A", "A", "A", "E", "E", "E", "E",
				   "I", "I", "I", "I", "O", "O", "O", "O", "O",
				   "U", "U", "U", "U", "C");
	for (index in chrEspeciais) {
		texto = texto.replace(chrEspeciais[index], chrNormais[index]);
	}

	return texto.toUpperCase();
}


