
function Location(state, city, zipCode, count, state_full_name)
{
	this.id = state + city + zipCode;
	this.state = state;
	this.city = city;
	this.zipCode = zipCode;
	this.count = count ? count : 0;
	this.state_full_name = state_full_name;
	
	if (typeof(_location_prototype_called) == 'undefined')
	{
 		Location.prototype.toString = toString;
 		Location.prototype.asRequestParameter = asRequestParameter;
 		Location.prototype.hasStateOnly = hasStateOnly;
 		Location.prototype.equals = equals;
	}
	
	function toString(includeCount, useFullState)
	{
		var string;
		var stateLocal = (useFullState && this.state_full_name) ? this.state_full_name : this.state;
		if (this.city.length > 0) string = this.city + ", " + stateLocal;
		else if (this.zipCode.length > 0) string = this.zipCode + ", " + stateLocal;
		else string = stateLocal;
		if (includeCount) string += " (" + this.count + ")";
		return string;
	}
	
	function asRequestParameter()
	{
		var parameter = "";
		if (this.state.length > 0)
			parameter += "[s:" + encodeURIComponent(this.state) + "]";
		if (this.city.length > 0)
			parameter += "[c:" + encodeURIComponent(this.city) + "]";
		if (zipCode.length > 0)
			parameter += "[z:" + encodeURIComponent(this.zipCode) + "]";
		return parameter;
	}
	
	function hasStateOnly()
	{
		return this.state != null && this.state.length > 0 &&
			(this.city == null || this.city.length == 0) &&
			(this.zipCode == null || this.zipCode == 0);
	}
	
	function equals(location)
	{
		return (this.id = location.id);
	}
}