$(document).ready(function(){
	$('#newsletter input:text').focus(function(){
		var el = $(this);
		if( el.attr('title') == el.val() )
			el.val('');
	});
	$('#newsletter input:text').blur(function(){
		var el = $(this);
		if( el.val().length <= 0 )
			el.val(el.attr('title'));
	});
	
	
	$('#quote input:text').focus(function(){
		var el = $(this);
		if( el.attr('title') == el.val() )
			el.val('');
	});
	$('#quote input:text').blur(function(){
		var el = $(this);
		if( el.val().length <= 0 )
			el.val(el.attr('title'));
	});

	$('#quote form').submit(function(){
		
		var err = false;
		
		$(this).find("input:text").each(function(){
			var el = $(this);
			var origBorder = el.css('border-color');

			if( el.val().length > 0 && el.attr('title') == el.val() ){
				el.css({'border':'1px dotted red'});
				err = true;
			}else if(el.attr('name') == 'email'){
				
				if( validateEmail(el.val()) ){
					el.css({'border':'1px solid #ccc'});
				}else{
					el.css({'border':'1px dotted red'});
					err = true;
				}
			}
		});
		
		if(err == true)
			return false;
	});

	$('#newsletter').submit(function(){
		
		var err = false;
		
		$(this).find("input:text").each(function(){
			var el = $(this);
			var origBorder = el.css('border-color');

			if( el.val().length > 0 && el.attr('title') == el.val() ){
				el.css({'border':'1px dotted red'});
				err = true;
			}else if(el.attr('name') == 'email'){
				
				if( validateEmail(el.val()) ){
					el.css({'border':'1px solid #ccc'});
				}else{
					el.css({'border':'1px dotted red'});
					err = true;
				}
			}
		});
		
		if(err == true)
			return false;
	});
});

function validateEmail(email){
	var emailMatch = email.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	if (emailMatch == null)
		return false;
	else
		return true; 	
}
