function OnLoginHTMLLoaded() {
	//alert('you are here');
  try{ 
    $('.error').hide();  
		$("#error_message").hide();			
    $(".button").click(function() {										
      $('.error').hide();
			var Username = $("input#Username").val();
       if (Username == "") {  
        $("label#Username_error").show();  
        $("input#Username").focus();  
        return false;  
      }
			var Password = $("input#Password").val();
       if (Password == "") {  
        $("label#Password_error").show();  
        $("input#Password").focus();  
        return false;  
      }  
	    var dataString = (
			  'request=Authenticate' +
    	  '&Username=' + Username +
				'&Password=' + Password);
      //alert (dataString);return false;
      $.ajax({
        type: "POST",
        url: "/reg_sys/login.php",
        data: dataString,
        success: function(json) {
					var data = eval("(" + json + ")");
					if (data.success) {
						$('#user').html(data.user);
            $('#ajax_content').html("<div id='message'></div>");
            $('#message').html("<h2>Login Successfull!</h2>")
            .append("<p>Welcome " + data.user + "!</p>")
            .hide()
            .fadeIn(1500, function() {
              $('#message').append("<img id='checkmark' src='images/login/check.png' />");
            });
						setTimeout("window.location='index.php'",2500);				 
					}
					else{
						$('#error_message').html(data.message);
						$('#error_message').show();
						$('#user').html("Guest");
					};
        }
      });
      return false;
    });
	}
	catch(err){
		alert("Bad");
	  return false;
	}  
};
