function initMessage(map) {
  if ($('#loginMsgWrapper').length == 0) {
    setTimeout(function() {
      initMessage(map);
    }, 100);
  }
  $('#loginMsgWrapper').html(map.msg);
}

/* Init to be called before page is ready, so that the message available when ready */
function init() {
  var url = '/welcomeMsg';
  if (contextPath) {
    url = (contextPath + url);
  }
  
  $.getJSON(url, {}, function(data) {
    initMessage(data);
  });
}

function setMessagePadding() {
  // Set welcome message position
  var docHeight = $(document).height();
  var headerHeight = ($('.header').height() + $('.menu').height() + $('.footer').height());
  var msgHeight = $('#loginMsgWrapper').height();
  var top = docHeight - headerHeight - msgHeight - 30;
  
  $('#loginMsgWrapper').css('padding-top', top / 2);
}

$(document).ready(function() {
	disableSearch();
	if ($('#username').val() == "") {
		$('#username').focus();
	} else {
		$('#password').focus();
	}
	$('#loginForm').bind('keypress', function(e) {
		checkReturnKey(e, 'loginBtn');
	});
    if (location.search.indexOf('error') > -1) {
		$('.error').show();
	}

  setMessagePadding();
  $(window).resize(setMessagePadding);
});

