    function trim(str, chars) {
        return ltrim(rtrim(str, chars), chars);
    }

    function ltrim(str, chars) {
        chars = chars || "\\s";
        return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
    }

    function rtrim(str, chars) {
        chars = chars || "\\s";
        return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
    }


    function login(url, msg, user_id, is_private) {
        $.post("/register/login.php?" + Math.random(), { login: $('#txtlogin').val(), password: $('#txtpwd').val(), url:url }, function(data){
	    $('#loginmsg').html('');
            data = trim(data);
            if(data == "ERROR") {
		$('#loginmsg').html("<div class='error' style='margin-bottom:10px; width:190px;'>Invalid User ID or Password, Please try again.</div>");
            } else if(data == "INVALID") {
		$('#loginmsg').html("<div class='error' style='margin-bottom:10px; width:190px;'>Invalid User ID. User is either temporarily suspended or removed.</div>");
	    } else if (data != "") {
                window.location.href = data;
	    } else {
		window.location.href = "/";
            }
        });
    }

  function catchEnter(e, url)
  {
    if (!e) {
      var e = window.event;
    }
    if (e.keyCode == 13) {
	  login(url);
    }
  }
