function Address(){
	this.addr1 = '';
	this.addr2 = '';
	this.addr3 = '';
	this.city = '';
	this.state = '';
	this.zip = '';

	if (!String.prototype.trim)
		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

	this.loadFromForm = function(frm){
		this.addr1 = frm.addr1.value,
		this.addr1.trim();
		this.addr2 = frm.addr2.value,
		this.addr2.trim();
		this.addr3 = frm.addr3.value,
		this.addr3.trim();
		this.city = frm.city.value,
		this.city.trim();
		this.state = frm.state.options[frm.state.selectedIndex].value,
		this.state.trim();
		this.zip = frm.zip.value
		if(typeof(this.zip) == "string") this.zip.trim();
	};

	this.loadFromObject = function(obj){
		this.addr1 = obj.addr1,
		this.addr1.trim();

		this.addr2 = obj.addr2,
		this.addr2.trim();
		if(obj.addr3){
			this.addr3 = obj.addr3,
			this.addr3.trim();
		}
		this.city = obj.city,
		this.city.trim();
		this.state = obj.state;
		this.state.trim();
		this.zip = obj.zip
		if(typeof(this.zip) == "string") this.zip.trim();
	};


	this.toString = function(){
		var s = '';
		s += 'addr1: ' + this.addr1 + '\n' +
		'addr2: ' + this.addr2 + '\n' +
		'addr3: ' + this.addr3+ '\n' +
		'city: ' + this.city + '\n' +
		'state: ' + this.state+ '\n' +
		'zip: ' + this.zip+ '\n'
		return s;
	};
	
	this.toGoogleString = function(){
		var s = this.addr1;
		s += ' ' + this.addr2;
		s.trim();
		s += ' ' + this.addr3;
		s.trim();

		var citystate = '';
		if(this.city.length && this.state.length)
			citystate = this.city + ', ' + this.state;
		else
			citystate = this.city + this.state;

		citystate.trim();			

		s += citystate;
		s.trim();
		s += ' ' + this.zip;
		s.trim();
		return s;
	};

	this.addLine = function(str,newline){
		if(newline.length > 0){
			if(str.length > 0){
				str += '<br>';
			}
			str += newline;
		}
		return str;
	}

	this.toHTMLString = function(){
		var spacer = '';
		var s = '';
		/*
		s = this.addLine(s,this.addr1);
		s = this.addLine(s,this.addr2);
		s = this.addLine(s,this.addr3);
		*/
		s = s + this.addr1 + ' ' + this.addr2 + ' ' + this.addr3 + '<br />';

		var citystate = '';
		if(this.city.length && this.state.length)
			citystate = this.city + ', ' + this.state;
		else
			citystate = this.city + this.state;
		citystate.trim();
		citystate = citystate + ' ' + this.zip;
		citystate.trim();
		s = s + citystate;
		return s;
	};
	

	this.merge = function(addr){
		var fields = 'addr1,addr2,addr3,city,state,zip';
		var fldarr = fields.split(',');
		var a = new Address();
		for (var i = 0; i < fldarr.length; i++){
			var fldname = fldarr[i];
			if(this[fldname].length > 0)
				a[fldname] = this[fldname];
			if(addr[fldname].length > 0)
				a[fldname] = addr[fldname];					
		}
		return a;
	}
}
