﻿function AjaxLoaderBricofichas(type, parentCatalogId, catalogId, target, search, index) {
    var ajaxUrl = 'Ajax/' + type + '.aspx?cid=' + catalogId + '&search=' + search + '&index=' + index;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function(data) {
            $(target).html(data);
            initPopEnc();
            if (type == 'Bricofichas') {
                initTabsPagination('#tabContent'+ index, '#pTabContent'+ index, 4);

            }
            if (type == 'IdeiasSugestoes') {
                initTabsPagination('#secondTabContent'+ index, '#secondpTabContent'+ index, 4);
            }
            if (type == 'Dicas') {
                initTabsPagination('#thirdTabContent'+ index, '#thirdpTabContent'+ index, 4);
            }
            
        }
    });
}

function AjaxLoaderIdeiasAkiHomepage(type, catalogId, target, search, tabid) {
    var ajaxUrl = 'Ajax/' + type + 'Home.aspx?cid=' + catalogId + '&tabid=' + tabid + '&search=' + search;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function (data) {
            $(target).html(data);

            if (type == 'Bricofichas') {
                var highCarr2 = $('#highlightCarrocel2');
                if (highCarr2.length) {
                    carroucelStart2(highCarr2, '#highlightCarrocel2');
                }
                $('#highlightCarrocel2 li').css('height', '184px');
            }
            if (type == 'IdeiasSugestoes') {
                var highCarr3 = $('#highlightCarrocel3');
                if (highCarr3.length) {
                    carroucelStart2(highCarr3, '#highlightCarrocel3');
                }
                $('#highlightCarrocel3 li').css('height', '184px');
            }
            if (type == 'Dicas') {
                var elTips = $('#tips');
                if (elTips.length) {
                    initTipsPagination();
                }
            }
        }
    });
}

function AjaxLoaderNovidades(catalogId, target) {
    var ajaxUrl = 'Ajax/Novidades.aspx?cid=' + catalogId;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function(data) {
            $(target).html(data);
            initTabsPagination(target + ' #tabContent01', target + ' #pTabContent01', 3);
        }
    });
}

function AjaxLoaderPromocoes(catalogId, target, parentcatalogid) {
    var ajaxUrl = 'Ajax/Promocoes.aspx?cid=' + catalogId + '&pcid=' + parentcatalogid;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function(data) {
            $(target).html(data);
            initTabsPagination(target + ' #secondTabContent01', target + ' #secondpTabContent01', 4);
            initPopEnc();
        }
    });
}

function AjaxLoaderMenu(catalogId, target) {
    var ajaxUrl = 'Ajax/Menu.aspx?cid=' + catalogId;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function(data) {
            $(target).html(data);
        }
    });
}
function ajaxloadLatestNews(catalogId, sourceCatalogId,  target) {
    var ajaxUrl = 'Ajax/LatestNews.aspx?cid=' + catalogId + '&scid=' + sourceCatalogId;
    $.ajax({ cache: false,
        url: ajaxUrl,
        success: function (data) {
            if (data != '') {
                $(target).html(data);
                var elHighCarr4 = $('#highlightCarrocel4');
                if (elHighCarr4.length) {
                    elHighCarr4.data('visible', 4);
                    carroucelStart2(elHighCarr4, '#highlightCarrocel4');
                }
            }
            else {
                $('#imgloaderNews').parent('div').parent('div').parent('div').hide();
            }
        },
        error: function () {
            $('#imgloaderNews').parent('div').parent('div').parent('div').hide();
        }
    });
}

function ajaxloadCatalog(catalogId, sourceCatalogId, mo, pgsize, target) {
    var ajaxUrl = 'Ajax/Catalog.aspx?cid=' + catalogId + '&scid=' + sourceCatalogId + '&mo=' + mo + '&pgsize=' + pgsize;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function (data) {
            $(target).html(data);
        },
        error: function () {
            $('#imgloaderCatalog').parent('div').parent('div').parent('div').hide();
        }
    });
}

function ajaxCall(add, newProj, proj, pid) {
    var ajaxUrl = 'Ajax/AddToProject.aspx?add=' + add + "&newProj=" + newProj + "&proj=" + proj + "&pid=" + pid;

    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function (data) {
            if (data != '') {
                $('.modAddInfo2 select').append(data);
            }
        }
    });

    $('.modAddInfo2 input[type=checkbox]').attr('checked', '');
    $('.modAddInfo2 input[type=text]').attr('value', '');
    $('.modAddInfo2').css('display', 'none');
}

function ajaxLoadCatalogPages(parentCatalogId, catalogId, target, index) {
    var ajaxUrl = 'Ajax/CatalogPages.aspx?cid=' + catalogId + '&parentid=' + parentCatalogId + '&pgsize=12&index=' + index;
    $.ajax({ cache:false,
        url: ajaxUrl,
        success: function (data) {
            $(target).html(data);
            initTabsPagination('#tabContent-' + index, '#pTabContent-' + index, 4);
            }
    });
}
