function disableEnterKey(e) {
	var key;
	if(window.event) {
		key = window.event.keyCode;     //IE
	} else {
		key = e.which;     //firefox
	}
	
	if(key == 13) {
		return false;
	} else {
		return true;
	}
}

jQuery(function( $ ){
	$("#textToAdd").keyup(function() {
		var box=$(this).val();
		var main = box.length *100;
		var value= (main / 50);
		var count= 50 - box.length;
		
		if(box.length <= 50) {
			$('#count').html(count);
			$('#bar').animate({
				"width": value+'%',
			}, 1);
		} else {
			alert('Full');
		}
		return false;
	});
});
setInterval(function() {
	var theTime = new Date();
	var userID = $("#userID").val();
	$.ajax({
		   url: 'shoutBoxChat.php',
		   data: 'userID='+ userID +'&time=' + theTime.getTime(),
		   cache: false,
		   success: function(html) {
			   if (html == '') {
			   } else {
				   $('.flash').clone().appendTo($("ol#update li:first"));
				   $("ol#update .flash").show();
				   $("ol#update .flash").fadeIn(400).html('<img src="images/ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>');
				   getTweet();
			   }
		   }
	});
	   
}, 10000);
function getTweet() {
	var theTime = new Date();
	var userID = $("#userID").val();
	$.ajax({
		   url:'shoutBoxChat.php',
		   data: 'userID='+ userID +'&time=' + theTime.getTime(),
		   cache: false,
		   success: function(html) {
			   $("ol#update").prepend(html);
			   $("ol#update li:first").slideDown("slow");
			   $('ol#update').trigger( 'next' );
			   $("ol#update .flash").remove();
		   }
	});
}
function addText() {
		var boxval = $("#textToAdd").val();
		var userID = $("#userID").val();
		var dataString = 'userID='+ userID +'&textToAdd='+ boxval;
		
		if(boxval=='') {
			alert("Please Enter Some Text");
		} else {
			$('.flash').clone().prependTo($("ol#update"));
			$("ol#update .flash").show();
			$("ol#update .flash").fadeIn(400).html('<img src="images/ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>');
			$.ajax({
				   type: "POST",
				   url: "shoutBoxChat.php",
				   data: dataString,
				   cache: false,
				   success: function(html){
					   $("ol#update").prepend(html);
					   $("ol#update li:first").slideDown("slow");
					   $('ol#update').trigger( 'next' );
					   document.getElementById('textToAdd').value='';
					   $('#count').html('50');
					   $('#bar').animate({
					   		"width": '0%',
						}, 1);
					   $("ol#update .flash").remove();
				   }
				   });
		}
		return false;
}