function StateMachine() {

  //member variables
  this.path;
  this.get_data;
  this.total_properties;
  this.last_page;
  this.has_next_page;
  this.has_prev_page;
  this.port;
  this.is_authenticated;
  this.static_url;
  this.limit_cities = Array();

  //Set functions declaration
  this.set_path = set_path;
  this.set_port = set_port;
  this.set_get_data = set_get_data;
  this.set_search_radius = set_search_radius;
  this.set_min_price = set_min_price;
  this.set_max_price = set_max_price;
  this.set_min_beds = set_min_beds;
  this.set_max_beds = set_max_beds; 
  this.set_bathrooms = set_bathrooms;
  this.set_max_square_feet = set_max_square_feet;
  this.set_min_square_feet = set_min_square_feet;
  this.set_property_type = set_property_type;
  this.set_page_num = set_page_num;
  this.set_last_page = set_last_page;
  this.set_total_properties = set_total_properties;
  this.set_has_next_page = set_has_next_page;
  this.set_has_prev_page = set_has_prev_page;
  this.set_sort_method = set_sort_method;
  this.set_is_authenticated = set_is_authenticated;
  this.set_show_advanced = set_show_advanced;
  this.set_max_lot_size = set_max_lot_size;
  this.set_min_lot_size = set_min_lot_size;
  this.set_max_year_built = set_max_year_built;
  this.set_min_year_built = set_min_year_built;
  this.set_water_front = set_water_front;
  this.set_water_view = set_water_view;
  this.set_water_access = set_water_access;
  this.clear_bedrooms = clear_bedrooms;
  this.clear_bathrooms = clear_bathrooms;
  this.clear_search_radius = clear_search_radius;
  this.clear_property_type = clear_property_type;
  this.clear_limit_cities = clear_limit_cities;
  this.clear_min_price = clear_min_price;
  this.clear_max_price = clear_max_price;
  this.clear_min_square_feet = clear_min_square_feet;
  this.clear_max_square_feet = clear_max_square_feet;
  this.clear_min_lot_size = clear_min_lot_size;
  this.clear_max_lot_size = clear_max_lot_size;
  this.clear_min_year_built = clear_min_year_built;
  this.clear_max_year_built = clear_max_year_built;
  this.clear_water_front = clear_water_front;
  this.clear_water_view = clear_water_view;
  this.clear_water_access = clear_water_access;
  this.set_static_url = set_static_url;
  this.add_limit_city = add_limit_city;

  //Get Functions declaration
  this.get_last_page = get_last_page;
  this.get_total_properties = get_total_properties;
  this.get_url = get_url;
  this.get_get_data = get_get_data;
  this.get_has_next_page = get_has_next_page;
  this.get_has_prev_page = get_has_prev_page;
  this.get_default_url = get_default_url;
  this.get_perma_link = get_perma_link;
  this.get_xml_link = get_xml_link;
  this.get_rss_link = get_rss_link;
  this.get_is_authenticated = get_is_authenticated;
  this.get_base_url = get_base_url;
  this.get_static_url = get_static_url;
} 

//Set function implimentation
function set_port(_port) {
  if (_port == "80") {
    this.port = ""
  } else {
    this.port = ":" + _port;
  }
}

function set_static_url(_static_url) {
  this.static_url = _static_url;
}

function set_is_authenticated(_is_authenticated) {
  this.is_authenticated = _is_authenticated;
}

function get_default_url() {
  return 'http://' + window.location.hostname + this.port + this.path;
}

function set_show_advanced(_show_advanced) {
  if(_show_advanced == true) { 
    this.get_data["show_advanced"] = "t"; 
  } else {
    this.get_data["show_advanced"] = "f";
  }
}

function set_sort_method(_sort_method) {
  this.get_data["sort_method"]  = _sort_method;
}

function set_has_next_page(_has_next_page) {
  if(_has_next_page.toLowerCase() == "true") { _has_next_page = true; } else { _has_next_page = false; }
  this.has_next_page = _has_next_page;
}

function set_has_prev_page(_has_prev_page) {
  if(_has_prev_page.toLowerCase() == "true") { _has_prev_page = true; } else { _has_prev_page = false; }
  this.has_prev_page = _has_prev_page;
}

function set_page_num(_page_num) {
  this.get_data["page_num"]  = _page_num;
}

function set_last_page(_last_page) {
  this.last_page = _last_page;
}

function set_total_properties(_total_properties) {
  this.total_properties = _total_properties;
}

function set_property_type(_property_type) {
  this.get_data["property_type"] = _property_type;
}

function set_max_lot_size(_max_lot_size) {
  this.get_data["max_lot_size"] = _max_lot_size;
}

function set_min_lot_size(_min_lot_size) {
  this.get_data["min_lot_size"] = _min_lot_size;
}

function set_max_year_built(_max_year_built) {
  this.get_data["max_year_built"] = _max_year_built;
}

function set_water_front() {
  this.get_data["water_front"] = 't';
}

function set_water_view() {
  this.get_data["water_view"] = 't';
}

function set_water_access() {
  this.get_data["water_access"] = 't';
}

function set_min_year_built(_min_year_built) {
  this.get_data["min_year_built"] = _min_year_built;
}

function set_max_square_feet(_max_square_feet) {
  this.get_data["max_square_feet"] = _max_square_feet; 
}

function set_min_square_feet(_min_square_feet) {
  this.get_data["min_square_feet"] = _min_square_feet;
}

function set_bathrooms(_bathrooms) {
  this.get_data["bathrooms"] = _bathrooms;
}

function set_min_beds(_min_beds) {
  this.get_data["min_beds"] = _min_beds;
}

function set_max_beds(_max_beds) {
  this.get_data["max_beds"] = _max_beds;
}

function set_min_price(_min_rent) {
  this.get_data["min_price"] = _min_rent;
}
function set_max_price(_max_rent) {
  this.get_data["max_price"] = _max_rent;
}

function set_get_data(_get_data) {
  //This is the mother function where we do all our logic to 
  //determine how the page should be displayed.   All display logic
  //goes HERE not in the django code.
  this.get_data = _get_data;

  //Build limit cities list if we have it.
  if(typeof this.get_data['limit_cities'] != 'undefined') {
    this.limit_cities = String(this.get_data['limit_cities']).split("-");
  }
}

function set_path(_path) {
  this.path = _path;
}

function set_search_radius(_search_radius) {
  this.get_data['search_radius'] = _search_radius;
}

function add_limit_city(city_id) {
  this.limit_cities.push(city_id);
}

function clear_water_front() {
  delete this.get_data["water_front"];
}

function clear_water_view() {
  delete this.get_data["water_view"];
}

function clear_water_access() {
  delete this.get_data["water_access"];
}

function clear_min_square_feet() {
  delete this.get_data["min_square_feet"];
}

function clear_max_square_feet() {
  delete this.get_data["max_square_feet"];
}

function clear_min_lot_size() {
  delete this.get_data["min_lot_size"];
}

function clear_max_lot_size() {
  delete this.get_data["max_lot_size"];
}

function clear_min_year_built() {
  delete this.get_data["min_year_built"];
}

function clear_max_year_built() {
  delete this.get_data["max_year_built"];
}

function clear_min_price() {
  delete this.get_data["min_price"];
}

function clear_max_price() {
  delete this.get_data["max_price"];
}

function clear_limit_cities() {
  this.limit_cities = Array();
}

function clear_property_type() {
  delete this.get_data["property_type"];
}

function clear_search_radius() {
  delete this.get_data["search_radius"];
}

function clear_bedrooms() {
  delete this.get_data["min_beds"];
  delete this.get_data["max_beds"];
}

function clear_bathrooms() {
  delete this.get_data["bathrooms"];
}

//Get funtion implimentations
function get_has_next_page() {
  return this.has_next_page;
}

function get_has_prev_page() {
  return this.has_prev_page;
}

function get_last_page() {
  return this.last_page;
}

function get_total_properties() {
  return this.total_properties;
}

function get_get_data() {
  return this.get_data;
}

function get_is_authenticated() {
  return this.is_authenticated;
}

function get_static_url() {
  return this.static_url;
}

//This is the RESET url
function get_default_url() {
  return 'http://' + window.location.hostname + this.port + this.path;
}

//This is just the hostname with the port (no directories)
function get_base_url() {
  return 'http://' + window.location.hostname + this.port;
}

function get_perma_link() {
  return 'http://' + window.location.hostname + this.port + this.path + this.get_url();
}

function get_xml_link() {
  return 'http://' + window.location.hostname + this.port + '/properties_list.xml' + this.get_url();  
}

function get_rss_link() {
  return 'http://' + window.location.hostname + this.port + '/feeds/properties/' + this.get_url();
}

function get_url() {
  if(this.limit_cities.length == 0) {
    if (typeof this.get_data['limit_cities'] != 'undefined') {
      delete this.get_data['limit_cities'];
    }
  } else {
    this.get_data['limit_cities'] = this.limit_cities.join("-");
  }

  var url = "";
  var count = 0;
  for(var k in this.get_data) {
    if(count == 0) { url = url + "?" } else { url = url + "&" }
    url = url + k + "=" + this.get_data[k];
    count = count + 1;
  }
  return url;
}

