// JavaScript Document
var r = new Object();
// r["City of "] = new Object();
// r["City of "]["Bucktown"] = new Object();



var theString = "==3,All,316,Addison,627,Albany Park,749,Alden,317,Algonquin,319,Alsip,628,Andersonville,320,Antioch,629,Archer Heights,321,Arlington Heights,630,Armour Square,631,Ashburn,632,Auburn Gresham,322,Aurora,633,Austin,634,Avalon Park,635,Avondale,324,Bannockburn,325,Barrington,327,Barrington Hills,331,Bartlett,333,Batavia,334,Beach Park,335,Bedford Park,336,Beecher,337,Bellwood,636,Belmont Cragin,3406,Belvidere,338,Bensenville,339,Berkeley,340,Berwyn,637,Beverly,732,Big Rock,341,Bloomingdale,342,Blue Island,344,Bolingbrook,738,Bourbonnais,739,Braceville,731,Bradley,345,Braidwood,640,Bridgeport,346,Bridgeview,641,Brighton Park,740,Bristol,347,Broadview,348,Brookfield,642,Bucktown,350,Buffalo Grove,352,Burbank,353,Burlington,354,Burnham,645,Burnside,356,Burr Ridge,3408,Caldonia,357,Calumet City,646,Calumet Heights,358,Calumet Park,3407,Capron,359,Carol Stream,360,Carpentersville,520,Cary/Oakwood Hills,362,Channahon,647,Chatham,741,Chemung,3409,Cherry Valley,368,Chicago Heights,649,Chicago Lawn,369,Chicago Ridge,370,Cicero,371,Clarendon Hills,650,Clearing,742,Clifton,372,Cntry Club Hills,743,Coal City,744,Compton,745,Cortland,373,Countryside,374,Crest Hill,375,Crestwood,376,Crete,377,Crystal Lake,378,Darien,746,De Kalb,651,Dearborn Park,381,Deerfield,652,Depaul,382,Des Plaines,383,Diamond,384,Dixmoor,385,Dolton,653,Douglas,387,Downers Grove,654,Dunning,747,Dwight,748,Earlville,389,East Dundee,655,East Garfield Park,390,East Hazel Crest,656,East Side,657,Edgebrook,658,Edgewater,659,Edison Park,391,Elburn,392,Elgin,395,Elk Grove Vlg,396,Elmhurst,397,Elmwood Park,398,Elwood,660,Englewood,399,Evanston,400,Evergreen Park,401,Flossmoor,402,Ford Heights,661,Forest Glen,403,Forest Park,404,Forest View,750,Fort Sheridan,406,Fox Lake,407,Fox River Grove,411,Frankfort,412,Franklin Park,662,Fuller Park,663,Gage Park,664,Galewood,751,Garden Homes,3410,Garden Prairie,752,Gardner,665,Garfield Ridge,413,Geneva,753,Genoa,414,Gilberts,754,Gilman,415,Glen Ellyn,416,Glencoe,417,Glendale Heights,418,Glenview,755,Glenview Nvl Air Stn,419,Glenwood,420,Godley,666,Gold Coast,421,Golf,667,Grand Boulevard,756,Grant Park,422,Grayslake,757,Green Garden,423,Green Oaks,424,Greenwood,668,Grtr Grand Crossing,758,Grundy County (Other),425,Gurnee,426,Hainesville,427,Hampshire,429,Hanover Park,759,Harmony,430,Harvard,431,Harvey,432,Harwood Heights,433,Hawthorn Woods,434,Hazel Crest,435,Hebron,669,Hegewisch,670,Hermosa,760,Herscher,436,Hickory Hills,437,Highland Park,438,Highwood,439,Hillside,761,Hinckley,441,Hinsdale,442,Hodgkins,443,Hoffman Estates,762,Homer,6950,Homer Glen,445,Hometown,446,Homewood,763,Hoopeston,671,Humboldt Park,447,Huntley,672,Hyde Park-Kenwood,449,Indian Head Park,764,Ingleside,450,Inverness,673,Irving Park,451,Island Lake,453,Itasca,674,Jefferson Park,454,Johnsburg,455,Joliet,456,Justice,765,Kaneville,766,Kankakee,767,Keeneyville,457,Kenilworth,675,Kenwood,458,Kildeer,768,Kinsman,769,Kirkland,770,La Fox,459,La Grange,460,La Grange Park,771,La Salle County,772,LaGrange Highlands,461,Lake Barrington,462,Lake Bluff,463,Lake Forest,773,Lake Holiday,774,Lake in the Hills,464,Lake Villa,465,Lake Zurich,467,Lakemoor,676,Lakeview,468,Lakewood,469,Lansing,775,Lawrence,776,Lee,777,Leland,470,Lemont,778,Leyden Township,471,Libertyville,677,Lincoln Park,678,Lincoln Square,473,Lincolnshire,474,Lincolnwood,475,Lindenhurst,476,Lisle,478,Lockport,679,Logan Square,479,Lombard,480,Long Grove,680,Loop,3411,Loves Park,681,Lower West Side,481,Lynwood,482,Lyons,3412,Machesney Park,483,Manhattan,779,Manteno,484,Maple Park,485,Marengo,486,Markham,780,Marseilles,487,Matteson,488,Maywood,781,Mazon,489,McCook,490,McCullom Lake,491,McHenry,683,McKinley Park,782,Medinah,492,Melrose Park,783,Mendota,493,Merrionette Park,494,Mettawa,495,Midlothian,784,Milford,785,Millbrook,786,Millington,496,Minooka,497,Mokena,787,Momence,498,Monee,684,Montclare,499,Montgomery,685,Morgan Park,788,Morris,500,Morton Grove,686,Mount Greenwood,501,Mount Prospect,502,Mundelein,503,Naperville,687,Near North Side,688,Near South Side,689,Near West Side,690,New City,505,New Lenox,789,Newark,506,Niles,507,Norridge,508,North Aurora,509,North Barrington,691,North Center,510,North Chicago,692,North Lawndale,693,North Park,511,North Riverside,512,Northbrook,513,Northfield,514,Northlake,790,Norway,694,Norwood Park,515,Oak Brook,516,Oak Forest,517,Oak Lawn,518,Oak Park,519,Oakbrook Terrace,696,Oakland,361,Oakwood Hills/Cary,791,Odell,695,Ohare,521,Old Mill Creek,697,Old Town,522,Olympia Fields,523,Orland Hills,524,Orland Park,792,Oswego,525,Palatine,526,Palos Heights,527,Palos Hills,528,Palos Park,529,Park City,531,Park Forest,532,Park Ridge,793,Paw Paw,533,Peotone,534,Phoenix,535,Pingree Grove,536,Plainfield,794,Plano,795,Plato,3413,Poplar Grove,821,Portage Park,699,Portage Park,537,Posen,538,Prairie Grove,796,Prairie View,700,Printers Row,539,Prospect Heights,701,Pullman,702,Ravenswood,540,Richmond,541,Richton Park,542,Ringwood,797,Ritchie,543,River Forest,544,River Grove,703,River North,704,River West,705,Riverdale,545,Riverdale,546,Riverside,547,Riverwoods,548,Robbins,549,Rockdale,3414,Rockford,3415,Rockton,706,Rogers Park,550,Rolling Meadows,551,Romeoville,3416,Roscoe,707,Roscoe Village,708,Roseland,552,Roselle,554,Rosemont,555,Round Lake,798,Russell,709,Saint Bens,799,Sandwich,710,Sauganash,560,Sauk Village,563,Schaumburg,564,Schiller Park,800,Seneca,801,Serena,802,Shabbona,803,Sheridan,804,Shorewood,565,Shorewood,566,Skokie,567,Sleepy Hollow,805,Solon Mills,806,Somonauk,568,South Barrington,711,South Chicago,559,South Chicago Hgts,712,South Deering,569,South Elgin,570,South Holland,713,South Lawndale,714,South Loop,715,South Shore,807,South Wilmington,571,Spring Grove,808,St. Anne,573,St. Charles,574,Steger,809,Steward,576,Stickney,577,Stone Park,578,Streamwood,716,Streeterville,579,Sugar Grove,580,Summit,810,Sunnyside,811,Sycamore,581,Symerton,583,Thornton,585,Tinley Park,717,Ukrainian Village,587,Union  Hill,588,University Park,718,Uptown,589,Vernon Hills,812,Verona,590,Villa Park,813,Virgil,592,Wadsworth,593,Warrenville,814,Wasco,719,Washington Heights,720,Washington Park,815,Waterman,816,Watseka,594,Wauconda,595,Waukegan,596,Wayne,817,Wedron,598,West Chicago,599,West Dundee,721,West Elsdon,722,West Englewood,723,West Garfield Park,724,West Lawn,9309,West Loop,725,West Pullman,726,West Ridge,727,West Town,600,Westchester,601,Western Springs,602,Westmont,603,Wheaton,604,Wheeling,728,Wicker Park,605,Willow Springs,606,Willowbrook,607,Wilmette,608,Wilmington,818,Wilton Center,609,Winfield,610,Winnetka,611,Winthrop Harbor,612,Wonder Lake,613,Wood Dale,729,Woodlawn,615,Woodridge,616,Woodstock,617,Worth,730,Wrigleyville,819,Yorkfield,820,Yorkville,618,Zion,==1,City of Chicago,627,Albany Park,628,Andersonville,629,Archer Heights,630,Armour Square,631,Ashburn,632,Auburn Gresham,633,Austin,634,Avalon Park,635,Avondale,636,Belmont Cragin,637,Beverly,640,Bridgeport,641,Brighton Park,642,Bucktown,645,Burnside,646,Calumet Heights,647,Chatham,649,Chicago Lawn,650,Clearing,651,Dearborn Park,652,Depaul,653,Douglas,654,Dunning,655,East Garfield Park,656,East Side,657,Edgebrook,658,Edgewater,659,Edison Park,660,Englewood,661,Forest Glen,662,Fuller Park,663,Gage Park,664,Galewood,665,Garfield Ridge,666,Gold Coast,667,Grand Boulevard,668,Grtr Grand Crossing,669,Hegewisch,670,Hermosa,671,Humboldt Park,672,Hyde Park-Kenwood,673,Irving Park,674,Jefferson Park,675,Kenwood,676,Lakeview,677,Lincoln Park,678,Lincoln Square,679,Logan Square,680,Loop,681,Lower West Side,683,McKinley Park,684,Montclare,685,Morgan Park,686,Mount Greenwood,687,Near North Side,688,Near South Side,689,Near West Side,690,New City,691,North Center,692,North Lawndale,693,North Park,694,Norwood Park,696,Oakland,695,Ohare,697,Old Town,699,Portage Park,821,Portage Park,700,Printers Row,701,Pullman,702,Ravenswood,703,River North,704,River West,705,Riverdale,706,Rogers Park,707,Roscoe Village,708,Roseland,709,Saint Bens,710,Sauganash,711,South Chicago,712,South Deering,713,South Lawndale,714,South Loop,715,South Shore,716,Streeterville,717,Ukrainian Village,718,Uptown,719,Washington Heights,720,Washington Park,721,West Elsdon,722,West Englewood,723,West Garfield Park,724,West Lawn,9309,West Loop,725,West Pullman,726,West Ridge,727,West Town,728,Wicker Park,729,Woodlawn,730,Wrigleyville,==2,Suburbs,316,Addison,749,Alden,317,Algonquin,319,Alsip,320,Antioch,321,Arlington Heights,322,Aurora,324,Bannockburn,325,Barrington,327,Barrington Hills,331,Bartlett,333,Batavia,334,Beach Park,335,Bedford Park,336,Beecher,337,Bellwood,338,Bensenville,339,Berkeley,340,Berwyn,732,Big Rock,341,Bloomingdale,342,Blue Island,344,Bolingbrook,738,Bourbonnais,739,Braceville,731,Bradley,345,Braidwood,346,Bridgeview,740,Bristol,347,Broadview,348,Brookfield,350,Buffalo Grove,352,Burbank,353,Burlington,354,Burnham,356,Burr Ridge,357,Calumet City,358,Calumet Park,359,Carol Stream,360,Carpentersville,520,Cary/Oakwood Hills,362,Channahon,741,Chemung,368,Chicago Heights,369,Chicago Ridge,370,Cicero,371,Clarendon Hills,742,Clifton,372,Cntry Club Hills,743,Coal City,744,Compton,745,Cortland,373,Countryside,374,Crest Hill,375,Crestwood,376,Crete,377,Crystal Lake,378,Darien,746,De Kalb,381,Deerfield,382,Des Plaines,383,Diamond,384,Dixmoor,385,Dolton,387,Downers Grove,747,Dwight,748,Earlville,389,East Dundee,390,East Hazel Crest,391,Elburn,392,Elgin,395,Elk Grove Vlg,396,Elmhurst,397,Elmwood Park,398,Elwood,399,Evanston,400,Evergreen Park,401,Flossmoor,402,Ford Heights,403,Forest Park,404,Forest View,750,Fort Sheridan,406,Fox Lake,407,Fox River Grove,411,Frankfort,412,Franklin Park,751,Garden Homes,752,Gardner,413,Geneva,753,Genoa,414,Gilberts,754,Gilman,415,Glen Ellyn,416,Glencoe,417,Glendale Heights,418,Glenview,755,Glenview Nvl Air Stn,419,Glenwood,420,Godley,421,Golf,756,Grant Park,422,Grayslake,757,Green Garden,423,Green Oaks,424,Greenwood,758,Grundy County (Other),425,Gurnee,426,Hainesville,427,Hampshire,429,Hanover Park,759,Harmony,430,Harvard,431,Harvey,432,Harwood Heights,433,Hawthorn Woods,434,Hazel Crest,435,Hebron,760,Herscher,436,Hickory Hills,437,Highland Park,438,Highwood,439,Hillside,761,Hinckley,441,Hinsdale,442,Hodgkins,443,Hoffman Estates,762,Homer,6950,Homer Glen,445,Hometown,446,Homewood,763,Hoopeston,447,Huntley,449,Indian Head Park,764,Ingleside,450,Inverness,451,Island Lake,453,Itasca,454,Johnsburg,455,Joliet,456,Justice,765,Kaneville,766,Kankakee,767,Keeneyville,457,Kenilworth,458,Kildeer,768,Kinsman,769,Kirkland,770,La Fox,459,La Grange,460,La Grange Park,771,La Salle County,772,LaGrange Highlands,461,Lake Barrington,462,Lake Bluff,463,Lake Forest,773,Lake Holiday,774,Lake in the Hills,464,Lake Villa,465,Lake Zurich,467,Lakemoor,468,Lakewood,469,Lansing,775,Lawrence,776,Lee,777,Leland,470,Lemont,778,Leyden Township,471,Libertyville,473,Lincolnshire,474,Lincolnwood,475,Lindenhurst,476,Lisle,478,Lockport,479,Lombard,480,Long Grove,481,Lynwood,482,Lyons,483,Manhattan,779,Manteno,484,Maple Park,485,Marengo,486,Markham,780,Marseilles,487,Matteson,488,Maywood,781,Mazon,489,McCook,490,McCullom Lake,491,McHenry,782,Medinah,492,Melrose Park,783,Mendota,493,Merrionette Park,494,Mettawa,495,Midlothian,784,Milford,785,Millbrook,786,Millington,496,Minooka,497,Mokena,787,Momence,498,Monee,499,Montgomery,788,Morris,500,Morton Grove,501,Mount Prospect,502,Mundelein,503,Naperville,505,New Lenox,789,Newark,506,Niles,507,Norridge,508,North Aurora,509,North Barrington,510,North Chicago,511,North Riverside,512,Northbrook,513,Northfield,514,Northlake,790,Norway,515,Oak Brook,516,Oak Forest,517,Oak Lawn,518,Oak Park,519,Oakbrook Terrace,361,Oakwood Hills/Cary,791,Odell,521,Old Mill Creek,522,Olympia Fields,523,Orland Hills,524,Orland Park,792,Oswego,525,Palatine,526,Palos Heights,527,Palos Hills,528,Palos Park,529,Park City,531,Park Forest,532,Park Ridge,793,Paw Paw,533,Peotone,534,Phoenix,535,Pingree Grove,536,Plainfield,794,Plano,795,Plato,537,Posen,538,Prairie Grove,796,Prairie View,539,Prospect Heights,540,Richmond,541,Richton Park,542,Ringwood,797,Ritchie,543,River Forest,544,River Grove,545,Riverdale,546,Riverside,547,Riverwoods,548,Robbins,549,Rockdale,550,Rolling Meadows,551,Romeoville,552,Roselle,554,Rosemont,555,Round Lake,798,Russell,799,Sandwich,560,Sauk Village,563,Schaumburg,564,Schiller Park,800,Seneca,801,Serena,802,Shabbona,803,Sheridan,804,Shorewood,565,Shorewood,566,Skokie,567,Sleepy Hollow,805,Solon Mills,806,Somonauk,568,South Barrington,559,South Chicago Hgts,569,South Elgin,570,South Holland,807,South Wilmington,571,Spring Grove,808,St. Anne,573,St. Charles,574,Steger,809,Steward,576,Stickney,577,Stone Park,578,Streamwood,579,Sugar Grove,580,Summit,810,Sunnyside,811,Sycamore,581,Symerton,583,Thornton,585,Tinley Park,587,Union  Hill,588,University Park,589,Vernon Hills,812,Verona,590,Villa Park,813,Virgil,592,Wadsworth,593,Warrenville,814,Wasco,815,Waterman,816,Watseka,594,Wauconda,595,Waukegan,596,Wayne,817,Wedron,598,West Chicago,599,West Dundee,600,Westchester,601,Western Springs,602,Westmont,603,Wheaton,604,Wheeling,605,Willow Springs,606,Willowbrook,607,Wilmette,608,Wilmington,818,Wilton Center,609,Winfield,610,Winnetka,611,Winthrop Harbor,612,Wonder Lake,613,Wood Dale,615,Woodridge,616,Woodstock,617,Worth,819,Yorkfield,820,Yorkville,618,Zion,==4,Northern Suburbs,324,Bannockburn,381,Deerfield,399,Evanston,416,Glencoe,418,Glenview,422,Grayslake,425,Gurnee,437,Highland Park,457,Kenilworth,462,Lake Bluff,463,Lake Forest,464,Lake Villa,471,Libertyville,473,Lincolnshire,474,Lincolnwood,475,Lindenhurst,494,Mettawa,500,Morton Grove,502,Mundelein,506,Niles,512,Northbrook,513,Northfield,547,Riverwoods,555,Round Lake,566,Skokie,589,Vernon Hills,592,Wadsworth,595,Waukegan,607,Wilmette,610,Winnetka,==7,Northwestern Suburbs,317,Algonquin,320,Antioch,321,Arlington Heights,325,Barrington,327,Barrington Hills,350,Buffalo Grove,360,Carpentersville,377,Crystal Lake,382,Des Plaines,389,East Dundee,392,Elgin,395,Elk Grove Vlg,406,Fox Lake,414,Gilberts,422,Grayslake,426,Hainesville,427,Hampshire,433,Hawthorn Woods,443,Hoffman Estates,447,Huntley,764,Ingleside,450,Inverness,458,Kildeer,461,Lake Barrington,774,Lake in the Hills,464,Lake Villa,465,Lake Zurich,468,Lakewood,475,Lindenhurst,480,Long Grove,491,McHenry,501,Mount Prospect,509,North Barrington,361,Oakwood Hills/Cary,525,Palatine,532,Park Ridge,539,Prospect Heights,540,Richmond,550,Rolling Meadows,555,Round Lake,563,Schaumburg,567,Sleepy Hollow,568,South Barrington,571,Spring Grove,578,Streamwood,594,Wauconda,599,West Dundee,604,Wheeling,612,Wonder Lake,616,Woodstock,==5,Western Suburbs,316,Addison,322,Aurora,331,Bartlett,333,Batavia,337,Bellwood,338,Bensenville,340,Berwyn,341,Bloomingdale,347,Broadview,348,Brookfield,356,Burr Ridge,359,Carol Stream,370,Cicero,371,Clarendon Hills,373,Countryside,378,Darien,387,Downers Grove,391,Elburn,392,Elgin,396,Elmhurst,397,Elmwood Park,403,Forest Park,407,Fox River Grove,412,Franklin Park,413,Geneva,415,Glen Ellyn,417,Glendale Heights,429,Hanover Park,432,Harwood Heights,439,Hillside,441,Hinsdale,449,Indian Head Park,453,Itasca,459,La Grange,460,La Grange Park,772,LaGrange Highlands,476,Lisle,479,Lombard,482,Lyons,488,Maywood,782,Medinah,492,Melrose Park,499,Montgomery,503,Naperville,507,Norridge,508,North Aurora,511,North Riverside,514,Northlake,515,Oak Brook,518,Oak Park,519,Oakbrook Terrace,792,Oswego,543,River Forest,544,River Grove,546,Riverside,552,Roselle,564,Schiller Park,569,South Elgin,573,St. Charles,579,Sugar Grove,590,Villa Park,593,Warrenville,596,Wayne,598,West Chicago,600,Westchester,601,Western Springs,602,Westmont,603,Wheaton,606,Willowbrook,609,Winfield,613,Wood Dale,615,Woodridge,==8,Southwestern Suburbs,319,Alsip,342,Blue Island,344,Bolingbrook,346,Bridgeview,352,Burbank,369,Chicago Ridge,374,Crest Hill,375,Crestwood,400,Evergreen Park,411,Frankfort,434,Hazel Crest,436,Hickory Hills,762,Homer,6950,Homer Glen,455,Joliet,456,Justice,470,Lemont,478,Lockport,481,Lynwood,495,Midlothian,497,Mokena,505,New Lenox,516,Oak Forest,517,Oak Lawn,523,Orland Hills,524,Orland Park,526,Palos Heights,527,Palos Hills,528,Palos Park,536,Plainfield,551,Romeoville,565,Shorewood,804,Shorewood,585,Tinley Park,605,Willow Springs,617,Worth,==6,Southern Suburbs,357,Calumet City,358,Calumet Park,368,Chicago Heights,372,Cntry Club Hills,376,Crete,385,Dolton,401,Flossmoor,419,Glenwood,431,Harvey,446,Homewood,469,Lansing,487,Matteson,522,Olympia Fields,531,Park Forest,541,Richton Park,545,Riverdale,570,South Holland,583,Thornton,588,University Park,==110,Rockford Area,3406,Belvidere,3408,Caldonia,3407,Capron,3409,Cherry Valley,3410,Garden Prairie,3411,Loves Park,3412,Machesney Park,3413,Poplar Grove,3414,Rockford,3415,Rockton,3416,Roscoe,==174,Wisconsin,6886,Beloit,6887,Bloomfield/Genoa City,6888,Brighton,6889,Bristol,6890,Burlington/Springfield/Wheaton,6891,Darien,6892,Delavan,6893,Dover/Kansasville,6894,East Troy/La Grange/Lyons,6895,Elkhorm,6896,Fontana,6897,Franksville/Raymond,6898,Geneva/Lake Geneva/Linn,6899,Kenosha,6900,Milwaukee,6901,Mt. Pleasant/Racine,6902,Norway/Union Grove,6903,Paddock Lake/Salem,6904,Paris/Somers,6905,Pell Lake,6906,Pleasant Prarie,6907,Powers Lake,6908,Randall/Twin Lakes,6909,Sharon,6910,Silver Lake,6911,Trevor,6912,Walworth,6913,Williams Bay,6914,Wilmot,6915,Wisconsin Dells";

var locationArray = new Array();
var regionArray = new Array();

locationArray = theString.split(",");

var counter = 0;
// for (i=0;i <locationArray.length;i++) {
// 	var aString = location[i];
// 	if ( aString.search("|") != -1 ) {
// 		regionArray[counter] = aString;
// 		counter++;
// 	}
// }

// Build Region Select Box
function buildTestSelect() {
	var counter = 0;
	for (i=0;i <locationArray.length;i=i+2) {
		var aString = locationArray[i];
		var aString2 = locationArray[i+1];
	 	if ( aString.search("==") != -1 ) {
			var newopt = new Option( aString2, escape( aString.substr(2) ) );
			document.custom.product.options[counter] = newopt;
			counter++;
	 	}
	}
	document.custom.product.selectedIndex = 0;
	refreshLocations();
}

// Build Region Select Box
function refreshLocations() {
	var counter = 0;
	var selectedRegionID = document.custom.product.options[document.custom.product.selectedIndex].value;
	var theCompare = "==" + selectedRegionID;
	// alert(theCompare);
	var foundRegion = false;
	document.custom.version.options.length = 0

	for (i=0;i <locationArray.length;i=i+2) {
		var aString = locationArray[i];
		var aString2 = locationArray[i+1];

	 	// alert(aString.search(theCompare));

	 	if (foundRegion == true) {
			// alert("Found Region");
			if ( aString.search("==") != -1 ) {
				foundRegion = false;
			} else {
			var newopt = new Option( aString2, escape( aString ) );
			document.custom.version.options[counter] = newopt;
			counter++;
			}
	 	} else if ( aString == theCompare ) {
			foundRegion = true;
		}

	}
}

var selectversionstring = "Select a version";
var allstring = "All";
var submitcount = 0;

var browserTag = "Unknown";
if ( navigator.appName == "Microsoft Internet Explorer" ) {
    browserTag = "MSIE";
}
else if ( navigator.appName == "Netscape" ) {
    browserTag = "NS";
}
var majorVer = parseInt( navigator.appVersion );

function supportedBrowser() {
    return( ( ( browserTag == "NS"   && majorVer >= 3 )
			  || ( browserTag == "MSIE" && majorVer >= 4 ) ) ? 1 : 0 );
}

function rebuildSelect( object, options ) {
    if ( ! supportedBrowser() ) return( 0 );
	if ( object.options == null ) {
		return( 0 );
	}
    if ( options != null && options.length > 0 ) {
		object.options.length = 0;
		for ( var i = 0; i < options.length; i++ ) {
			var newopt = new Option( options[i], escape( options[i] ) );
			object.options[i] = newopt;
		}
		object.selectedIndex = 0;
    }
    return( 1 );
}

function updateVersions() {
    if ( ! supportedBrowser() ) return( 0 );
    var prodsel	= document.custom.product;
    var product	= prodsel.options[prodsel.selectedIndex].text;
    var versions = new Array();
    var i = 0;
    for ( var version in r[product] ) {
		// alert("got here");
		versions[i++] = version;
    }
    if ( prodsel.selectedIndex == 0 ) {
		// versions[0] = selectversionstring;
    } else if ( versions.length < 1 ) {
		// versions[0] = allstring;
    }
	rebuildSelect( document.custom.version, versions );
    return( 1 );
}

function updateProducts() {
    if ( ! supportedBrowser() ) return( 0 );
    var products = new Array();
    var i = 0;
    for ( var prod in r ) {
		products[i++] = prod;
    }
    rebuildSelect( document.custom.product, products );
	if ( document.custom.version ) {
	    updateVersions();
	}
    return( 1 );
}

function countProducts() {
    var last = 0;
    for ( var i = 0; i < document.custom.elements.length; i++ ) {
		var n = document.custom.elements[i].name;
		var l = n.length;
		if ( n.substring(0,8) == "product_" && n.substring(l-5) == "_name" ) {
			var num = parseInt( n.substring(8,l-5) );
			if ( num > last ) last = num;
		}
    }
    return( last );
}

function refreshLocation(command,top) {
    if ( supportedBrowser() && ( command == "refreshproduct" || command == "refreshversion" ) ) {
		if ( document.custom.version && ( command == "refreshproduct" ) ) {
			updateVersions();
		}
    }
    else {
		if ( ! supportedBrowser() ) {
			return( false );
		}
		if ( command == "addproduct" && browserTag == "MSIE" && majorVer == 3 ) {
			var last = countProducts();
			if ( last > 2 ) {
				alert( "Because of limitations in cookie size, you may only have three products in Microsoft Internet Explorer 3.x." );
				return( false );
			}
		}
		var url = buildURL(command);
		if ( top ) {
			window.top.location = url;
		}
		else {
			window.location = url;
		}
	}
    return( false );
}

sortitems = 1;  // Automatically sort items within lists? (1 or 0)

function additem(fbox,tbox) {
	move(fbox,tbox);
	removeitembyname(tbox,"None Selected")
	if (sortitems) SortD(tbox);
}

function additembyname(tbox, theName) {
	if (tbox.options.length == 0) {
			var no = new Option();
			no.value = theName;
			no.text = theName;
			tbox.options[0] = no;
			tbox.length++;
	}
	BumpUp(tbox);
}

function removeitembyname(fbox, theName) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].value == theName) {
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		   }
	}
	BumpUp(fbox);
}

function removeitem(fbox) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			// var no = new Option();
			// no.value = fbox.options[i].value;
			// no.text = fbox.options[i].text;
			// tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		   }
	}
	BumpUp(fbox);
	additembyname (fbox,"None Selected")
}

function move(fbox,tbox) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;

			// check that this entry doesn't already exist.  If it doesn't, then add it

			var len = tbox.length;
			var found = false;
			for(var count = 0; count < len; count++) {
				if (tbox.options[count] != null) {
					if (no.text == tbox.options[count].text) {
					found = true;
					break;
					}
				}
			}


			if (found != true) {
				tbox.options[tbox.options.length] = no;
				len++;
			}
			// tbox.options[tbox.options.length] = no;
			// fbox.options[i].value = "";
			// fbox.options[i].text = "";
		   }
	}
	// BumpUp(fbox);
	if (sortitems) SortD(tbox);
}


function BumpUpold(box)  {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "")  {
for(var j=i; j<box.options.length-1; j++)  {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
   }
}
if(ln < box.options.length)  {
box.options.length -= 1;
BumpUp(box);
   }
}

/***********************
Name:			BumpUp
Description:	This function removes empty Option objects from the Select object array
Input:			box, a Select object
Programmer:	Michael Coca
Date:			4.30.02
************************/
function BumpUp(box) {
	var i=0;
	while (i < box.options.length) {
		if (box.options[i].value == "")
			box.options[i] = null;
			// by setting the individual Option object to null, it is removed from the array
			// and the other objects indexes are automatically adjusted
		else
			i++; // otherwise look at the next item
	}
} // end function

function SortD(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}




function checkAndGetNumber2(aField, aName)
	{
	var checkOK = "0123456789-,.";
	var checkStr = aField.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
				if (ch != ",")
			{
				allNum += ch;
			}
		}

	if (!allValid)
	{	// alert("Please enter only numbers for the " + aName);
		// aField.value = "";
		// aField.focus();
		return false
	}
	return true
}

function checkAndGetNumber(aField, aName)
	{
	var checkOK = "0123456789-,";
	var checkStr = aField.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
				if (ch != ",")
			{
				allNum += ch;
			}
		}

	if (!allValid)
	{	// alert("Please enter only numbers for the " + aName);
		// aField.value = "";
		// aField.focus();
		return false
	}
	return true
}

function submit_page(form) {
	var theForm = form;
    foundError = false;
    foundNameBlankError = false;
    foundEmailBlankError = false;
    foundEmailBadError = false;
    foundEmailError = false;
    foundPhoneBlankError = false;
    foundLowPriceError = false;
    foundHighPriceError = false;
    foundPriceError = false;
    foundPasswordError = false;
    foundLocationNoneError = false;
    foundLocationTooManyError = false;
    foundHeardAboutServiceError = false;
    foundBuyingTimeframeError = false;
    foundProspectAgentUseError = false;
    foundAcreageOptionError = false;

    foundSpecialOptions1Error = false;
    foundSpecialOptions2Error = false;
    foundSpecialOptions3Error = false;

	selectAll(form.selectedVersion)

	// Price field
        if(isFieldBlank(form.priceLow)) {
            foundLowPriceError = true;
            foundError = true;
        }
        if(isFieldBlank(form.priceHigh)) {
            foundHighPriceError = true;
            foundError = true;
        }

	// low price < high price
	if(checkAndGetNumber(form.priceLow)==false)
	{  foundLowPriceError = true;
	foundError = true; }
	if (checkAndGetNumber(form.priceHigh) == false)
	{ foundHighPriceError = true;
	foundError = true; }

	if(parseInt(form.priceLow.value) >= parseInt(form.priceHigh.value))
	{
		foundPriceError = true;
		foundError = true;
	}

	// Name field
        if(isFieldBlank(form.nameField)) {
            foundNameBlankError = true;
            foundError = true;
        }

        if(isFieldBlank(form.lastName)) {
            foundNameBlankError = true;
            foundError = true;
        }

    // Password
        if(isFieldBlank(form.password) == true) {
			foundPasswordError = true;
			foundError = true;
        }

        if(form.password.value != form.password2.value) {
			foundPasswordError = true;
			foundError = true;
		 }

    // Email
        if(form.emailAddress.value != form.emailAddress2.value) {
			foundEmailError = true;
			foundError = true;
		 }

        if(isFieldBlank(form.emailAddress) == true) {
            foundEmailBlankError = true;
            foundError = true;
        } else {
			if(isValidEmail(form.emailAddress) == false) {
			    foundEmailBadError = true;
			    foundError = true;
			}
			if(!checkEmail(form.emailAddress.value)) {
			    foundEmailBadError = true;
			    foundError = true;
			}
		}

	// Check that something was entered in buying timeframe
		if(form.buyingTimeframeID.options[form.buyingTimeframeID.selectedIndex].value == -1) {
			    foundBuyingTimeframeError = true;
			    foundError = true;
		}


	// Check that something was entered in prospect agent use
		if(form.prospectAgentUseID.options[form.prospectAgentUseID.selectedIndex].value == -1) {
			    foundProspectAgentUseError = true;
			    foundError = true;
		}

	// Check that showSpecialOptions1 was checked
	if (form.showSpecialOptions1.checked == false) {
		foundSpecialOptions1Error = true;
		foundError = true;
	}

	// Check that showSpecialOptions2 was checked
	if (form.showSpecialOptions2.checked == false) {
		foundSpecialOptions2Error = true;
		foundError = true;
	}


	// Check that something was entered in howHeardAbout
	if(form.howHeardAboutID.options[form.howHeardAboutID.selectedIndex].value == -1) {
	    foundHeardAboutServiceError = true;
	    foundError = true;
	}

	if(numberOfSelectedEntries(form.selectedVersion) > 18){
		foundLocationTooManyError = true;
		foundError = true;
	}

	if(numberOfSelectedEntries(form.selectedVersion) == 0){
		foundLocationNoneError = true;
		foundError = true;
	}

	// Find out if we have an Acreage field to process
	var fieldacreage = form.acreageOptionExists;
	if(fieldacreage)
	{
		if (checkAndGetNumber2(form.lotSize) == false)
		{ foundAcreageOptionError = true;
		foundError = true; }
	}


	// If made it through all edits, submit form

	if (foundError == true) {
		lnfd = "\n";
		msgString = "Please correct the following:" + lnfd + lnfd;
		if (foundLowPriceError == true ) {
			msgString += "The lower price range is not a valid number" + lnfd;
		}
		if (foundHighPriceError == true ) {
			msgString += "The upper price range is not a valid number" + lnfd;
		}
		if (foundPriceError == true ) {
			msgString += "The low price must be less than the high price" + lnfd;
		}
		if (foundLocationTooManyError == true ) {
			msgString += "A maximum of 18 locations can be selected" + lnfd;
		}
		if (foundLocationNoneError == true ) {
			msgString += "At least one location must be selected" + lnfd;
		}
		if (foundBuyingTimeframeError == true ) {
			msgString += "Make a selection for 'How long before you expect to buy'" + lnfd ;
		}
		if (foundNameBlankError == true ) {
			msgString += "The first and last names can not be blank" + lnfd ;
		}
		if (foundEmailBlankError == true ) {
			msgString += "The email address can not be blank" + lnfd;
		}
		if (foundEmailBadError == true ) {
			msgString += "The email address does not appear to be valid" + lnfd;
		}
		if (foundEmailError == true ) {
			msgString += "The email addresses do not match each other" + lnfd;
		}
		if (foundPasswordError == true ) {
			msgString += "The passwords are blank or do not match each other" + lnfd;
		}
		if (foundProspectAgentUseError == true ) {
			msgString += "Make a selection for 'Are you working with a buyer's agent?'" + lnfd;
		}
		if (foundHeardAboutServiceError == true ) {
			msgString += "Make a selection for 'How did you hear about this service'" + lnfd;
		}
		if (foundSpecialOptions1Error == true ) {
			msgString += 'Please indicate that you have read the Terms of Use and Privacy Policy' + lnfd;
		}
		if (foundSpecialOptions2Error == true ) {
			msgString += 'Please indicate that you have read the HomeFinder Terms of Use' + lnfd;
		}
		if (foundSpecialOptions3Error == true ) {
			msgString += '' + lnfd;
		}
		if (foundAcreageOptionError == true ) {
			msgString += "The Acreage Option is not a valid number" + lnfd;
		}

		//Set focus
		if (foundAcreageOptionError == true ) {
			form.lotSize.focus();
		}
		if (foundHeardAboutServiceError == true ) {
			form.howHeardAboutID.focus();
		}
		if (foundProspectAgentUseError == true ) {
			form.prospectAgentUseID.focus();
		}
		if (foundPasswordError == true ) {
			form.password.focus();
		}
		if (foundEmailBadError == true ) {
			form.emailAddress.focus();
		}
		if (foundEmailBlankError == true ) {
			form.emailAddress.focus();
		}
		if (foundEmailError == true ) {
			form.emailAddress.focus();
		}
		if (foundNameBlankError == true ) {
			form.nameField.focus();
		}
		if (foundBuyingTimeframeError == true ) {
			form.buyingTimeframeID.focus();
		}
		if (foundLocationNoneError == true ) {
			form.product.focus();
		}
		if (foundLocationTooManyError == true ) {
			form.product.focus();
		}
		if (foundPriceError == true ) {
			form.priceLow.focus();
		}
		if (foundHighPriceError == true ) {
			form.priceHigh.focus();
		}
		if (foundLowPriceError == true ) {
			form.priceLow.focus();
		}


		alert(msgString);
		return false;

	}

		if (submitcount == 0) {
		      submitcount++;
		      return true;
		      }
		else {
		      alert("Your information is being processed.  Thanks!");
		      return false;
      	}

    }

// Check for a blank field
function isFieldBlank(theField) {
    if(theField.value == "")
        return true;
    else
        return false;
}



function numberOfSelectedEntries(theSelect) {
	n = 0
	count = 0
	while (n < theSelect.options.length) {
	if(theSelect.options[n].selected && theSelect.options[n].value != "None Selected") {
		count ++ }
	n ++ }
	return count
}

function selectAll(theSelect) {
	for(var i =0;i < theSelect.options.length; i++) {
		theSelect.options[i].selected = true;
	}
}


// Check for a valid email address (Does it contain a "@")
function isValidEmail(theField) {
	if((theField.value.indexOf('@', 0) == -1) || (theField.value.indexOf(' ', 0) != -1) || (theField.value.indexOf(',', 0) != -1))
		return false;
	else
		return true;
}

function checkEmail(str) {
  if (str.length == 0) {
    return true
  }
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\s)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
    return true;
  }
  return false;
}

function popWindow2(theLink) {
	var initialX =	100;
	var initialY = 	100;
	if (navigator.appName == "Netscape") {
		theWindow = open(	theLink,
			"Lookup",
			"width=560,height=400," +
						"screenX=" + initialX + ",screenY=" + initialY +
				",scrollbars");
			theLink.focus();		// make sure our new window is in front
	}
	else {
		theWindow = open(	theLink,
			"Lookup",
			"width=760,height=600" +
			",left=" + initialX + ",top=" + initialY +
				",scrollbars");
	}
	theWindow.focus();
}


