// JavaScript Document

$(document).ready(function() {
	initInputs();
	initFormElems();
});
function initInputs() {
	$("input:text").focus(function() {
		var title = $(this).siblings(".default").html();
		if($(this).val()==title) {
			$(this).val("");	
		}
	});
	$("input:text").blur(function() {
		var title = $(this).siblings(".default").html();
		if(!$(this).val()&&title) {
			$(this).val(title);	
		}
	});
	$("input,select,textarea").focus(function() {
		$(this).css("border-color", "#ad1d1d");
	});
	$("input,select,textarea").blur(function() {
		$(this).css("border-color", "#ffffff");
	});
	jQuery.validator.messages.required = "";
	jQuery.validator.messages.email = "";
	$("#newsletter_footer").validate({
		invalidHandler: function(form,validator) {
			alert("Please enter a valid email address.");
		},
		errorPlacement: function(error, element) {
			error.appendTo($("#newsletter_footer"));
		},
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		submitHandler: function(form) {
			$.post("scripts/newsletter.php", $("#newsletter_footer").serialize(), function(data) {
				if(data) {
					alert(data);
				}
			});
		}
	});
}
function initFormElems() {
	$('input[type=checkbox]').checkbox({
		empty: 'js/checkbox/empty.png'
	});
	$('input[type=radio]').checkbox({
		cls: 'jquery-radio',
		empty: 'js/checkbox/empty.png'
	});
}
function redirect(url) {
	window.location = url;
}
