function showHideDiv(divName) {
    if (($(divName).style.visibility == 'hidden') || ($(divName).style.visibility == '')) {
        showDiv(divName)
    } else {
        hideDiv(divName);
    }
}

function showDiv(divName) {
    $(divName).style.visibility = 'visible';
    $(divName).style.overflow   = 'visible';
    $(divName).style.position   = 'relative';
}

function hideDiv(divName) {
    $(divName).style.visibility = 'hidden';
    $(divName).style.overflow   = 'hidden';
    $(divName).style.position   = 'absolute';
}


function changeCssClass(componentId, newClassName) {
    $(componentId).className = newClassName;
}

function validaEmail(email) {
    var re = new RegExp("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$");
    var m = re.exec(email);
    
    if (m == null) {
        return 1;
    } else {
        return 0;
    }
}

function sendForm(url, errorMessage) {
    var flag = 0;
    
    if ($('frm_nome').value == '') {
        changeCssClass('frm_nome', 'input_error');
        flag = 1;
    }
    
    if ($('frm_email').value == '') {
        changeCssClass('frm_email', 'input_error');
        flag = 1;
    } else if (validaEmail($('frm_email').value)) {
        changeCssClass('frm_email', 'input_error');
        flag = 1;
    }
    
    if ($('frm_comment').value == '') {
        changeCssClass('frm_comment', 'textarea_error');
        flag = 1;
    }
    
    if (flag > 0) {
        $('form_error').innerHTML = errorMessage;
    } else {
        newPost(url, $('frm_nome').value, $('frm_email').value, $('frm_url').value, $('frm_comment').value);
    }
    
}

function newPost(url, nome, email, site, mensagem) {
    var pars  = 'nome=' + nome + '&email=' + email + '&url=' + site + '&mensagem=' + mensagem;
    var myDiv = 'formulario';
    
    for (i = 0; i < 30000; i++) {} // funcao bolha
    
    var myAjax = new Ajax.Updater(myDiv,
                                  url,
                                  {
                                      method: 'get',
                                      parameters: pars
                                  }
                                  );
}
