﻿/* Método que valida a introdução de valores numéricos */
function numeric_Validate(e, obj) {
    var evt = e ? e : window.event;
    var keycode;
    if (document.all)
        keycode = evt.keyCode;
    else
        keycode = evt.which;
    if (keycode >= 48 && keycode <= 57 || (keycode == 0 || keycode == 8))
        return true;
    else
        return false;
}

/* Método que valida se o endereço de e-mail está correcto */
function validateEmail(e) {
    if (e != "") {
        var objRegExp = /^.+@.+\..{2,3}$/;
        return objRegExp.test(e);
    } else {
        return true;
    }
}

/* Método que valida se todos os campos do formulário de Recrutamento estão preenchidos */
function frmBudget_Validate(clientID) {
    var msg = '';
    if (document.getElementById(clientID + "_tbPersonalName").value == "") msg += '» Nome\n';
    if (document.getElementById(clientID + "_tbPersonalPhone").value == "") msg += '» Telefone\n';
    if (document.getElementById(clientID + "_tbPersonalEmail").value == "") msg += '» E-mail\n';
    if (document.getElementById(clientID + "_tbCondoName").value == "") msg += '» Nome do Condomínio\n';
    if (document.getElementById(clientID + "_tbCondoAdress").value == "") msg += '» Morada do Condomínio\n';
    if (msg.length > 0) {
        alert("Os seguintes campos são de preenchimento obrigatório:\n" + msg);
        return false;
    }
    if (!validateEmail(document.getElementById(clientID + "_tbPersonalEmail").value)) {
        alert("Não é possível enviar o formulário.\nIntroduza um endereço de e-mail válido.");
        return false;
    }
    return true;
}

// Validação do Formulário de Subscrição da Newsletter
function frmContactRequest_Validate(clientID) {
    var msg = '';
    if (document.getElementById(clientID + "_tbName").value == "") msg += '» Nome\n';
    if (document.getElementById(clientID + "_tbPhone").value == "") msg += '» Telefone\n';
    if (document.getElementById(clientID + "_tbEmail").value == "") msg += '» E-mail\n';
    if (msg.length > 0) {
        alert("Os seguintes campos são de preenchimento obrigatório:\n" + msg);
        return false;
    }
    if (!validateEmail(document.getElementById(clientID + "_tbEmail").value)) {
        alert("Introduza um endereço de e-mail válido.");
        return false;
    }
    return true;
}

function doc_GetHeight() {
    var h = 0;

    if (typeof (window.innerWidth) == 'number') {
        h = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        h = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        h = document.body.clientHeight;
    }

    return h;
}

function dialog_OnInit(w, h, src) {
    var lb = document.createElement('div');
    var sw = doc_GetHeight();

    if (document.body.scrollHeight > sw) sw = document.body.scrollHeight;

    with (lb) {
        id = 'lightbox';
        style.height = sw + 'px';

        setAttribute("onclick", "dialog_OnUnload();");
    }

    document.body.appendChild(lb);

    dialog_OnLoad(w, h, src);
}

function dialog_OnLoad(w, h, s) {
    var d = document.createElement('div');

    with (d) {
        id = 'dialog';

        style.width = w + 'px';
        style.height = h + 'px';

        style.top = ($(window).height() - h) / 2 + $(window).scrollTop() + 'px';
    }

    var cd = document.createElement('div');

    with (cd) {
        className = 'close';
        innerHTML = 'Fechar';

        setAttribute("onclick", "dialog_OnUnload();");
    }

    d.appendChild(cd)

    var i = document.createElement('iframe');

    var mw = 4;
    var mh = 18;

    with (i) {
        width = (w - mw) + 'px';
        height = (h - mh) + 'px';

        setAttribute('frameborder', 0);
        setAttribute('scrolling', 'no');
        setAttribute('src', s);
        setAttribute('allowtransparency', 'true');
    }

    d.appendChild(i);
    document.body.appendChild(d);
}

function dialog_OnUnload() {
    document.body.removeChild(document.getElementById('lightbox'));
    document.body.removeChild(document.getElementById('dialog'));
}

/* Método que permite esconder e mostrar o conteudo */
//<![CDATA[
function ShowHide(DivID) {
    $("#" + DivID).animate({ "height": "toggle" }, { duration: 300 });
}
//]]>
