// JavaScript Document
var region = new Array();
region["Northland"] = new Array(
								new Array("Dargaville", "JSHL&O_p=DMYd7&"),
								new Array("Kaikohe", "JSHL&O_p=nOYd7&"),
								new Array("Kaitaia", "JSHL&O_p=eQYd7&"),
								new Array("Snells Beach", "JSHL&O_p=bSYd7&"),
								new Array("Waipapa", "JSHL&O_p=eUYd7&"),
								new Array("Whangarei", "JSHL&O_p=O0Ld7&")
								);
region["Auckland"] = new Array(
					   			new Array("Airport", "JSHL&C_p=true&O_p=KZKd7&"),
								new Array("Albany", "JSHL&O_p=RZKd7&"),
								new Array("Balmoral", "JSHL&O_p=VZKd7&"),
								new Array("Birkenhead", "JSHL&O_p=ZZKd7&"),
								new Array("Botany Downs", "JSHL&O_p=66Zd7&"),
								new Array("Clendon", "JSHL&O_p=h8Zd7&"),
								new Array("Downtown", "JSHL&O_p=yaZd7&"),
					   			new Array("Glenfield", "JSHL&O_p=pfZd7&"),
								new Array("Lincoln Road (Henderson)", "JSHL&O_p=FkZd7&"),
								new Array("Manukau", "JSHL&O_p=qnZd7&"),
								new Array("Milford", "JSHL&O_p=iqZd7&"),
								new Array("Mt Wellington", "JSHL&O_p=gtZd7&"),
								new Array("New Lynn", "JSHL&O_p=kwZd7&"),
								new Array("Newmarket", "JSHL&O_p=uAZd7&"),
								new Array("Pakuranga", "JSHL&O_p=7HZd7&"),
								new Array("Papakura", "JSHL&O_p=AKZd7&"),
								new Array("Pukekohe", "JSHL&O_p=xVZd7&"),
								new Array("Sylvia Park", "JSHL&O_p=l30e7&"),
								new Array("Westcity (Henderson)", "JSHL&O_p=xb0e7&"),
								new Array("Westgate (Massey)", "JSHL&O_p=Nf0e7&"),
								new Array("Whangaparaoa", "JSHL&O_p=8k0e7&")
								);

region["Waikato"] = new Array(
								new Array("Cambridge", "JSHL&O_p=h0Ld7&"),
								new Array("Hamilton Central", "JSHL&O_p=p0Ld7&"),
								new Array("Hillcrest", "JSHL&O_p=t0Ld7&"),
								new Array("Matamata", "JSHL&O_p=x0Ld7&"),
								new Array("Morrinsville", "JSHL&O_p=S0Ld7&"),
								new Array("Te Awamutu", "JSHL&O_p=C0Ld7&"),
								new Array("Te Kuiti", "JSHL&O_p=G0Ld7&"),
								new Array("Te Rapa", "JSHL&O_p=K0Ld7&"),
								new Array("Thames", "JSHL&O_p=X21e7&"),
								new Array("Tokoroa", "JSHL&O_p=S61e7&")
					   )

region["Bay of Plenty"] = new Array(
								new Array("Fraser Cove (Tauranga)", "JSHL&O_p=n9ie7&"),
								new Array("Papamoa", "JSHL&O_p=3k1e7&"),
								new Array("Rotorua", "JSHL&O_p=Pn1e7&"),
								new Array("Taupo", "JSHL&O_p=Hr1e7&"),
								new Array("Tauranga", "JSHL&O_p=Fv1e7&"),
								new Array("Whakatane", "JSHL&O_p=TE1e7&")
					   )

region["East Coast"] = new Array(
								new Array("Gisborne", "JSHL&O_p=lT1e7&")
					   )

region["Taranaki"] = new Array(
								new Array("Bell Block", "JSHL&O_p=6Xhe7&"),
								new Array("Hawera", "JSHL&O_p=W72e7&"),
								new Array("New Plymouth", "JSHL&O_p=cc2e7&")
					   )

region["Manawatu/Wanganui"] = new Array(
								new Array("Dannevirke", "JSHL&O_p=cw2e7&"),
								new Array("Feilding", "JSHL&O_p=GB2e7&"),
								new Array("Levin", "JSHL&O_p=Eu3e7&"),
								new Array("Masterton", "JSHL&O_p=fG2e7&"),
								new Array("Palmerston North", "JSHL&O_p=VK2e7&"),
								new Array("Wanganui", "JSHL&O_p=HP2e7&")
					   )

region["Hawkes Bay"] = new Array(
								new Array("Hastings", "JSHL&O_p=n63e7&"),
								new Array("Napier", "JSHL&O_p=cb3e7&")
					   )

region["Wellington"] = new Array(
								new Array("Johnsonville", "JSHL&O_p=60Ld7&"),
								new Array("Lower Hutt", "JSHL&O_p=FA3e7&"),
								new Array("Lyall Bay", "JSHL&O_p=MF3e7&"),
								new Array("Paraparaumu", "JSHL&O_p=ZK3e7&"),
								new Array("Petone", "JSHL&O_p=iQ3e7&"),
								new Array("Porirua", "JSHL&O_p=IV3e7&"),
								new Array("Upper Hutt", "JSHL&O_p=d14e7&"),
								new Array("Wainuiomata", "JSHL&O_p=P64e7&"),
								new Array("Wellington Central", "JSHL&O_p=wc4e7&")
					   )

region["Nelson/Malborough"] = new Array(
								new Array("Blenheim", "JSHL&O_p=31Ld7&"),
								new Array("Nelson", "JSHL&O_p=f1Ld7&"),
								new Array("Motueka", "JSHL&O_p=n1Ld7&")
					   )

region["West Coast"] = new Array(
								new Array("Greymouth", "JSHL&O_p=j1Ld7&")
					   )

region["Canterbury"] = new Array(
								new Array("Ashburton", "JSHL&O_p=71Ld7&"),
								new Array("Barrington", "JSHL&O_p=71Ld7&"),
								new Array("Belfast", "JSHL&O_p=b1Ld7&"),
								new Array("Eastgate", "JSHL&O_p=8a8e7&"),
								new Array("Hornby", "JSHL&O_p=Sl8e7&"),
								new Array("Northlands", "JSHL&O_p=TK8e7&"),
								new Array("Rangiora", "JSHL&O_p=N99e7&"),
								new Array("Riccarton", "JSHL&O_p=qm9e7&"),
								new Array("South City", "JSHL&O_p=fA9e7&"),
								new Array("Timaru", "JSHL&O_p=fN9e7&")
					   )

region["Otago"] = new Array(
								new Array("Alexandra", "JSHL&O_p=Qpae7&"),
								new Array("Balclutha", "JSHL&O_p=GDae7&"),
								new Array("Dunedin Central", "JSHL&O_p=HQae7&"),
								new Array("Oamaru", "JSHL&O_p=T3be7&"),
								new Array("Queenstown", "JSHL&O_p=ghbe7&"),
								new Array("South Dunedin", "JSHL&O_p=4vbe7&")
					   )

region["Southland"] = new Array(
								new Array("Gore", "JSHL&O_p=2cce7&"),
								new Array("Invercargill", "JSHL&O_p=Jpce7&")
					   )


var regionSelectValue = "";

function setLocations(regionSelect) {
	var locationSelect = document.getElementById("locations");
	//locationSelect.innerHTML = '<option value="">All</option>';
	regionSelectValue = regionSelect.options[regionSelect.selectedIndex].value;
	var regionName = regionSelect.options[regionSelect.selectedIndex].text;
	//alert(regionSelectValue+", "+regionName);
	locationSelect.options[0].text = "All";
	while (locationSelect.options.length > 1) {
		locationSelect.remove(1);
	}
	for (var i = 0; i < region[regionName].length; i++) {
		var optNew = document.createElement('option');
		optNew.text = region[regionName][i][0];
		optNew.value = region[regionName][i][1];
		try {
		  locationSelect.add(optNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
		  locationSelect.add(optNew, (i+1)); // IE only
		}
		
	}
}

function searchSubmit() {
	//alert("regionSelectValue "+regionSelectValue);
	var searchURL = "http://www.thewarehousecareers.co.nz/jobseeker/";
	var query = "safelink=";
	var locationSelect = document.getElementById("locations");
	var alertstr = "the form was submitted ";
	if (regionSelectValue != "") {
		if (locationSelect.options[locationSelect.selectedIndex].value != "") {
			query += locationSelect.options[locationSelect.selectedIndex].value;
		} else {
			query += regionSelectValue;
		}
		alertstr += query;
		//alert(alertstr);
		window.location = searchURL+query;
	} else {
		//alert("regionSelectValue is empty "+regionSelectValue);		
	}
	return false;
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
