var $s_fname; var $s_lname; var $s_email; var valid;
$(document).ready(function(){
	doDownload();
});
function validateDataSheet() {
	$("#downloadForm").submit(function(){
		s_clearErrors();
		if($s_fname.attr('value') == '') {s_showError($s_fname, "Please enter your first name"); valid = 0;}
		if($s_lname.attr('value') == '') {s_showError($s_lname, "Please enter your last name"); valid = 0;}
		if($s_email.attr('value') == '') {s_showError($s_email, "Please enter your email address"); valid = 0;}
		if($s_email.attr('value') != '') {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test($s_email.attr('value')) == false) {s_showError($s_email, "Please enter a valid email address"); valid = 0;}
		}
		if(valid == 1) {var where = $("#whereTo").attr("value") + ""; window.location = where; return false;}
		else {return false;}
	});
}
function s_clearErrors() {
	valid = 1;
	$s_fname = $("#firstName");
	$s_lname = $("#lastName");
	$s_email = $("#emailAddress");
	$("#downloadForm small").remove();
}
function s_showError(obj, msg) {
	$(obj).before("<small class='error'>"+msg+"</small>");
}
function doDownload() {
	$("#firstName").blur(function(){if($(this).attr("value")) {$(this).addClass('focused', !$(this).hasClass('focused'));} else {$(this).removeClass('focused');}});
	$("#firstName").focus(function(){$(this).addClass('focused', !$(this).hasClass('focused'));});
	$("#lastName").blur(function(){if($(this).attr("value")) {$(this).addClass('focused', !$(this).hasClass('focused'));} else {$(this).removeClass('focused');}});
	$("#lastName").focus(function(){$(this).addClass('focused', !$(this).hasClass('focused'));});
	$("#emailAddress").blur(function(){if($(this).attr("value")) {$(this).addClass('focused', !$(this).hasClass('focused'));} else {$(this).removeClass('focused');}});
	$("#emailAddress").focus(function(){$(this).addClass('focused', !$(this).hasClass('focused'));});
}
