// JavaScript Document

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// BRANCH AREA

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//NewCastleEmlyn Branch Declaration
/*
var newcastleEmlynAreas = new Array();
bInc=0;

//newcastleEmlynAreas[bInc++] = new Array("aloCardigan and surrounding areas", "aloCardiganandsurroundingareas", "Cardigan and surrounding areas");
newcastleEmlynAreas[bInc++] = new Array("aloNewcastle Emlyn and surrounding areas", "aloNewcastleEmlynandsurroundingareas", "Newcastle Emlyn and surrounding areas");
newcastleEmlynAreas[bInc++] = new Array("aloNewcastle Emlyn", "aloNewcastleEmlyn", "Newcastle Emlyn");
*/

//Cardigan Branch Declaration


/*
else if (branchName=="newcastleEmlynAreas"){
		boxVal = document.getElementById("cardiganAreas");
		if (!boxVal.checked){
				branchArray = eval("cardiganAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="cardiganAreas"){
		boxVal = document.getElementById("newcastleEmlynAreas");
		if (!boxVal.checked){
				branchArray = eval("cardiganAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}
*/

var cardiganAreas = new Array();
bInc=0;

cardiganAreas[bInc++] = new Array("aloCardigan and surrounding areas", "aloCardiganandsurroundingareas", "Cardigan and surrounding areas");
cardiganAreas[bInc++] = new Array("aloSouth East Of Cardigan","aloSouthEastOfCardigan","South East Of Cardigan");
cardiganAreas[bInc++] = new Array("aloNewcastle Emlyn and surrounding areas", "aloNewcastleEmlynandsurroundingareas", "Newcastle Emlyn and surrounding areas");
cardiganAreas[bInc++] = new Array("aloNewcastle Emlyn", "aloNewcastleEmlyn", "Newcastle Emlyn");

//Ammanford Branch Declaration

var ammanfordAreas = new Array();
bInc=0;

ammanfordAreas[bInc++] = new Array("aloAmmanford", "aloAmmanford", "Ammanford");
ammanfordAreas[bInc++] = new Array("aloNorth of Ammanford", "aloNorthofAmmanford", "North of Ammanford");
ammanfordAreas[bInc++] = new Array("aloSouth of Ammanford", "aloSouthofAmmanford", "South of Ammanford");
ammanfordAreas[bInc++] = new Array("aloEast of Ammanford", "aloEastofAmmanford", "East of Ammanford");
ammanfordAreas[bInc++] = new Array("aloWest of Ammanford", "aloWestofAmmanford", "West of Ammanford");
ammanfordAreas[bInc++] = new Array("aloLlandeilo", "aloLlandeilo", "Llandeilo");


//Bury Port Branch Declaration

/*var buryPortAreas = new Array();
bInc=0;

buryPortAreas[bInc++] = new Array("aloWest  of LlanelliWest  of Llanelli", "aloWestofLlanelliWestofLlanelli", "West  of LlanelliWest  of Llanelli");
buryPortAreas[bInc++] = new Array("aloWest  of Llanelli /nWest  of Llanelli", "aloWestofLlanellinWestofLlanelli", "West  of Llanelli /nWest  of Llanelli");
*/

//Carmarthen Branch Declaration

var carmarthenAreas = new Array();
bInc=0;

//carmarthenAreas[bInc++] = new Array("aloLaugharne","aloLaugharne","Laugharne");
carmarthenAreas[bInc++] = new Array("aloCarmarthen town","aloCarmarthentown","Carmarthen town");
carmarthenAreas[bInc++] = new Array("aloNorth Carmarthen","aloNorthCarmarthen","North Carmarthen");
carmarthenAreas[bInc++] = new Array("aloSouth Carmarthen","aloSouthCarmarthen","South Carmarthen");
carmarthenAreas[bInc++] = new Array("aloWest Carmarthen","aloWestCarmarthen","West Carmarthen");
carmarthenAreas[bInc++] = new Array("aloEast Carmarthen","aloEastCarmarthen","East Carmarthen");
carmarthenAreas[bInc++] = new Array("aloLampeter and surrounding areas","aloLampeterandsurroundingareas","Lampeter and surrounding areas");


//Fishguard Branch Declaration

var fishguardAreas = new Array();
bInc=0;

fishguardAreas[bInc++] = new Array("aloLetterston","aloLetterston","Letterston");
fishguardAreas[bInc++] = new Array("alofishguard/goodwick","alofishguardgoodwick","fishguard/goodwick");
fishguardAreas[bInc++] = new Array("alowest of fishguard","alowestoffishguard","west of fishguard");
fishguardAreas[bInc++] = new Array("aloeast of fishguard","aloeastoffishguard","east of fishguard");
fishguardAreas[bInc++] = new Array("alosouth of fishguard"," alosouthoffishguard","south of fishguard");
fishguardAreas[bInc++] = new Array("alonewport","alonewport","newport");
fishguardAreas[bInc++] = new Array("aloNorth Pembrokeshire Coastline","aloNNorthPembrokeshireCoastline","North Pembrokeshire Coastline");
fishguardAreas[bInc++] = new Array("aloDale/marloes","aloDalemarloes"," Dale/marloes");
fishguardAreas[bInc++] = new Array("aloNewport / Dinas","aloNewportDinas","Newport / Dinas");
fishguardAreas[bInc++] = new Array("aloSt Davids/solva/newgale","aloStDavidssolvanewgale","St Davids/solva/newgale");
fishguardAreas[bInc++] = new Array("aloAmbleston/ Llys-y-fran / Rosebush","aloAmblestonLlysyfranRosebush","Ambleston/ Llys-y-fran / Rosebush");



//Haverfordwest Branch Declaration

var haverfordwestAreas = new Array();
bInc=0;

haverfordwestAreas[bInc++] = new Array("aloHaverfordwest Town Centre","aloHaverfordwestTownCentre","Haverfordwest Town Centre");
haverfordwestAreas[bInc++] = new Array("aloNorth Of Haverfordwest","aloNorthOfHaverfordwest","North Of Haverfordwest");
haverfordwestAreas[bInc++] = new Array("aloSouth Of Haverfordwest","aloSouthOfHaverfordwest","South Of Haverfordwest");
haverfordwestAreas[bInc++] = new Array("aloWest Of Haverfordwest","aloWestOfHaverfordwest","West Of Haverfordwest");
haverfordwestAreas[bInc++] = new Array("aloEast Of Haverfordwest","aloEastOfHaverfordwest","East Of Haverfordwest");
haverfordwestAreas[bInc++] = new Array("aloBroad/little Haven Coastal","aloBroadlittleHavenCoastal","Broad/little Haven Coastal");
//haverfordwestAreas[bInc++] = new Array("aloSt Davids/solva/newgale","aloStDavidssolvanewgale","St Davids/solva/newgale");
//haverfordwestAreas[bInc++] = new Array("aloMilford Town","aloMilfordTown","Milford Town");
//haverfordwestAreas[bInc++] = new Array("aloDale/marloes/ st ishmaels","aloDalemarloesstishmaels","Dale/marloes/ st ishmaels");
//haverfordwestAreas[bInc++] = new Array("aloNeyland/llanstadwell","aloNeylandllanstadwell","Neyland/llanstadwell");
//haverfordwestAreas[bInc++] = new Array("aloNarberth Town","aloNarberthTown","Narberth Town");


//Llanelli Branch Declaration

var llanelliAreas = new Array();
bInc=0;

llanelliAreas[bInc++] = new Array("aloLlanelli","aloLLanelli","LLanelli");
llanelliAreas[bInc++] = new Array("aloNorth of Llanelli","aloNorthofLlanelli","North of Llanelli");
llanelliAreas[bInc++] = new Array("aloEast of Llanelli","aloEastofLlanelli","East  of Llanelli");
llanelliAreas[bInc++] = new Array("aloWest of Llanelli","aloWestofLlanelli","West  of Llanelli");
llanelliAreas[bInc++] = new Array("aloWest  of LlanelliWest  of Llanelli", "aloWestofLlanelliWestofLlanelli", "West  of LlanelliWest  of Llanelli");
llanelliAreas[bInc++] = new Array("aloWest  of Llanelli /nWest  of Llanelli", "aloWestofLlanellinWestofLlanelli", "West  of Llanelli /nWest  of Llanelli");



//Milford Branch Declaration

var milfordAreas = new Array();
bInc=0;

//milfordAreas[bInc++] = new Array("aloSouth Of Haverfordwest","aloSouthOfHaverfordwest","South Of Haverfordwest");
milfordAreas[bInc++] = new Array("aloMilford Town","aloMilfordTown","Milford Town");
milfordAreas[bInc++] = new Array("aloHakin/herbrandston/","aloHakinherbrandston","Hakin/herbrandston/");
milfordAreas[bInc++] = new Array("aloDale/marloes/ st ishmaels","aloDalemarloesstishmaels","Dale/marloes/ st ishmaels");
milfordAreas[bInc++] = new Array("aloNeyland/llanstadwell","aloNeylandllanstadwell","Neyland/llanstadwell");


// Narberth Branch Declaration

var narberthAreas = new Array();
bInc=0;

narberthAreas[bInc++] = new Array("aloNarberth Town","aloNarberthTown","Narberth Town");
narberthAreas[bInc++] = new Array("aloNorth Of Narberth","aloNorthOfNarberth","North Of Narberth");
narberthAreas[bInc++] = new Array("aloSouth Of Narberth","aloSouthOfNarberth","South Of Narberth");
narberthAreas[bInc++] = new Array("aloWest Of Narberth","aloWestOfNarberth","West Of Narberth");
narberthAreas[bInc++] = new Array("aloEast Of Narberth","aloEastOfNarberth","East Of Narberth");


// Pembroke Branch Declaration

var pembrokeAreas = new Array();
bInc=0;

pembrokeAreas[bInc++] = new Array("aloPembroke","aloPembroke","Pembroke");
pembrokeAreas[bInc++] = new Array("aloFreshwater East","aloFreshwaterEast","Freshwater East");
pembrokeAreas[bInc++] = new Array("aloMilton","aloMilton","Milton");
pembrokeAreas[bInc++] = new Array("aloAngle","aloAngle","Angle");
pembrokeAreas[bInc++] = new Array("aloHundleton","aloHundleton","Hundleton");

// Pembroke Dock Declaration

var pembrokeDockAreas = new Array();
bInc=0;

pembrokeDockAreas[bInc++] = new Array("aloPembroke Dock","aloPembrokeDock","Pembroke Dock");
pembrokeDockAreas[bInc++] = new Array("aloCosheston","aloCosheston","Cosheston");
pembrokeDockAreas[bInc++] = new Array("aloLlanreath","aloLlanreath","Llanreath");

// saundersfoot Declaration

/*var saundersfootAreas = new Array();
bInc=0;

//saundersfootAreas[bInc++] = new Array("aloTenby","aloTenby","Tenby");
saundersfootAreas[bInc++] = new Array("aloSaundersfoot","aloSaundersfoot","Saundersfoot");
saundersfootAreas[bInc++] = new Array("aloKilgetty","aloKilgetty","Kilgetty");
saundersfootAreas[bInc++] = new Array("aloLaugharne","aloLaugharne","Laugharne");
*/
//St Davids Branch Declaration

var stdavidsAreas = new Array();
bInc=0;

//stdavidsAreas[bInc++] = new Array("aloNorth Of Haverfordwest","aloNorthOfHaverfordwest","North Of Haverfordwest");
stdavidsAreas[bInc++] = new Array("aloSt Davids/solva/newgale","aloStDavidssolvanewgale","St Davids/solva/newgale");
//stdavidsAreas[bInc++] = new Array("aloSouth East Of Cardigan","aloSouthEastOfCardigan","South East Of Cardigan");

// tenby Branch Declaration

var tenbyAreas = new Array();
bInc=0;

//Saundersfoot???

tenbyAreas[bInc++] = new Array("aloSageston","aloSageston","Sageston");
tenbyAreas[bInc++] = new Array("aloSageston/carew/crescelly","aloSagestoncarewcrescelly","Sageston/carew/crescelly");
tenbyAreas[bInc++] = new Array("aloTenby","aloTenby","Tenby");
tenbyAreas[bInc++] = new Array("aloSt Florence","aloStFlorence","St Florence");
tenbyAreas[bInc++] = new Array("aloPenally","aloPenally","Penally");
tenbyAreas[bInc++] = new Array("aloLawrenny","aloLawrenny","Lawrenny");
tenbyAreas[bInc++] = new Array("aloSaundersfoot","aloSaundersfoot","Saundersfoot");
tenbyAreas[bInc++] = new Array("aloKilgetty","aloKilgetty","Kilgetty");
tenbyAreas[bInc++] = new Array("aloLaugharne","aloLaugharne","Laugharne");
tenbyAreas[bInc++] = new Array("aloAmroth/ Wisemans Bridge","aloAmroth/ Wisemans Bridge","Amroth/ Wisemans Bridge");
tenbyAreas[bInc++] = new Array("aloAmroth","aloAmroth","Amroth");


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	function check ( box ) {
		boxy = document.getElementById(box);
		boxy.checked = !boxy.checked;
		return true;
	}


function checkAreas(branchName){
	if (branchName=="saundersfootAreas"){
		boxVal = document.getElementById("tenbySr");
		//alert(boxVal.checked);
		if (!boxVal.checked){
				branchArray = eval("tenbyAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="tenbyAreas"){
		boxVal = document.getElementById("saundersfootSr");
		if (!boxVal.checked){
				branchArray = eval("tenbyAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="fishguardAreas"){
		boxVal = document.getElementById("stdavidsSr");
		//alert(boxVal.checked);
		if (!boxVal.checked){
				branchArray = eval("fishguardAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="stdavidsAreas"){
		boxVal = document.getElementById("fishguardSr");
		if (!boxVal.checked){
				branchArray = eval("fishguardAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="newcastleEmlynAreas"){
		boxVal = document.getElementById("cardiganSr");
		if (!boxVal.checked){
				branchArray = eval("cardiganAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="cardiganAreas"){
		boxVal = document.getElementById("newcastleEmlynSr");
		if (!boxVal.checked){
				branchArray = eval("cardiganAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="llanelliAreas"){
		boxVal = document.getElementById("buryPortSr");
		if (!boxVal.checked){
				branchArray = eval("llanelliAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else if (branchName=="buryPortAreas"){
		boxVal = document.getElementById("llanelliSr");
		if (!boxVal.checked){
				branchArray = eval("llanelliAreas");
				for (var i=0;i<branchArray.length;i++){	
					check (branchArray[i][1]);
				}		
		}
	}else {
		branchArray = eval(branchName);
		for (var i=0;i<branchArray.length;i++){	
			check (branchArray[i][1]);
		}
	}
}


function writeBranchAreas(){
	document.write("<div id='searchCheckBoxes' style='visibility:hidden;z-index:0;position:absolute;'>");
	//newcastle emlyn
	/*for (var i=0;i<newcastleEmlynAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ newcastleEmlynAreas[i][0] +'" id="'+ newcastleEmlynAreas[i][1] +'" value="'+ newcastleEmlynAreas[i][2] +'" >');
	}*/
	//Ammanford
	for (var i=0;i<ammanfordAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ ammanfordAreas[i][0] +'" id="'+ ammanfordAreas[i][1] +'" value="'+ ammanfordAreas[i][2] +'" >');
	}
	//Bury Port
	/*for (var i=0;i<buryPortAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ buryPortAreas[i][0] +'" id="'+ buryPortAreas[i][1] +'" value="'+ buryPortAreas[i][2] +'" >');
	}*/
	//cardigan
	for (var i=0;i<cardiganAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ cardiganAreas[i][0] +'" id="'+ cardiganAreas[i][1] +'" value="'+ cardiganAreas[i][2] +'" >');
	}
	//carmarthen 
	for (var i=0;i<carmarthenAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ carmarthenAreas[i][0] +'" id="'+ carmarthenAreas[i][1] +'" value="'+ carmarthenAreas[i][2] +'" >');
	}
	//fishguard 
	for (var i=0;i<fishguardAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ fishguardAreas[i][0] +'" id="'+ fishguardAreas[i][1] +'" value="'+ fishguardAreas[i][2] +'" >');
	}
	//haverfordwest 
	for (var i=0;i<haverfordwestAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ haverfordwestAreas[i][0] +'" id="'+ haverfordwestAreas[i][1] +'" value="'+ haverfordwestAreas[i][2] +'" >');
	}
	//Llanelli 
	for (var i=0;i<llanelliAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ llanelliAreas[i][0] +'" id="'+ llanelliAreas[i][1] +'" value="'+ llanelliAreas[i][2] +'" >');
	}
	//Milford 
	for (var i=0;i<milfordAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ milfordAreas[i][0] +'" id="'+ milfordAreas[i][1] +'" value="'+ milfordAreas[i][2] +'" >');
	}
	//Narberth 
	for (var i=0;i<narberthAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ narberthAreas[i][0] +'" id="'+ narberthAreas[i][1] +'" value="'+ narberthAreas[i][2] +'" >');
	}
	//Pembroke 
	for (var i=0;i<pembrokeAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ pembrokeAreas[i][0] +'" id="'+ pembrokeAreas[i][1] +'" value="'+ pembrokeAreas[i][2] +'" >');
	}
	//Pembroke Dock
	for (var i=0;i<pembrokeDockAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ pembrokeDockAreas[i][0] +'" id="'+ pembrokeDockAreas[i][1] +'" value="'+ pembrokeDockAreas[i][2] +'" >');
	}
	//Saundersfoot
	/*for (var i=0;i<saundersfootAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ saundersfootAreas[i][0] +'" id="'+ saundersfootAreas[i][1] +'" value="'+ saundersfootAreas[i][2] +'" >');
	}*/
	//stdavids
/*	for (var i=0;i<stdavidsAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ stdavidsAreas[i][0] +'" id="'+ stdavidsAreas[i][1] +'" value="'+ stdavidsAreas[i][2] +'" >');
	}*/
	//Tenby
	for (var i=0;i<tenbyAreas.length;i++){	
		document.write('<input type="checkbox" name="'+ tenbyAreas[i][0] +'" id="'+ tenbyAreas[i][1] +'" value="'+ tenbyAreas[i][2] +'" >');
	}
	document.write("</div>");
}

function mapSearchCall(sArea){
	checkAreas(sArea);
	sForm = document.getElementById("searchform");
	sForm.submit();
}

function clearSearch(){
	
		boxy = document.getElementById("haverfordwestSr"); boxy.checked = false;
		boxy = document.getElementById("milfordSr"); boxy.checked = false;
		boxy = document.getElementById("narberthSr"); boxy.checked = false;
		boxy = document.getElementById("newcastleEmlynSr"); boxy.checked = false;
		boxy = document.getElementById("buryPortSr"); boxy.checked = false;
		boxy = document.getElementById("ammanfordSr"); boxy.checked = false;
		boxy = document.getElementById("fishguardSr"); boxy.checked = false;
		boxy = document.getElementById("stdavidsSr"); boxy.checked = false;
		boxy = document.getElementById("pembrokeSr"); boxy.checked = false;
		boxy = document.getElementById("pembrokedockSr"); boxy.checked = false;
		boxy = document.getElementById("cardiganSr"); boxy.checked = false;
		boxy = document.getElementById("saundersfootSr"); boxy.checked = false;
		boxy = document.getElementById("llanelliSr"); boxy.checked = false;
		boxy = document.getElementById("carmarthenSr"); boxy.checked = false;
		boxy = document.getElementById("tenbySr"); boxy.checked = false;

		/*branchArray = eval("newcastleEmlynAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}*/
		
		/*branchArray = eval("buryPortAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}*/
		
		branchArray = eval("ammanfordAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("cardiganAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("carmarthenAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("fishguardAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("haverfordwestAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("llanelliAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("milfordAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("narberthAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("pembrokeAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("pembrokeDockAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
	
		branchArray = eval("stdavidsAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}
		
		branchArray = eval("tenbyAreas");
		for (var i=0;i<branchArray.length;i++){	
			boxy = document.getElementById((branchArray[i][1]));
			boxy.checked = false;
		}


}
