var dlgMailInviata = null;
var dlgReqFields = null;

$(function() {
    dlgMailInviata = new Boxy("#Contatti_divC_div1", {modal: true, show: false, closeable: false});
    dlgReqFields = new Boxy("#Contatti_divC_div2", {modal: true, show: false, closeable: false});
});

function SendMail() {
    var bOk = true;

    var oNominativo = '';
    var oEmail = '';
    var oTelefono = '';
    var oMessaggio = '';

    var oTempValue = $("input[id='Contatti_divC_inp1']").getValue();
    if ((typeof oTempValue == 'undefined') ||
        (oTempValue == null) ||
        (oTempValue == 'undefined') ||
        (oTempValue == 'null') ||
        ($.trim(oTempValue) == '')) {
        bOk = false;
    } else {
        oNominativo = oTempValue;
    }

    oTempValue = $("input[id='Contatti_divC_inp2']").getValue();
    if ((typeof oTempValue == 'undefined') ||
        (oTempValue == null) ||
        (oTempValue == 'undefined') ||
        (oTempValue == 'null') ||
        ($.trim(oTempValue) == '')) {
        bOk = false;
    } else {
        oEmail = oTempValue;
    }

    oTempValue = $("input[id='Contatti_divC_inp3']").getValue();
    if ((typeof oTempValue != 'undefined') &&
        (oTempValue != null) &&
        (oTempValue != 'undefined') &&
        (oTempValue != 'null') &&
        ($.trim(oTempValue) != '')) {
        oTelefono = oTempValue;
    }

    oTempValue = $('#Contatti_divC_inp4').val();
    if ((typeof oTempValue == 'undefined') ||
        (oTempValue == null) ||
        (oTempValue == 'undefined') ||
        (oTempValue == 'null') ||
        ($.trim(oTempValue) == '')) {
        bOk = false;
    } else {
        oMessaggio = oTempValue;
    }

    if (bOk) {
        $.ajax({
            type: 'POST',
            url: '/public/webhandler/sendmailxcontatti.aspx',
            data: ({i1:oNominativo,i2:oEmail,i3:oTelefono,i4:oMessaggio}),
            cache: false,
            dataType: 'html',
            complete: function(dataReturned, s) {
                if ((typeof dataReturned != 'undefined') &&
                    (dataReturned != null) &&
                    (typeof dataReturned.responseText != 'undefined') &&
                    (dataReturned.responseText != null) &&
                    ($.trim(dataReturned.responseText) != '') &&
                    ($.trim(dataReturned.responseText) == 'ok')) {
                    
                    dlgMailInviata.show().center();
                    $('#Contatti_divC_div1_btnOk').focus();
                } else {
                    alert('error!');
                }
            }
        });
    } else {
        dlgReqFields.show().center();
        $('#Contatti_divC_div2_btnOk').focus();
    }
}