$.ready(function() {
	$('.contactwidget input').addEvent('focus', function() {
		if (this.blanked) return;
		if (this.type == 'text') {
			this.defaultValue = this.value;
			this.value = '';			
			this.blanked = true;
		}
	});
	
	$('.contactwidget textarea').addEvent('focus', function() {
		if (this.blanked) return;
		this.defaultValue = this.value;
		this.value = '';
		this.blanked = true;
	});
	
	
	$('.contactwidget textarea').addEvent('keydown', function() {
		text = this;
		var maxHeight = 500;
		var adjustedHeight = text.clientHeight;
		   if (!maxHeight || maxHeight > adjustedHeight )
		   {
		      adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);
		      if ( maxHeight )
		         adjustedHeight = Math.min(maxHeight, adjustedHeight);
		      if ( adjustedHeight > text.clientHeight )
		         text.style.height = adjustedHeight + "px";
		   }
	});
		
	
	if ($('#contactwidgetform')) {
	
	$('#contactwidgetform').addEvent('submit', function(e) {		
		new Ajax({url: 'contactwidget/quickform/' + getPage(),
			  params: $('#contactwidgetform'),			  
			  callback: function() {
				// $('.contactwidget').innerHTML = 'Thank you for your enquiry';  
				 //$('.contactwidget').style.height = '230px';
				  alert('Thank you for your enquiry. You will receive a response as soon as possible.');
				  $('.contactwidget input').apply(function() {
					 this.value = this.defaultValue;
					 this.blanked = false;
				  });
				  
				  $('.contactwidget textarea').apply(function() {
						 this.value = this.defaultValue;
						 this.blanked = false;
				  });
			  }
		});
	
		
		$.killEvent(e);
		return false;
	});
	
	}
});
