﻿function validaformpesquisa() {
    if (document.getElementById('TextoPesquisaNoticias').value == 'pesquisar')
        return false;
}

function cleanInputFieldsEnviar(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}
function ValidaCamposContacto() {
    $('.error').html("");

    if ($("#txt_nome").val() == "") {
        $('#txt_nome_error').html("* ");
        return false;
    }

    if (!validateEmail($("#txt_email").val())) {
        $('#txt_email_error').html("* ");
        return false;
    }
    
    if ($("#txt_assunto").val() == "") {
        $('#txt_assunto_error').html("* ");
        return false;
    }
   
    if ($("#txt_mensagem").val == "") {
        $('#txt_mensagem_error').html("* ");
        return false;
    }

    if ($("#txt_telefone").val == "") {
        $('#txt_telefone_error').html("* ");
        return false;
    }

    return true;
}

function submitformcontactos() {
    
    if (!ValidaCamposContacto())
        return false;

    var txt_autorizacao_value = "0";
    if (document.getElementById("autorizacao").checked)
        txt_autorizacao_value = "1";
    
    $.ajax({ url: "/AJAX/contactos.aspx",
        type: "POST",
        dataType: "text",
        async: false,
        data: { request: "contactar",
            txt_nome: $("#txt_nome").val(),
            txt_email: $("#txt_email").val(),
            txt_assunto: $("#txt_assunto").val(),
            autorizacao: txt_autorizacao_value,
            txt_mensagem: $("#txt_mensagem").val(),
            txt_telefone: $("#txt_telefone").val()
        },
        success: function() {
            $('#contactos_form').html("<div id='message'></div>");
            $('#message')
        .html("<h2>O seu pedido de contacto, foi registado com sucesso</h2>")
        .append("<p>Entraremos em contacto consigo brevemente.</p>")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/check.png' />"); });
        },
        error: function(req, error, ex) {
            $('#contactos_form').html("<div id='message'></div>");
            $('#message')
        .html("<h2>Não nos foi possivel registar o seu pedido desde já as nossas desculpas.</h2>")
        .append("<p>Tente mais tarde, esperamos ser breves.</p>")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/cancel.png' />"); });

        }
    });
}


function ValidaCamposRegisto() {
    $('.error').html("");

    
    if ($("#txt_nome").val() == "" || String($("#txt_nome").val()) == "undefined") {
        $('#txt_nome_error').html("* Obrigatorio");
        return false;
    }

    
    if (!validateEmail($("#email").val())) {
        $('#email_error').html("* Obrigatorio");
        return false;
    }

    if ($("#txt_localidade").val() == "") {
        $('#txt_localidade_error').html("* Obrigatorio");
        return false;
    }
    

    return true;
}

function validateEmail(elementValue) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue);
}

function submitformregisto() {

    if (!ValidaCamposRegisto())
        return false;

    var txt_autorizacao_value = "0";
    if (document.getElementById("autorizacao").checked)
        txt_autorizacao_value = "1";

    $.ajax({ url: "/AJAX/registo.aspx",
        type: "POST",
        dataType: "text",
        async: false,
        data: { request: "registo",
            txt_nome: $("#txt_nome").val(),
            email: $("#email").val(),
            txt_localidade: $("#txt_localidade").val(),
            autorizacao: txt_autorizacao_value,
            dia: $("#dia").val(),
            mes: $("#mes").val(),
            ano: $("#ano").val()
        },
        success: function() {
        $('#registo_form').html("<div id='message'></div>");
            $('#message')
        .html("<h2>O seu registo, foi efectuado com sucesso</h2>")
        .append("<p>Em breve receberá noticias nossas, obrigado pelo seu registo.</p>")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/check.png' />"); });
        },
        error: function(req, error, ex) {
            $('#registo_form').html("<div id='message'></div>");
            $('#message')
        .html("<h2>Não nos foi possivel registar o seu pedido desde já as nossas desculpas.</h2>")
        .append("<p>Tente mais tarde, esperamos ser breves.</p>")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/cancel.png' />"); });

        }
    });
}

function submitFormBolsaEmprego(str) {

    if (!ValidaCamposBolsaEmprego())
        return false;
    else
        return true;





    /*var txt_autorizacao_value = "0";
    if (document.getElementById("autorizacao").checked)
        txt_autorizacao_value = "1";

    var cap = $("#certificado").val();
    if (cap == "não")
        cap = "0";
    if (cap == "sim")
        cap = "1";
    */    
        
        
        

    /*$.ajax({ url: "/AJAX/emprego.aspx",
        type: "POST",
        dataType: "text",
        async: false,
        data: { request: "emprego",
            nomeCompleto: $("#nomeCompleto").val(),
            habilitacoes: $("#habilitacoes").val(),
            habilitacoesCurtas: $("#habilitacoesCurtas").val(),
            dia: $("#dia").val(),
            mes: $("#mes").val(),
            ano: $("#ano").val(),
            experiencia: $("#experiencia").val(),
            nomeEmpresa: $("#nomeEmpresa").val(),
            actividade: $("#actividade").val(),
            telefone: $("#telefone").val(),
            email: $("#email").val(),
            observacoes: $("#observacoes").val(),
            curriculo: $("#curriculo").val(),
            certificado: cap,
            autorizacao: txt_autorizacao_value
            
            },
        success: function() {
            $('#emprego_form').html("<div id='message'></div>");
            $('#message')
        .html("<h2>Os seus dados foram processados com sucesso</h2>")
        .append("<p>Em breve receberá noticias nossas, obrigado pelo seu registo.</p>")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/check.png' />"); });
        },
        error: function(req, error, ex) {
            $('#emprego_form').html("<div id='message'></div>");
            $('#message')
        .html("<h2>Não nos foi possivel registar o seu pedido desde já as nossas desculpas.</h2>")
        .append("<p>Tente mais tarde, esperamos ser breves.</p>")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/cancel.png' />"); });

        }
    });*/
}

function ValidaCamposBolsaEmprego() {

    $('.error').html("");

    if ($("#nomeCompleto").val() == "") {
        $('#nomeCompleto_error').html("* Obrigatorio");
        return false;
    }

    if ($("#nomeEmpresa").val() == "") {
        $('#nomeEmpresa_error').html("* Obrigatorio");
        return false;
    }

    if (!validateEmail($("#email").val())) {
        $('#email_error').html("* Obrigatorio");
        return false;
    }

    if ($("#curriculo").val() != '') {
        var urlFile = $("#curriculo").val();
        
        if (urlFile.indexOf(".doc") > -1 || urlFile.indexOf(".docx") > -1 || urlFile.indexOf(".pdf") > -1) {
            return true;
        }
        else {
            $('#curriculo_error').html("* Tipo de ficheiro inválido");
            return false;
        }
    }

    return true;
}


function validateFormCandidatar() {

    $('.error').html("");

    if ($("#nome").val() == "") {
        $('#nome_error').html("* Obrigatorio");
        return false;
    }


    if (!validateEmail($("#email").val())) {
        $('#email_error').html("* Obrigatorio");
        return false;
    }

    if ($("#telefone").val() == "") {
        $('#telefone_error').html("* Obrigatorio");
        return false;
    }

    return true;
}

function submitFormCandidatar() {

    if (!validateFormCandidatar())
        return false;

    document.getElementById("formCandidatar").style.display = "none";
    document.getElementById("formResposta").style.display = "block";

    $.ajax({ url: "/AJAX/email.aspx",
        type: "POST",
        dataType: "text",
        async: false,
        data: { request: "candidatura",
            nome: $("#nome").val(),
            email: $("#email").val(),
            destinatario: $("#telefone").val(),
            txt_titulo : $("#txt_titulo").val(),
            contentidnoticia: $("#contentidnoticia").val(),
            channelidnoticia: $("#channelidnoticia").val()
        },
        success: function(result) {
            
            if (result == "true") {
                $('#enviar_form').html("<div id='message' style='text-align:left;'></div>");
                $('#message')
        .html("O seu email foi enviado com sucesso")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/check.png' />"); });
            }
            else {
                $('#enviar_form').html("<div id='message'></div>");
                $('#message')
        .html("Não nos foi possivel enviar o seu email, desde já as nossas desculpas.")
        .append("Tente mais tarde, esperamos ser breves.")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/cancel.png' />"); });
            }


        },
        error: function(req, error, ex) {
            //alert("3");
            $('#enviar_form').html("<div id='message'></div>");
            $('#message')
        .html("Não nos foi possivel enviar o seu email, desde já as nossas desculpas.<br/>")
        .append("Tente mais tarde, esperamos ser breves.")
        .hide()
        .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='/images/cancel.png' />"); });

        }
    });
}


    