var popup=0;
function abre_popup()
{
	if (popup==0)
	{
		$('#screen').show();
	/*	$('#screen').fadeTo("slow",1);
		$('#overlay').show();*/
		$('#overlay').fadeTo("slow",0.6,function () { popup=1 });
	}
}

function fecha_popup()
{
//	$('div.popup2').fadeTo("slow",0);
	$('#overlay').fadeOut("slow",function () { $('#screen').hide(); $('#screen').empty(); $('#screen').append('<div id="overlay" style="filter:alpha(opacity=0);"></div>'); popup=0; } );
}

function fecha_janela(janela)
{
	if (janela==null)
	{
		$('div.popup2').fadeOut("normal");
		fecha_popup();
	} else {
		$('#janela'+janela).fadeOut("normal",function () 
																	{
																		$('#popup'+janela).hide(); $('#popup'+janela).remove();
																		if ($('div.popup2').html()==null)
																		{
																			fecha_popup();
																		}
																	} );
	}
}

var index=1;
function abre_janela(janela)
{
	abre_popup();
	var str='<div id="popup'+index+'" align="center" style="z-index:'+(500+index)+'" class="popup2"><div class="popup" id="janela'+index+'"></div></div>';
	$('#screen').append(str);
	$('#janela'+index).load('popups/'+janela+'.php', { 'index': index, 'outro': arguments[1]  }, function() { /*alert('ok');*/ });
	$('#popup'+index).show();
	$('#janela'+index).fadeIn("slow",function () { $('#janela'+index).Draggable({ handle:'#titulo', zIndex:1000 }); index++; } );
}

function remove_imagem()
{
	$("input[name='rem_imagem']").val('1');
	$('#ico_foto').css('background','#ff9900');
	fecha_janela();
}

function loading() {
	
}

function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
//    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
//    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
	 $('#not_legenda').val($('#input_leg').val());
	 $('#not_fotografo').val($('#input_fot').val());
    return true; 
} 

function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
//    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
//        '\n\nThe output div should have already been updated with the responseText.'); 
//	abre_janela('img_carr',responseText);
$('#cod_imagem').val(responseText);
fecha_janela();
//	alert('#cod_imagem').val();
}