//COMUN SCRIPTS SECTION

function ShowLoading() {
    var loading = $(".divLoading");
    var grayBox = $(".grayBox");

    var posX = (document.body.clientWidth / 2) - (loading.width() / 2);
    var posY = (document.body.clientHeight / 2) - (loading.height() / 2);

    loading.css("left", posX);
    loading.css("top", posY);
    loading.css("display", "inherit");
    grayBox.css("width", screen.width + "px");
    grayBox.css("height", screen.height + "px");
    grayBox.css("display", "inherit");
    return;
}


function HideLoading() {
    $(document).ready(function () {
        $(".divLoading").css("display", "none");
        var grayBox = $(".grayBox");
        grayBox.css("display", "none");
        grayBox.css("width", "0px");
        grayBox.css("height", "0px");
    });
}

function KeyEnterPress(event, fnAction) {
    var key = event.keyCode | event.which;
    if (key == 13) {
        setTimeout(fnAction, 1);
    }
}

function EnterInSearch(event) {
    var key = event.keyCode | event.which;
    if (key == 13) {
        event.preventDefault();
        $(".btnSearch").click();
    }
}

function PerformClick(idBtn) {
    $(idBtn).click();
}

function ShowAddtinfo(productID) {
    productID = $(productID);
    PageMethods.GetAddtInfo(productID.attr("pn"), (productID.offset().left + productID.width() + 2) + ";" + (productID.offset().top), onSuccessGetAddtInfo);
}

function onSuccessGetAddtInfo(result) {
    if (result.length > 1) {
        var addtInfo = $("#addtInfo");
        var addtInfoMain = $("#addtImain");

        var posX = new Number(result[result.length - 1].split(";")[0]);
        var posY = new Number(result[result.length - 1].split(";")[1]);

        addtInfo.css("left", posX + "px");
        addtInfo.css("top", posY + "px");



        var cont = "";
        for (var i = 0; i < result.length - 1; i++) {
            cont = cont + "&nbsp" + result[i] + "<br/>";
        }
        cont = cont + "<br/>";
        addtInfoMain.attr("innerHTML", cont);
        addtInfo.fadeTo("fast", 1);

    }
    else {
        HiddeAddtInfo();
    }
}

function HiddeAddtInfo() {
    $("#addtInfo").fadeOut("fast");
}


function ShowAddtinfoFB(imageID) {
    var imgFooter = $(imageID);
    PageMethods.GetAddtInfoFB(imgFooter.attr("imn"), (imgFooter.offset().left + imgFooter.width() + 2) + ";" + (imgFooter.offset().top), onSuccessGetAddtInfoFB);

}

function onSuccessGetAddtInfoFB(result) {
    if (result.length > 1) {
        var addtInfoFB = $("#addtInfoFB");
        var addtInfoMainFB = $("#addtImainFB");

        var posX = new Number(result[result.length - 1].split(";")[0]);
        var posY = new Number(result[result.length - 1].split(";")[1]);

        addtInfoFB.css("left", posX + "px");
        addtInfoFB.css("top", posY + "px");



        var cont = "";
        for (var i = 0; i < result.length - 1; i++) {
            cont = cont + "&nbsp" + result[i] + "<br/>";
        }
        addtInfoMainFB.attr("innerHTML", cont);
        addtInfoFB.fadeTo("fast", 1);

    }
    else {
        HiddeAddtInfoFB();
    }
}

function HiddeAddtInfoFB() {
    $("#addtInfoFB").fadeOut("fast");
}

function GetScrollPos(idElement) {
    $("#scrollPosition").attr("value", $(idElement).attr("scrollTop"));
}

function SetScrollPos(idElement) {
    $(document).ready(function () {
        $(idElement).attr("scrollTop", $("#scrollPosition").attr("value"));
    });
}

function ReadOnly(event) {
    event.preventDefault();
}


//END SECTION


//SLICE IMAGE SECTION

function NextImg() {
    areaImages = $("#divImagesCont");
    var fD = areaImages.scrollLeft();

    if (fD > 0) {
        if (((fD / 840) + "").indexOf(".") == -1) {
            areaImages.animate({ scrollLeft: (fD + 840) }, 500);
        }
    }
    else {
        areaImages.animate({ scrollLeft: (fD + 840) }, 500);
    }

    if (fD == ($(".tbImages").width() - areaImages.width())) {
        areaImages.animate({ scrollLeft: (0) }, 300);
    }
}

function PreviousImg() {
    areaImages = $("#divImagesCont");
    var fD = areaImages.scrollLeft();

    if (((fD / 840) + "").indexOf(".") == -1) {
        areaImages.animate({ scrollLeft: (fD - 840) }, 500);
    }
    else {
        if (fD == ($(".tbImages").width() - areaImages.width())) {
            fD = (Math.floor(fD / 840)) * 840;
            areaImages.animate({ scrollLeft: (fD) }, 500);
        }
    }
}

function ShowSlice() {
    $(document).ready(function () {
        $("#divSlice").css("display", "inherit");
    });
}

//END SECTION

//NEWS SCROLL

var speed = 15;

function ScrollNews() {
    var TbScrollContent = $(".ScrollContent");
    var width = TbScrollContent.width();
    var posLeftCont = new Number($("#ScrollContainer").css("left").replace("px", ""));
    var left = new Number(TbScrollContent.css("left").replace("px", ""));

    if (((left - 0) + width) <= posLeftCont) {
        left = $("#ScrollContainer").width();
    }
    else {
        left--;
    }

    TbScrollContent.css("left", left + "px");
    StartScroll();
}

function StartScroll() {
    setTimeout("ScrollNews();", speed);
}

//END


//ECR SECTION

function EnabledECRControls() {
    $(document).ready(function () {
        $('.disabledText').removeClass("disabledText");
        $('.disabledButton').attr("disabled", false);
        $('.disabledButton').attr("value", "GO");
        $('.disabledButton').removeClass("disabledButton");
    });
}

//END SECTION


//FILE MANAGER SECTION
function SetFileToUpload(fileUpload) {
    $(".linkUpload").attr("value", $(fileUpload).attr("value"));
}

function PreUpload() {
    if ($(".linkUpload").attr("value") != "") {
        ShowLoading();
    }
}

function PreviewDocImg(url, elementId) {
    var item = $(elementId).attr("selectedIndex");
    if (item > -1) {
        var url = url + "/" + $(elementId).attr("value");
        window.open(url);
    }
}

function RemoveDocImg(elementId) {
    var item = $(elementId).attr("selectedIndex");
    if (item > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            $(".btnDel").click();
        }
    }
}

function PreviewImag(imageName, ext) {

    if (ext != null) {
        imageName = imageName + ext;
    }

    var src = "Abamaster/WebImages/" + imageName;
    $("#imgPreview").attr("src", src);
}

//END SECTION


//PRODUCTS CATEGORIES SECTION

function PrepareToAddCateg() {
    ClearCateg();
    $("#infoAction").attr("innerHTML", "ADDING CATEGORY");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditCateg() {
    ClearCateg();
    var index = $(".listCateg").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetCategToEdit(index, OnSuccesPrepareToEditCateg);
    }
}

function OnSuccesPrepareToEditCateg(result) {
    $(".textNameCateg").attr("value", result[0]);
    $(".dropDownImgCateg").attr("value", result[1]);
    $(".checkEDCateg").attr("checked", result[2]);

    $("#infoAction").attr("innerHTML", "EDITING CATEGORY");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}


function RemoveCateg() {
    var index = $(".listCateg").attr("selectedIndex");
    if (index > -1) {
        var categName = $(".currentCateg").attr("value");
        PageMethods.CanDeleteCateg(categName, OnSuccesCanDeleteCateg);
    }
}

function OnSuccesCanDeleteCateg(result) {
    if (result) {
        GoToRemoveCateg();
    }
    else {
        alert("this category cannot be deleted because it is still associated products.      To remove it you must delete all associated products first.");
    }
}

function GoToRemoveCateg() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        var index = $(".listCateg").attr("selectedIndex");
        PageMethods.RemoveCateg(index, OnSuccessRemoveCateg);
    }
}

function OnSuccessRemoveCateg(result) {
    $(".btnDelCateg").click();
}

function ClearCateg() {
    $(".textNameCateg").attr("value", "");
    $(".dropDownImgCateg").attr("selectedIndex", 0);
    $(".checkEDCateg").attr("checked", true);
    $(".divAcction").css("display", "none");
}


function SelectTypeLink(radio) {
    var radioCateg = $("#RadioCateg");
    var radioFile = $("#RadioFile");
    var radioOther = $("#RadioOther");
    var dropCateg = $(".DropDownCateglink");
    var dropLink = $(".DropDownLink");
    var dropDoc = $(".dropDownDoc");
    var linkOther = $(".txtOtherLink");

    try { dropCateg.attr("selectedIndex", 0); } catch (err) { }
    dropLink.attr("selectedIndex", 0);
    linkOther.attr("value", "");

    switch ($(radio).attr("ID")) {

        case "RadioCateg":
            radioCateg.css("checked", true);
            radioFile.attr("checked", false);
            radioOther.attr("checked", false);
            linkOther.css("display", "none");
            dropLink.css("display", "none");
            dropDoc.css("display", "none");
            dropCateg.css("display", "inherit");
            break;

        case "RadioFile":
            radioFile.attr("checked", true);
            radioOther.attr("checked", false);
            try {
                radioCateg.attr("checked", false);
                dropCateg.css("display", "none");
            } catch (err) { }
            linkOther.css("display", "none");
            dropLink.css("display", "inherit");
            dropDoc.css("display", "inherit");
            break;

        case "RadioOther":
            radioOther.attr("checked", true);
            radioFile.attr("checked", false);
            dropDoc.css("display", "none");
            try {
                radioCateg.attr("checked", false);
                dropCateg.css("display", "none");
            } catch (err) { }
            dropLink.css("display", "none");
            linkOther.css("display", "inherit");
            break;
    }
}


function PrepareToAddProduc() {
    if ($(".DropDownPCateg").attr("selectedIndex") > -1) {
        ClearProd();
        $("#infoActionP").attr("innerHTML", "ADDING PRODUCT");
        $(".divPreviewImg").css("display", "none");
        $(".divAcction").css("display", "inherit");
        $(".currentAction").attr("value", "Add");
        SelectTypeLink($("#RadioFile"));
    }
}

function PrepareToEditProduct() {
    ClearProd();
    $(".divPreviewImg").css("display", "none");
    var index = $(".ListProd").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetProdToEdit(index, OnSuccesPrepareToEditProduct);
    }
}

function OnSuccesPrepareToEditProduct(result) {
    $(".DropDownImgProd").attr("value", result[0]);
    $(".DropDownImgProd").attr("disabled", true);
    var link = result[1];
    $(".checkEDProd").attr("checked", result[2]);
    var typeLink = result[3];

    if (typeLink == 0) {
        $(".DropDownLink").attr("value", link);
    }
    else {
        SelectTypeLink($("#RadioOther"));
        $(".txtOtherLink").attr("value", link);
    }

    $("#infoActionP").attr("innerHTML", "EDITING PRODUCT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function GoToRemoveProd() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        var index = $(".ListProd").attr("selectedIndex");
        PageMethods.RemoveProd(index, OnSuccesRemoveProd);
    }
}


function OnSuccesRemoveProd() {
    $(".btnDelProd").click();
}

function ClearProd() {
    SelectTypeLink("RadioFile");
    $(".checkEDProd").attr("checked", true);
    $(".divAcction").css("display", "none");
    $(".divPreviewImg").css("display", "");
}



function SelectTypeLinkAddtInfo(radio) {
    var radioFile = $("#RadioAddtInfoFile");
    var radioOther = $("#RadioAddtInfoOther");
    var dropLink = $(".DropDownLinkAddtinfo");
    var linkOther = $(".txtOtherLinkAddtInfo");

    dropLink.attr("selectedIndex", 0);
    linkOther.attr("value", "");

    switch ($(radio).attr("ID")) {

        case "RadioAddtInfoFile":
            radioFile.attr("checked", true);
            radioOther.attr("checked", false);
            linkOther.css("display", "none");
            dropLink.css("display", "inherit");
            break;

        case "RadioAddtInfoOther":
            radioOther.attr("checked", true);
            radioFile.attr("checked", false);
            dropLink.css("display", "none");
            linkOther.css("display", "inherit");
            break;
    }
}


function PrepareToAddAddt() {
    if ($(".DropDownProdAddtInfo").attr("selectedIndex") > -1) {
        ClearAddt();
        $("#infoActionAddtInfo").attr("innerHTML", "ADDING ADDITIONAL INFO");
        $(".divAcction").css("display", "inherit");
        $(".currentAction").attr("value", "Add");
        SelectTypeLinkAddtInfo($("#RadioAddtInfoFile"));
    }
}

function PrepareToEditAddt() {
    ClearAddt();
    var index = $(".ListBoxAddtInfo").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetAddtToEdit(index, OnSuccesPrepareToEditAddt);
    }
}

function OnSuccesPrepareToEditAddt(result) {
    $(".txtAddtInfo").attr("value", result[0]);
    var link = result[1];
    $(".checkEDAddtInfo").attr("checked", result[2]);
    var typeLink = result[3];

    if (typeLink == 0) {
        $(".DropDownLinkAddtinfo").attr("value", link);
    }
    else {
        SelectTypeLinkAddtInfo($("#RadioAddtInfoOther"));
        $(".txtOtherLinkAddtInfo").attr("value", link);
    }

    $("#infoActionAddtInfo").attr("innerHTML", "EDITING ADDITIONAL INFO");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveAddt() {
    var index = $(".ListBoxAddtInfo").attr("selectedIndex");
    if (index > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            PageMethods.RemoveAddt(index, OnSuccesRemoveAddt);
        }
    }
}

function OnSuccesRemoveAddt() {
    $(".btnDelAddt").click();
}


function ClearAddt() {
    SelectTypeLinkAddtInfo("RadioAddtInfoFile");
    $(".txtAddtInfo").attr("value", "");
    $(".checkEDAddtInfo").attr("checked", true);
    $(".divAcction").css("display", "none");
}

//END SECTION


//WEB MAIN MENU SECTION

function SetlinkMenu(selector) {
    var selector = $(selector);
    var typeLink = "";

    switch (selector.attr("className").replace("txtBox ", "")) {
        case "DropDownCateglink":
            typeLink = "[[C";
            break;
        case "DropDownLink":
            typeLink = "[[F";
            break;
        case "txtOtherLink":
            typeLink = "[[O";
            break;

    }
    $(".txtLink").attr("value", "");
    var selectorValue = selector.attr("value");
    $(".txtLink").attr("value", selector.attr("value") + typeLink);
}



function PrepareToAddMM() {
    ClearMM();
    $("#infoActionMM").attr("innerHTML", "ADDING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
    $(".DropDownCateglink").attr("selectedIndex", 0);
    $("#RadioCateg").attr("checked", true);
}

function PrepareToEditMM() {
    ClearMM();
    var values = $(".hiddenCurrentNode").attr("value").split("_EV_");
    $('.DropDownListTarget').attr("value", values[3]);


    if (values[0] != "null") {

        var typeLink = values[1].split("[[")[1];
        var txtLink = $(".txtLink");
        txtLink.attr("value", values[1].replace(values[0] + '_N_', ''));
        var realLink = txtLink.attr("value").replace("[[" + typeLink, '');
        $(".textNameMM").attr("value", values[0]);
        $(".checkMMProd").attr("checked", true);

        if (values[2] == "False") {
            $(".checkMMProd").attr("checked", false);
        }

        $("#infoActionMM").attr("innerHTML", "EDITING ELEMENT");
        $(".currentAction").attr("value", "Edit");
        $(".divAcction").css("display", "inherit");

        switch (typeLink) {
            case "C":
                SelectTypeLink("#RadioCateg");
                $(".DropDownCateglink").attr("value", realLink);
                break;
            case "F":
                SelectTypeLink("#RadioFile");
                $(".DropDownLink").attr("value", realLink);
                break;
            case "O":
                SelectTypeLink("#RadioOther");
                $(".txtOtherLink").attr("value", realLink);
                break;
            default:
                SelectTypeLink("#RadioFile");
                break;

        }
    }
    else {
        $(".divAcction").css("display", "inherit");
    }

}

function PrepareToDelMM() {
    var values = $(".hiddenCurrentNode").attr("value").split("_EV_");
    if (values[0] != "null") {
        if (confirm("Are you sure you want to delete the category and all its subcategories?")) {
            ShowLoading();
            ClearMM();
            $(".btnMDel").click();
        }
    }
}

function ClearMM() {
    SelectTypeLink($("#RadioCateg"));
    $(".textNameMM").attr("value", "");
    $(".checkMMProd").attr("checked", true);
    $(".divAcction").css("display", "none");
}

//END SECTION

//INFO BOXES SECTION

function PrepareToAddIB() {
    ClearIB();
    $("#infoActionIB").attr("innerHTML", "ADDING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
    $(".DropDownCateglink").attr("selectedIndex", 0);
    $(".DropDownLink").attr("selectedIndex", 0);
    $("#RadioCateg").attr("checked", true);
}

function PrepareToEditIB() {
    ClearIB();
    if ($(".listInfoB").attr("selectedIndex") > -1) {
        var values = $(".listInfoB").attr("value").split("_N_");
        var typeLink = values[1].split("[[")[1];
        $(".txtNameIB").attr("value", values[0]);
        $("#infoActionIB").attr("innerHTML", "EDITING ELEMENT");
        $(".currentAction").attr("value", "Edit");
        $(".divAcction").css("display", "inherit");
        $(".txtLink").attr("value", values[1]);
        var realLink = $(".txtLink").attr("value").replace("[[" + typeLink, '');

        switch (typeLink) {
            case "C":
                SelectTypeLink("#RadioCateg");
                $(".DropDownCateglink").attr("value", realLink);
                break;
            case "F":
                SelectTypeLink("#RadioFile");
                $(".DropDownLink").attr("value", realLink);
                break;
            case "O":
                SelectTypeLink("#RadioOther");
                $(".txtOtherLink").attr("value", realLink);
                break;
            default:
                SelectTypeLink("#RadioFile");
                break;
        }
    }
}

function PrepareToDelIB() {
    if ($(".listInfoB").attr("selectedIndex") > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            ClearIB();
            $(".btnIBDel").click();
        }
    }
}

function ClearIB() {
    SelectTypeLink($("#RadioCateg"));
    $(".txtNameIB").attr("value", "");
    $(".divAcction").css("display", "none");
}

//END SECTION


//FOOTER BANNER SECTION

function SetLinkAddtInfoFB(idSelector) {
    var selectorImg = $(idSelector);
    var index = selectorImg.attr("selectedIndex");
    if (index > -1) {
        var imgName = $(selectorImg[0][index]).attr("innerHTML");
        $("#addtInfoFB").attr("href", "FootBAddtInfo.aspx?ci='" + imgName + "'");
    }
    else {
        $("#addtInfoFB").attr("href", "#");
    }
    PreviewImag(imgName);
}

function SelectTypeLinkFB(radio) {
    var radioCateg = $("#RadioCategFB");
    var radioFile = $("#RadioFileFB");
    var radioOther = $("#RadioOtherFB");
    var dropCateg = $(".DropDownCateglinkFB");
    var dropLink = $(".DropDownLinkFB");
    var linkOther = $(".txtOtherLinkFB");

    try { dropCateg.attr("selectedIndex", 0); } catch (err) { }
    dropLink.attr("selectedIndex", 0);
    linkOther.attr("value", "");

    switch ($(radio).attr("ID")) {

        case "RadioCategFB":
            radioCateg.css("checked", true);
            radioFile.attr("checked", false);
            radioOther.attr("checked", false);
            linkOther.css("display", "none");
            dropLink.css("display", "none");
            dropCateg.css("display", "inherit");
            break;

        case "RadioFileFB":
            radioFile.attr("checked", true);
            radioOther.attr("checked", false);
            try {
                radioCateg.attr("checked", false);
                dropCateg.css("display", "none");
            } catch (err) { }
            linkOther.css("display", "none");
            dropLink.css("display", "inherit");
            break;

        case "RadioOtherFB":
            radioOther.attr("checked", true);
            radioFile.attr("checked", false);
            try {
                radioCateg.attr("checked", false);
                dropCateg.css("display", "none");
            } catch (err) { }
            dropLink.css("display", "none");
            linkOther.css("display", "inherit");
            break;
    }
}


function SetlinkMenuFB(selector) {
    var selector = $(selector);
    var typeLink = "";

    switch (selector.attr("className").replace("txtBox ", "")) {
        case "DropDownCateglinkFB":
            typeLink = "[[C";
            break;
        case "DropDownLinkFB":
            typeLink = "[[F";
            break;
        case "txtOtherLinkFB":
            typeLink = "[[O";
            break;

    }
    $(".txtLink").attr("value", "");
    var selectorValue = selector.attr("value");
    $(".txtLink").attr("value", selector.attr("value") + typeLink);
}


function PreviewImg() {
    var index = $(".ListBoxFootBanner").attr("selectedIndex");
    if (index > -1) {
        var imgName = $($(".ListBoxFootBanner")[0][index]).attr("innerHTML");
        window.open("http://www.abamaster.com/Abamaster/WebImages/" + imgName);
    }
}

function PrepareToAddFB() {
    ClearFB();
    $("#infoActionFB").attr("innerHTML", "ADDING ELEMENT");
    $(".divPreviewImg").css("display", "none");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
    $(".DropDownCateglinkFB").attr("selectedIndex", 0);
    $(".DropDownLinkFB").attr("selectedIndex", 0);
    //$("#RadioCategFB").attr("checked", true);
    $("#RadioFileFB").attr("checked", true);
}


function PrepareToEditFB() {
    ClearFB();
    $(".divPreviewImg").css("display", "none");
    if ($(".ListBoxFootBanner").attr("selectedIndex") > -1) {
        var values = $(".ListBoxFootBanner").attr("value").split("_N_");
        var typeLink = values[1].split("[[")[1];
        $(".DropDownImgFB").attr("value", values[0]);
        $("#infoActionFB").attr("innerHTML", "EDITING ELEMENT");
        $(".currentAction").attr("value", "Edit");
        $(".divAcction").css("display", "inherit");
        $(".txtLink").attr("value", values[1]);
        var realLink = $(".txtLink").attr("value").replace("[[" + typeLink, '');

        switch (typeLink) {
            case "C":
                SelectTypeLinkFB("#RadioCategFB");
                $(".DropDownCateglinkFB").attr("value", realLink);
                break;
            case "F":
                SelectTypeLinkFB("#RadioFileFB");
                $(".DropDownLinkFB").attr("value", realLink);
                break;
            case "O":
                SelectTypeLinkFB("#RadioOtherFB");
                $(".txtOtherLinkFB").attr("value", realLink);
                break;
            default:
                SelectTypeLinkFB("#RadioFileFB");
                break;
        }
    }
}

function PrepareToDelFB() {
    if ($(".ListBoxFootBanner").attr("selectedIndex") > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            ClearFB();
            $(".btnDelFB").click();
        }
    }
}

function ClearFB() {
    SelectTypeLinkFB("#RadioCategFB");
    $(".DropDownImgFB").attr("selectedIndex", 0);
    $(".divAcction").css("display", "none");
    $(".divPreviewImg").css("display", "");
}

//END SECTION


//MORE LESSS SECTION

//este funcion solo se utiliza para reajestar el scroll al seleccionar una categoria cuando se tiene el product category
//configurado para que se expanda al cargar la pagina, si no no es nesesaria esta funcion
function CalculateDivCategHeigth(idMoreLess) {
    var divMoreLess = $("#" + idMoreLess);
    var divCont = divMoreLess.find(".divContent");
    var intHeight = divCont.find(".divInternalContent").height() + 15;
    return intHeight;
}

function MoreLess(idMoreLess) {
    var divMoreLess = $("#" + idMoreLess);
    var btn = divMoreLess.find(".btnMoreLess");
    var divCont = divMoreLess.find(".divContent");
    var intHeight = divCont.find(".divInternalContent").height() + 15;

    if (intHeight >= 190) {
        if (btn.attr("innerHTML") == "BROWSE MORE ▼") {
            divCont.animate({ height: intHeight }, 500);
            btn.attr("innerHTML", "BROWSE LESS ▲");
        }
        else {
            divCont.animate({ height: '184' }, 500);
            btn.attr("innerHTML", "BROWSE MORE ▼");
        }
    }
}

//END SECTION

//SECTION E-NEWS CUSTOMER

function RemoveEnewsCustomer(custID) {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".currentID").attr("value", custID);
        $(".RemECust").click();
    }
}

function GenerateEnewsCustomerList() {
    window.open("ENewsCustomerList.aspx");
}

//END SECTION


//SECTION CUSTOMERS

function OnlyNumber(event) {
    var key = event.which;
    if ((key < 48 || key > 57) && key != 8 && key != 40 && key != 41 && key != 45 && key != 0 && key != 99 && key != 118 && key != 0 && key != 32) {
        event.preventDefault();
    }
}

function OnBlurTxtNumber(idText, defaultValue) {
    var text = $(idText);
    if (defaultValue == null)
        var defaultValue = "0";

    if (text.attr("value").length == 0) {
        text.attr("value", defaultValue);
    }
}

function ShowLoadinAddEditCustomer() {
    //if ($(".textCompany").attr("value").length > 0 && $(".validatorEmail").attr("isvalid")) {
    if ($(".textCompany").attr("value").length > 0) {
        ShowLoading();
    }
}

function RemoveCustomer(idCust) {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".currentID").attr("value", idCust);
        $(".btnRem").click();
    }
}

function EditCustomer(idCust) {
    $(".currentID").attr("value", idCust);
    $(".btnEdit").click();
}

function LabelCustomer(idCust) {
    window.open("LabelPage.aspx?cid=" + idCust);
}


function GenerateCustomerList() {
    window.open("CustomerList.aspx");
}

function FilterByLetter(letter) {
    ShowLoading();
    $(".currentLetter").attr("value", letter);
    $(".btnLoadByLetter").click();
}
function SetSelecteLretter(letter) {
    $(document).ready(function () {
        $("#" + letter).css("font-size", "22px");
        $("#" + letter).css("font-weight", "bolder");
    });
}

function GoToFullInfo(idCust) {
    window.open("CustomerFullInfo.aspx?cid=" + idCust);
}

function NavigateTo(url, inPage) {
    if (inPage == null) {
        window.open(url);
    }
    else {
        window.location.href = url;
    }
}

function PrintUserInfo() {
    $("#btnPrint").css("display", "none");
    $("#btnClose").css("display", "none");
    window.print();
    $("#btnPrint").css("display", "inline");
    $("#btnClose").css("display", "inline");
}

//END SECTION


//SECTION BUSINESS TYPE

function ShowLoadingBT() {
    if ($(".textBusinessT").attr("value").length > 0 && $(".RequiredBusinessT").attr("isvalid")) {
        ShowLoading();
    }
}

function PrepareToAddBusinessT() {
    ClearBusinessT();
    $("#infoActionBT").attr("innerHTML", "ADDING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditBusinessT() {
    ClearBusinessT();
    var selectedIndex = $(".listBusinessT").attr("selectedIndex");
    $(".textBusinessT").attr("value", $($(".listBusinessT")[0][selectedIndex]).attr("innerHTML"));
    $("#infoActionBT").attr("innerHTML", "EDITING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveBusinessT() {
    var selectedIndex = $(".listBusinessT").attr("selectedIndex");
    if (selectedIndex > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            var id = $($(".listBusinessT")[0][selectedIndex]).attr("Value");
            $(".listBusinessT")[0].options.remove(selectedIndex);
            PageMethods.RemoveBusinessType(id, OnSuccessRemoveBusinessType);
        }
    }
}

function OnSuccessRemoveBusinessType() {
    HideLoading();
}

function SaveBusinessType() {
    ShowLoading();
    var listBussiness = $(".listBusinessT");
    var count = listBussiness[0].length;
    var business = new Array();

    for (var i = 0; i < count; i++) {
        business[i] = ($(listBussiness[0][i]).attr("value"));
    }

    PageMethods.SaveBusinessType(business, onSucessSaveBusinessType);
}

function onSucessSaveBusinessType() {
    HideLoading();
}

function ClearBusinessT() {
    $(".textBusinessT").attr("value", "");
    $(".divAcction").css("display", "none");
}


//END SECTION


//SECTION HOME FUNCTIONS

function ClickLink(imgLink) {
    var link = $(imgLink).attr("link");
    window.open(link);
}


function GoToCategorie(selectedCateg) {
    var selectedCateg = $(selectedCateg).attr("title");
    $(".hiddenSelectCateg").attr("value", selectedCateg);
    $(".selectCateg").click();
}

function GoToRPCategorie(selectedRPCateg) {
    var selectedRPCateg = $(selectedRPCateg).attr("title");
    $(".hiddenSelectRPCateg").attr("value", selectedRPCateg);
    $(".selectRPCateg").click();
}


function ScrollToSelectedCateg() {
    $(document).ready(function () {
        var divP1 = $("#divP1");

        //esta linea es nesesaria para reajustar el scroll cuando se pone que el product category se expanda al cargar la pagina
        //si no se pone el product category a expandirce al cargar la pagina no es necesatio CalculateDivCategHeigth("divCateg") - 184
        //solo con divP1.offset().top es suficiente.
        var pos = divP1.offset().top + CalculateDivCategHeigth("divCateg") - 184;

        $('html,body').animate({ scrollTop: pos }, 800);
        $("#divMoreLessHeadSelected").css("background-color", "#d8251d");
        setTimeout("MoreLess('divP1');", 600);
    });
}

function HideCategSection(idSection) {
    $(document).ready(function () {
        $(idSection).css("display", "none");
    });

}

//END SECTION



//CP USERS SECTION

function PrepareToAddCPUser() {
    ClearCPUser();
    $("#infoAction").attr("innerHTML", "ADDING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditCPUser() {
    ClearCPUser();
    var index = $(".listUsers").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetCPUserToEdit(index, OnSuccesPrepareToEditCPUser);
    }
}

function OnSuccesPrepareToEditCPUser(result) {
    $(".textUserName").attr("value", result[0]);
    $(".textPassword").attr("value", result[1]);
    $(".checkAdmin").attr("checked", result[2]);

    $("#infoAction").attr("innerHTML", "EDITING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveCPUser() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".btnDelUser").click();
    }
}

function ClearCPUser() {
    $(".textUserName").attr("value", "");
    $(".textPassword").attr("value", "");
    $(".checkAdmin").attr("checked", true);
    $(".divAcction").css("display", "none");
}

//END SECTION

//SECTION CATALOG

function PreviewImgCatalog(nameImg) {
    window.open("Abamaster/WebImages/" + nameImg);
}

function GenerateCatalog() {
    window.open("CatalogPage.aspx");
}

//ENDSECTION


//SECTION PRICE LIST

function OnlyMoney(event, idText) {
    var key = event.which;
    var countP = $(idText).attr("value").indexOf(".");
    var countC = $(idText).attr("value").indexOf(",");
    if ((key < 48 || key > 57) && key != 8 && key != 46 && key != 0) {
        event.preventDefault();
    }
    else if (key == 46 && countP > -1 && countC > -1) {
        event.preventDefault();
    }
}

function OnBlurTxtDecimal(idText, defaultValue) {
    var text = $(idText);
    if (defaultValue == null)
        var defaultValue = "0";

    if (text.attr("value").length == 0) {
        text.attr("value", defaultValue);
    }
}

function RemovePrice(idPrice) {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".currentID").attr("value", idPrice);
        $(".btnRem").click();
    }
}

function EditPrice(idCust) {
    $(".currentID").attr("value", idCust);
    $(".btnEdit").click();
}

function SelectDeselectFields(fields, select) {
    for (var i = 0; i < fields.length; i++) {
        $(fields[i]).attr("checked", select);
    }
}

function GoToFullInfoPrice(idPrice) {
    window.open("PriceFullInfo.aspx?cid=" + idPrice);
}

function PrintUserInfo() {
    $("#btnPrint").css("display", "none");
    $("#btnClose").css("display", "none");
    window.print();
    $("#btnPrint").css("display", "inline");
    $("#btnClose").css("display", "inline");
}

//END SECTION

//MANUFACTURER SECTION

function ShowLoadingMF() {
    if ($(".textManufacturer").attr("value").length > 0 && $(".RequiredManufacturer").attr("isvalid")) {
        ShowLoading();
    }
}

function PrepareToAddManufacturer() {
    ClearManufacturer();
    $("#infoActionMF").attr("innerHTML", "ADDING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditManufacturer() {
    ClearManufacturer();
    var selectedIndex = $(".listManufacturer").attr("selectedIndex");
    $(".textManufacturer").attr("value", $($(".listManufacturer")[0][selectedIndex]).attr("innerHTML"));
    $("#infoActionMF").attr("innerHTML", "EDITING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveManufacturer() {
    var selectedIndex = $(".listManufacturer").attr("selectedIndex");
    if (selectedIndex > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            var id = $($(".listManufacturer")[0][selectedIndex]).attr("Value");
            $(".listManufacturer")[0].options.remove(selectedIndex);
            PageMethods.RemoveManufacturer(id, OnSuccessRemoveManufacturer);
        }
    }
}

function OnSuccessRemoveManufacturer() {
    HideLoading();
}

function ClearManufacturer() {
    $(".textManufacturer").attr("value", "");
    $(".divAcction").css("display", "none");
}

//END SECTION

//SECTION NFCPRODCATEG

function ShowLoadingNCFPC() {
    if ($(".textNCFProdCateg").attr("value").length > 0 && $(".RequiredNCFProdCateg").attr("isvalid")) {
        ShowLoading();
    }
}

function PrepareToAddNCFProdCateg() {
    ClearNCFProdCateg();
    $("#infoActionPC").attr("innerHTML", "ADDING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditNCFProdCateg() {
    ClearNCFProdCateg();
    var selectedIndex = $(".listNCFProdCateg").attr("selectedIndex");
    $(".textNCFProdCateg").attr("value", $($(".listNCFProdCateg")[0][selectedIndex]).attr("innerHTML"));
    $("#infoActionPC").attr("innerHTML", "EDITING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveNCFProdCateg() {
    var selectedIndex = $(".listNCFProdCateg").attr("selectedIndex");
    if (selectedIndex > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            var id = $($(".listNCFProdCateg")[0][selectedIndex]).attr("Value");
            $(".listNCFProdCateg")[0].options.remove(selectedIndex);
            PageMethods.RemoveProdCateg(id, OnSuccessRemoveProdCateg);
        }
    }
}

function OnSuccessRemoveProdCateg() {
    HideLoading();
}

function ClearNCFProdCateg() {
    $(".textNCFProdCateg").attr("value", "");
    $(".divAcction").css("display", "none");
}

//ENDSECTION

//SECTION MATERIAL CATEGORY

function ShowMatCost() {
    var selectedIndex = $(".listNCFMatCateg").attr("selectedIndex");
    $("#txtMCost").attr("innerHTML", $($(".listNCFMatCateg")[0][selectedIndex]).attr("value").split("|")[1]);
}

function ShowLoadingNCFMC() {
    if ($(".textNCFMatCateg").attr("value").length > 0 && $(".RequiredNCFMatCateg").attr("isvalid")) {
        ShowLoading();
    }
}

function PrepareToAddNCFMatCateg() {
    ClearNCFMatCateg();
    $("#infoActionMC").attr("innerHTML", "ADDING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditNCFMatCateg() {
    ClearNCFMatCateg();
    var selectedIndex = $(".listNCFMatCateg").attr("selectedIndex");
    $(".textNCFMatCateg").attr("value", $($(".listNCFMatCateg")[0][selectedIndex]).attr("innerHTML"));
    $(".textMatCost").attr("value", $($(".listNCFMatCateg")[0][selectedIndex]).attr("value").split("|")[1]);
    $("#infoActionMC").attr("innerHTML", "EDITING ELEMENT");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveNCFMatCateg() {
    var selectedIndex = $(".listNCFMatCateg").attr("selectedIndex");
    if (selectedIndex > -1) {
        if (confirm("Are you sure you want to delete the selected item?")) {
            ShowLoading();
            var id = $($(".listNCFMatCateg")[0][selectedIndex]).attr("Value");
            $(".listNCFMatCateg")[0].options.remove(selectedIndex);
            PageMethods.RemoveMatCateg(id, OnSuccessRemoveMatCateg);
        }
    }
}

function OnSuccessRemoveMatCateg() {
    HideLoading();
}

function ClearNCFMatCateg() {
    $(".textNCFMatCateg").attr("value", "");
    $(".textMatCost").attr("value", "");
    $(".divAcction").css("display", "none");

}

//ENDSECTION

//SECTION NCFILES

function ShowMaterialCost() {
    var selectedIndex = $(".DropDownListMatCategory").attr("selectedIndex");
    $(".textMatCost").attr("value", $($(".DropDownListMatCategory")[0][selectedIndex]).attr("value").split("|")[1]);
    CalculateNCFCost();
}

function RemoveNCFile(idNCfile) {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".currentID").attr("value", idNCfile);
        $(".btnRem").click();
    }
}

function EditNCFile(idNCFile) {
    $(".currentID").attr("value", idNCFile);
    $(".btnEdit").click();
}

function AddEditNCFAddtInfo(idNCFile) {
    $(".currentID").attr("value", idNCFile);
    $(".btnAddtInfo").click();
}

function GoToFullInfoNCFile(idNCFile) {
    window.open("AbbaNCFileFullInfo.aspx?cid=" + idNCFile, '', 'width=905,height=625,toolbar=0,resizable=1');
}

function GoToNCFileAddtInfo(idNCFile) {
    window.open("NCFileAdditionalInfo.aspx?cid=" + idNCFile, '', 'width=905,height=625,toolbar=0,resizable=1');
}

function PrepareToAddNCFileUser() {
    ClearNCFileUser();
    $("#infoAction").attr("innerHTML", "ADDING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditNCFileUser() {
    ClearNCFileUser();
    var index = $(".listUsers").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetNCFileUserToEdit(index, OnSuccesPrepareToEditNCFileUser);
    }
}

function OnSuccesPrepareToEditNCFileUser(result) {
    $(".textUserName").attr("value", result[0]);
    $(".textPassword").attr("value", result[1]);

    $("#infoAction").attr("innerHTML", "EDITING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveNCFileUser() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".btnDelUser").click();
    }
}

function ClearNCFileUser() {
    $(".textUserName").attr("value", "");
    $(".textPassword").attr("value", "");
    $(".divAcction").css("display", "none");
}

function CalculateNCFCost() {
    var blankSizeW = $(".textBlankSizeW").attr("value");
    var blankSizeD = $(".textDepth").attr("value");
    var materialCost = $(".textMatCost").attr("value");
    var quantity = $(".textQtyUnit").attr("value");

    PageMethods.CalculateNCFCost(blankSizeW, blankSizeD, materialCost, quantity, OnSuccessCalculateNCFCost);
}

function OnSuccessCalculateNCFCost(result) {
    $(".textMaterialUse").attr("value", result[0]);
    $(".textmatUseTotal").attr("value", result[1]);
    $(".textMetalPCost").attr("value", result[2]);
    $(".textQtyUnit").attr("value", result[3]);
}

function CalculateTotalNCFCost() {
    var partCost = $(".lbTotalPartCost").attr("innerHTML");
    var labor = $(".textLabor").attr("value");
    var overhead = $(".textOverHead").attr("value");
    var freigth = $(".textFreight").attr("value");
    var netPrice = $(".textNetPrice").attr("value");

    PageMethods.CalculateTotalNCFCost(partCost, labor, overhead, freigth, netPrice, OnSuccessCalculateTotalNCFCost);
}

function OnSuccessCalculateTotalNCFCost(result) {
    $(".lbLabor").attr("innerHTML", result[0]);
    $(".lbOverhead").attr("innerHTML", result[1]);
    $(".lbFreigth").attr("innerHTML", result[2]);
    $(".lbNetPrice").attr("innerHTML", result[3]);
    $(".lbTotaltotalPartCost").attr("innerHTML", result[4]);
    $(".lbTotalNetPriceList").attr("innerHTML", result[5]);
}

function SavePercentValues() {
    ShowLoading();
    var labor = $(".textLabor").attr("value");
    var overhead = $(".textOverHead").attr("value");
    var freigth = $(".textFreight").attr("value");
    var netPrice = $(".textNetPrice").attr("value");
    PageMethods.SavePercentValues(labor, overhead, freigth, netPrice, OnSuccessSavePercentValues);
}

function OnSuccessSavePercentValues() {
    HideLoading();
}

//END SECTION

//SECTION NCFILE PARTS

function ShowHiddeAddNCFMetalPart(action) {
    var selectedIndex = $(".listProducts").attr("selectedIndex");
    $(".textQtyNCFMetalparts").attr("value", "1");
    $(".divParts").css("display", "none");

    if (selectedIndex > -1) {
        if (action == "show") {
            $(".divMetalParts").css("display", "inherit");
            $(".currentAction").attr("value", "1");
        }
    }
    if (action != "show") {
        $(".divMetalParts").css("display", "none");
    }
}


function ShowHiddeAddNCFPart(action) {
    var selectedIndex = $(".listProducts").attr("selectedIndex");
    $(".textQtyNCFparts").attr("value", "1");
    $(".divMetalParts").css("display", "none");

    if (selectedIndex > -1) {
        if (action == "show") {
            $(".divParts").css("display", "inherit");
            $(".currentAction").attr("value", "1");
        }
    }
    if (action != "show") {
        $(".divParts").css("display", "none");
    }
}

function PrepareToEditpart(partID, typePart) {
    $(".curentPartData").attr("value", partID + "|" + typePart);
    $(".btnLoadPartToEdit").click();
}

function RemovePart(idNCFpart) {
    if (confirm("Are you sure you want to remove the selected part?")) {
        ShowHiddeAddNCFPart("hide");
        ShowLoading();
        $(".currentNcfPartID").attr("value", idNCFpart);
        $(".btnRemNCFpart").click();
    }
}

//ENSECTION


//SECTION DEALER DISTRIBUTORS

function PrepareToAddDalerDist() {
    ClearDealerList();
    $("#infoActionDD").attr("innerHTML", "ADDING DEALER DISTRIBUTOR");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
    SelectTypeLink($("#RadioFile"));
}

function PrepareToEditDalerDist() {
    ClearDealerList();
    var index = $(".listDealerDist").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetDealerDistEdit(index, OnSuccesPrepareToEditDalerDist);
    }
}

function OnSuccesPrepareToEditDalerDist(result) {
    var link = result[1];
    $(".checkEDDealerDist").attr("checked", result[2]);
    var typeLink = result[3];

    if (typeLink == 0) {
        $(".dropDownDoc").attr("value", link);
    }
    else {
        SelectTypeLink($("#RadioOther"));
        $(".txtOtherLink").attr("value", link);
    }

    $('.textName').attr("value", result[0])
    $("#infoActionDD").attr("innerHTML", "EDITING DEALER DISTRIBUTOR");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}


function RemoveDalerDist() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        var index = $(".listDealerDist").attr("selectedIndex");
        PageMethods.RemoveDalerDist(index, OnSuccessRemoveDalerDist);
    }
}

function OnSuccessRemoveDalerDist(result) {
    $(".btnDelDealerDist").click();
}

function ClearDealerList() {
    $(".dropDownDoc").attr("selectedIndex", 0);
    $('.textName').attr("value", "");
    $(".checkEDDealerDist").attr("checked", true);
    $(".divAcction").css("display", "none");
}

function GotoAddEditDealerDist() {
    if ($('.textName').attr("value").length > 0) {
        ShowLoading();
    }

    $('.btnAddEditDealerDist').click();
}



function PrepareToAddDealerDistUser() {
    ClearDealerDistUser();
    $("#infoAction").attr("innerHTML", "ADDING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditDealerDistUser() {
    ClearDealerDistUser();
    var index = $(".listUsers").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetDealerDistUserToEdit(index, OnSuccesPrepareToEditDealerDistUser);
    }
}

function OnSuccesPrepareToEditDealerDistUser(result) {
    $(".textUserName").attr("value", result[0]);
    $(".textPassword").attr("value", result[1]);

    $("#infoAction").attr("innerHTML", "EDITING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveDealerDistUser() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".btnDelUser").click();
    }
}

function ClearDealerDistUser() {
    $(".textUserName").attr("value", "");
    $(".textPassword").attr("value", "");
    $(".divAcction").css("display", "none");
}


//END SECTION


//VENDORS SECTION

function PrepareToAddVendor() {
    ClearVendor();
    $("#infoActionV").attr("innerHTML", "ADDING ABAMASTER VENDOR");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
    SelectTypeLink($("#RadioFile"));
}

function PrepareToEditVendor() {
    ClearVendor();
    var index = $(".listVendors").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetVendorEdit(index, OnSuccesPrepareToEditVendor);
    }
}

function OnSuccesPrepareToEditVendor(result) {
    var link = result[1];
    $(".checkEVendor").attr("checked", result[2]);
    var typeLink = result[3];

    if (typeLink == 0) {
        $(".dropDownDoc").attr("value", link);
    }
    else {
        SelectTypeLink($("#RadioOther"));
        $(".txtOtherLink").attr("value", link);
    }

    $('.textName').attr("value", result[0])
    $("#infoActionV").attr("innerHTML", "EDITING ABAMASTER VENDOR");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}


function RemoveVendor() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        var index = $(".listVendors").attr("selectedIndex");
        PageMethods.RemoveVendor(index, OnSuccessRemoveVendor);
    }
}

function OnSuccessRemoveVendor(result) {
    $(".btnDelVendor").click();
}

function ClearVendor() {
    $(".dropDownDoc").attr("selectedIndex", 0);
    $('.textName').attr("value", "");
    $(".checkEVendor").attr("checked", true);
    $(".divAcction").css("display", "none");
}

function GotoAddEditVendor() {
    if ($('.textName').attr("value").length > 0) {
        ShowLoading();
    }

    $('.btnAddEditVendor').click();
}


function PrepareToAddVendorUser() {
    ClearVendorUser();
    $("#infoAction").attr("innerHTML", "ADDING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditVendorUser() {
    ClearVendorUser();
    var index = $(".listUsers").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetVendorUserToEdit(index, OnSuccesPrepareToEditVendorUser);
    }
}

function OnSuccesPrepareToEditVendorUser(result) {
    $(".textUserName").attr("value", result[0]);
    $(".textPassword").attr("value", result[1]);

    $("#infoAction").attr("innerHTML", "EDITING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveVendorUser() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".btnDelUser").click();
    }
}

function ClearVendorUser() {
    $(".textUserName").attr("value", "");
    $(".textPassword").attr("value", "");
    $(".divAcction").css("display", "none");
}


//END SECTION


//SECTION NOTES

function PrepareToAddEmails() {
    ClearEmails();
    $("#infoActionEmails").attr("innerHTML", "ADDING EMAIL");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditEmails() {
    ClearEmails();
    var index = $(".listEmails").attr("selectedIndex");
    if (index > -1) {
        var email = $($(".listEmails")[0]).attr("value");
        $(".textEmail").attr("value", email);
        $("#infoActionEmails").attr("innerHTML", "EDITING EMAIL");
        $(".divAcction").css("display", "inherit");
        $(".currentAction").attr("value", "Edit");
    }
}

function RemoveEmail() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        var index = $(".listEmails").attr("selectedIndex");
        PageMethods.RemoveEmail(index, OnSuccessRemoveEmail);
    }
}

function OnSuccessRemoveEmail(result) {
    $(".btnDelEmail").click();
}

function ClearEmails() {
    $(".textEmail").attr("value", "");
    $(".divAcction").css("display", "none");
}


function PrepareToAddNotesUser() {
    ClearNotesUser();
    $("#infoAction").attr("innerHTML", "ADDING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
}

function PrepareToEditNotesUser() {
    ClearNotesUser();
    var index = $(".listUsers").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetNotesUserToEdit(index, OnSuccesPrepareToEditNotesUser);
    }
}

function OnSuccesPrepareToEditNotesUser(result) {
    $(".textUserName").attr("value", result[0]);
    $(".textPassword").attr("value", result[1]);

    $("#infoAction").attr("innerHTML", "EDITING USER");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveNotesUser() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        $(".btnDelUser").click();
    }
}

function ClearNotesUser() {
    $(".textUserName").attr("value", "");
    $(".textPassword").attr("value", "");
    $(".divAcction").css("display", "none");
}

function CheckNotesStatus() {
    if ($('.NotesStatus').attr("value") == 1) {
        if (confirm("You have not saved the changes you made. Do you want to save before closing?")) {
            $('.btnSave').click();
        }
    }
}

function SetNotesStatus(status) {
    $('.NotesStatus').attr("value", status);
}


//END SECTION


//SECTION NEWS

function PrepareToAddNew() {
    ClearNew();
    $("#infoActionNews").attr("innerHTML", "ADDING ABAMASTER NEW");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Add");
    SelectTypeLink($("#RadioFile"));
}

function PrepareToEditNew() {
    ClearNew();
    var index = $(".listNews").attr("selectedIndex");
    if (index > -1) {
        PageMethods.GetNewEdit(index, OnSuccesPrepareToEditNew);
    }
}

function OnSuccesPrepareToEditNew(result) {
    var link = result[1];
    $(".checkENews").attr("checked", result[2]);
    var typeLink = result[3];

    if (typeLink == 0) {
        $(".dropDownDoc").attr("value", link);
    }
    else {
        SelectTypeLink($("#RadioOther"));
        $(".txtOtherLink").attr("value", link);
    }

    $('.textName').attr("value", result[0])
    $("#infoActionNews").attr("innerHTML", "EDITING ABAMASTER NEW");
    $(".divAcction").css("display", "inherit");
    $(".currentAction").attr("value", "Edit");
}

function RemoveNew() {
    if (confirm("Are you sure you want to delete the selected item?")) {
        ShowLoading();
        var index = $(".listNews").attr("selectedIndex");
        PageMethods.RemoveNew(index, OnSuccessRemoveNew);
    }
}

function OnSuccessRemoveNew(result) {
    $(".btnDelNew").click();
}

function ClearNew() {
    $(".dropDownDoc").attr("selectedIndex", 0);
    $('.textName').attr("value", "");
    $(".checkENews").attr("checked", true);
    $(".divAcction").css("display", "none");
}

function GotoAddEditNew() {
    if ($('.textName').attr("value").length > 0) {
        ShowLoading();
    }

    $('.btnAddEditNew').click();
}

//END SECTION

//INVOICES SECTION

function GetPageScrollPos() {
    var scrollPos = $(document).scrollTop();
    $(".PageScrollPos").attr("value", scrollPos)
    ShowLoading();
}

function SetPageScrollPos() {
    var scrollPos = $(".PageScrollPos").attr("value");
    $(document).scrollTop(scrollPos);
}

function Calculate(txtQtyID, priceEachID, textAmountID) {
    var qty = $(txtQtyID).attr("value");
    var price = $($(priceEachID)[0]).attr("value");

    var amount = (qty * price).toFixed(2);
    $(textAmountID).attr("value", amount);

    var controlsAmount = $(".AmountColl").children();
    var total = 0.00;

    for (var i = 0; i < controlsAmount.length; i++) {
        if ($(controlsAmount[i]).attr("type") == "text") {
            total += new Number($(controlsAmount[i]).attr("value"));
        }
    }

    $(".lbTotal").attr("value", "$ " + total.toFixed(2));
}

//END INVOICES
