function irNueva(pagina) {
    var win = window.open(pagina, 'Identia', "toolbar=no,location=no,direction=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=1024,height=768");
    win.focus();
    return false;
}

function ir(pagina) {
    if (pagina && pagina != "") { self.location = pagina; }
}

function irPaginaProyecto(pagId)
{
    if (pagId != 0) { ir(homeUrl + '/index.php?pagId=' + pagId); }
}

function confirmarSubmit(f, pregunta, accion)
{
    if (confirm("¿Está seguro/a de que desea " + pregunta + "?")) {
        f.action = accion;
        f.submit();
    }
}

function submitTo(f, accion)
{
    f.attr('action', accion);
    f.submit();
}

function statusMsg(msg) {
    window.status = msg;
    return true
}

function fondo(elem, color)
{
    $(elem).css('background-color', color);
}

function enviarForm(id)
{
    var pieza = '#pieza' + id, error = '', valores = {};
    $(pieza + ' label').removeClass('b');
    $(pieza + ' input').each( function(i) {
        if ($(this).val() == '') { error = $(this).attr('name'); $(pieza + ' label[for="' + error + '"]').addClass('b'); }
        else { valores[$(this).attr('name')] = $(this).val(); }
    });

    if (error != '') { alert(traduce('ERROR_CAMPOS')); return; }

    $.post(homeUrl + '/form.php', valores, function(data) { alert(data); });
}

function enviarForm2(id)
{
    var pieza = '#pieza' + id, error = '', valores = {};
    $(pieza + ' label').removeClass('b');
    $(pieza + ' input').each( function(i) {
        if ($(this).val() == '') { error = $(this).attr('name'); $(pieza + ' label[for="' + error + '"]').addClass('b'); }
        else { valores[$(this).attr('name')] = $(this).val(); }
    });

    $(pieza + ' textarea').each( function(i) {
        if ($(this).val() == '') { error = $(this).attr('name'); $(pieza + ' label[for="' + error + '"]').addClass('b'); }
        else { valores[$(this).attr('name')] = $(this).val(); }
    });

    if (error != '') { alert(traduce('ERROR_CAMPOS')); return; }

    $.post(homeUrl + '/form2.php', valores, function(data) { alert(data); });
}

function irPrincipal(url)
{
    setTimeout('ir("' + url + '")', 4000);
}

function init()
{
    Cufon.replace('h1');
    Cufon.replace('h3');
}

function traduce(llave)
{
    if (llave == 'ERROR_CAMPOS') { return idioma == 'ES' ? 'Debe rellenar todos los campos' : 'All fields are obligatory'; }

    return '';
}

$(document).ready( init );

