function Depot(selectFieldId) {

	this.selectField = document.getElementById(selectFieldId);
	
	this.depotAjax = new AjaxWrapper();
	this.address1Elem = document.getElementById(selectFieldId + "_address1");
	this.address2Elem = document.getElementById(selectFieldId + "_address2");
	this.suburbElem = document.getElementById(selectFieldId + "_suburb");
	this.suburbHiddenElem = document.getElementById(selectFieldId + "_suburb_hidden");
	//this.nameElem = document.getElementById(selectFieldId + "_name");


/*
	this.loadAddresses = function() {
		var url = "depot_addresses?output=list";
		this.depotAjax.post(url, callback(this, this.handleAddressLoad));
	}
	
	this.handleAddressLoad = function() {
		if(this.depotAjax.isProcessed()) {
			// The below mess is necessary because IE doesn't allow
			// updating a select element using innerHTML...
			
			this.selectField.length = 0; // Clear the old options
			var optionsXML = this.depotAjax.getResponseXml();
			var opts = optionsXML.getElementsByTagName("opt");
			for(var idx=0; idx<opts.length; idx++) {
				var option = document.createElement("option");
				option.text = opts[idx].firstChild.nodeValue;
				option.id = opts[idx].attributes.getNamedItem("id").value;
				this.selectField.add(option, null);
			}
		}
	}
	*/
	
	this.updateDepotDetails = function() {
		var suburb = this.selectField[this.selectField.selectedIndex].id;
		if(suburb != "select") {
			var url = "depot_addresses?output=details&suburb=" + suburb;
			this.depotAjax.post(url, callback(this, this.handleUpdateDepotDetails));
		}
	}
	
	this.handleUpdateDepotDetails = function() {
		if(this.depotAjax.isProcessed()) {
			var resultXML = this.depotAjax.getResponseXml();
			var address1Node = resultXML.getElementsByTagName("address1")[0];
			var address2Node =resultXML.getElementsByTagName("address2")[0];
			var nameNode = resultXML.getElementsByTagName("name")[0];
			var suburbNode = resultXML.getElementsByTagName("suburb")[0];

			this.address1Elem.innerHTML = address1Node.firstChild.nodeValue;
			this.address2Elem.innerHTML = address2Node.firstChild.nodeValue;
			//this.nameElem.innerHTML = nameNode.firstChild.nodeValue;
			this.suburbElem.innerHTML = suburbNode.firstChild.nodeValue;
			this.suburbHiddenElem.value = suburbNode.firstChild.nodeValue;
		}
		
	}
	
	/*
	this.getDepotAddressesStatic = function(srcId, suburb) {
		var cTypeElem = document.getElementById("courierType");
		if( !cTypeElem || cTypeElem.value != 'depot') { 	
			return;
		}
		this.activeSrcId = srcId;
		var url = "depot_addresses?suburb=" + suburb;	
		this.depotAjax.post(url, callback(this, this.updateAddressFields));	
	}
	*/

}



function openDepotInfoWin() {
	window.open('depot_locations.do', 
				'packagewin', 
				  'width=400, \
				   height=600, \
				   directories=no, \
				   location=no, \
				   menubar=no, \
				   resizable=no, \
				   scrollbars=1, \
				   status=no, \
				   toolbar=no'); 
  return false;
	
}