function getChat(){
	$.post("../includes/chat.php", {
		actionid: "1",
		eventid: $("#chatevent").attr("value"),
		timezone: $("#chattimezone").attr("value")
		},
		function(data) {
      $("#messages").empty().html(data);
		}
	);
}

function sendChat() {
	if ( $("#chatinput").attr("value") != "" ) {
		$.post("../includes/chat.php", {
			actionid: "2",
			eventid: $("#chatevent").attr("value"),
			textbody: $("#chatinput").attr("value"),
			userid: $("#chatuser").attr("value")
		},
		function(data) {
      $("#chatinput").attr("value", "");
      	getChat();
			}
		);
	}
}

function autoRefresh() {
	var intID = setInterval("getChat()", 3000);
}

$(document).ready(function(){
	$("#autorefresh").click( function() {
		if ( $('#autorefresh').attr('checked') ) {

		} else {

		}
	});
	$("#sendmessage").click( function() {
    sendChat();
	});
  $("#chatinput").keypress(function (e) {
		if ( e.which == 13 ) {
			sendChat();
		}
	});

  getChat();
  autoRefresh();
});
