jQuery.fn.labelOver = function(overClass) {
	return this.each(function(){
		var label = jQuery(this);
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);
			
			this.hide = function() {
			  label.css({ textIndent: -10000 })
			}
			
			this.show = function() {
			  if (input.val() == '') label.css({ textIndent: 0 })
			}

			// handlers
			input.focus(this.hide);
			input.blur(this.show);
		  label.addClass(overClass).click(function(){ input.focus() });
			
			if (input.val() != '') this.hide(); 
		}
	})
};


$(document).ready(function()
{
	$('#login-form label').labelOver('over'); 
	$('#quote-form label').labelOver('over'); 
	
	$('#quote-form').submit(function()
	{
		var name = $('#quote-form #full_name').val();
		var phone = $('#quote-form #phone').val();
		
		if(name.length == 0)
		{
			alert('Please enter your full name!');
			return false;
		}
		
		if(phone.length == 0)
		{
			alert('Please enter your phone!');
			return false;
		}
		
		
		var html = $('#quote-form').html();
		
		$('#quote-form').html('<div class="loading" style="font-weight: bold; color: #fff; padding: 10px; height: 77px;">Loading...</div>');
		
		$.getJSON('/quote.php', {full_name: name, phone: phone}, function(data) {
			if(data.error)
			{
				$('#quote-form .loading').html(data.error);
			}
			
			if(data.message)
			{
				$('#quote-form .loading').html(data.message);
			}
		});
		
		return false;
	});

});
		
