function navigateWithParam(paramName, paramValue)
{
	var qs = location.search;
	if (qs.length <= 1) {
		if(paramValue != null)
			location.href = location.href+"?" + paramName + "=" + paramValue;
		else
			location.href = location.href;
		return;
	}
	qs = qs.substring(1, qs.length);
	var newQs = "";
	var parts = qs.split("&");
	for (var i = 0; i < parts.length; i++) {
		var data = parts[i].split("=");
		var argName = data[0];
		if (argName != paramName) {
			var argValue = "";
			for (var j = 1; j < data.length; j++) {
				argValue += data[j];
				if (j < data.length - 1)
					argValue += "=";
			}
			newQs += argName + "=" + argValue + "&";
		}
	}
	
	if(paramValue == null)
		location.href = location.protocol+"//"+location.host+"/"+location.pathname+"?" + newQs.substring(0, newQs.length - 1);
	else
		location.href = location.protocol+"//"+location.host+location.pathname+"?" + newQs + paramName + "=" + paramValue;
}

function cleanCombo(comboId)
{
	var combo = document.getElementById(comboId);
	if (combo) {
		var knownValues = new Object();
		var indexesToRemove = new Array();
		for (var i = 0; i < combo.options.length; i++) {
			if (knownValues[combo.options[i].value]) {
				indexesToRemove.push(i);
			} else {
				knownValues[combo.options[i].value] = true;
			}
		}
		for (var i = indexesToRemove.length - 1; i >= 0; i--) {
			combo.remove(indexesToRemove[i]);
		}
	}
}

function NextPrevious(start, num, total, hasNext, hasPrev)
{
	this.start= start;
	this.num = num;
	this.total = total;
	this.hasNext = hasNext;
	this.hasPrevious = hasPrev;
};

NextPrevious.prototype.write = function()
{
	// determine pages to link to
	var linkArr = new Array();
	
	if (this.hasPrevious || this.hasNext) {
		var prev = new Object();
		prev.name = "<< Prev ";
		prev.link = this.hasPrevious ? "javascript:navigateWithParam('start', " + (this.start - this.num) + ");" : null;
		linkArr.push(prev);
	}
	
	var selected = this.name = this.start / this.num + 1;
	var start = 1;
	if (selected > 5) {
		start = selected - 4;
	}
	var end = start + 10;
	if (end * this.num > this.total) {
		end = this.total / this.num;
	}
	for (var i = start; i < end; i++) {
		var x = new Object();
		x.name = new String(i);
		x.link = i != selected ? "javascript:navigateWithParam('start', " + ((i-1)*this.num) + ");" : null;
		linkArr.push(x);
	}
	
	if (this.hasPrevious || this.hasNext) {
		var next = new Object();
		next.name = " Next >>";
		next.link = this.hasNext ? "javascript:navigateWithParam('start', " + (this.start + this.num) + ");" : null;
		linkArr.push(next);
	}
	
	// write out the array
	for (var i = 0; i < linkArr.length; i++) {
		var link = linkArr[i];
		if (link.link) {
			document.write("<a href=\"" + link.link + "\" class=\"next_prev_link\">" + link.name + "</a> ");
		} else {
			document.write("<span class=\"next_prev_inactive\">" + link.name + "</span> ");
		}
		document.write("&nbsp;");
	}
}

