﻿function PhBusinessLabel( index, map, name, street1, street2, street3, phone_number, website, mc_accessible )
{
	//this.m_oLocation		= map_location;
	this.m_oMap				= map,
	this.m_iIndex			= index;
	this.m_strName			= name;
	this.m_strStreet1		= street1;
	this.m_strStreet2		= street2;
	this.m_strStreet3		= street3;
	this.m_strPhoneNumber	= phone_number;
	this.m_strWebsite		= website;
	this.m_bMcAccessible	= mc_accessible;
	
	this.InitObject();
}

PhBusinessLabel.prototype = new PhWidget();

PhBusinessLabel.prototype.InitObject = function()
{
	var me		= this;
	var table	= new PhTable( 2, 2, 3, 0 );
	var mc		= (this.m_bMcAccessible)? ' *' : '';
	
	var index	= document.createElement( 'div' );
	var wrapper	= document.createElement( 'div' );
	var name	= document.createElement( 'div' );
	var map		= document.createElement( 'img' );
	var address	= document.createElement( 'div' );
	var phone	= document.createElement( 'div' );
	var website	= document.createElement( 'div' );
	
	this.m_oContainer = document.createElement( 'div' );
	this.m_oContainer.style.width			= '250px';
	this.m_oContainer.style.marginTop		= '10px'
	
	//if( this.m_strStreet1 != '' )
	//	this.m_oContainer.style.cursor = 'pointer';
	
	wrapper.style.width		= '223px';
	wrapper.style.top		= '0px';
	wrapper.style.height	= '0px';
	
	index.id			= 'index';
	index.innerHTML		= this.m_iIndex+'.';
	
	map.src		= 'system/resources/global/mapIcon.gif';
	map.setAttribute( 'width', '24px' );
	map.setAttribute( 'height', '23px' );
	map.style.cursor = 'pointer';
	
	name.id				= 'name';
	name.innerHTML		= this.m_strName+mc+' ';
	name.appendChild( map );
	table.Cells[0][0].appendChild( index );
	
	table.Cells[0][0].setAttribute( 'valign', 'top' );
	table.Cells[0][0].setAttribute( 'width', '20px' );
	table.Cells[0][0].vAlign = 'top';
	table.Cells[0][0].width = '20px';
	
	table.Cells[0][1].appendChild( name );
	
	address.id			= 'address';
	address.innerHTML	= this.BuildAddress();
	table.Cells[1][1].appendChild( address );
	
	if( this.m_strPhoneNumber != '?' && this.m_strPhoneNumber != '' )
	{
		phone.id			= 'phone_number';
		phone.innerHTML		= this.m_strPhoneNumber;
		table.Cells[table.AddRow()][1].appendChild( phone );
	}
	
	if( this.m_strWebsite != '' )
	{
		website.id			= 'website';
		website.innerHTML	= this.BuildUrl();
		table.Cells[table.AddRow()][1].appendChild( website );	
	}
	
	this.m_oContainer.appendChild( table.Table );
	g_oClient.AttachEvent( map, "click", function(){me.ShowInfoWindow();} );
}

PhBusinessLabel.prototype.BuildAddress = function()
{
	var address = this.m_strStreet1;
	
	if( address == '' )
		return 'No address on file';
		
	if( this.m_strStreet2 != '' )
		address += '<br />'+this.m_strStreet2;
		
	return address+'<br />'+this.m_strStreet3;
}

PhBusinessLabel.prototype.BuildUrl = function()
{
	var url = this.m_strWebsite.split( '://' );
	return '<a class="business_url" href="'+this.m_strWebsite+'">'+url[1]+'</a>';
}

PhBusinessLabel.prototype.ShowInfoWindow = function()
{
	//if( this.m_oLocation.Marker != null )
	//	this.m_oLocation.Marker.showMapBlowup( {zoomLevel:16, mapType:G_SATELLITE_MAP} );

	//alert( this.m_oDirections.getMarker( this.m_iIndex-1 ).showMapBlowup );
	
	//var marker = null;
	
	if( this.m_oMap != null )
	{
		marker = this.m_oMap.GetMarker( this.m_iIndex-1 );
		
		marker.showMapBlowup( {zoomLevel:16, mapType:G_SATELLITE_MAP} );
		//alert( marker.getTitle() );
	}
}