function p_email_link (domain, user) {
    email = user + '@' + domain;
    document.write('<a href="mailto:' + email + '">' + email + '</a>');
}

function navi_on(e) {
    if (e.src.indexOf ('_current') < 1) {
        e.src = e.src.substr (0,e.src.indexOf('.png')) + '_rollover.png';
    }
}

function navi_out(e) {
    if (e.src.indexOf ('_current') < 1) {
        e.src = e.src.substr (0,e.src.indexOf('_rollover.png')) + '.png';
    }
}

function validate_email_address(email) {
    if ((email.indexOf('.') < 2) || (email.indexOf('@') < 2)) { return false; } else { return true; }
}

function validate_mailinglist(form, jq_form, options) {
    valid = validate_email_address($('#email').val());
    if (! valid) {
        error_message = $('#email_error').text();
        alert(error_message);
        return false;
    }
}

function maybe_show_fullpage() {
    if (! ($('#container > div').get().length < 4)) { return; }
    if ($('.smallbox').get().length > 0)            { return; }

    $('#container').addClass('fullpage');

    // show featured artist image
    if ($('.artist_feature_page').get().length < 1) {
        $('.artist_feature_footer').removeClass('hide');
        // for ie6
        $('.artist_feature_footer').css('display', 'inline');
    }
}

function maybe_correct_captcha() {
    $('#captchaInputDiv').children().text("CAPTCHA-koodi (pakollinen)");
}


function add_link_targets_to_content() {
    $('span.boxcontent a').each(function() {
        if (this.host != window.location.host) { $(this).attr('target', '_blank'); }
    });
}

$(function() {
    $('#mailinglist')
        .ajaxForm({ target: '#mailinglist',
                    beforeSubmit: validate_mailinglist,
                    success: function()
                    { $('#mailinglisthead').text("");
                        if ($('#mailinglist').html().search("SUCCESS") != -1) {
                            $('#mailinglist_div').addClass("mailing_success");
                        } else {
                            $('#mailinglist_div').addClass("mailing_error"); } } });
    $(".artistinfoboxtoggle").click(function () { $(this).next().toggleClass('hide'); });
    maybe_show_fullpage();
    maybe_correct_captcha();
    add_link_targets_to_content();
});
