﻿function processFakeClick(event, target) {
    if (window.event) {
        event = window.event;
    }

    if (event.keyCode == 13) {
        $("#" + target).click();
        return false;
    }
}

function changeCustomer(d) {
    var id = d.options[d.selectedIndex].value;

    var url = "/mod/clientes/selecionar.aspx?id=" + id;
    location.href = url;
}

function showAuth(d) {
    var auth = "auth" + d;
    var minus = "authmin" + d;

    if ($("#" + auth).css("display") == "none" || $("#" + auth).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(auth);
}
function selecionarTodos(c) {
    if (c.checked) {
        $(".checkboxes").attr('checked', true);
    } else {
        $(".checkboxes").attr('checked', false);
    }
}
function changeStyle(id, style) {
    if (id) {
        id.className = style;
    }
}
function showHide(div) {
    if ($("#" + div).css("display") == "none" || $("#" + div).css("display") == "") {
        $("#" + div).slideDown('fast');
    } else {
        $("#" + div).slideUp('fast');
    }
}
function showHiddenTableRow(d) {
    if ($.browser.msie)
        $('#' + d).css("display", "block");
    else
        $('#' + d).css("display", "table-row");
}

function showLicense(d) {
    var product = "prd" + d;
    var minus = "min" + d;

    if ($("#" + product).css("display") == "none" || $("#" + product).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(product);
}
function showSwAdditionalData(d) {
    var license = "lic" + d;

    if ($('#' + license).html().length == 0) {
        addLoading(license);
        $("#" + license).load("/mod/licencas/ajax/licSwAdditionalInfo.aspx?sn=" + d);
    }
    //showHide(license);
}
function showSwLicenseData(d) {
    var order = "lic" + d;
    var minus = "licmin" + d;

    if ($("#" + order).css("display") == "none" || $("#" + order).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
        showSwAdditionalData(d);
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
        //showSwAdditionalData(d);
    }
    showHide(order);
}
function showOrderData(d) {
    var order = "order" + d;
    var minus = "ordermin" + d;

    if ($("#" + order).css("display") == "none" || $("#" + order).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(order);
}
function showManagerOrderData(d) {
    var order = "order" + d;
    var minus = "ordermin" + d;

    if ($("#" + order).css("display") == "none" || $("#" + order).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
        
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showOrderInfo(d);
    showHide(order);
}
function showOrderInfo(d) {
    var order = "order" + d;

    if ($('#' + order).html().length == 0) {
        addLoading(order);
        $("#" + order).load("/manager/order/ajax/orderInfo.aspx?id=" + d);
    }
}

function showCustomerInformations(d) {
    var license = "lic" + d;
    var minus = "licmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(license);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        addLoading(license);
    }
    showHide(license);
}

function showInvoicesDetails(c, i) {
    var invoice = "inv" + i;
    var minus = "invmin" + i;

    if ($("#" + invoice).css("display") == "none" || $("#" + invoice).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(invoice);
                $("#" + invoice).load("/manager/administration/invoices_details.aspx?col=" + c + "&id=" + i);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        addLoading(invoice);
                $("#" + invoice).load("/manager/administration/invoices_details.aspx?col=" + c + "&id=" + i);
    }
    showHide(invoice);
}

function showPreInvoicesDetails(c, i) {
    var invoice = "preinv" + i;
    var minus = "preinvmin" + i;

    if ($("#" + invoice).css("display") == "none" || $("#" + invoice).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(invoice);
                $("#" + invoice).load("/manager/administration/preInvoices_details.aspx?col=" + c + "&id=" + i);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        addLoading(invoice);
                $("#" + invoice).load("/manager/administration/preInvoices_details.aspx?col=" + c + "&id=" + i);
    }
    showHide(invoice);
}

function showBondsDetails(c, i) {
    var bond = "bond" + i;
    var minus = "bondmin" + i;

    if ($("#" + bond).css("display") == "none" || $("#" + bond).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(bond);
                $("#" + bond).load("/manager/administration/bonds_details.aspx?col=" + c + "&id=" + i);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        addLoading(bond);
                $("#" + bond).load("/manager/administration/bonds_details.aspx?col=" + c + "&id=" + i);
    }
    showHide(bond);
}

function showNotifications(d, minus, btnAdditionalID) {

    var not = "not" + d;

    if ($("#" + not).css("display") == "none" || $("#" + not).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
        if (btnAdditionalID) {
            var btnAdditional = document.getElementById(btnAdditionalID);
            btnAdditional.click();
        }
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(not);
}

function clientActiveTabChanged(tabContanterID, btnAdditionalID, btnComputerID, btnExceptionID, btnUnconformityID, btnPromobID) {

    if (!tabContanterID || !btnAdditionalID || !btnComputerID
    || !btnExceptionID || !btnPromobID || !btnUnconformityID) return;

    var tabContainer = $find(tabContanterID);
    var tabIndex = tabContainer.get_activeTabIndex();

    if (tabIndex == 0) {
        $get(btnAdditionalID).click();
    }
    else if (tabIndex == 1) {
        $get(btnComputerID).click();
    }
    else if (tabIndex == 2) {
        $get(btnExceptionID).click();
    }
    else if (tabIndex == 3) {
        $get(btnUnconformityID).click();
    }
    else if (tabIndex == 4) {
        $get(btnPromobID).click();
    }
}

function showPluginData(d, serial, sp, spCustomerID) {

    var license = "lic" + d;
    var minus = "licmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
        showAdditionalPluginData(d, serial, sp, spCustomerID);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        showAdditionalPluginData(d, serial, sp, spCustomerID);
    }
    showHide(license);
}
function showLicenseData(d, serial, sp, spCustomerID) {

    var license = "lic" + d;
    var minus = "licmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
        showAdditionalData(d, serial, sp, spCustomerID);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        showAdditionalData(d, serial, sp, spCustomerID);
    }
    showHide(license);
}
function showSupportLicenseData(d, serial, cid, contractid, contractitemid) {
    var license = "lic" + d;
    var minus = "licmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showSupportAdditionalData(d, serial, cid, contractid, contractitemid);
    showHide(license);
}
function showSupportAdditionalData(d, serial, cid, contractid, contractitemid) {
    var license = "licadt" + d;
    var minus = "licadtmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        if ($('#' + license).html().length == 0) {
            $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(license);
            $("#" + license).load("/manager/support/ajax/licSupportAdditionalInfo.aspx?sn=" + serial + "&cid=" + cid + "&contractid=" + contractid + "&contractitemid=" + contractitemid);
        }
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(license);
}


function showManufacturerLicenseData(d, serial) {
    var license = "lic" + d;
    var minus = "licmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        $("#" + minus).attr({ src: "/_images/minus.jpg" });
        showManufacturerAdditionalData(d, serial);
    } else {
    $("#" + minus).attr({ src: "/_images/plus.jpg" });
        showManufacturerAdditionalData(d, serial);
    }
    showHide(license);
}

function showManufacturerAdditionalData(d, serial) {
    var license = "licadt" + d;
    var minus = "licadtmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        if ($('#' + license).html().length == 0) {
            $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(license);
            $("#" + license).load("/mod/licencas/ajax/licManufacturerAdditionalInfo.aspx?sn=" + serial);
        }
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(license);
}

function showAdditionalData(d, serial, sp, spCustomerID) {
    var license = "licadt" + d;
    var minus = "licadtmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        if ($('#' + license).html().length == 0) {
            $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(license);
            if (sp == 1)
                $("#" + license).load("/mod/licencas/ajax/licAdditionalInfo.aspx?sn=" + serial + "&sp=" + sp + "&spCustomerID=" + spCustomerID);
            else
                $("#" + license).load("/mod/licencas/ajax/licAdditionalInfo.aspx?sn=" + serial);
        }
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(license);
}
function showAdditionalPluginData(d, serial, sp, spCustomerID) {
    var license = "licadt" + d;
    var minus = "licadtmin" + d;

    if ($("#" + license).css("display") == "none" || $("#" + license).css("display") == "") {
        if ($('#' + license).html().length == 0) {
            $("#" + minus).attr({ src: "/_images/minus.jpg" });
            addLoading(license);
            if (sp == 1)
                $("#" + license).load("/mod/licencas/ajax/licPluginAdditionalInfo.aspx?sn=" + serial + "&sp=" + sp + "&spCustomerID=" + spCustomerID);
            else
                $("#" + license).load("/mod/licencas/ajax/licPluginAdditionalInfo.aspx?sn=" + serial);
        }
    } else {
        $("#" + minus).attr({ src: "/_images/plus.jpg" });
    }
    showHide(license);
}
function addLoading(div) {
    var divId = document.getElementById(div);
    if (divId) {
        divId.innerHTML = "<img src='/_images/loading.gif' border='0'>";
    }
}

function validateDate(litAlertID, txtBeginDateID, txtEndDateID) {

    var txtBeginDate = document.getElementById(txtBeginDateID);
    var txtEndDate = document.getElementById(txtEndDateID);

    var var1 = validingDate(txtBeginDate, litAlertID);
    if (validingDate(txtEndDate, litAlertID) && var1) {
        $("#" + litAlertID).attr({ value: "" });
    }
}

function validingDate(obj, litAlertID) {

    if (!obj || !obj.value) return true;

    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;

    if (!(obj.value.match(RegExPattern) && obj.value != '')) {

        $("#" + litAlertID).attr({ value: "Data inválida" });
        return false;
    }
    else if (obj.value.length == 8) {

        var value = obj.value.slice(0, 2);
        var new_str = value.concat("/");
        value = obj.value.slice(2, 4);
        new_str = new_str + value + "/";

        value = obj.value.slice(4, 8);
        new_str += value;

        obj.value = new_str;
    }
    return true;
}

function OnlyNumbers(e) {
    if (navigator.appName == "Microsoft Internet Explorer") {
        if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode == 8)) {
            return true;
        } else {
            return false;
        }
    } else {
        if ((e.charCode >= 48 && e.charCode <= 57) || (e.charCode == 0)) {
            return true;
        } else {
            return false;
        }
    }
}

function changeComputerName(campo1, campo2) {
    var newvalue = campo1;
    var fieldname = campo2;

    var fieldname_exp = fieldname.split('_')
    var aidNum = fieldname_exp.length - 1;
    var snNum = fieldname_exp.length - 2;
    var serial = fieldname_exp[snNum];
    var accountid = fieldname_exp[aidNum];

    $.get("/mod/licencas/ajax/licUpdateComputerName.aspx", { sn: serial, aid: accountid, cn: newvalue }, function(data) {
        return data;
    });
}

var rdbClientID = null;
var hdlNameID = null;

function callEventClick(objID, name) {

    if (!objID) return;

    document.getElementById(rdbClientID).checked = true;
    var hdlName = document.getElementById(hdlNameID);
    
    if(hdlName) hdlName.value = name;
       
    $get(objID).click();
}

function setControlsSupportUsers(hdlName, rdbClient) {

    hdlNameID = hdlName;
    rdbClientID = rdbClient;
}

function sendOrder(uid) {
    if (confirm('Deseja continuar? Seu pedido será enviado para faturamento, e você será direcionado(a) para a forma de pagamento selecionada.')) {
        setTimeout('disableButton(\''+uid+'\')', 100);
        return true;
    } else {
        return false;
    }
}

function disableButton(uid) {
    var btn = document.getElementById(uid);
    if (btn)
        btn.disabled = true;
}