function limitChars(textid, limit, infodiv) {
 	var text = $('#'+textid).val(); 
	//newlines are counted as 2 characters in the ruby activerecord validations
	var textlength = text.length + countNewline(text);

 	if(textlength > limit) {
		$('#' + infodiv).html('You cannot write more than '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else {
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

function countNewline(text) {
	var newLines = 0
	for (i=0; i<=text.length-1; i++) {
    	if (text.charAt(i) == '\n') {
			newLines++
		}
  	}
	return newLines
}

function feedback() {
  var msg = $('#feedbackmessage').val();
  if (msg) {
    $('#feedbackstatus').html('Sending...');
    $('#feedbackbutton').attr('disabled', 'disabled').addClass('disabled').removeClass('default').blur();
    $.ajax({type: "POST", url: "/send-feedback", data: {message:msg, email: $('#feedbackemail').val()},
            error: function(x,ts,et) {
              $('#feedbackstatus').html("Whoops! We're experiencing some technical hiccups. If you're not too frustrated by this, please e-mail us at customerservice@limos.com instead.");
            },
            success: function(d,t) {
              $('#feedbackstatus').html('Thanks for taking the time to write!');
            }
    });
  }
}