/* Get the query string to append to the url to maintain the current settings 
 * and add the new params (dictionary of key=value) and remove the values of
 * the keys given in remove_list. */
var get_query_string = function( orig, params, remove_list ){
     var options = orig.split('&');
     var newOptions = {};
     for ( b in options ){
      if ((typeof options[b] != 'function') && (options[b].split('=').length > 1 )){
        var c = options[b].split( '=' );
        newOptions[c[0]] = c[1];
      }
     }
   for (p in params){
     newOptions[escape(p)] = escape(params[p]);
   }
   for ( r in remove_list ){
     delete newOptions[ remove_list[r] ];
   }
   var newQString = "?";
   for ( option in newOptions ){
     newQString += "&" + option+"="+newOptions[option];
   }
   return newQString;
};

/* Set the query string to append to the url to maintain the current settings 
 * and add the new params (dictionary of key=value) and remove the values of
 * the keys given in remove_list.
 * Reloads the page with the new settings. */
var set_query_string=function( params, remove_list  ){
  if (window.location.href.split('#').length > 1){
     var end = "#" + window.location.href.split('#')[1];
     var begin = window.location.href.split('#')[0];
  }else{
    var begin = window.location.href;
    var end = "";
  }
  if ( begin.split( '?' ).length > 1){
     var orig = begin.split( '?' )[1];
     var newQString = get_query_string( orig, params, remove_list );
   }else{
     var newQString = get_query_string( '', params, remove_list );
   }
   window.location.href = begin.split('?')[0] + newQString + end;
};
