
function branch(name, comment, country, state, city, street, postcode, phoneArea, phoneNumber, faxArea, faxNumber) {
	this.name = name;
	this.comment = comment;
	this.country = country;
	this.state = state;
	this.city = city;
	this.street = street;
	this.postcode = postcode;
	this.phone = "(" + phoneArea + ")" + phoneNumber;
	this.fax = "(" + faxArea + ")" + faxNumber;
}

var branches = new Array();
branches[0] = new branch("Gregory & Carr Funerals (Head Office and Chapel)", "", "Australia", "NSW", "Gordon", "850 Pacific Highway", "2072", "02", "9498 4455", "02", "9844 5606");
branches[1] = new branch("Gregory & Carr Funerals", "", "Australia", "NSW", "Mona Vale", "1747 Pittwater Road", "2103", "02", "9999 1522", "02", "9997 7172");
branches[2] = new branch("Gregory & Carr Funerals", "Incorporating T. Tighe & Co", "Australia", "NSW", "Brookvale", "555 Pittwater Road", "2100", "02", "9977 8011", "02", "9939 2066");
branches[3] = new branch("Gregory & Carr Funerals", "Incorporating Boland Funerals", "Australia", "NSW", "Kogarah", "53 Rocky Point Road", "2217", "02", "9553 8560", "02", "9587 9538");
branches[4] = new branch("Boland Funerals (Head office and Chapel)", "", "Australia", "NSW", "Newtown", "40 Brown Street", "2042", "02", "9519 8272", "02", "9519 3453");
branches[5] = new branch("Boland Funerals", "", "Australia", "NSW", "Maroubra", "29 Maroubra Road", "2035", "02", "9314 2778", "02", "9349 6179")
branches[6] = new branch("Boland Funerals", "Incorporating William Lee & Sons", "Australia", "NSW", "North Strathfield", "100 Concord Road", "2137", "02", "9746 9666", "02", "9746 3455");
branches[7] = new branch("Boland Funerals", "Incorporating Timmins Family Funerals", "Australia", "NSW", "Parramatta", "2 Fennell Street", "2150", "02", "9630 6444", "02", "9630 6620");
branches[8] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Aspley", "782 Zillmere Road", "4034", "07", "3263 5044", "07", "3263 7973");
branches[9] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Cleveland", "109 Queen Street", "4163", "07", "3245 4358", "07", "3286 4999");
branches[10] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Deception Bay", "Tallowwood Drive", "4508", "07", "3888 6469", "07", "3888 6503");
branches[11] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Carbrook", "1774 – 1794 Mt Cotton Road", "4130", "07", "3206 6467", "07", "3206 6875");
branches[12] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Mt Gravatt", "224 Newnham Road", "4122", "07", "3349 9211", "07", "3349 1169");
branches[13] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Palm Beach", "1174 Gold Coast Highway", "4221", "07", "5525 7777", "07", "5525 0329");
branches[14] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Petrie", "1 Young Street", "4502", "07", "3285 4522", "07", "3285 6015");
branches[15] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Redcliffe", "174 Anzac Avenue", "4020", "07", "3284 3799", "07", "3883 2323");
branches[16] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Southport", "44 Nind Street", "4215", "07", "5531 1722", "07", "5531 3809");
branches[17] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Toowong", "20A Jephson Street", "4066", "07", "3870 1044", "07", "3870 7411");
branches[18] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Wynnum", "57 Bay Terrace", "4178", "07", "3893 1711", "07", "3893 271");
branches[19] = new branch("Beaudesert Funerals", "", "Australia", "QLD", "Beaudesert", "177 Brisbane Street", "4285", "07", "5541 2511", "07", "5541 3572");
branches[20] = new branch("Hiram Philp Funerals", "", "Australia", "QLD", "Toowoomba", "52 Herries Street", "4350", "07", "4632 4211", "07", "4639 3477");
branches[21] = new branch("Gatton Funerals", "", "Australia", "QLD", "Gatton", "8 Crescent Street", "4343", "07", "5462 1808", "07", "5462 3220");
branches[22] = new branch("City Funeral Services", "", "Australia", "QLD", "Mackay", "105-107 Sydney St", "4740", "07", "4957 4653", "07", "4957 4444");
branches[23] = new branch("Mackay Funerals", "", "Australia", "QLD", "Mackay", "189 Alfred Street", "4740", "07", "4957 3248", "07", "4953 1366");
branches[24] = new branch("Sarina Funerals", "", "Australia", "QLD", "Sarina", "Malins Road, Bruce Highway", "4737", "07", "4943 0880", "07", "4943 2199");

branches[25] = new branch("WD Rose Funerals", "", "Australia", "VIC", "Brighton", "139 Marriage Road", "3186", "03", "9593 1000", "03", "9592 9777");
branches[26] = new branch("WD Rose Funerals", "", "Australia", "VIC", "Burwood", "339 Warrigal Road", "3125", "03", "9808 8888", "03", "9250 1250");
branches[27] = new branch("WD Rose Funerals", "", "Australia", "VIC", "Cheltenham", "221 Charman Road", "3192", "03", "9584 2222", "03", "9583 9561");
branches[28] = new branch("WD Rose Funerals", "", "Australia", "VIC", "Mornington", "953 Nepean Highway", "3931", "03", "5975 9292", "03", "5975 3661");
branches[29] = new branch("Joseph Allison Funerals", "", "Australia", "VIC", "Brunswick", "788 Sydney Road", "3056", "03", "9383 6675", "03", "9383 4034");
branches[30] = new branch("Joseph Allison Funerals", "", "Australia", "VIC", "Carlton", "22 Lygon Street", "3056", "03", "9387 4044", "03", "9387 0075");
branches[31] = new branch("Joseph Allison Funerals", "", "Australia", "VIC", "Essendon", "941 Mt Alexander Road", "3040", "03", "9379 6223", "03", "9379 7485");
branches[32] = new branch("Joseph Allison Funerals", "", "Australia", "VIC", "Werribee", "11-13 Greaves Street", "3030", "03", "9741 4603", "03", "9742 4223");
branches[33] = new branch("Gianarelli Funerals", "", "Australia", "VIC", "Carlton", "22 Lygon Street", "3056", "03", "9387 4044", "03", "9387 0075");

branches[34] = new branch("Sibuns Funeral Directors & Advisors", "", "NewZealand", "", "Auckland", "583 Remuera Road", "1005", "09", "520 3119", "09", "520 3116");
branches[35] = new branch("Forrest Funeral Services", "", "NewZealand", "", "Auckland", "8 Glen Road, Browns Bay", "1311", "09", "479 5956", "09", "479 5955");
branches[36] = new branch("Murray Brown Funeral Home", "", "NewZealand", "", "Auckland", "39 Riverside Road, Orewa", "1461", "09", "426 7950", "09", "426 3810");
branches[37] = new branch("Manukau City Funeral Services", "", "NewZealand", "", "Auckland", "36 Maich Road, Manurewa", "1702", "09", "266 6177", "09", "267 2881");
branches[38] = new branch("Lambert R Fountain", "", "NewZealand", "", "Auckland", "Cnr Elliott & Wood Streets, Papakura", "1703", "09", "298 2957", "09", "298 2959");
branches[39] = new branch("Pellows Funeral Directors & Advisors", "", "NewZealand", "", "Hamilton", "138 Grey Street", "2001", "07", "856 5129", "07", "856 5132");
branches[40] = new branch("James R Hill", "", "NewZealand", "North Island", "Hamilton", "1004 Heaphy Terrace", "2001", "07", "855 5541", "07", "854 7090");
branches[41] = new branch("Elliotts Funeral Services", "", "NewZealand", "", "Tauranga", "25 Nineth Avenue", "3001", "07", "578 3338", "07", "578 3920");
branches[42] = new branch("Vospers", "", "NewZealand", "", "New Plymouth", "257 Devon Street East", "4601", "06", "758 6039", "06", "758 8669");
branches[43] = new branch("Cleggs Funeral Services", "", "NewZealand", "", "Hawera", "268 High Street", "4800", "06", "278 8088", "06", "278 7643");
branches[44] = new branch("Dempsey & Forrest", "", "NewZealand", "", "Wanganui", "208 Guyton Street", "5001", "06", "345 5569", "06", "345 3931");
branches[45] = new branch("Wairarapa Funeral Services", "", "NewZealand", "", "Masterton", "35 Lincoln Road", "5901", "06", "378 2300", "06", "378 2301");
branches[46] = new branch("Gee & Hickton", "", "NewZealand", "", "Lower Hutt", "1 Cornwall Street", "", "04", "566 3103", "04", "569 5569");
branches[47] = new branch("Geoffrey T Sowman Funeral Directors", "", "NewZealand", "", "Blenheim", "Cnr Hutcheson & Parker Street", "7301", "03", "578 4719", "03", "578 4769");
branches[48] = new branch("John Rhind Funeral Directors", "", "NewZealand", "", "Christchurch", "19 London Street", "8001", "03", "379 9920", "03", "366 7488");
branches[49] = new branch("Gee & Hickton", "", "NewZealand", "", "Upper Hutt", "Cnr King & Cairo Streets", "", "04", "528 2331", "04", "528 2351");


var regions = new Array();
var QLDregions = new Array();
QLDregions[0] = ["Brisbane - Inner City", branches[17], branches[12]];
QLDregions[1] = ["Brisbane - Northern Suburbs", branches[8], branches[10], branches[14], branches[11], branches[15]];
QLDregions[2] = ["Brisbane - Western Suburbs", branches[17]];
QLDregions[3] = ["Brisbane - Eastern Suburbs", branches[9], branches[18], branches[12]];
QLDregions[3] = ["Brisbane - Southern Suburbs", branches[18], branches[12]];
QLDregions[3] = ["Gold Coast", branches[16], branches[13]];
QLDregions[4] = ["Regional", branches[19], branches[20], branches[21], branches[22], branches[23], branches[24]];

var VICregions = new Array();
VICregions[0] = ["Melbourne", branches[25], branches[26], branches[27], branches[28], branches[29], branches[30], branches[31], branches[32], branches[33]];

var NSWregions = new Array();
NSWregions[0] = ["Blue Mountains", branches[7]];
NSWregions[1] = ["Canterbury/Bankstown", branches[6]];
NSWregions[2] = ["Sydney City", branches[4]];
NSWregions[3] = ["Eastern Suburbs", branches[4], branches[5]];
NSWregions[4] = ["Hawkesbury", branches[0]];
NSWregions[5] = ["Hills", branches[7]];
NSWregions[6] = ["Inner West", branches[0], branches[6]];
NSWregions[7] = ["Liverpool/Fairfield", branches[7]];
NSWregions[8] = ["Macarthur/Camden", branches[7]];
NSWregions[9] = ["Central & North Coasts, Newcastle & Hunter Valley", branches[0]];
NSWregions[10] = ["North Shore - Lower", branches[2]];
NSWregions[11] = ["North Shore - Upper", branches[0]];
NSWregions[12] = ["Northern Beaches", branches[1], branches[2]];
NSWregions[13] = ["Northern Districts", branches[0], branches[2]];
NSWregions[14] = ["Parramatta", branches[7]];
NSWregions[15] = ["St George", branches[3]];
NSWregions[16] = ["Sutherland", branches[3]];
NSWregions[17] = ["Western Sydney", branches[7]];

var NorthIslandregions = new Array();
NorthIslandregions[0] = ["Auckland", branches[34], branches[35], branches[36], branches[37], branches[38], branches[39]];
NorthIslandregions[1] = ["Hamilton", branches[40]];
NorthIslandregions[2] = ["Tauranga", branches[41]];
NorthIslandregions[3] = ["New Plymouth", branches[42]];
NorthIslandregions[4] = ["Hawera", branches[43]];
NorthIslandregions[5] = ["Wanganui", branches[44]];
NorthIslandregions[6] = ["Masterton", branches[45]];
NorthIslandregions[7] = ["Lower Hutt", branches[46]];
NorthIslandregions[8] = ["Wellington", branches[46]];

var SouthIslandregions = new Array();
SouthIslandregions[0] = ["Blenheim", branches[47]];
SouthIslandregions[1] = ["Christchurch", branches[48]];

var countries = new Array();
countries[0] = "Australia";
countries[1] = "New Zealand";

var States = new Array();

var NewZealandStates = new Array();
NewZealandStates[0] = "North_Island";
NewZealandStates[1] = "South_Island";

var AustraliaStates = new Array();
stateCounter = 0;
AustraliaStates[0] = branches[0].state;
for ( i = 0; i < branches.length; i++) {
	if ((branches[i].country == "Australia") && (branches[i].state != AustraliaStates[stateCounter])) {
		stateCounter++;
		AustraliaStates[stateCounter] = branches[i].state;
	}
}

function loadCountries() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		for ( i = 0; i < countries.length; i++) {
			var optObj = document.createElement("OPTION");
			document.myForm.ctyID.options.add(optObj);
			optObj.text = optObj.value = countries[i];
		}
	} else {
		for ( i = 0; i < countries.length; i++) {
			var optObj = document.createElement("OPTION");
			document.myForm.ctyID.add(optObj, null);
			optObj.text = optObj.value = countries[i];
		}
	}
	loadStates("");
}

function loadStates(country) {
	reg = / /gi;
	myCountry=country.replace(reg, "");
	stateArray = eval(myCountry + "States");
	statesNumber = document.myForm.staID.options.length;
	for ( i = 1; i < statesNumber; i++) {
		document.myForm.staID.options[1] = null;
	}
	if (navigator.appName == "Microsoft Internet Explorer") {
		for ( i = 0; i < stateArray.length; i++) {
			var optObj = document.createElement("OPTION");
			document.myForm.staID.options.add(optObj);
			re = /_/g;
			optObj.text = stateArray[i].replace(re, " ");
			optObj.value = stateArray[i].replace(re, "");
		}
	} else {
		for ( i = 0; i < stateArray.length; i++) {
			var optObj = document.createElement("OPTION");
			document.myForm.staID.add(optObj, null);
			re = /_/g;
			optObj.text = stateArray[i].replace(re, " ");
			optObj.value = stateArray[i].replace(re, "");
		}
	}
	loadRegions("");
}

function loadRegions(state) {
	reg = / /gi;
	myState=state.replace(reg, "");
	regionArray = eval(myState + "regions");
	regionsNumber = document.myForm.areID.options.length;
	for ( i = 1; i < regionsNumber; i++) {
//		alert(i + ": " + document.myForm.areID.options[1].value);
		document.myForm.areID.options[1] = null;
	}
	if (navigator.appName == "Microsoft Internet Explorer") {
		if (regionArray.length == 0 && state != "") {
			document.myForm.areID.options[0].text = "There are no regions";
		} else {
			document.myForm.areID.options[0].text = "Choose a region";
		}
		for ( i = 0; i < regionArray.length; i++) {
			var optObj = document.createElement("OPTION");
			document.myForm.areID.options.add(optObj);
			optObj.text = regionArray[i][0];
			optObj.value = i;
		}
	} else {
		if (regionArray.length == 0 && state != "") {
			document.myForm.areID.options[0].text = "There are no regions";
		} else {
			document.myForm.areID.options[0].text = "Choose a region";
		}
		for ( i = 0; i < regionArray.length; i++) {
			var optObj = document.createElement("OPTION");
			document.myForm.areID.add(optObj, null);
			optObj.text = regionArray[i][0];
			optObj.value = i;
		}
	}
}

function displayBranches(formObj) {
	selectedState = formObj.staID.options[formObj.staID.selectedIndex].value;
//	selectedState = formObj.state.value;
	regionID = formObj.areID.options[formObj.areID.selectedIndex].value;
	regionsArray = eval(selectedState + "regions");
	selectedRegionArray = regionsArray[regionID];
//	alert("region: " + selectedRegionArray[0]);
//	alert("length: " + selectedRegionArray.length);
	newContent = "";
	newContent += "Funeral homes in the " + selectedRegionArray[0] + " region<hr><br>";
	/*if(selectedState != "NSW"){
		newContent += "<br>The following schedule of locations also includes funeral homes in other States of Australia and in New Zealand who we are pleased to recommend the services of.";
	}*/
	for (i = 1; i < selectedRegionArray.length; i++) {
		branchName = selectedRegionArray[i].name;
		branchCity = selectedRegionArray[i].city;
		branchComment = selectedRegionArray[i].comment;
		branchCountry = selectedRegionArray[i].country;
		branchState = selectedRegionArray[i].state;
		branchCity = selectedRegionArray[i].city;
		branchStreet = selectedRegionArray[i].street;
		branchPostcode = selectedRegionArray[i].postcode;
		branchPhone = selectedRegionArray[i].phone
		branchFax = selectedRegionArray[i].fax;

//		alert("branchName: " + branchName + "; branchCity: " + branchCity + "; for Region: " + selectedRegionArray[0]);
		newContent += "<h2>" + branchName;
		newContent += branchComment == "" ? "</h2>" : "<br>" + branchComment + "</h2>";
		newContent += "<p>" + branchStreet;
		newContent += "<br>" + branchCity + " " + branchState + " " + branchPostcode;
		newContent += "<br>Telephone: " + branchPhone;
		newContent += branchFax != "" ? "<br>Fax: " + branchFax: "";
		newContent += i != (selectedRegionArray.length-1) ? "<hr>":"";
//		newContent += "branchName: " + branchName + "; branchCity: " + branchCity + "; for Region: " + selectedRegionArray[0];
	}
		writeDocument(newContent);

}


function writeDocument(content){
//config = "";
	//branches = window.open("", "branches", config);
	//branches.document.write(content);
	//branches.document.close();
	//branches.focus();
	document.getElementById('mysearch').innerHTML = content + "<br><hr><br>";
}

