function clearForm(data){
	$('.subscriber').fadeOut(500, function(){$('.scroll').append(data)});
}
function addEmail(newEmail, newType, newFirst, newLast){
	if(newFirst.length < 1 || newLast.length < 1){
		void(0);
	} else {
		$.get(
			'/serverIncludes/addEmail.php', {useremail:newEmail, usertype:newType, userfirst:newFirst, userlast:newLast}, function(data){clearForm(data);}
	);
	}
}
function showSubmit(){
				$('.emailForm').attr('action', 'javascript:addEmail($(\'.emailInput\').val(), $(\'.userType\').val(),$(\'.firstInput\').val(),$(\'.lastInput\').val())');
				$('.emailFeedback').html('<br/>Which of the following describes you best?<br/><br/><select class="userType"><option value="professional">Interior Designer/Architect</option><option value="consumer">Private Party (Home Use)</option></select>').show();
				$('.emailSubmit').attr('disabled', false).show();
}
function hideSubmit(){
				$('.emailSubmit').hide().attr('disabled', true);
				$('.emailFeedback').show();
				$('.emailFeedback').text('* Please enter your first name, last name, and valid email address');
				$('.emailForm').attr('action', 'javascript:void(0);');
}
function validateEmail(addSubmit){
		mailReg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
		if (!mailReg.exec(addSubmit)){
				$('.emailInput').css('color', '#d9b746');
				$('.emailLabel').css('color', '#d9b746');
				hideSubmit();
			} else {
				showSubmit();
				$('.emailInput').css('color', '#000000');
				$('.emailLabel').css('color', '#ffffff');
			}
}
function checkFirst(val){
	if(val.length > 1){
		$('.lastInput').attr('disabled', false);
		$('.firstLabel').css('color', '#ffffff');
		if($('.lastInput').val().length > 1){
			validateEmail($('.emailInput').val());
			$('.emailInput').attr('disabled', false);
		}
		
	} else {
		hideSubmit();
		$('.lastInput').attr('disabled', true);
		$('.firstLabel').css('color', '#d9b746');
		$('.emailInput').attr('disabled', true);
		//$('.emailLabel').css('color', '#d9b746');
	}
}
function checkLast(val){
	if(val.length > 1 && $('.firstInput').val().length > 1){
		$('.emailInput').attr('disabled', false);
		$('.lastLabel').css('color', '#ffffff');
		validateEmail($('.emailInput').val());
	} else {
		hideSubmit();
		$('.emailInput').attr('disabled', true);
		$('.lastLabel').css('color', '#d9b746');
	}
}
$(
	function(){
		$('.lastInput').attr('disabled', true);
		$('.emailInput').attr('disabled', true);
	}
)
//$('.firstInput').keyup(function(){}).keyup();
$(document).ready(function() {
	$('.firstInput').keyup(function () {
	      var valueFirst = $(this).val();
	      checkFirst(valueFirst);
	    }).keyup();
	$('.lastInput').keyup(function () {
	      var valueLast = $(this).val();
	      checkLast(valueLast);
	    }).keyup();
});


