﻿function closeCP(_remains, _count) {
    try {
        for (var i = 1; i <= _count; i++) {
            var _prefix = "";
            if (i.toString().length < 2) _prefix = "0" + i.toString(); else _prefix = i.toString();
            if (_prefix != _remains && !$find("ctl00_cpeMasterContent_cpe_" + _prefix.toString()).get_Collapsed()) {
                $find("ctl00_cpeMasterContent_cpe_" + _prefix.toString())._doClose();
            }
        }
    }
    catch (e) {

    }
    finally {

    }
}

function disableEnter() {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox
    if (key == 13) {
        event.returnValue = false;
        event.cancel = true;
    } 
}

function searchKS(e) {
    if (e.keyCode == 13) {
        var keyword = $(".txtArama").val();
        if (keyword.length >= 2) {
            var searchType;
            if ($('.rbUrunAra:checked').length > 0) {
                searchType = 1;
            }
            if ($('.rbFirmaAra:checked').length > 0) {
                searchType = 2;
            }
            if ($('.rbKategoriAra:checked').length > 0) {
                searchType = 3;
            }
            $.ajax({
                type: "POST",
                url: "Default.aspx/aramaSonuclari",
                data: "{'keyword':'" + keyword + "','aramaTip':'" + searchType + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                success: function(msg) {
                    var islemBilgisi = msg.d;
                    $(".subCategoriesSearch").html("");
                    for (var i = 0; i < islemBilgisi.length; i++) {
                        var classSelector = "class=\"sponsorLink\"";
                        switch (islemBilgisi[i].plan_type) {
                            case 1:
                                classSelector = "class=\"sponsorLink\"";
                                break;
                            case 2:
                                classSelector = "class=\"standartLink\"";
                                break;
                            case 3:
                                classSelector = "class=\"basicLink\"";
                                break;
                            default:
                                break;
                        }
                        switch (searchType) {
                            case 1:
                                $(".subCategoriesSearch").append("<li style=\"width:700px;\"><a " + classSelector + " href=\"" + islemBilgisi[i].country + "-" + islemBilgisi[i].language + "/" +
                                                        islemBilgisi[i].mainCatID + "-" + islemBilgisi[i].mainCatName + "/" +
                                                        islemBilgisi[i].subCatID + "-" + islemBilgisi[i].subCatName + "-1/" +
                                                        islemBilgisi[i].companyID + "-" + islemBilgisi[i].companyName + ".aspx\">" + islemBilgisi[i].shownText + "</a></li>");
                                break;
                            case 2:
                                $(".subCategoriesSearch").append("<li style=\"width:700px;\"><a " + classSelector + " href=\"" + islemBilgisi[i].country + "-" + islemBilgisi[i].language + "/" +
                                                        islemBilgisi[i].mainCatID + "-" + islemBilgisi[i].mainCatName + "/" +
                                                        islemBilgisi[i].subCatID + "-" + islemBilgisi[i].subCatName + "-1/" +
                                                        islemBilgisi[i].companyID + "-" + islemBilgisi[i].companyName + ".aspx\">" + islemBilgisi[i].shownText + "</a></li>");
                                break;
                            case 3:
                                $(".subCategoriesSearch").append("<li><a href=\"" + islemBilgisi[i].country + "-" + islemBilgisi[i].language + "/" +
                                                        islemBilgisi[i].mainCatID + "-" + islemBilgisi[i].mainCatName + "/" +
                                                        islemBilgisi[i].subCatID + "-" + islemBilgisi[i].subCatName + "-1.aspx\">" + islemBilgisi[i].shownText + "</a></li>");
                                break;
                        }
                        var pnlArama = $find("cpe_Arama");
                        pnlArama._expandedSize = (document.getElementById("searchContainer").offsetHeight + 50);
                        if (pnlArama._expandedSize < 250) {
                            pnlArama._expandedSize = 250;
                        }
                        pnlArama._doOpen();
                    }
                }
            });
        }
    }
}


function openCP() {
    try{
        var keyword = $(".txtArama").val();
        if (keyword.length >= 2) {
            var searchType;
            if ($('.rbUrunAra:checked').length > 0) {
                searchType = 1;
            }
            if ($('.rbFirmaAra:checked').length > 0) {
                searchType = 2;
            }
            if ($('.rbKategoriAra:checked').length > 0) {
                searchType = 3;
            }
            $.ajax({
                type: "POST",
                url: "Default.aspx/aramaSonuclari",
                data: "{'keyword':'" + keyword + "','aramaTip':'" + searchType + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: true,
                success: function(msg) {
                    var islemBilgisi = msg.d;
                    $(".subCategoriesSearch").html("");
                    for (var i = 0; i < islemBilgisi.length; i++) {
                        var classSelector = "class=\"sponsorLink\"";
                        switch (islemBilgisi[i].plan_type) {
                            case 1:
                                classSelector = "class=\"sponsorLink\"";
                                break;
                            case 2:
                                classSelector = "class=\"standartLink\"";
                                break;
                            case 3:
                                classSelector = "class=\"basicLink\"";
                                break;
                            default:
                                break;
                        }
                        switch (searchType) {
                            case 1:
                                $(".subCategoriesSearch").append("<li style=\"width:700px;\"><a " + classSelector + " href=\"" + islemBilgisi[i].country + "-" + islemBilgisi[i].language + "/" +
                                                        islemBilgisi[i].mainCatID + "-" + islemBilgisi[i].mainCatName + "/" +
                                                        islemBilgisi[i].subCatID + "-" + islemBilgisi[i].subCatName + "-1/" +
                                                        islemBilgisi[i].companyID + "-" + islemBilgisi[i].companyName + ".aspx\">" + islemBilgisi[i].shownText + "</a></li>");
                                break;
                            case 2:
                                $(".subCategoriesSearch").append("<li style=\"width:700px;\"><a " + classSelector + " href=\"" + islemBilgisi[i].country + "-" + islemBilgisi[i].language + "/" +
                                                        islemBilgisi[i].mainCatID + "-" + islemBilgisi[i].mainCatName + "/" +
                                                        islemBilgisi[i].subCatID + "-" + islemBilgisi[i].subCatName + "-1/" +
                                                        islemBilgisi[i].companyID + "-" + islemBilgisi[i].companyName + ".aspx\">" + islemBilgisi[i].shownText + "</a></li>");
                                break;
                            case 3:
                                $(".subCategoriesSearch").append("<li><a href=\"" + islemBilgisi[i].country + "-" + islemBilgisi[i].language + "/" +
                                                        islemBilgisi[i].mainCatID + "-" + islemBilgisi[i].mainCatName + "/" +
                                                        islemBilgisi[i].subCatID + "-" + islemBilgisi[i].subCatName + "-1.aspx\">" + islemBilgisi[i].shownText + "</a></li>");
                                break;
                        }
                        var pnlArama = $find("cpe_Arama");
                        pnlArama._expandedSize = (document.getElementById("searchContainer").offsetHeight + 50);
                        if (pnlArama._expandedSize < 250) {
                            pnlArama._expandedSize = 250;
                        }
                        pnlArama._doOpen();
                    }
                }
            });
        }
    }
    catch (e) {

    }
    finally {

    }
}

setInterval(RightBannerContainer, 100);

function RightBannerContainer() {
    try {
        document.getElementById('<%=divRightContainer.ClientID %>').style.height = document.getElementById("divLeftContainer").offsetHeight - 2 + 'px';
    }
    catch (e) {

    }
    finally {

    }
}
$(document).ready(function() {
    $("#featured > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 5000, true);
    var watermarkText = $("#txtWatermarkJS").val();
    var keyword = $(".txtArama").val();
    if (keyword != null && keyword != "Aramaya Başlamak İçin Buraya Tıklayınız."
        && keyword != "Detailsuche" && keyword != "Click Here to Start Searching"
        && keyword != "BÚSQUEDA DETALLADA" && keyword != "BÚSQUEDA DETALLADA"
        && keyword != "ΛΕΠΤΟΜΕΡΙΑΚΗ ΕΡΕΥΝΑ" && keyword != "Ricerca Avanzata"
        && keyword != "ДЕТАЛЬНЫЙ ПОИСК") {
        if (keyword.length > 0) {
            openCP();
        }
    }
});

