var ajax = null;

function load()
{
	initMouseEvent();
	
	try {
		ajax = new AJAXHandler();
	} catch (e) {
		alert("Navegador no compatible con AJAX!\n\nUsá Firefox!");
	}
}

function searchGallery()
{
	if (!trim(get('gallery-name').value))
	{
		alert('Ingresa un usuario o parte del mismo.');
		return false;
	}
	return true;
}

function showHide(id)
{
	if (get(id).style.display == 'none')
		get(id).style.display = 'block';
	else
		get(id).style.display = 'none';
}

function validatePassword()
{
	if (!trim(get('private-password').value))
	{
		alert('El password no puede estar vacío!');
		return;
	}
	ajax.setReadyStateListener(function() {
		ajax.showStatus('Comprobando...', 'validate-password-status');
		if (ajax.ready()) window.location.reload();
	});
	ajax.request('POST', 'private-password=' + encode(get('private-password').value), get('password-form').action);
}

function validateLogin()
{
	if (!trim(get('username').value) || !trim(get('password').value))
	{
		alert('Debes ingresar tu nombre de usuario y contraseña');
		return;
	}
	ajax.setReadyStateListener(function() {
		ajax.showStatus('Comprobando...',null,false,'images/loading3.gif');
		if (ajax.ready()) window.location.href = 'admin/index.php';
	});
	var URI = 'username=' + encode(get('username').value) + '&password=' + encode(get('password').value);
	ajax.request('POST', URI, 'index.php?task=login');
}