function excluirFoto(foto){
	if(foto == "logo_revenda"){
		if($("#botaoAlterarLogo").css("display") == "none"){
			$("#botaoAlterarLogo").show();
		} else {
			$("#botaoAlterarLogo").hide();
		}
	} else if (foto == "foto_revenda"){
		if($("#botaoAlterarFoto").css("display") == "none"){
			$("#botaoAlterarFoto").show();
		} else {
			$("#botaoAlterarFoto").hide();
		}
	}
}

function apagaFotoSession(foto){
	$.ajax(
		{
			type: "POST",
			url: "inc/ajax_site/deleta_foto_revenda.php",
			dataType: "json",
			data: "foto="+foto	,
			success: function(data, status){
					 },
			beforeSend: function(){
				if(foto == "foto_revenda"){
					$("#load_foto").hide();
					$("#conteudo_foto").hide();
					$("#load_foto").html("");
				} else {
					$("#load_logo").hide();
					$("#conteudo_logo").hide();
					$("#load_logo").html("");
				}
			}
		}
	)
}

function alteraFotoRevenda(foto){
	if(foto == "logo_revenda"){
		$("#load_logo").html("");
		$("#load_logo").hide();
		$("#conteudo_logo").hide();
		$("#remove_upload_logo").hide();
		$("#campo_upload_logo").show();
		apagaFotoSession(foto);
	} else if (foto == "foto_revenda"){
		$("#load_foto").html("");
		$("#load_foto").hide();
		$("#conteudo_foto").hide();
		$("#remove_upload_foto").hide();
		$("#campo_upload_foto").show();
		apagaFotoSession(foto);
	}
}

function uploadLogoRevenda(foto,id_manipula,id_campo)
	{
		
		if(foto == "logo_revenda"){
			$("#load_logo").show();
			$("#conteudo_logo").show();
			$("#load_logo").html("Enviando a foto...");
		} else if (foto == "foto_revenda"){
			$("#load_foto").show();
			$("#conteudo_foto").show();
			$("#load_foto").html("Enviando a foto...");
		}

		$.ajaxFileUpload
		(
			{
				url:'inc/ajax_site/upload_logo_revenda.php?foto='+foto,
				secureuri:false,
				fileElementId:id_campo,
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							
							if(foto == "logo_revenda"){
								$("#load_logo").html(data.error);
							} else if (foto == "foto_revenda"){
								$("#load_foto").html(data.error);
							}
							
						}else
						{
							
							if(foto == "logo_revenda"){
								
								$("#"+id_manipula).html(data.msg+"<br /><input type=\"button\" value=\"Alterar\" id=\"botaoAlterarLogo\" onclick=\"return alteraFotoRevenda('logo_revenda')\" style=\"width:80px;height:20px;\" class=\"faz-cadastro\" />");
								$("#campo_upload_logo").hide();
								$("#remove_upload_logo").show();
								$("#botaoAlterarLogo").show();
								$("#load_logo").show();
								
							} else if (foto == "foto_revenda"){
								
								$("#"+id_manipula).html(data.msg+"<br /><input type=\"button\" value=\"Alterar\" id=\"botaoAlterarFoto\" onclick=\"return alteraFotoRevenda('foto_revenda')\" style=\"width:80px;height:20px;\" class=\"faz-cadastro\" />");
								$("#campo_upload_foto").hide();
								$("#remove_upload_foto").show();
								$("#botaoAlterarFoto").show();
								$("#load_foto").show();
								
							}
							
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		return false;
	}
