﻿


function Location(id, name, streetName, streetNumber, box, zip, city, municipality, county, country)
{
	this.Id = parseInt(id);
	this.Name = name;
	this.StreetName = streetName;
	this.StreetNumber = streetNumber;
	this.Box = box;
	this.Zip = zip;
	this.City = city;
	this.Municipality = municipality;
	this.County = county;
	this.Country = country;

	this.ToString = function ()
	{
		var location = "";
		if (this.Name != "")
			location += this.Name;
		if (this.City != "" && this.City != null)
		{
			if (location != "")
				location += "&#44;&#160;";

			location += this.City;
		}
		if (this.Municipality != "" && this.Municipality != null)
		{
			if (location != "")
				location += "&#160;&#45;&#160;";

			location += this.Municipality;
		}

		return location;
	}
}

Location.FromString = function (data)
{
	var location = new Location("");
	data = data.split(";;");

	for (var i = 0; i < data.length; i++)
	{
		var value = data[i].split(":")[1];

		switch (data[i].split(":")[0])
		{
			case "id":
				location.Id = parseInt(value);
				break;
			case "name":
				location.Name = value;
				break;
			case "streetName":
				location.StreetName = value;
				break;
			case "streetNumber":
				location.StreetNumber = value;
				break;
			case "box":
				location.Box = value;
				break;
			case "zip":
				location.Zip = value;
				break;
			case "city":
				location.City = value;
				break;
			case "municipality":
				location.Municipality = value;
				break;
			default:
				break;
		}
	}

	return location;
}

Location.FromHTML = function (container)
{
	var properties = container.getElementsByTagName("p");
	var location = new Location("");

	for (var i = 0; i < properties.length; i++)
	{
		var value = properties[i].innerHTML;

		switch (properties[i].className)
		{
			case "Id":
				location.Id = parseInt(value);
				break;
			case "Name":
				location.Name = value;
				break;
			case "StreetName":
				location.StreetName = value;
				break;
			case "StreetNumber":
				location.StreetNumber = value;
				break;
			case "Box":
				location.Box = value;
				break;
			case "Zip":
				location.Zip = value;
				break;
			case "City":
				location.City = value;
				break;
			case "Municipality":
				location.Municipality = value;
				break;
			default:
				break;
		}
	}

	return location;
}
