
function getLocationHashVar(name) {
	var hashString = window.location.hash.substring(1, window.location.hash.length);
	var hashCouples = hashString.split('&');
	for (var i = 0; i < hashCouples.length; i++) {
		var couple = hashCouples[i].split('=');
		if (couple.length != 2) continue;
		var key = decodeURIComponent(couple[0]);
		if (key == name) {
			return decodeURIComponent(couple[1]);
		}
	}
	return null;
}

function setLocationHashVar(name, value) {
	var hashString = window.location.hash.substring(1, window.location.hash.length);
	var hashCouples = hashString.length > 0 ? hashString.split('&') : [];
	var add = true;
	for (var i = 0; i < hashCouples.length; i++) {
		var couple = hashCouples[i].split('=');
		if (couple.length != 2) continue;
		var key = decodeURIComponent(couple[0]);
		if (key == name) {
			if (value == null) {
				hashCouples.splice(i, 1);
			} else {
				couple[1] = value;
				hashCouples[i] = couple.join('=');
			}
			add = false;
			break;
		}
	}
	if (add && value != null) {
		hashCouples.push(encodeURIComponent(name) + '=' + encodeURIComponent(value));
	}
	window.location.hash = (hashCouples.length == 0) ? '' : ('#' + hashCouples.join('&'));
}

