/**
 * @author Mark
 */
$(document).ready(function(e){
	
	$('.message').val("Seriously, I'm curious.");
	$('.alias').val('You could atleast tell me your name.');
	
	$('.message').focus(function(e){
		var val = $(this).val();
		if(val.toLowerCase() == "seriously, i'm curious."){
			$(this).val('');
		}
	});
	$('.message').blur(function(e){
		var val = $(this).val();
		if(val == ""){
			$(this).val("Seriously, I'm curious.");
		}
	});
	
	$('.alias').focus(function(e){
		var val = $(this).val();
		if(val.toLowerCase() == "you could atleast tell me your name."){
			$(this).val('');
		}
	});
	$('.alias').blur(function(e){
		var val = $(this).val();
		if(val.toLowerCase() == ""){
			$(this).val('You could atleast tell me your name.');
		}
	});
	
	$('.submit').click(function(e){
		e.preventDefault();
		
		var response = $(document).find('.message').val();
		var user = $('.alias').val();
		
		if(user.toLowerCase() == "you could atleast tell me your name."){
			user = "Anonymous";
		}
		
		if (response == null || response == "") {
			$('.message').val("Hey, you've got to tell me why first.  Maybe this can be you reason.");
			$('.message').css('color', '#FF0000');
		}
		else {
			$('.message').attr('enabled', false);
			$('.alias').attr('enabled', false);
			$.ajax({
				type: "GET",
				url: "/includes/addResponse.php",
				data: "response=" + response + "&user=" + user,
				dataType: "xml",
				success: function(msg){
					window.location = "/";
				},
				error: function(msg){
					window.location = "/";
				}
			});
		}
	});
	
	$('.message').keyup(function(){
		var max = parseInt($(this).attr('maxlength'));
		if($(this).val().length > max){
			$(this).val($(this).val().substr(0, $(this).attr('maxlength')));
		}
		//$(this).parent().find(’.charsRemaining’).html(’You have ‘ + (max - $(this).val().length) + ‘ characters remaining’);
	});
});


function checkLength(form, limit){
	var val = $(form).val();
    if (val.length > limit){
		alert('done');
        return false;
    }
    return true;
}

