/*
 * Delete Image
 */
function deleteImage( id_image )
{
	jQuery.noConflict();
	domain_url = new String( document.domain );
	url_profile = "http://" + domain_url + '/admin/deletephoto'

	if( confirm( 'Quieres eliminar esta foto?' ) )
	{
		jQuery.ajax({
			type: "POST",
			url: url_profile,
			data: "id_image="+id_image,
			dataType: "json",
			success: function(json)
			{
				if ( json['response'] == 'OK' )
				{
					location.reload();
				}
				else
				{
					alert( "No se ha podido eliminar la foto" );
				}
			}
		});
	}
}

/*
 * Delete Product
 */
function deleteProduct( id_product )
{
	jQuery.noConflict();
	domain_url = new String( document.domain );
	url_profile = "http://" + domain_url + '/admin/deleteprod'

	if( confirm( 'Quieres eliminar este producto?' ) )
	{
		jQuery.ajax({
			type: "POST",
			url: url_profile,
			data: "id_product="+id_product,
			dataType: "json",
			success: function(json)
			{
				if ( json['response'] == 'OK' )
				{
					location.reload();
				}
				else
				{
					alert( "No se ha podido eliminar el producto" );
				}
			}
		});
	}
}

/*
 * Delete Company
 */
function deleteCompany( id_comp )
{
	jQuery.noConflict();
	domain_url = new String( document.domain );
	url_profile = "http://" + domain_url + '/admin/deletecomp'

	if( confirm( 'Quieres eliminar esta sección?' ) )
	{
		jQuery.ajax({
			type: "POST",
			url: url_profile,
			data: "id_company="+id_comp,
			dataType: "json",
			success: function(json)
			{
				if ( json['response'] == 'OK' )
				{
					location.reload();
				}
				else
				{
					alert( "No se ha podido eliminar la sección" );
				}
			}
		});
	}
}
	
function mainEvents()
{
	jQuery.noConflict();

	jQuery("a.delete_prod").click(function(){
		id_prod = this.getAttribute("rel");
		deleteProduct( id_prod );
		return false;
	});

	jQuery("a.delete_comp").click(function(){
		id_comp = this.getAttribute("rel");
		deleteCompany( id_comp );
		return false;
	});

	jQuery("a.delete_image").click(function(){
		id_image = this.getAttribute("rel");
		deleteImage( id_image );
		return false;
	});
}
