function ajax() {

};

ajax.prototype.iniciar = function() {

	try{
		this.xmlhttp = new XMLHttpRequest();
	}

	catch(ee){
		try{
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E){
				this.xmlhttp = false;
			}
		}
	}
	return true;
}

ajax.prototype.ocupado = function() {
	estadoAtual = this.xmlhttp.readyState;
	return (estadoAtual && (estadoAtual < 4));
}

ajax.prototype.processa = function(){
	if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200){
		return true;
	}
}

ajax.prototype.enviar = function(url, metodo, modo){
	if (!this.xmlhttp){
        this.iniciar();
	}

	if (!this.ocupado()) {
		if(metodo == "GET") {
			this.xmlhttp.open("GET", url, modo);
			this.xmlhttp.send(null);
		}
		else{
			this.xmlhttp.open("POST", url, modo);
			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			this.xmlhttp.setRequestHeader("Pragma", "no-cache");
			this.xmlhttp.send(url);
		}

		if (this.processa) {
			return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
		}
	}
	return false;
}

function AdicionaImagem(Id_Imagem)
{
	//alert('Id_Imagem	'	+ Id_Imagem);

	xmlhttp = new ajax();
	xmlhttp.enviar('sql_ajax.php?id_img=' + Id_Imagem + '&action=I', "POST", false);
	return false;

}

function ExcluirImagem(Id_Imagem)
{
	//alert('Id_Imagem	'	+ Id_Imagem);

	xmlhttp = new ajax();
	xmlhttp.enviar('sql_ajax.php?id_img=' + Id_Imagem + '&action=D', "POST", false);
	return false;
}

function SomaClique(ObjId)
{
	//alert('ObjId		'		+ ObjId);

	xmlhttp = new ajax();
	xmlhttp.enviar('soma_clique.php?imagem=' + ObjId, "POST", false);
	return false;

}

function AdicionaFotoFavorita(Id_Foto,Id_Usuario,Pagina)
{
	//alert('AdicionaFotoFavorita');
	//alert('Id_Foto		'		+ Id_Foto);
	//alert('Id_Usuario		'		+ Id_Usuario);

	if(Pagina == 1){
		valor = "<hr /><center><img src='img/botao_foto_favorita.jpg' border='0' hspace='5' /></center>";
	} else {
		valor = "<center><img src='img/botao_foto_favorita.jpg' border='0' hspace='5' /></center>";
	}
	
	//document.getElementById("FOTO"+Id_Foto).style.display = 'block';
	var obj = document.getElementById("FOTO"+Id_Foto);
	obj.innerHTML = valor;

	xmlhttp = new ajax();
	xmlhttp.enviar('sql_favoritos.php?id_usuario=' + Id_Usuario + '&id_foto=' + Id_Foto + '&action=I', "POST", false);
	return false;

}

function ExcluirFotoFavorita(Id_Foto,Id_Usuario)
{
	//alert('ExcluirFotoFavorita');
	//alert('Id_Foto		'		+ Id_Foto);
	//alert('Id_Usuario		'		+ Id_Usuario);

	valor = "Foto apagada com sucesso";
	//valor = "<img src='img/botao_favoritos_vwlovers.jpg' border='0' hspace='5' title='Adicionar aos Favoritos' onclick='AdicionaFotoFavorita('"+Id_Foto+"','"+Id_Usuario+"','2');' class='cursor' />";
	//alert(valor);
	//document.getElementById("FOTO"+Id_Foto).style.display = 'block';
	var obj = document.getElementById("FOTO"+Id_Foto);
	obj.innerHTML = valor;

	xmlhttp = new ajax();
	xmlhttp.enviar('sql_favoritos.php?id_usuario=' + Id_Usuario + '&id_foto=' + Id_Foto + '&action=E', "POST", false);
	return false;

}


