function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

var url = '/index.php?option=com_zipsearch';
	
if ( window.location.hash.length > 1 && 
		(window.location.href.match('zipsearch') || 
		 window.location.href.match('zip-search') ||
		 window.location.href.match('senior-community-finder'))
	) {
		var hash = window.location.hash;
		var vars = hash.substr(1).split('/');
		
		var types = [];
		var features = [];
		
		for (var i = 0; i < vars.length; i++) {
			if (vars[i].match('l_')) {
				url += '&location=' + vars[i].substr(2);
			} else if (vars[i].match('r_')) {
				url += '&range=' + vars[i].substr(2);
			} else if (vars[i].match('t_')) {
				types = vars[i].substr(2).split(',');
				for (var j = 0; j < types.length; j++) {
					url += '&type[]=' + types[j];
				}
			} else if (vars[i].match('f_')) {
				features = vars[i].substr(2).split(',');
				for (var k = 0; k < features.length; k++) {
					url += '&f[]=' + features[k];
				}
			} else if (vars[i].match('p_')) {
				url += '&limitstart=' + vars[i].substr(2);
			}
		}

		url += '&Itemid=31';
		
		//jQuery.cookie('last_query', url, { path: '/' });
		document.cookie = 'last_query=' + url + '; path=/';

		window.location = url;
}

