/**
 * Bibliotek for håndtering postnummeroppslag
 * 
 * @author	Thomas Sømoen <thomas at apt.no>
 * @version	20061005
 * @package	form
 * @copyright	apt as 2006
 */
var post = new Object();

/**
 * Kort
 * 
 * @access	public
 * @since	20061006
 * @param	string	postcode	postnummer som skal slås opp
 * @param	string	postoffice	id-en på feltet som poststedet skal settes
 * @param	string	country		navnet på select-boxen hvor landet skal settes til norge.
 */
post.getPostoffice = function(postcode,postoffice,country){
	if(postcode.length > 3){
		if(!(postoffice=document.getElementById(postoffice))) postoffice = null;
		if(!(country=document.getElementById(country))) country = null;
		
		handler = new net.Observer();
		objXmlHttp = new net.XmlHttp();
		
		handler.postoffice = postoffice;
		handler.country = country;
		
		handler.notify = function(result){
			this.postoffice.value = result['postoffice'];
			if(this.country){
				this.selectCountryNO();
			}
		}
		
		handler.selectCountryNO = function(){
			if(this.country && this.country.type == 'select-one'){
				for(I=150;I<170;I++){
					if(this.country.options[I].value == 'NO'){
						this.country.options[I].selected = 'true';
					}
				}
			}
		}
		if(postoffice){
			objXmlHttp.attach(handler);
			objXmlHttp.reqParam("postcode", postcode);
			objXmlHttp.load("remote.php");
		}
	}	
}