/*


				This script relies on:
				master.js


*/

function Agency(agencyId, name, address, telephone, cityIdsArrayString, url, email, isASAP, isAAA)
{
	this.AgencyId = agencyId;
	this.Name = name;
	this.Address = address;
	this.Contacts = 'Ask for our Information and Referral Specialist';
	this.Telephone = telephone;
	this.Url = (url && typeof (url) == "string" && url.length > 0) ? url : '';
	this.Email = (email && typeof (email) == "string" && email.length > 0) ? email : '';
	this.CityIdsArray = (cityIdsArrayString && typeof (cityIdsArrayString) == "string" && cityIdsArrayString.length > 0) ? cityIdsArrayString.split(',') : [];
	this.CityNamesArray = this.GetAgencyCityNames(this.CityIdsArray);
	this.ForMoreInformationHtml = '<a href="#">Click here for complete information on this agency.</a>';
	this.CallYourLocalAgencyText = '800AgeInfo Information & Referral:\n\n1-800-Age-Info / 800-243-4636 or 800-872-0166 (TTY)';
	this.NotSureWhereToStartHtml = 'Click <a href="http://qa-www.800ageinfo.com/Start?agencyId=' + this.AgencyId + '">here</a> to send questions or comments to your Local Agency.';
	this.IsASAP = isASAP == true; 	// to make sure we assign false if the param is "undefined" or null
	this.IsAAA = isAAA == true; 		// to make sure we assign false if the param is "undefined" or null
}

Agency.prototype.ServicesThisCity = function(cityId)
{
	var numCities = this.CityIdsArray.length;
	for (var i = 0; i < numCities; i++)
	{
		if (this.CityIdsArray[i] == cityId)
			return true;
	}

	return false;
}

Agency.prototype.GetInfoHtmlElement = function(navAnchorLink)
{
	// Create container
	agencyInfoHtmlElement = document.createElement('div');
	agencyInfoHtmlElement.className = 'agencyInfoContainer';

	// Add anchor
	agencyInfoHtmlElement.appendChild(this.GetAnchor());

	// Add title
	var title = document.createElement('h2');
	title.className = 'title';
	title.innerHTML = this.Name;
	agencyInfoHtmlElement.appendChild(title);

	// Add navAnchorLinkif provided
	if (navAnchorLink && navAnchorLink.href && typeof (navAnchorLink.href) == "string" && navAnchorLink.href.length > 0)
	{
		agencyInfoHtmlElement.appendChild(navAnchorLink);
	}

	// Add Address
	var address1 = document.createElement('div');
	address1.className = 'address';
	address1.innerHTML = nl2br(this.Address);
	agencyInfoHtmlElement.appendChild(address1);

	// Add phone
	var phone = document.createElement('div');
	phone.className = 'phone';
	phone.innerHTML = 'Phone: ' + nl2br(this.Telephone);
	agencyInfoHtmlElement.appendChild(phone);

	// Add website
	var website = document.createElement('div');
	website.className = 'website';
	website.innerHTML = 'Web: ';
	var websiteLink = document.createElement('a');
	websiteLink.href = this.Url;
	websiteLink.innerHTML = this.Url; //this.Name + ' website';
	website.appendChild(websiteLink);
	agencyInfoHtmlElement.appendChild(website);

	// Add towns served
	var townsServed = document.createElement('div');
	townsServed.className = 'townsServed';
	var townsServedTitle = document.createElement('strong');
	townsServedTitle.innerHTML = 'Areas served:';
	townsServed.appendChild(townsServedTitle);
	var townsServedList = document.createElement('div');
	townsServedList.innerHTML = this.CityNamesArray.join(', ');
	townsServed.appendChild(townsServedList);
	agencyInfoHtmlElement.appendChild(townsServed);

	// Add more info section
	var moreInfo = document.createElement('div');
	moreInfo.className = 'moreInfo';
	// Add more info icon
	var moreInfoIcon = document.createElement('img');
	moreInfoIcon.src = 'images/Question_mark_on_blue_circle.jpg';
	moreInfoIcon.alt = 'Click here for more information on this agency';
	moreInfoIcon.className = 'leftIcon';
	moreInfo.appendChild(moreInfoIcon);
	// Add more info link
	var moreInfoLink = document.createElement('a');
	moreInfoLink.href = '/moreinfo.asp?agencyId=' + this.AgencyId;
	moreInfoLink.innerHTML = 'Click here for more information on this agency';
	moreInfo.appendChild(moreInfoLink);
	agencyInfoHtmlElement.appendChild(moreInfo);

	// Add send message section
	var sendMessage = document.createElement('div');
	sendMessage.className = 'sendMessage';
	// Add send message icon
	var sendMessageIcon = document.createElement('img');
	sendMessageIcon.src = 'images/Blue_Check_In_Yellow_Box.jpg';
	sendMessageIcon.alt = 'Send a message to this agency';
	sendMessageIcon.className = 'leftIcon';
	sendMessage.appendChild(sendMessageIcon);
	// Add send message link
	var sendMessageLink = document.createElement('a');
	sendMessageLink.href = 'contact_us.html?agencyId=' + this.AgencyId;
	sendMessageLink.innerHTML = 'Send a message to this agency';
	sendMessage.appendChild(sendMessageLink);
	agencyInfoHtmlElement.appendChild(sendMessage);

	return agencyInfoHtmlElement;
}

Agency.prototype.GetAgencyCityNames = function()
{
	var cityNamesArray = new Array();

	if (document.CityLookup)
	{
		for (var i = 0; i < this.CityIdsArray.length; i++)
		{
			var curCityId = this.CityIdsArray[i];
			var curCityName = document.CityLookup.GetCityName(curCityId);
			if (curCityName.length > 0)
				cityNamesArray[cityNamesArray.length] = curCityName;
		}
	}

	return cityNamesArray;
}

Agency.prototype.GetAnchorName = function()
{
	return 'Agency_' + this.AgencyId;
}

Agency.prototype.GetAnchorLink = function(cssClassName)
{
	var anchorName = this.GetAnchorName();
	var anchorLink = document.createElement('a');
	anchorLink.href = '#' + anchorName;
	anchorLink.innerHTML = 'Skip to next agency';
	anchorLink.title = 'Skip to next agency';
	anchorLink.className = cssClassName ? cssClassName : '';

	return anchorLink;
}

Agency.prototype.GetAnchor = function()
{
	var a = document.createElement('a');
	a.name = this.GetAnchorName();

	return a;
}

//==============================================================================

function GetCityAgencies()
{
	var agencies = new Array();
	//agencies[agencies.length] = new Agency( agencyId, name, address, telephone, cityIdsArrayString, url, email);
	agencies[agencies.length] = new Agency(1, 'BayPath Elder Services', '33 Boston Post Road West\nMarlborough, MA 01752-1853', '(508) 573-7200\nToll Free: (800) 287-7284', '42,43,44,45,46,47,48,49,50,51,52,53,54,55', 'http://www.baypath.org', 'Info@baypath.org', true, true);
	agencies[agencies.length] = new Agency(2, 'Boston Senior Home Care', 'Lincoln Plaza 89 South St., 5th Floor \nBoston, MA 02111', '(617) 451-6400\nBoston ElderINFO: (617) 292-6211', '3,4,6,8,10,17,21,22,24', 'http://www.bshcinfo.org', 'info@bshcinfo.org', true, false);
	agencies[agencies.length] = new Agency(3, 'Bristol Elder Services, Inc.', '1 Father DeValles Blvd., Unit 8\nFall River, MA 02723', '(508) 675-2101', '27,28,29,30,31,32,33,34,35,36,37,38,39,40,41', 'http://www.bristolelder.org', 'Info@BristolElder.org', true, true);
	agencies[agencies.length] = new Agency(4, 'Central Boston Elder Services, Inc.', '2315 Washington Street\nBoston, MA 02119', '(617) 277-7416\nBoston ElderINFO: (617) 292-6211', '1,2,4,5,11,13,20,23', 'http://www.centralboston.org', 'info@bshcinfo.org', true, false);
	agencies[agencies.length] = new Agency(5, 'Central Mass Agency on Aging, Inc. (AAA)', '360 West Boylston St\nWest Boylston, MA 01583', '(508) 852-5539\nToll Free: (800) 244-3032', '376,377,63,378,64,225,379,226,134,65,227,228,135,229,230,231,136,232,137,66,138,67,68,233,139,140,69,141,142,234,235,236,70,237,71,238,239,72,240,73,143,144,74,145,75,241,242,146,243,244,147,148,245,246', 'http://SeniorConnection.org', 'CMAAging@SeniorConnection.org', false, true);
	agencies[agencies.length] = new Agency(6, 'Chelsea/Revere/Winthrop Home Care Center, Inc.', 'PO Box 6427, 100 Everett Avenue Unit 10\nChelsea, MA 02150', '(617) 884-2500', '7,18,26', 'http://www.crwelderservices.org', 'crw@crwelderservices.org', true, true);
	agencies[agencies.length] = new Agency(7, 'City of Boston, Comm. On Affairs of the Elderly', null, null, null, 'http://www.cityofboston.gov/elderly/', 'elderly@ci.boston.ma.us', false, true);
	agencies[agencies.length] = new Agency(8, 'Coastline Elderly Services, Inc.', '1646 Purchase Street\nNew Bedford, MA 02740', '(508) 999-6400', '56,57,58,254,59,60,61,62', 'http://www.coastlineelderly.org', 'I-R@coastlineelderly.org', true, true);
	agencies[agencies.length] = new Agency(9, 'Elder Services of Berkshire County, Inc.', '66 Wendell Avenue\nPittsfield, MA 01201', '(413) 499-0524\nToll Free: (800) 544-5242', '78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,107,108,109', 'http://www.esbci.org', 'iandr@esbci.org', true, true);
	agencies[agencies.length] = new Agency(10, 'Elder Services of Cape Cod and the Islands, Inc.', '68 Route 134\nSouth Dennis, MA 02660', '(508) 394-4630', '110,111,112,113,114,115,116,117,118,119,120,255,256,257,258,259,260,261,262,263,264,265,266,267', 'http://www.escci.org', 'info@escci.org', true, true);
	agencies[agencies.length] = new Agency(11, 'Elder Services of Merrimack Valley, Inc.', 'Riverwalk, Building #5, 360 Merrimack St.\nLawrence, MA 01843', '(978) 683-7747\nToll Free: (800) 892-0890', '268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290', 'http://www.esmv.org', 'info@esmv.org', true, true);
	agencies[agencies.length] = new Agency(12, 'Elder Services of Worcester Area, Inc.', '411 Chandler Street\nWorcester, MA 01602', '(508) 756-1545', '63,64,65,66,67,68,69,70,71,72,73,74,75,76,77', 'http://www.eswa.org', 'irinfo@eswa.org', true, false);
	agencies[agencies.length] = new Agency(13, 'Ethos', '555 Armory St.\nJamaica Plain, MA 02130', '(617) 522-6700\nFAX: (617) 524-2899\nTDD: (617) 524-2687', '4,12,13,15,19,25', 'http://www.ethocare.org', 'info@bshcinfo.org', true, false);
	agencies[agencies.length] = new Agency(14, 'Franklin County Home Care Corporation', '330 Montague City Road\nTurners Falls, MA 01373', '(413) 773-5555', '291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,317,318,320,321,322', 'http://www.fchcc.org', 'Info@fchcc.org', true, true);
	agencies[agencies.length] = new Agency(15, 'Greater Lynn Senior Services, Inc.', '8 Silsbee St.\nLynn, MA 01901', '(781) 599- 0110\nTDD: (781) 477-9632', '323,324,325,326,327', 'http://www.glss.net', 'info@glss.net, cellis@glss.net', true, true);
	agencies[agencies.length] = new Agency(16, 'Greater Springfield Senior Services, Inc.', '66 Industry Ave.\nSpringfield, MA 01104', '(413) 781-8800\n(413) 781-0632', '328,329,330,331,332,333,334,335,336,337,338,339', 'http://www.gsssi.org', 'information@gsssi.org', true, true);
	agencies[agencies.length] = new Agency(17, 'HESSCO Elder Services', 'One Merchant St.\nSharon, MA 02067', '(781) 784-4944\nToll Free: (800) 462-5221', '340,341,342,343,344,345,346,367,347,348,349,350', 'http://www.hessco.org', 'info@hessco.org', true, true);
	agencies[agencies.length] = new Agency(18, 'Highland Valley Elder Services, Inc.', '320 Riverside Drive Suite B\nFlorence, MA 01062', '(413) 586-2000\nToll Free: (800) 322-0551', '351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,368,369,370,371,372,373,374,375', 'http://www.highlandvalley.org', 'qll@highlandvalley.org', true, true);
	agencies[agencies.length] = new Agency(19, 'Minuteman Senior Services', '24 Third Ave\nBurlington, MA 01803', '(781) 272-7177', '151,152,153,154,155,156,157,158,159,160,161,162,163,164,165', 'http://www.minutemansenior.org', 'elderinfo@minutemansenior.org', true, true);
	agencies[agencies.length] = new Agency(20, 'Montachusett Home Care Corporation', 'Crossroads Office Park\nLeominster, MA 01453', '(978) 537-7411\nToll Free: (800) 734-7312', '376,377,378,379,134,135,136,137,138,139,140,141,143,144,145,146,147,148,149,150', 'http://www.montachusetthomecare.org', 'INFO@MHCC-1.org', true, false);
	agencies[agencies.length] = new Agency(21, 'Mystic Valley Elder Services, Inc.', '300 Commercial Street, Suite #19\nMalden, MA 02148', '(781) 324-7705', '167,168,169,170,171,172,173,174', 'http://www.mves.org', 'info@mves.org', true, true);
	agencies[agencies.length] = new Agency(22, 'North Shore Elder Services, Inc.', '152 Sylvan St.\nDanvers, MA 01923', '(978) 750-4540\nTDD/TTY (978) 624-2244', '175,176,177,178,179', 'http://www.nselder.org', 'info@nselder.org', true, true);
	agencies[agencies.length] = new Agency(23, 'Old Colony Elderly Services, Inc.', '144 Main St.\nBrockton, MA 02301', '(508) 584-1561\nToll Free: (800) 242-0246', '183,184,185,186,187,188,180,181,189,190,191,192,193,194,182,195,196,197,198,199,200,201,202', 'http://www.oldcolonyelderservices.org', 'info@oldcolonyelderservices.org', true, false);
	agencies[agencies.length] = new Agency(24, 'Old Colony Planning Council (AAA)', '70 School St\nBrockton, MA 02401', '(508) 583-1833', '183,184,185,186,187,188,189,190,191,192,193,194,182,195,196,197,198,199,200,201,202', 'http://www.ocpcrpa.org', 'info@ocpcrpa.org', false, true);
	agencies[agencies.length] = new Agency(25, 'SeniorCare, Inc.', '5 Blackburn Center\nGloucester, MA 01930', '(978) 281-1750', '205,206,207,208,209,210,211,212,213', 'http://www.seniorcareinc.org', 'info@seniorcareinc.org', true, true);
	agencies[agencies.length] = new Agency(26, 'Somerville/Cambridge Elder Services, Inc.', '61 Medford Street\nSomerville, MA 02143', '(617) 628-2601; 2602\nTDD: 628-1705', '203,204', 'http://www.eldercare.org', 'sces@eldercare.org', true, true);
	agencies[agencies.length] = new Agency(27, 'South Shore Elder Services, Inc.', '159 Bay State Drive\nBraintree, MA 02184', '(781) 749-6832; 383-9790; 848-3910', '214,215,216,217,218,219,220,221,222,223,224', 'http://www.sselder.org', 'IOR@sselder.org, klevy@sselder.org', true, true);
	agencies[agencies.length] = new Agency(28, 'Springwell, Inc.', '125 Walnut Street\nWatertown, MA 02472', '(617) 926-4100', '125,126,127,133,129,130,131,132', 'http://www.springwell.com', 'inforef@springwell.com', true, true);
	agencies[agencies.length] = new Agency(29, 'Tri-Valley, Inc.', '10 Mill Street\nDudley, MA 01571', '(508) 949-6640\nToll Free: (800) 286-6640', '225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249', 'http://www.trivalleyinc.org', 'info@tves.org', true, false);
	agencies[agencies.length] = new Agency(30, 'WestMass Elder Care, Inc.', '4 Valley Mill Rd\nHolyoke, MA 01040', '(413) 538-9020\nHot Line: (800) 462-2301', '250,251,252,121,122,123,124', 'http://www.wmeldercare.org', 'info@wmeldercare.org', true, true);

	return agencies;
}

//==============================================================================

function Agency_Page_Load()
{
	SetupDocumentAgencyList();
}

function SetupDocumentAgencyList()
{
	document.AgencyList = {
		Agencies: GetCityAgencies(),

		GetAgency: function(agencyId)
		{
			var numAgencies = this.Agencies.length;
			for (var i = 0; i < numAgencies; i++)
			{
				var agency = this.Agencies[i];
				if (agency.AgencyId == agencyId)
					return agency;
			}

			return null;
		},

		GetAgencyIdsForCity: function(cityId)
		{
			var agencyIdsString = '';

			var numAgencies = this.Agencies.length;
			for (var i = 0; i < numAgencies; i++)
			{
				var agency = this.Agencies[i];
				if (agency.ServicesThisCity(cityId))
				{
					if (agencyIdsString.length > 0)
						agencyIdsString += ',';

					agencyIdsString += agency.AgencyId;
				}
			}

			return agencyIdsString;
		}
	}
}

//---------------------------------------------------

window.PageLoadEvents.Add(Agency_Page_Load);
