function toggleRegister(type)
{
    if (type == 2)
    {
        $('#sregister').val('Siguiente');
        $('#lusername').html('Nombre Comercial');
    }
    else
    {
        $('#sregister').val('Crear cuenta');
        $('#lusername').html('Nombre de Usuario');
    }
}

function checkEmail(email)
{
    var value = true;

    $.ajax({
        type: 'post',
        url: path + '/ajax.php',
        data: 'action=email&email=' + email,
        dataType: 'xml',
        success: function(xml)
        {
            var result = $(xml).find('result').text();
            if (result == 'true')
            {
                $('#email_check').fadeIn('fast');
                $('#remail').addClass('checkko');
                value = false;
            }
            else
            {
                $('#email_check').fadeOut('fast');
                $('#remail').removeClass('checkko');
                value = true;
            }
        }
    });

    return value;
}

function checkUsername(username)
{
    var value = true;

    $.ajax({
        type: 'post',
        url: path + '/ajax.php',
        data: 'action=username&username=' + username,
        dataType: 'xml',
        success: function(xml)
        {
            var result = $(xml).find('result').text();
            if (result == 'true')
            {
                $('#username_check').fadeIn('fast');
                $('#rusername').addClass('checkko');
                value = false;
            }
            else
            {
                $('#username_check').fadeOut('fast');
                $('#rusername').removeClass('checkko');
                value = true;
            }
        }
    });

    return value;
}

function checkRole()
{
    if (!$('#role_user')[0].checked && !$('#role_provider')[0].checked)
    {
        $('#role_check').fadeIn('fast');
        return false;
    }
    else
    {
        $('#role_check').fadeOut('fast');
        return true;
    }
}

function checkSubmit()
{
    var email = $('#remail').val();
    var username = $('#rusername').val();

    if (!checkEmail(email) || !checkUsername(username) || !checkRole())
        return false;

    return true;
}