function getHTTPObject(){
	// Mozilla, Safari,...
	if (window.XMLHttpRequest){
		return new XMLHttpRequest();
	
	// IE
	}else if (window.ActiveXObject){
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}		
}

function execAjax(url, funcRetorno){
	ajax = false ;
	ajax = getHTTPObject();
	
	ajax.onreadystatechange = funcRetorno;
	ajax.open("GET", url, true);
	ajax.setRequestHeader("Content-Type", "multipart/form-data");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	ajax.send(null);
}

function carregaMiniatura(){
	var divMiniatura	= document.getElementById("divMiniatura");
	if(ajax.readyState == 4){
		if(ajax.status == 200){
			divMiniatura.innerHTML = ajax.responseText;
		}else{
			divMiniatura.innerHTML = "Ocorreu um erro ao carregar galeria de fotos...";
		}
	}
}

function legenda(){
	var divDetalhes	= document.getElementById("divDetalhes");
	if(ajax.readyState == 4){
		if(ajax.status == 200){
			if (ajax.responseText == 'NaoExiste'){
				execAjax('miniaturas.asp', carregaMiniatura);
				setTimeout("execAjax('carregaDetalhes.asp?nomeFoto=padrao', legenda)", 100);
			}else{
			divDetalhes.innerHTML = ajax.responseText;
			}
		}		
	}
}

function processaRetorno(){
	if(ajax.readyState == 4){
		if(ajax.status == 200){
			if (ajax.responseText != ""){
				alert(ajax.responseText);

				// Limpa detalhes da imagem
				execAjax('carregaDetalhes.asp?nomeFoto=padrao', legenda);
				
				// Recarrega miniaturas
				setTimeout("execAjax('miniaturas.asp', carregaMiniatura)", 100);
			}
		}else{
			alert("Ocorreu um erro ao processar retorno Ajax.");
		}
	}
}