
function filllocation(){ 
 // this function is used to fill the category list on load
addOption(document.form1.location, "Malta", "Malta", "");
addOption(document.form1.location, "Gozo", "Gozo", "");

}
function SelectSubCat(towncity){
// ON selection of category this function will work
var town = towncity;
//alert(town);

removeAllOptions(document.form1.SubCat);addOption(document.form1.SubCat, "", "Anywhere", "Anywhere");

if(document.form1.location.value == 'Malta'){
	addOption(document.form1.SubCat,"Attard", "Attard",town);
	addOption(document.form1.SubCat,"Bahar ic Caghaq", "Bahar ic Caghaq",town);
	addOption(document.form1.SubCat,"Bahrija", "Bahrija",town);
	addOption(document.form1.SubCat,"Balzan", "Balzan",town);
	addOption(document.form1.SubCat,"Birgu", "Birgu",town);
	addOption(document.form1.SubCat,"Birguma", "Birguma",town);
	addOption(document.form1.SubCat,"Birkirkara", "Birkirkara",town);
	addOption(document.form1.SubCat,"Birzebbugia", "Birzebbugia",town);
	addOption(document.form1.SubCat,"Bormla", "Bormla",town);
	addOption(document.form1.SubCat,"Bugibba", "Bugibba",town);
	addOption(document.form1.SubCat,"Burmarrad", "Burmarrad",town);
	addOption(document.form1.SubCat,"Dingli", "Dingli",town);
	addOption(document.form1.SubCat,"Fgura", "Fgura",town);
	addOption(document.form1.SubCat,"Floriana", "Floriana",town);
	addOption(document.form1.SubCat,"Gharghur", "Gharghur",town);
	addOption(document.form1.SubCat,"Ghaxaq", "Ghaxaq",town);
	addOption(document.form1.SubCat,"Gudja", "Gudja",town);
	addOption(document.form1.SubCat,"Gzira", "Gzira",town);
	addOption(document.form1.SubCat,"Hamrun", "Hamrun",town);
	addOption(document.form1.SubCat,"Handaq", "Handaq",town);
	addOption(document.form1.SubCat,"Ibragg", "Ibragg",town);
	addOption(document.form1.SubCat,"Iklin", "Iklin",town);
	addOption(document.form1.SubCat,"Kalkara", "Kalkara",town);
	addOption(document.form1.SubCat,"Kappara", "Kappara",town);
	addOption(document.form1.SubCat,"Kirkop", "Kirkop",town);
	addOption(document.form1.SubCat,"Lija", "Lija",town);
	addOption(document.form1.SubCat,"Luqa", "Luqa",town);
	addOption(document.form1.SubCat,"Madliena", "Madliena",town);
	addOption(document.form1.SubCat,"Maghtab", "Maghtab",town);
	addOption(document.form1.SubCat,"Manikata", "Manikata",town);
	addOption(document.form1.SubCat,"Marsa", "Marsa",town);
	addOption(document.form1.SubCat,"Marsascala", "Marsascala",town);
	addOption(document.form1.SubCat,"Marsaxlokk", "Marsaxlokk",town);
	addOption(document.form1.SubCat,"Mdina", "Mdina",town);
	addOption(document.form1.SubCat,"Mellieha", "Mellieha",town);
	addOption(document.form1.SubCat,"Mgarr", "Mgarr",town);
	addOption(document.form1.SubCat,"Mosta", "Mosta",town);
	addOption(document.form1.SubCat,"Mqabba", "Mqabba",town);
	addOption(document.form1.SubCat,"Mriehel", "Mriehel",town);
	addOption(document.form1.SubCat,"Msida", "Msida",town);
	addOption(document.form1.SubCat,"Mtarfa", "Mtarfa",town);
	addOption(document.form1.SubCat,"Naxxar", "Naxxar",town);
	addOption(document.form1.SubCat,"Paceville", "Paceville",town);
	addOption(document.form1.SubCat,"Paola", "Paola",town);
	addOption(document.form1.SubCat,"Pembroke", "Pembroke",town);
	addOption(document.form1.SubCat,"Pieta", "Pieta",town);
	addOption(document.form1.SubCat,"Qawra", "Qawra",town);
	addOption(document.form1.SubCat,"Qormi", "Qormi",town);
	addOption(document.form1.SubCat,"Qrendi", "Qrendi",town);
	addOption(document.form1.SubCat,"Rabat", "Rabat",town);
	addOption(document.form1.SubCat,"Safi", "Safi",town);
	addOption(document.form1.SubCat,"Salina", "Salina",town);
	addOption(document.form1.SubCat,"San Gwann", "San Gwann",town);
	addOption(document.form1.SubCat,"San Pawl Tat Targa", "San Pawl Tat Targa",town);
	addOption(document.form1.SubCat,"Senglea", "Senglea",town);
	addOption(document.form1.SubCat,"Siggiewi", "Siggiewi",town);
	addOption(document.form1.SubCat,"Sliema", "Sliema",town);
	addOption(document.form1.SubCat,"Santat Lucia", "Santat Lucia",town);
	addOption(document.form1.SubCat,"St Julians", "St Julians",town);
	addOption(document.form1.SubCat,"St Pauls Bay", "St Pauls Bay",town);
	addOption(document.form1.SubCat,"St Venera", "St Venera",town);
	addOption(document.form1.SubCat,"Swieqi", "Swieqi",town);
	addOption(document.form1.SubCat,"Ta Xbiex", "Ta Xbiex",town);
	addOption(document.form1.SubCat,"Tarxien", "Tarxien",town);
	addOption(document.form1.SubCat,"Valletta", "Valletta",town);
	addOption(document.form1.SubCat,"Vittoriosa", "Vittoriosa",town);
	addOption(document.form1.SubCat,"Wardija", "Wardija",town);
	addOption(document.form1.SubCat,"Xemxija", "Xemxija",town);
	addOption(document.form1.SubCat,"Zabbar", "Zabbar",town);
	addOption(document.form1.SubCat,"Zebbug", "Zebbug",town);
	addOption(document.form1.SubCat,"Zejtun", "Zejtun",town);
	addOption(document.form1.SubCat,"Zurrieq", "Zurrieq",town);
	
	}
	
	if(document.form1.location.value == 'Gozo'){
		//addOption(document.form1.SubCat,"Anywhere", "Anywhere");
		addOption(document.form1.SubCat,"Fontana", "Fontana",town);
		addOption(document.form1.SubCat,"Ghajnsielem", "Ghajnsielem",town);
		addOption(document.form1.SubCat,"Ghammar", "Ghammar",town);
		addOption(document.form1.SubCat,"Gharb", "Gharb",town);
		addOption(document.form1.SubCat,"Ghasri", "Ghasri",town);
		addOption(document.form1.SubCat,"Kercem", "Kercem",town);
		addOption(document.form1.SubCat,"Marsalforn", "Marsalforn",town);
		addOption(document.form1.SubCat,"Mgarr", "Mgarr",town);
		addOption(document.form1.SubCat,"Munxar", "Munxar",town);
		addOption(document.form1.SubCat,"Nadur", "Nadur",town);
		addOption(document.form1.SubCat,"Qala", "Qala",town);
		addOption(document.form1.SubCat,"Sannat", "Sannat",town);
		addOption(document.form1.SubCat,"San Lawrenz", "San Lawrenz",town);
		addOption(document.form1.SubCat,"Santa Lucia", "Santa Lucia",town);
		addOption(document.form1.SubCat,"Victoria", "Victoria",town);
		addOption(document.form1.SubCat,"Xaghra", "Xaghra",town);
		addOption(document.form1.SubCat,"Xewkija", "Xewkija",town);
		addOption(document.form1.SubCat,"Xlendi", "Xlendi",town);
		addOption(document.form1.SubCat,"Zebbug", "Zebbug",town);
		
		}
}


		

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text, town )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
///////////////////////////////////
var i;
for (var i=0; i < selectbox.options.length; i++)
{
	if(selectbox.options[i].value == town)
	selectbox.options[i].selected = true;
}
/////////////////////////////////
	selectbox.options.add(optn);
}
