/* Retrives all categories */
function get_all_categories() {
	var the_url = document_root+"categories/?"+Math.random();
	var cats = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				cats = data;
		}
	});
	return cats;
}

/* Retrives a category by id */
function get_category(id) {
	var the_url = document_root+"categories/?category="+id+"&"+Math.random();
	var cat = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				cat = data[0];
		}
	});
	return cat;
}

/* Retrives all products */
function get_all_products() {
	var the_url = document_root+"products/?"+Math.random();
	var prods = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				prods = data;
		}
	});
	return prods;
}

/* Retrives a product by id */
function get_product(id) {
	var the_url = document_root+"products/?product="+id+"&"+Math.random();
	var prod = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				prod = data[0];
		}
	});
	return prod;
}

/* Retrives all products that belong to the given category */
function get_products_by_category(id) {
	var the_url = document_root+"products/?category="+id+"&"+Math.random();
	var prods = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				prods = data;
		}
	});
	return prods;
}

/* Retrives all categories to which a given product belongs */
function get_product_categories(id) {
	var the_url = document_root+"categories/?product="+id+"&"+Math.random();
	var cats = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				cats = data;
		}
	});
	return cats;
}

/* Retrives all measures of a given product */
function get_product_measures(id) {
	var the_url = document_root+"products/?product="+id+"&measures&"+Math.random();
	var meas = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				meas = data;
		}
	});
	return meas;
}

/* Retrives all images of a given product */
function get_product_images(id) {
	var the_url = document_root+"products/?product=" + id + "&images&"+Math.random();
	var images = null;
	$.ajax({type:"GET", url:the_url, dataType:"json", async: false,
		success: function(data) {
				images = data;
		}
	});
	return images;
}
