﻿if (typeof (index1024_showdate) == 'undefined') index1024_showdate = '';
if (typeof (User_index1024_showdate) == 'undefined') User_index1024_showdate = '';
var qs = (function (a) {
    if (a == "") return {};
    var b = {};
    for (var i = 0; i < a.length; ++i) {
        var p = a[i].split('=');
        if (p.length != 2) continue;
        b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    }
    return b;
})(window.location.search.substr(1).split('&'));
function GetDateObject(_date) {
    if (_date == null) return null;
    var _date = _date.replace(/\/Date\((.*?)\)\//gi, '$1');
    var date = new Date();
    date.setTime(_date)
    return date;
}
function GetDate(_date) {
    if (_date == null) return null;
    var _date = _date.replace(/\/Date\((.*?)\)\//gi, '$1');
    var date = new Date();
    date.setTime(_date)
    _date = date.getFullYear() + '-' + (parseInt(date.getMonth()) + 1) + '-' + date.getDate();
    return _date + ' ' + date.getHours() + ':' + date.getMinutes();
}
function SizeToString(size) {
    size = parseInt(size);
    if (size > 1024 * 1024 * 1024) return  Math.round(size / (1024 * 1024 * 1024)) + "GB";
    if (size > 1024 * 1024) return Math.round(size / (1024 * 1024)) + "MB";
    if (size > 1024) return Math.round(size / 1024) + "KB";
    return size+"B" ;
}
 
 
//GTP(GetDate(data.d.Rows[i].RegisterDate), true)
function isNullOrEmpty(p) {
    return ((p == undefined) || (p == '') || (p == null));
}
function getThisOrAlt(p, alt) {
    if (isNullOrEmpty(alt)) alt = '';
    return isNullOrEmpty(p) ? alt : p;
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
            ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function CheckMail(email) {
    if (email == '') return true;
    var filter = /^https?:\/\/(www\.|ftp\.)?([a-zA-Z0-9\-]{1,}\.)*([a-zA-Z0-9\-]{1,})\.([a-zA-Z0-9\-]{1,})+\/?.*$/;
    if (filter.test(email)) return true;
    else return false;
}

function CheckColor(value) {
    var filter = /^\#|#[0-9aAbBcCdDeEfF]{6}/;
    if (filter.test(value)) return true;
    else return false;
}
function CheckNumber(value) {
    var filter = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
    if (filter.test(String(value))) return true;
    else return false;
}
function PComma(nStr) {
    nStr += '';
    nStr = nStr.replace(/,/gi, '');
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
function commafy(val1, val2) {
    val1 = val1.replace(/,/gi, '');
    val2 = val2.replace(/,/gi, '');
    var StringVal1 = String(val1).split("").reverse().join("")
                      .replace(/(.{3}\B)/g, "$1,")
                      .split("").reverse().join("");
    var StringVal2 = String(val2).split("").reverse().join("")
                      .replace(/(.{3}\B)/g, "$1,")
                      .split("").reverse().join("");
    $('.statistic').find('span[id$=Count]:first').html(StringVal1);
    $('.statistic').find('span[id$=Count]:last').html(StringVal2);
}

$(document).ready(function () {
    $('.setcolor li').click(function () {
        var TColor = $(this).attr('ColorID');
        setCookie('tebclr', TColor, null);
        GoToServer('/WebServices/Page/PageService.asmx/SetSkin', { skin: TColor }, function (data) {
            if (data != null && data.d != null) {
                if (onsuccess != null) { onsuccess(data.d.Items); }
            }
        }, null, true);
        LoadCssTebMain(GCN(TColor));
        if (typeof (LoadCssTebBox) == 'function') LoadCssTebBox(GCN(TColor));
        $('.mainwindow').removeClass().addClass('mainwindow' + ' ' + GCN(TColor))
    });
    $('.btnsearch').click(function () {
        var parts = $('.linkbox').find('.activep').attr("SID");
        if (parts != '-1')
            document.location.href = 'http://tebyan.net/newindex.aspx?pid=19608&keyword=' + $('.inputsearch').val() + '&parts=' + parts;
        else document.location.href = 'http://www.tebyan.net/newindex.aspx?pid=43316&keyword=' + $('.inputsearch').val();
    });
    $('.inputsearch').keypress(function (e) {
        if (e.keyCode == 13) { $('.btnsearch').click(); return false; }
    });

    var StatusSetting = false;
    var StatusLanB = false;
    var StatusILogin = false;
    $('.InputLogin .InputVIL').focus(function () {
        $(this).addClass('SelectedVIL');
    }).blur(function () { $(this).removeClass('SelectedVIL') });

    $('.NextIco,.BackIco').live('click', function () {
        $(this).click(function () {
            stayOpen();
        })
    })
    $('.TabI .MainItems,.TabII .MainItems,.TabGallery .TabItems').click(function () {
        stayOpen();
    })
    function stayOpen() {
        if ($('.subsetting').css('display') == 'block') {
            StatusSetting = true;
            $('.subsetting').show();
        }
        if ($('.ValuesLB').css('display') == 'block') {
            StatusLanB = true;
            $('.ValuesLB').show();
        }
        if ($('.InputLogin').css('display') == 'block') {
            StatusILogin = true;
            $('.InputLogin').show();
            setCookie('StatusILogin', StatusILogin, null);
        }
    };
    $('.setting').click(function () {
        $(this).siblings('.subsetting').slideToggle();
        StatusSetting = true;
    })
    $('.subsetting').click(function () {
        $(this).show();
        StatusSetting = true;
    })
    $('.ValuesLB').click(function () {
        $(this).show();
        StatusLanB = true;
    })


    $('body').click(function () {
        if (StatusSetting != true)
            $('.subsetting').slideUp();
        StatusSetting = false;
        if (StatusLanB != true)
            $('.ValuesLB').slideUp();
        StatusLanB = false;
        if (StatusILogin != true)
            $('.InputLogin').slideUp();
        StatusILogin = false;
        setCookie('StatusILogin', StatusILogin, null);
    });

    $(document).keydown(function (e) {
        if (e.keyCode == 27) {
            if (StatusSetting != true)
                $('.subsetting').slideUp();
            StatusSetting = false;
            if (StatusLanB != true)
                $('.ValuesLB').slideUp();
            StatusLanB = false;
            if (StatusILogin != true)
                $('.InputLogin').slideUp();
            StatusILogin = false;
            setCookie('StatusILogin', StatusILogin, null);
        }
    });

    if ($('.userinfo').css('display') == 'block')
        $('.InputLogin').slideUp();
    StatusILogin = false;
    var GetCookieLGN = getCookie('StatusILogin');
    if ((GetCookieLGN != '') && (GetCookieLGN == 'true')) $('.InputLogin').show();

    var StatusLanB = false;
    $('.TitleLB,.ArrowLB').click(function () {
        $(this).siblings('.ValuesLB').slideToggle();
        StatusLanB = true;
    });
    $('.LogIn').live('click', function () {
        if ($('.InputLogin').css('display') == 'block') {
            $('.InputLogin').slideUp();
            StatusILogin = true;
        }
        else {
            $('.InputLogin').slideDown();
            StatusILogin = false;
            setCookie('StatusILogin', true, null);
        }

    });
    $('.CloseIL').click(function () {
        $('.InputLogin').slideUp();
        StatusILogin = false;
        setCookie('StatusILogin', StatusILogin, null);
    });
    $('.InputLogin').click(function () {
        $(this).show();
        StatusILogin = true;
    });

    $('.itemslb .rpnl').live('click',function () {
        $(this).find('.pointer').fadeIn().closest('.rpnl').addClass('activep').siblings('.rpnl').find('.pointer').fadeOut().closest('.rpnl').removeClass('activep');
    })

});
function Paging1024(Way, Paging1024Object, obj) {
    $(Paging1024Object.btnNext).unbind('click');
    $(Paging1024Object.btnBack).unbind('click');
    $this = $(Paging1024Object.DataPanel.split(' ')[0]);
    var np = $this.find('.NewPanel');

    $('.Destination').removeClass('Destination');
    np.html('<img class="loadingimage" src="http://img.tebyan.net/MainParts/Persian/Thesarus/Tcore/loading.gif"/>');
    np.show();
    var Width = Paging1024Object.Width;
    var right = '-' + Width + 'px';
    var Newright = Width + 'px';
    if (Way == 'Back') { right = Width + 'px'; Newright = '-' + Width + 'px'; }

    np.css({ 'right': right });

    np.animate({ 'right': '0px' }, Paging1024Object.RateAnimate, null,
                        function () { $(this).removeClass("NewPanel").addClass('Current'); }
                        ).addClass('Destination');

    $this.find('.Current').css({ 'right': 0 });
    $this.find('.Current').animate({ 'right': Newright }, Paging1024Object.RateAnimate, null, function () {
        $(this).removeClass("Current").addClass('NewPanel');
    });

    GetPageIndex(Way, Paging1024Object);

    GetBoxTebyan(Paging1024Object, function (data) {
        $(Paging1024Object.DataPanel).empty();
        $("#" + Paging1024Object.jTemplateID).tmpl(data).prependTo(Paging1024Object.DataPanel);
        np.html($(Paging1024Object.DataPanel).html());

        setTimeout(function () {
            $(Paging1024Object.btnNext).one('click', function () { Paging1024("Next", Paging1024Object, obj); });
            $(Paging1024Object.btnBack).one('click', function () { Paging1024("Back", Paging1024Object, obj); });
            if (Paging1024Object.OnSuccess != null) { Paging1024Object.OnSuccess(data); }
        }, Paging1024Object.RateAnimate - 100);

    }, true);
}
function GetPageIndex(Way, Paging1024Object) {
    var RowCount = Paging1024Object.RowCount;
    var PageIndex = Paging1024Object.PageIndex;
    var PageSize = Paging1024Object.PageSize;
    if (Way == 'Back') {
        var _temp = Math.floor(RowCount / PageSize);
        var __temp = 1;
        if (RowCount % PageSize != 0) __temp = 0;

        if (PageIndex <= 0) {
            PageIndex = _temp - __temp;
        }
        else PageIndex--;
    }
    else {
        var _temp = Math.floor(RowCount / PageSize);
        var __temp = 0;
        if (RowCount % PageSize != 0) __temp = 1;
        if (PageIndex < _temp + __temp - 1) {
            PageIndex++;
        }
        else PageIndex = 0;
    }
    //Paging1024Object.PageIndex = PageIndex;
    Paging1024Object.setPageIndex(PageIndex);
    //return Paging1024Object;
}

function GetBannerTebyan(drpPart, drpLanguage, drpCreationType, onsuccess, ispaging) {
    if (qs['BoxID'] == null || qs['BoxID'] == '' || qs['BoxID'] == 'undefined') {
        GoToServer('/WebServices/Page/PageService.asmx/GetBanner', { drpPart: drpPart, drpLanguage: drpLanguage, drpCreationType: drpCreationType, PageSize: ispaging, PageIndex: 0, showDate: index1024_showdate }, function (data) {
            if (data != null && data.d != null) {
                if (onsuccess != null) { onsuccess(data.d.Items); }
            }
        }, null, true);
    }
}
var RequestArray1024 = [];
function SetRequestBox(BoxObject, onsuccess, ispaging, loading) {
    if (typeof (BoxObject) != 'object') {
        if (qs['BoxID'] == null || qs['BoxID'] == '' || qs['BoxID'] == 'undefined' ||
        parseInt(qs['BoxID']) == parseInt(BoxObject)
        ) {
            RequestArray1024.push({ BoxObject: false, BoxID: BoxObject, PageSize: ispaging, PageIndex: 0, Onsuccess: onsuccess });
        }
    }
    else
        if (qs['BoxID'] == null || qs['BoxID'] == '' || qs['BoxID'] == 'undefined' ||
        parseInt(qs['BoxID']) == BoxObject.BoxID
        ) {
            RequestArray1024.push({ BoxObject: BoxObject, BoxID: BoxObject.BoxID, PageSize: BoxObject.PageSize, PageIndex: BoxObject.PageIndex, Onsuccess: onsuccess });
        }
}
function StartSendRequest() {
    var array1024 = new Array();
    for (k = 0; k < RequestArray1024.length; ++k) {
        array1024[k] = '{UDate:"' + User_index1024_showdate + '", ShowDate: "' + index1024_showdate + '",  BoxID: ' + RequestArray1024[k].BoxID + ', PageSize: ' + RequestArray1024[k].PageSize + ', PageIndex: ' + RequestArray1024[k].PageIndex + ' }';
    }
    GoToServer('/WebServices/Page/PageService.asmx/GetBoxs', '{ request: [' + array1024.join(',') + '] }', function (data) {
        try {
            if (data != null && data.d != null) {

                for (y = 0; y < data.d.length; ++y) {
                    if (data.d[y]) {
                        if (typeof (RequestArray1024[y].BoxObject) == 'object') {
                            var $this = $(RequestArray1024[y].BoxObject.DataPanel.split(' ')[0]);
                            $("#" + RequestArray1024[y].BoxObject.jTemplateID).tmpl(data.d[y].Items).prependTo(RequestArray1024[y].BoxObject.DataPanel);
                            $this.find('.Current').html($(RequestArray1024[y].BoxObject.DataPanel).html());
                            if (data.d[y].RowCount == null) data.d[y].RowCount = 15;
                            RequestArray1024[y].BoxObject.SetRowCount(data.d[y].RowCount);
                        }
                        //ListBoxesWithDate.push(data.d[y]);
                        if (data.d[y] != null && data.d[y].IsActive == false) {
                            HiddenBox1024(data.d[y].BoxID);
                        }
                        else if (RequestArray1024[y].Onsuccess != null) { RequestArray1024[y].Onsuccess(data.d[y].Items, data.d[y]); }
                    }
                    //else alert(y);
                }

            }
        }
        catch (ex) { }

    }, null, true);
}
//var ListBoxesWithDate = [];

function GetBoxTebyan(BoxObject, onsuccess, ispaging, loading) {

    if (typeof (BoxObject) != 'object') {
        if (qs['BoxID'] == null || qs['BoxID'] == '' || qs['BoxID'] == 'undefined' ||
        parseInt(qs['BoxID']) == parseInt(BoxObject)
        ) {

            GoToServer('/WebServices/Page/PageService.asmx/GetBox', { UDate: User_index1024_showdate, ShowDate: index1024_showdate, BoxID: BoxObject, PageSize: ispaging, PageIndex: 0 }, function (data) {
                if (data != null && data.d != null) {
                    //ListBoxesWithDate.push(data.d);
                    if (data.d.IsActive == false) {
                        HiddenBox1024(BoxObject);
                    }
                    else if (onsuccess != null) { onsuccess(data.d.Items, data.d); }
                }
            }, loading, true);
        }
    }
    else
        if (qs['BoxID'] == null || qs['BoxID'] == '' || qs['BoxID'] == 'undefined' ||
        parseInt(qs['BoxID']) == BoxObject.BoxID
        ) {
            GoToServer('/WebServices/Page/PageService.asmx/GetBox', { UDate: User_index1024_showdate, ShowDate: index1024_showdate, BoxID: BoxObject.BoxID, PageSize: BoxObject.PageSize, PageIndex: BoxObject.PageIndex }, function (data) {
                if (data != null && data.d != null) {
                    //ListBoxesWithDate.push(data.d);
                    if (data.d.IsActive == false && typeof (HiddenBox1024) == 'function') {
                        HiddenBox1024(BoxObject.BoxID);
                    }
                    else {
                        if (ispaging == null) {
                            var $this = $(BoxObject.DataPanel.split(' ')[0]);
                            $("#" + BoxObject.jTemplateID).tmpl(data.d.Items).prependTo(BoxObject.DataPanel);
                            $this.find('.Current').html($(BoxObject.DataPanel).html());
                            if (data.d.RowCount == null) data.d.RowCount = 15;
                            BoxObject.SetRowCount(data.d.RowCount);
                        }
                        if (onsuccess != null) { onsuccess(data.d.Items, data.d); }
                    }
                }

            }, loading, true);
        }
}
// JScript source code


