//var apiRoot = "/api";
var apiRoot = "http://localhost:4567/api";
var coverRoot = apiRoot + "/cover";
var libraryRoot = apiRoot + "/library";
var infoRoot = apiRoot + "/manga_info";
var snackbar;
//TODO copy the QueryParams object from reader to here

//Api functions
function buildCoverUrl(mangaId) {
    return coverRoot + "/" + mangaId;
}

//Remove all children from element
function clearElement(myNode) {
    while (myNode.firstChild) {
        myNode.removeChild(myNode.firstChild);
    }
}

//Is a variable valid?
function valid(v) {
	return v !== undefined && v !== null;
}

function rawElement(element) {
	if(element instanceof jQuery) {
		return element[0];
	} else {
		return element;
	}
}

function mdlCheckboxCheck(checkbox, check) {
	//For some stupid reason, we need the parent label to change the checkbox!
	if(check) {
		rawElement(checkbox.parent()).MaterialCheckbox.check();
	} else {
		rawElement(checkbox.parent()).MaterialCheckbox.uncheck();
	}
}

//Catch onload
window.onload = function() {
	//Setup snackbar
	snackbar = $("#snackbar");
	if(valid(snackbar)) {
		snackbar = snackbar[0];
		if(valid(snackbar)) {
			snackbar = snackbar.MaterialSnackbar;
		}
	}
	//Call other onload listeners
	if(valid(onLoad)) {
		onLoad();
	}
};

@@ -194,62 +194,746 @@
 ar;%0A
-//TODO copy the QueryParams object from reader to here
+var QueryString = function () %7B%0A%09// This function is anonymous, is executed immediately and%0A%09// the return value is assigned to QueryString!%0A%09var query_string = %7B%7D;%0A%09var query = window.location.search.substring(1);%0A%09var vars = query.split(%22&%22);%0A%09for (var i=0;i%3Cvars.length;i++) %7B%0A%09%09var pair = vars%5Bi%5D.split(%22=%22);%0A%09%09// If first entry with this name%0A%09%09if (typeof query_string%5Bpair%5B0%5D%5D === %22undefined%22) %7B%0A%09%09%09query_string%5Bpair%5B0%5D%5D = decodeURIComponent(pair%5B1%5D);%0A%09%09%09// If second entry with this name%0A%09%09%7D else if (typeof query_string%5Bpair%5B0%5D%5D === %22string%22) %7B%0A%09%09%09query_string%5Bpair%5B0%5D%5D = %5Bquery_string%5Bpair%5B0%5D%5D, decodeURIComponent(pair%5B1%5D)%5D;%0A%09%09%7D else %7B%0A%09%09%09query_string%5Bpair%5B0%5D%5D.push(decodeURIComponent(pair%5B1%5D));%0A%09%09%7D%0A%09%7D%0A%09return query_string;%0A%7D();
 %0A%0A//

Copy over QueryString from reader.