$(document).ready(function() {
  $('#s').focus(function() {
    if ($('#s').val() == 'Find a user') {
      $('#s').val('');
    }  
  });
  
  $('#s').blur(function() {
    if ($('#s').val() == '') {
      $('#s').val('Find a user');
    }  
  });
  
	$('#gofind').click(function(data) {
    $('#search_form').submit();
    return false;  
  });
  
  $("#go").click(function() {
		$.ajax({
			type: "POST",
			url: "/shoutbox/add/"+$("#countries_id").val(),
			data: "name="+escape($("#name").val())+"&message="+escape($("#message").val()),
			success: function(msg){
				if (msg.indexOf("fail:") >= 0) {
					msg = msg.substring(msg.indexOf(':')+1);
					$("#word_popup").html(msg).fadeIn("slow").animate({opacity: 1.0}, 3000).fadeOut("slow");
				}
				else if (msg.indexOf("success:") >= 0) {
					msg = msg.substring(msg.indexOf(':')+1);
					$("#word_popup").html(msg).fadeIn("slow").animate({opacity: 1.0}, 3000).fadeOut("slow");
					$("#name").val('');
					$("#message").val('');
				}
			}
		});
		return false;
	});
	
	$.fn.handleInput = function() {
		return this.blur(function(){
			if ($(this).val().length == 0) {
				$(this).addClass("word_input_off");
				$(this).removeClass("word_input_on");
				this.value = this.defaultValue;
			}
		}).
		bind("focus click", function() {
			$(this).addClass("word_input_on");
			$(this).removeClass("word_input_off");
			if (this.value == this.defaultValue) { this.value = ''; }
		});
	};
	$("#name").handleInput();
	$("#message").handleInput();

	$("#message").bind("change keypress keyup keydown click", function() {
		if (this.value.length > 255) {
			this.value = this.value.substr(0,255);
			$("#word_popup").html('Message cannot exceed 255 characters').fadeIn("slow").animate({opacity: 1.0}, 1000).fadeOut("slow");
		}
	});
});

function ValidateForm(theform)
{
	/*
	if(theform.country.value=='') {
		alert('Please specify country')
		theform.country.focus()
		return false
	}

	if(theform.shortForm.value=='') {
		alert('Please specify short form')
		theform.shortForm.focus()
		return false
	}

	if(checkSelect(theform.continent_id)==false) {
		alert('Please select continent')
		theform.continent_id.focus()
		return false
	}

	if(checkSelect(theform.region_id)==false) {
		alert('Please select region')
		theform.region_id.focus()
		return false
	}
	*/

	return true
}

function checkSelect(theSelect)
{
	if (theSelect.options[0].selected == true) {
		return false;
	}
	return true;
}
