$(document).ready(function() {
	$('.privacy').click(function (e) {
		$('#modal_privacy_policy').modal({onOpen: function (dialog) {
									dialog.overlay.fadeIn('fast', function () {
										dialog.data.hide();
										dialog.container.fadeIn('slow', function () {
											dialog.data.slideDown('slow');
										});
									});
								}});
		return false;
	});

	$('.terms').click(function (e) {
		$('#modal_terms').modal({onOpen: function (dialog) {
							dialog.overlay.fadeIn('fast', function () {
								dialog.data.hide();
								dialog.container.fadeIn('slow', function () {
									dialog.data.slideDown('slow');
								});
							});
						}});
		return false;
	});


	$('.submit_btn').hover(function(){
		$(this).animate({opacity: 0.75}, 300);
	}, function () {
		$(this).animate({opacity: 1}, 300);
	});


	$('.notice, .error, .success').append('<a href="#" class="close">Close</a>');

	$('.notice a.close, .error a.close, .success a.close').click(function () {
		
		$(this.parentNode).hide('slow', function () {
			$(this).remove();
		});
		
		//$(this.parentNode).animate({"height": "toggle"}, { duration: 400 });

	});

});


function validEmail(str) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(str) == false) {
		return false;
	}
	return true;
}

function validate_form(){

	error = 0;
	error_msg = '<strong>Error:</strong> Please correct the following errors.';
	name = $('#name_field').val();
	email = $('#email_field').val();
	$('#error_box').hide();

	if(name == '' || name == null){
		error = 1;
		error_msg += '<br />&nbsp;&nbsp;&nbsp;&bull; Please enter your first name.';
		$('#name_field').focus();
	}

	if(email == '' || email == null || !validEmail(email)){
		error = 1;
		error_msg += '<br />&nbsp;&nbsp;&nbsp;&bull; Please enter a valid email address.';
		$('#name_field').focus();
	}

	if(error){
		error_msg += '<a href="#" class="close" onclick="$(this.parentNode).hide(\'slow\'); return false;">Close</a>';
		$('#error_box').html(error_msg);
		$('#error_box').show('fast');
		return false;
	}

	return true;

}

