function LoginForm(){   	

	this.form = document.getElementById("loginAction");
	if (!this.form) return;
	this.form.handler = this;

	this.usrInp = document.getElementById("loginusr2") || document.getElementById("loginusr");
	this.pwdInp = document.getElementById("loginpwd2") || document.getElementById("loginpwd");
	this.remInp = document.getElementById("rememberme2") || document.getElementById("rememberme");
	if (!this.usrInp || !this.pwdInp || !this.remInp) return;

	this.form.onsubmit = function(){
		this.handler.setCredentials();
	}
	this.getCredentials();
}

LoginForm.prototype = {

	setCredentials: function(){
		
		var cookiedata = "";
		var remember = this.remInp.checked;

		if (remember == true) {
			var username = this.usrInp.value;
			var password = this.pwdInp.value;
			cookiedata = username + "," + password;
		} else cookiedata = "";
		
		$.cookie("logincredentials", cookiedata, { path: "/", expires: 31 });
	},

	getCredentials: function(){
		
		var cookie = $.cookie("logincredentials");

		if (cookie) {
			this.remInp.checked = true;
			var cookiedata = cookie.split(",");
			var username = cookiedata[0];
			var password = cookiedata[1];
			this.usrInp.value = username;
			this.pwdInp.value = password;
		}
		else this.remInp.checked = false;
	}
}

if (onloadHandler) onloadHandler.add(function() {
	window.loginForm = new LoginForm();
});
