var dynamicList = new DynamicOptionList("L1","L2","L3");
var cities=new Array()
var branches=new Array()

function insertForm(){
	var myDiv=document.getElementById("branchLocatorForm");
	var formHtml="<form action=\"\" method=\"\"><select id=\"L1\" name=\"L1\"><option value=\"\" selected>Select Country</option><option value=\"Australia\">Australia</option><option value=\"Canada\">Canada</option><option value=\"Italy\">Italy</option><option value=\"New Zealand\">New Zealand</option><option value=\"Singapore\">Singapore</option><option value=\"United Kingdom\">United Kingdom</option><option value=\"United States\">United States</option></select> <select id=\"L2\" name=\"L2\" ><script type=\"text/javascript\">dynamicList.printOptions(\"L2\")</script></select> <select id=\"L3\" name=\"L3\" onChange=\"getLocation(this);\"><script type=\"text/javascript\">dynamicList.printOptions(\"L3\")</script></select></form>";
	myDiv.innerHTML=formHtml;
}

function instructions(){
	var myDiv=document.getElementById("locationsPlaceholder");
	//myDiv.innerHTML="<div class=\"branchContainer\">"+branches[regionIndex][0]+"Adelaide (Corporate):</div><div class=\"branchMap\"><img src='../../_images/company/genericMap.gif'></div>";
 myDiv.innerHTML=buildDiv(branches[regionIndex][0],branches[regionIndex][1],branches[regionIndex][2],branches[regionIndex][3],branches[regionIndex][4],branches[regionIndex][5],branches[regionIndex][6],branches[regionIndex][7],branches[regionIndex][8],"Head Office");
}
				
function getLocation(locationList){
	//alert(locationList.value.substring(0,3));
	
	if(!isNaN(locationList.value.substring(0,3))){
	//if(document.getElementById("L3").value!=""){
		//alert("Branch number:"+locationList.value);
		//var id=document.getElementById("L2").value+document.getElementById("L3").value;
		var branchId=locationList.value;
		//	0 = branch name, 1 = address, 2 = city, 3	= province, 4 = postal, 
		//  5 = telephone, 6 = toll free number, 7 = fax, 8 = userid

		//var service=document.getElementById("L3").text;
		var service=locationList.options[locationList.selectedIndex].text;
		var myDiv=document.getElementById("locationsPlaceholder");
		var myHTML="";
		myHTML+="<div class=\"branchContainer\"><p class=\"branchTitle\">"+branches[branchId][0]+" ("+service+"):</p>";
		if(branches[branchId][1]!=""){
			myHTML+="<p>"+branches[branchId][1]+"<br />"+branches[branchId][2]+", "+branches[branchId][3]+" "+branches[branchId][4]+"</p>";
		}
		myHTML+="<p>";
		if(branches[branchId][5]!=""){
			myHTML+="Telephone: "+branches[branchId][5]+"<br>";
		}
		if(branches[branchId][6]!=""){
			myHTML+="Toll Free: "+branches[branchId][6]+"<br>";
		}
		if(branches[branchId][7]!=""){
			myHTML+="Fax: "+branches[branchId][7]+"<br>";
		}
		if(branches[branchId][8]!=""){
			// KGM this is a hack to prevent plain-text email addresses ever being displayed
			// or stored in the source of this page.
			myHTML+="Email: <a href=\"mailto:"+branches[branchId][8]+"&#x40;&#x63;&#x75;&#115;&#116;&#x6F;&#109;&#x68;&#x6F;&#x75;&#115;&#101;&#x2E;&#x63;&#111;&#x6D;\">"+branches[branchId][8]+"&#x40;&#x63;&#x75;&#115;&#116;&#x6F;&#109;&#x68;&#x6F;&#x75;&#115;&#101;&#x2E;&#x63;&#111;&#x6D;</a>";
		}
		myHTML+="</p></div><div class=\"branchMap\"><a href='http://maps.google.ca/maps?f=q&hl=en&geocode=&q="+branches[branchId][1]+", "+branches[branchId][2]+", "+branches[branchId][3]+"' target='_blank'><img src='../../_images/company/genericMap.gif'></a><p class=\"mapClick\"><span>Click map for directions</p></span><div>"
		if(location!=""){
				myDiv.innerHTML=myHTML;
			}
		}
		
	}
function buildDiv(name,address,city,province,postal,telephone,tfNumber,faxNumber,id,service){
	var html="";
	html+="<div class=\"branchContainer\"><p class=\"branchTitle\">"+name+" ("+service+"):</p>";
	if(address!=""){
			html+="<p>"+address+"<br />"+city+", "+province+" "+postal+"</p>";
		}
	html+="<p>";
		if(telephone!=""){
			html+="Telephone: "+telephone+"<br>";
		}
		if(tfNumber!=""){
			html+="Toll Free: "+tfNumber+"<br>";
		}
		if(faxNumber!=""){
			html+="Fax: "+faxNumber+"<br>";
		}
		if(id!=""){
			// KGM this is a hack to prevent plain-text email addresses ever being displayed
			// or stored in the source of this page.
			html+="Email: <a href=\"mailto:"+id+"&#x40;&#x63;&#x75;&#115;&#116;&#x6F;&#109;&#x68;&#x6F;&#x75;&#115;&#101;&#x2E;&#x63;&#111;&#x6D;\">"+id+"&#x40;&#x63;&#x75;&#115;&#116;&#x6F;&#109;&#x68;&#x6F;&#x75;&#115;&#101;&#x2E;&#x63;&#111;&#x6D;</a>";
		}
		html+="</p></div><div class=\"branchMap\"><a href='http://maps.google.ca/maps?f=q&hl=en&geocode=&q="+address+", "+city+", "+province+"' target='_blank'><img src='../../_images/company/genericMap.gif'></a><p class=\"mapClick\"><span>Click map for directions</p></span><div>"
	return html;
}
	insertForm();
		generateArrays();
		initDynamicOptionLists();
		instructions();