function Confirmar( mensaje )
{
	var Respuesta = confirm( mensaje );
	return Respuesta;
}

function AnadirFoto()
{
	var longitud = document.form_propiedades.elements.length;
	
	for(i=0; i<longitud; i++)
	{
		if ( document.form_propiedades.elements[i].style.display == 'none' )
		{
			if ( document.form_propiedades.elements[i].type == 'file' )
			{
				$('#'+document.form_propiedades.elements[i].id).fadeIn(1000);
				break;
			}
		}
	}
}

function QuitarFoto()
{
	var longitud = document.form_propiedades.elements.length;
	
	for(i=0; i<longitud; i++)
	{
		if ( document.form_propiedades.elements[longitud-1-i].id == 'ocultar' )
		{
			break;
		}
			
		if ( document.form_propiedades.elements[longitud-1-i].style.display != 'none' )
		{
			if ( document.form_propiedades.elements[longitud-1-i].type == 'file' )
			{
				$('#'+document.form_propiedades.elements[longitud-1-i].id).fadeOut(1000);
				document.form_propiedades.elements[longitud-1-i].value = '';
				break;
			}
		}
	}
}

function MostrarFotos( id )
{
	$('#fotos-adicionales-'+id+' img')
		.each(function(i){
			if ($(this).attr('src') != $(this).attr('src-orig')) {
				$(this).attr('src', $(this).attr('src-orig'));
			}
		});

	$('#fotos-adicionales-'+id).slideToggle('slow');
}

function MasFotos()
{
	$('#fotos-adicionales').slideDown('slow');
	$('#fotos-adicionales-enlace').hide();
}

function BorrarFotos( tipo )
{
	var propiedad = document.getElementById('propiedad_id').value;

	if (tipo == 'principales')
	{
		if ( document.form_propiedades.borrar_fotos_principales.type == 'checkbox' )
		{
			if (document.form_propiedades.borrar_fotos_principales.checked) {
				$.ajax( {
					url: '?a=cargar&t=fotos&c=borrar&id=' + document.form_propiedades.borrar_fotos_principales.value,
					success: function() { CargarFotos('principales') }
				} );	
			}
		}
		else
		{
			for (var i = 0; document.form_propiedades.borrar_fotos_principales.length; i++) {
				if (document.form_propiedades.borrar_fotos_principales[i].checked) {
					$.ajax( {
						url: '?a=cargar&t=fotos&c=borrar&id=' + document.form_propiedades.borrar_fotos_principales[i].value,
						success: function() { CargarFotos('principales') }
					} );	
				}
			}
		}
	}
	
	if (tipo == 'adicionales')
	{
		if ( document.form_propiedades.borrar_fotos_adicionales.type == 'checkbox' )
		{
			if (document.form_propiedades.borrar_fotos_adicionales.checked) {
				$.ajax( {
					url: '?a=cargar&t=fotos&c=borrar&id=' + document.form_propiedades.borrar_fotos_adicionales.value,
					success: function() { CargarFotos('adicionales') }
				} );	
			}
		}
		else
		{
			for (var i = 0; document.form_propiedades.borrar_fotos_adicionales.length; i++) {
				if (document.form_propiedades.borrar_fotos_adicionales[i].checked) {
					$.ajax( {
						url: '?a=cargar&t=fotos&c=borrar&id=' + document.form_propiedades.borrar_fotos_adicionales[i].value,
						success: function() { CargarFotos('adicionales') }
					} );	
				}
			}
		}
	}
}

function CargarFotos( tipo )
{
	var propiedad_id = document.getElementById('propiedad_id').value;
	$('#fotos-'+tipo).load('?a=cargar&t=fotos&c='+tipo+'&id='+propiedad_id);
}

