/* ---------------------------------

collected and fixed by Mark Hicken (nekcih@yahoo.com)

EXAMPLE USAGE:

var variableValue = querystring.getValue('variableName');

----------------------------------- */
var queryString = new Object();
querystring = queryString;
QueryString = queryString;
Querystring = queryString;

queryString.aParams = window.location.search.substring(1).split('&'); // chop ? and split at &

queryString.get = function(sKey) {
	for(i=0; i<this.aParams.length; i++){
		if(sKey == this.aParams[i].split('=')[0]) {
			return this.aParams[i].split('=')[1];
		}
	}
	return '';
}

queryString.set = function(sKey, sValue) {
	for(i=0; i<this.aParams.length; i++){
		if(sKey == this.aParams[i].split('=')[0]) {
			this.aParams[i] = this.aParams[i].split('=')[0] + '=' + sValue;
			break;
		}
	}
}

queryString.add = function(sKey, sValue) {
	this.aParams.push(sKey+'='+sValue);
}

queryString.remove = function(sKey) {
	var aNewParams = new Array();
	var sRemovedValue = '';
	for(i=0; i<this.aParams.length; i++){
		if(sKey != this.aParams[i].split('=')[0]) {
			sRemovedValue = this.aParams[i].split('=')[1];
			aNewParams.push(this.aParams[i].split('=')[0] + '=' + this.aParams[i].split('=')[1]);
		}
	}
	this.aParams = aNewParams;
	return sRemovedValue;
}

queryString.serialize = function() {
	var sSerialized = '';
	for(i=0; i<this.aParams.length; i++){
		sSerialized += this.aParams[i].split('=')[0] + '=' + this.aParams[i].split('=')[1];
		if(i+1 != this.aParams.length) { sSerialized += '&'; }
	}
	return sSerialized;
}
