// JavaScript Document
function div_loader(id, stuff) {
        el = document.getElementById(id);
        el.innerHTML = stuff;
}

function Region(form){
	town = form.inputbox.value;
	var thisRegion = "";
	var yourRegion = "<h1 style='text-align: center; margin-bottom: 0px;'>"+town+" is in Region ";

	region5array = new Array("Abington","Allston","Auburndale","Avon","Belmont","Boston","Braintree","Brighton","Brookline","Cambridge","Canton","Charlestown","Chelsea","Chestnut Hill","Concord","Dedham","Dorchester","East Bridgewater","Easton","Everett","Holbrook","Hyde Park","Jamaica Plain","Mattapan","Medford","Milton","Newton","Newton Center","Newton Highlands","Newton Upper Falls","Newtonville","Norwood","Quincy","Randolph","Readville","Revere","Rockland","Roslindale","Roxbury","Saugus","Sharon","Somerville","Squantum","Stoughton","Waban","Watertown","Wellesley","West Bridgewater","West Roxbury","Westwood","Winchester","Winter Hill","Winthrop","Woburn","Wollaston"); 
	region4array = new Array("Amesbury","Andover","Arlington","Bedford","Beverly","Billerica","Boxford","Bradford","Burlington","Byfield","Carlisle","Chelmsford","Concord","Danvers","Dracut","Dunstable","Essex","Georgetown","Gloucester","Groton","Groveland","Hamilton","Hanscom AFB","Hathorne","Haverhill","Ipswich","Lawrence","Lexington","Lincoln","Lowell","Lynn","Lynnfield","Magnolia","Malden","Manchester","Marblehead","Melrose","Merrimac","Methuen","Middleton","Nahant","Newbury","Newburyport","North Andover","North Billerica","North Chelmsford","North Reading","Peabody","Pepperell","Prides Crossing","Reading","Rockport","Rowley","Salem","Salisbury","Saugus","South Hamilton","Stoneham","Sudbury","Swampscott","Tewksbury","Topsfield","Tyngsboro","Wakefield","Waltham","Ward Hill","Wenham","West Newbury","Westford","Weston","Wilmington","Woburn");
	region3array = new Array("Accord","Acushnet","Aquinnah","Assonet","Attleboro","Barnstable","Bass River","Berkley","Bourne","Brant Rock","Brewster","Bridgewater","Brockton","Bryantville","Buzzards Bay","Carver","Cataumet","Centerville","Chartley","Chatham","Chilmark","Cohasset","Cotuit","Cummaquid","Cuttyhunk","Dartmouth","Dennis","Dennisport","Dighton","Dover","Duxbury","East Bridgewater","East Dennis","East Falmouth","East Freetown","East Sandwich","East Taunton","East Walpole","East Wareham","East Weymouth","Eastham","Easton","Edgartown","Elmwood","Fairhaven","Fall River","Falmouth","Forestdale","Foxborough","Gay Head","Green Harbor","Greenbush","Halifax","Hanover","Hanson","Harwich","Harwich Port","Hingham","Hull","Humarock","Hyannis","Hyannis Port","Kingston","Lakeville","Manomet","Mansfield","Marion","Marshfield","Marshfield Hills","Marston Mills","Mashpee","Mattapoisett","Medfield","Middleboro","Monponsett","Monument Beach","Nantucket","New Bedford","North Dartmouth","North Dighton","North Falmouth","North Marshfield","North Pembroke","North Scituate","North Truro","Norton","Norwell","Oak Bluffs","Ocean Bluff","Onset","Orleans","Osterville","Pembroke","Plymouth","Plympton","Pocasset","Provincetown","Raynham","Rehoboth","Rochester","Sagamore","Sandwich","Scituate","Seekonk","Sharon","Siaconset","Somerset","South Walpole","Swansea","Taunton","Teaticket","Truro","Vineyard Haven","Walpole","Waquoit","Wareham","Wellfleet","West Barnstable","West Tisbury","Westport","Weymouth","White Horse Beach","Whitman","Woods Hole","Yarmouth");
	region2array = new Array("Acton","Ashburnham","Ashby","Ashland","Athol","North Attleboro","Auburn","Ayer","Baldwinville","Barre","Bellingham","Berlin","Blackstone","Bolton","Boxboro","Boylston","Brimfield","Brookfield","Charlton","Cherry Valley","Clinton","Douglas","Dudley","East Brookfield","Fayvillle","Fiskdale","Fitchburg","Framingham","Franklin","Gardner","Gilbertville","Grafton","Harvard","Hardwick","Holden","Holland","Holliston","Hopedale","Hopkinton","Hubbardston","Hudson","Jefferson","Lancaster","Leicester","Leominster","Linwood","Littleton","Lunenburg","Manchaug","Marlboro","Maynard","Medway","Mendon","Milford","Millbury","Millis","Millville","Monson","Natick","New Braintree","Needham","Norfolk","North Attleboro","North Brookfield","North Grafton","North Oxford","Northborough","Northbridge","Oakham","Orange","Oxford","Palmer","Paxton","Petersham","Phillipston","Plainville","Princeton","Rochdale","Roylston","Rutland","Sheltonville","Sherborn","Shirley","Shrewsbury","South Grafton","South Lancaster","Southborough","Southbridge","Spencer","Sterling","Still River","Stow","Sturbridge","Sudbury","Sutton","Templeton","Townsend","Upton","Uxbridge","Wales","Ware","Warren","Warwick","Wayland","Webster","Wellesley","West Boylston","West Brookfield","Westborough","Westminster","Wheelwright","Whitinsville","Wilkonsonville","Winchendon","Woodville","Worcester","Wrentham"); 
	region1array = new Array("Adams","Agawam","Aldenville","Alford","Amherst","Ashfield","Ashley Falls","Becket","Belchertown","Berkshire","Bernardston","Blandford","Bondsville","Buckland","Charlemont","Cheshire","Chester","Chesterfield","Chicopee","Clarksburg","Colrain","Conway","Cummington","Dalton","Deerfield","East Longmeadow","Easthampton","Egremont","Erving","Feeding Hills","Florence","Florida","Gill","Glendale","Goshen","Granby","Granville","Great Barrington","Greenfield","Hadley","Hampden","Hancock","Hatfield","Hawley","Haydenville","Heath","Hinsdale","Holyoke","Housatonic","Huntington","Indian Orchard","Lanesboro","Lee","Leeds","Lenox","Leverett","Leyden","Longmeadow","Ludlow","Middlefield","Millers Falls","Montague","Montgomery","New Ashford","New Marlboro","New Salem","North Adams","North Hatfield","Northampton","Northfield","Otis","Pelham","Peru","Pittsfield","Plainfield","Richmond","Rowe","Russell","Sandisfield","Savoy","Sheffield","Shelburne Falls","Shutesbury","South Deerfield","South Hadley","Southampton","Southfield","Southwick","Springfield","Stockbridge","Sunderland","Thorndike","Three Rivers","Turner's Falls","Tyringham","Washington","Wendell","West Hatfield","West Springfield","West Stockbirdge","Westfield","Westhampton","Whately","Wilbraham","Williamsburg","Williamstown","Windsor","Worthington"); 	

	
	for (i=0; i<55; i++){
		if (town == region5array[i]){
			thisRegion = "5";
			break;
		}
	}
	if (thisRegion == ""){
		for (i=0; i<72; i++){
			if (town == region4array[i]){
				thisRegion = "4";
				break;
			}
		}
	}
	if (thisRegion == ""){
		for (i=0; i<125; i++){
			if (town == region3array[i]){
				thisRegion = "3";
				break;
			}
		}
	}
	if (thisRegion == ""){
		for (i=0; i<117; i++){
			if (town == region2array[i]){
				thisRegion = "2";
				break;
			}
		}
	}
	if (thisRegion == ""){
		for (i=0; i<108; i++){
			if (town == region1array[i]){
				thisRegion = "1";
				break;
			}
		}
	}
	if (thisRegion == ""){
	
		yourRegion = "<h2 style='text-align: center; margin-bottom: 0px; color: #000;'>We couldn't find the town you typed. Please check your spelling.<br />Then reload this page, and try again.</p></ br>"
		
	}else{
	
		yourRegion = yourRegion+thisRegion+".</h1><p style='text-align: center; margin-bottom: 0px;'><strong>Reload the page to try another town.</strong></p>";
	}
	
	div_loader('contentRegion', yourRegion);

}
