function postcodeCheck(postcode, postcodebutton) {
	postcode.value = postcode.value.replace(/[^A-Z0-9 ]/gi, '')
	if(postcode.value.length > 0) {
		postcodebutton.removeClassName('disabledbutton');
		postcodebutton.addClassName('editbutton');
	}
	else {
		postcodebutton.removeClassName('editbutton');
		postcodebutton.addClassName('disabledbutton');
	}
}

function postcodeLookup(key, postcode, b_number) {
	
	if($(key + '_findaddress').className == 'disabledbutton') {
		return;
	}
	
	b_postcd = postcode.replace(/[^A-Z0-9]/gi, '')
	b_number = (b_number == null) ? '' : b_number;
	
	new Ajax.Request('http://www.designertags.com/ajax/getaddresslist/' + b_postcd + '/' + b_number, {
		onSuccess: function(transport, json) {
			
			if(json != null && !json.fail) {
				$(key + '_street').value 	= json.line1;
				$(key + '_town').value 		= json.post_town;
				$(key + '_county').value 	= json.county;
				$(key + '_postcode').value	= json.postcode;
			}
			else {
				// Couldn't find a row for this postcode.
			}
		},
		onFailure: function() {
			// Failed AJAX transport.
			alert('JSON fail')
		}	
	});
}

// Prototypes.
/*
DONT WORK IN IE. MOZ ONLY.
HTMLSelectElement.prototype.clear = function(){
	while(this.length > 0) {
		this.remove(0);
	}
}

HTMLSelectElement.prototype.insert = function(id, textValue, position) {
	var newOpt = new Option(textValue, id);
 	
 	if(navigator.appName == 'Microsoft Internet Explorer') {
 		this.options[this.options.length] = newOpt;
 	}
 	else {
	 	if(!isNaN(position) && position < this.length - 1 && position >= 0) {
			this.add(newOpt, this.options[position]);
		} 
		else {
			this.add(newOpt, null);
		}
	}
}
*/
