/*
	Criado em: 29/Agosto/2007
	Autor: Gabriel Oliveira
	Fonte: Ajax com PHP de Lee Babin
*/

// Função para criar um XMLHttpRequest.
function getxmlhttp (){
	// Cria uma variável booleana para verificar a existência de uma instância Microsoft ative X válida.
	var xmlhttp = false;

	// Verifica se estamos usando o internet explorer.
	try {
		// Se aversão javascript for maior que 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		// Se não, então usar o obeto active X mais antigo.
		try {
			// Se estivermos usando o internet explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			// Ou devemos estar usando um navegador diferente do internet explore.
			xmlhttp = false;
		}
	}

	// Se não estiver usando o IE, cria uma instância JavaScript do objeto.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

// Função para processar um XMLHttpRequest.
function processajax (serverPage, obj, getOrPost, str){
	getOrPost = getOrPost == undefined ? 'GET' : getOrPost;
	str = str == undefined ? null : str;
	// Acha um objeto XMLHttpRequest para uso.
	xmlhttp = getxmlhttp();
	if (getOrPost == 'GET'){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(str);
	} else {
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(str);
	}
}

// Função para determinar quando o arquivo de upload acabou de executar.
function doneloading(theframe,thefile){
	var theloc = "http://sistec.rjhost.net/adm/showimg.php?thefile=" + thefile
	theframe.processajax("showimg",theloc);
}

function uploadimg (theform){
	// Envia o formulário.
	theform.submit();
	// Em seguida exibir uma mensagem de "Carregando..." para o usuário.
	//alert('teste');
	setStatus ("Carregando...","showimg");
}

// 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 changesize (img, sml){
	// Então exibir uma mensagem de "Carregando..." para o usuário.
	theobj = document.getElementById("showimg");
	if (theobj){
		setStatus ("Carregando...","showimg");
		var loc = "thumb.php?img=" + img + "&sml=" + sml;
		processajax ("showimg",loc);
	}
}
