/* (c) Sam Gratrix */


// ===========================================================================================================

function Address(dwelling, street, place, area, county, country)
{
	this.dwelling = dwelling // house name, number etc
	this.street   = street;  // street, road etc
	this.place    = place;   // village, town etc
	this.area     = area;    // town, city etc
	this.county   = county;  // historic county
	this.country  = country; // country
}

Address.prototype.brief = function()
{
	var html = '';

	if(this.dwelling.length    ) html += this.dwelling;
	if(this.dwelling.length > 3) html += ',';
	if(this.dwelling.length    ) html += ' ';
	if(this.street.length      ) html += this.street   + ', ';
	if(this.place.length       ) html += this.place    + ', ';
	if(this.area.length        ) html += this.area           ;

	return html;
}

Address.prototype.nice = function()
{
	var html = '';

	if(this.dwelling.length    ) html += this.dwelling;
	if(this.dwelling.length > 3) html += ',';
	if(this.dwelling.length    ) html += ' ';
	if(this.street.length      ) html += this.street   + ', ';
	if(this.place.length       ) html += this.place    + ', ';
	if(this.area.length        ) html += this.area     + ', ';
	if(this.county.length      ) html += this.county         ;

	return html;
}

Address.prototype.full = function()
{
	var html = '';

	if(this.dwelling.length    ) html += this.dwelling;
	if(this.dwelling.length > 3) html += ',';
	if(this.dwelling.length    ) html += ' ';
	if(this.street.length      ) html += this.street   + ', ';
	if(this.place.length       ) html += this.place    + ', ';
	if(this.area.length        ) html += this.area     + ', ';
	if(this.county.length      ) html += this.county   + ', ';
	if(this.country.length     ) html += this.country        ;

	return html;
}

Address.prototype.map = function()
{
	map_search_mark_center( full() );
}


// ===========================================================================================================

var TDateData = ['Q4', 'Q3', 'Q2', 'Q1', '?','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

function TDate(year, month, day)
{
	this.year  = parseInt(year);
	this.month = parseInt(month);
	this.day   = parseInt(day);

	this.stamp = 10000 * this.year + 100 * ((this.month < 0) ? -(3 * this.month + 2) : this.month) + this.day;

	this.f_simple = this.make_simple();
	this.f_tiny   = this.make_tiny();
	this.f_nice   = this.make_nice();
}

TDate.prototype.make_simple = function()
{
	var y = (this.year ) ?                                                                               this.year    : '????';
	var m = (this.month) ? ((this.month < 0) ? 'Q'+(-this.month) : ((this.month <= 9) ? '0'+this.month : this.month)) : '??';
	var d = (this.day  ) ?                                         ((this.day   <= 9) ? '0'+this.day   : this.day  )  : '??';

	return(y+'-'+m+'-'+d);
}

TDate.prototype.make_tiny = function()
{
	var y = (this.year ) ?                                                                                    this.year     : '';
	var m = (this.month) ? '-'+(((this.month < 0) ? 'Q'+(-this.month) : ((this.month <= 9) ? '0'+this.month : this.month))) : '';
	var d = (this.day  ) ? '-'+(                                        ((this.day   <= 9) ? '0'+this.day   : this.day  ) ) : '';

	return(y+m+d);
}

TDate.prototype.make_nice = function()
{
	var y = (this.year ) ?             this.year     : '';
	var m = (this.month) ? TDateData[this.month+4] : '';
	var d = (this.day  ) ?             this.day      : '';

	return(d+' '+m+' '+y);
}

TDate.prototype.simple = function()
{
	return this.f_simple;
}

TDate.prototype.tiny = function()
{
	return this.f_tiny;
}

TDate.prototype.nice = function()
{
	return this.f_nice;
}

