var txtUserName;
var txtPassword;

Ext.onReady(function () {
	
	if (Ext.get('username')) {
		txtUserName = new Ext.form.TextField({
			allowBlank: false,
			applyTo: 'username',
			emptyText: 'Enter your user name',
			width: 205
		});
	}
	
	if (Ext.get('password')) {
		txtPassword = new Ext.form.TextField({
			allowBlank: false,
			applyTo: 'password',
			emptyText: 'Enter your password',
			width: 205
		});
	}
	
});


function ValidateLogin() {

	if (!txtUserName.isValid() || !txtPassword.isValid()) {
		Ext.Msg.alert('Status', 'Please enter the user name and password.');
		return false;
	}
	
	var filterObj = new Object();
	filterObj.email = txtUserName.getValue();								
	filterObj.password = txtPassword.getValue();												
	filterObj.action = 'do_mbu_client_authenticate';
	
	Ext.Ajax.request({
		url: home_url +'/wp-admin/admin-ajax.php',
		success: function(c, r, o) {							
			if (c.responseText == 'ok') {
				location.href =  home_url;
			}
			else {
				Ext.Msg.alert('Login Failed', 'Invalid Username or Password, please try again');
			}
		},
		params: filterObj,
		timeout: 1200000
	});
	
	return false;

}
