//remove field label when user focuses on field
function shoutboxField(field, value) {
	if($('#' + field).attr("value") == value) {
		$('#' + field).attr("value", "");
	}
}

//add label back if user left field empty
function shoutboxFieldOut(field, value) {
	if($('#' + field).attr("value") == "") {
		$('#' + field).attr("value", value);
	}
}

//send shout to server
function shoutboxShout(pathToShoutbox) {
	var username = $("#shoutboxName").attr("value");
	var message = $("#shoutboxMessage").attr("value");

	$.ajax({
		type: "POST",
		url: pathToShoutbox + "/shoutbox.php",
		data: "shoutboxUsername=" + username + "&shoutboxMessage=" + message,
		success: function(msg){
			$("#shoutboxMessage").attr("value", "Message");
			$("#shoutboxMessage").focus();
		}
	});
}

//update arte output to page
function updateShoutbox(data) {
	if(data != $("#shoutboxShouts").attr("innerHTML")) {
		$("#shoutboxShouts").attr("innerHTML", data);
	}
}

//add ability to use enter key to add shout
function shoutboxKeyPress(character, pathToShoutbox) {
	var characterCode = character.keyCode;
	if(characterCode == 13) shoutboxShout(pathToShoutbox);
}

//create popup window for shoutbox history
function shoutboxPopup(link, name) {
	if(!window.focus)return true;
	var href = link;
	window.open(href, name, 'width=300,height=400,scrollbars=yes');
	return false;
}
