$.fn.clearInput = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};


function getLength () {
	var length = 0;
	$('.sms').each(function(){
			// get current number of characters
			length += $(this).val().length;
		});
		return length;
}

$(document).ready(function() {
	$('.sms').keyup(function () {
		var length = getLength();
		$(this).parent().find('.counter').html(150 - length + ' characters left');
	});
	
	$('.sms').keydown(function (e) {	
		if ((e.keyCode != 8) && (e.keyCode != 46)) {
			var length = getLength();
			if (length >= 150) {
				return false;
			}
		}
	});
	
});






