// JavaScript Document
$(function(){
	$("a.currency").click(function(){
		switchCurrency($(this).attr("id"));
	});
	$("td.currencyswitch").css({width:"31px", cursor:"pointer"}).click(function(){
	  	switchCurrency($(this).attr("id"));
	});
});
function switchCurrency(sym){
	var keys = {};
	var a = location.search;
	var q = "" + a;
	q = q.replace(/^\?/,''); // remove any leading ?
	q = q.replace(/\&$/,''); // remove any trailing &
	jQuery.each(q.split('&'), function(){
		var key = this.split('=')[0];
		var val = this.split('=')[1];
		if(/^[0-9.]+$/.test(val))
			val = parseFloat(val);
		else if (/^[0-9]+$/.test(val))
			val = parseInt(val);
		keys[key] = val;
	});
	
	//keys["currency"] = $(this).attr("id");
	keys["currency"] = sym;
	
	window.location = newQueryString(keys);
}
function newQueryString(keys) {
	var i = 0, queryString = [];
	jQuery.each(keys, function(key, value) {
		var o = [];
		if (value !== false) {
			if (i++ == 0)
				o.push("?");
			o.push(key);
			if (value !== true) {
				o.push("=");
				o.push(encodeURIComponent(value));
			}
		}
		queryString.push(o.join(""));
	});
	return queryString.join("&");
}  