﻿function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}
function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}
function getMyCookies() {
    var i, x, y, ARRcookies = document.cookie.split(";");
    var res = new Array();
    var c = 0;
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x.indexOf("urHidenDivID__") == 0) {
            res[c] = unescape(y);
            c++;
        }
    }
    if (res.length == 0)
        return "";
    else
        return res+",";
}
function advAjax(divId, ResponserUrl, request) {
    $.ajax({
        type: 'POST',
        url: ResponserUrl,
        data: request,
        cache: false,
        success: function(data) {
            $('#' + divId).append(data);
            $("#trFlashOverLay").hide();
            $("#ImgAndTxtPartOverLay").hide();
            $("#TxtPartOverLay").hide();
            checkDashLine();
        }
    })
}
function checkDashLine() {
        document.getElementById("tr1").style.display = "none";
        document.getElementById("tr2").style.display = "none";
        var c1 = 0, c2 = 0, c3 = 0;
        if (document.getElementById(_trFlashID) != null)
            c1 = document.getElementById(_trFlashID).getElementsByTagName("div").length;
        if (document.getElementById("ImgAndTxtPart") != null)
            c2 = document.getElementById("ImgAndTxtPart").getElementsByTagName("div").length;
        if (document.getElementById("OnlyTxtPart") != null)
            c3 = document.getElementById("OnlyTxtPart").getElementsByTagName("div").length;

        if (c1>1 && c2>1)
            document.getElementById("tr1").style.display = "block";

        if (c2>1 && c3>1)
            document.getElementById("tr2").style.display = "block";

        if (c1>1 && c3>1 && c2==1)
            document.getElementById("tr1").style.display = "block";
}

function initAdvAjax(divId, ResponserUrl, request) {
    $.ajax({
        type: 'POST',
        url: ResponserUrl,
        data: request,
        cache: false,
        success: function(data) {
            $('#' + divId).html(data);
            $("#trFlashOverLay").hide();
            $("#ImgAndTxtPartOverLay").hide();
            $("#TxtPartOverLay").hide();
           // checkDashLine();
        }
    })
}
function colorize(advType) {
    if (advType == 1) {
        $("td[advT1=true]").each(function(i) {
            $(this).removeClass();
            if (i % 2 == 0) {
                $(this).addClass("bkadver");
            }
            else {
                $(this).addClass("bkadverGray");
            }
        })
    }
    if (advType == 2) {
        $("td[advT2=true]").each(function(i) {
            $(this).removeClass();
            if (i % 2 == 0) {
                $(this).addClass("EvenRowTxtAdv");
            }
            else {
                $(this).addClass("OddRowTxtAdv");
            }
        })
    }
}
function GetWideContainer() {
    TopCode = "0";
    MiddleCode = "0";
    BottomCode = "0";
    if ($("#TopBigAdvContainer").exists())
        TopCode = "1";
    if ($("#MiddleAdvContainer").exists())
        MiddleCode = "1";
    if ($("#BottomAdvContainer").exists())
        BottomCode = "1";
    return TopCode + MiddleCode + BottomCode;
}
function ResetClosableDives() {
    $('div[IsGeneratedCloseBtnDiv=true]').each(function() { $(this).remove() });
    $('div[closeable=true]').each(function() {
        var StayCloseCookie = getCookie("urHidenDivID__" + jQuery(this).attr("id4stayClose"));
        if (StayCloseCookie != null && StayCloseCookie != "") {
            $(this).remove();
        }
        var closeDiv = document.createElement("div");
        $(closeDiv).attr("IsGeneratedCloseBtnDiv", "true");
        $(closeDiv).css({ width: 15, height: 16, backgroundImage: 'url(' + _glHomePagePathUrl + 'img/CloseButton.png)', cursor: 'pointer', backgroundRepeat: 'no-repeat' });
        $(closeDiv).mouseover(function() {
            $(this).css({ backgroundPosition: '0px -16px' });
        });
        $(closeDiv).mouseleave(function() {
            $(this).css({ backgroundPosition: '0px 0px' });
        });
        $(closeDiv).bind('click', { currentDiv: this }, function(event) {
            $(this).hide();
            eval(jQuery(event.data.currentDiv).attr("afterClose"));
            jQuery(event.data.currentDiv).slideUp(200, function() {
                $(this).remove();
                $("#ImgAndTxtPartOverLay").height($("#ImgAndTxtPart").height());
                $("#TxtPartOverLay").height($("#OnlyTxtPart").height());
                $("#trFlashOverLay").height($("#" + _trFlashID).height());
            });


            var StayCloseCookie = getCookie("urHidenDivID__" + jQuery(event.data.currentDiv).attr("id4stayClose"));
            id4StayClose = jQuery(event.data.currentDiv).attr("id4stayClose");
            if (id4StayClose != null && id4StayClose != "") {
                setCookie("urHidenDivID__" + jQuery(event.data.currentDiv).attr("id4stayClose"), id4StayClose, 3);
            }
        });
        content = $(this).html();
        MainDiv = document.createElement("div");
        $(MainDiv).html(content);
        $(this).html("");
        $(MainDiv).appendTo($(this));
        $(MainDiv).css({ position: 'relative' });
        $(this).addClass('CloseableDiv');
        $(closeDiv).css({ position: 'absolute', top: 0, left: 0 });
        $(closeDiv).hide();
        $(this).bind('mouseover', { closeBtn: jQuery(closeDiv) }, function(event) { event.data.closeBtn.show(); $(this).removeClass("CloseableDiv").addClass("CloseableDivHover") });
        $(this).bind('mouseout', { closeBtn: jQuery(closeDiv) }, function(event) { event.data.closeBtn.hide(); $(this).removeClass("CloseableDivHover").addClass("CloseableDiv") });
        $(closeDiv).appendTo($(this));
    });
}
function AdvLoader(AdvType) {
    if (AdvType == 0) {
        $("#trFlashOverLay").fadeTo(1000, 0.75, function() {
            str = "";
            $("div[advDiv=true]").each(function() {
                str += $(this).attr("id4stayClose") + ",";
            })
            str += "0";
            advAjax(_trFlashID, _glHomePagePathUrl + "AjaxResponsers/advLoader.aspx", { cookies: getMyCookies().toString() + str, advType: "0", PageType: _PageType });
        });
    }
    if (AdvType == 1) {
        $("#ImgAndTxtPartOverLay").fadeTo(1000, 0.75, function() {
            str = "";
            $("div[advDiv=true]").each(function() {
                str += $(this).attr("id4stayClose") + ",";
            })
            str += "0";
            advAjax("ImgAndTxtPart", _glHomePagePathUrl + "AjaxResponsers/advLoader.aspx", { cookies: getMyCookies().toString() + str, advType: "1", PageType: _PageType });
        });
    }
    if (AdvType == 2) {
        $("#TxtPartOverLay").fadeTo(1000, 0.75, function() {
            str = "";
            $("div[advDiv=true]").each(function() {
                str += $(this).attr("id4stayClose") + ",";
            })
            str += "0";
            advAjax("OnlyTxtPart", _glHomePagePathUrl + "AjaxResponsers/advLoader.aspx", { cookies: getMyCookies().toString() + str, advType: "2", PageType: _PageType });
        });
    }
}
function WideAdvLoader(Container, AdvType) {
    str = "";
    $("div[advDiv=true]").each(function() {
        str += $(this).attr("id4stayClose") + ",";
    })
    str += "0";

    if (!(AdvType)) {
        AdvType = "";
    }

    if (Container == 0) {
        advAjax("TopBigAdvContainer", _glHomePagePathUrl + "AjaxResponsers/WideAdvLoader.aspx", { cookies: getMyCookies().toString() + str, AdvContainer: Container.toString(), advType: AdvType.toString(), PageType: _PageType });
    }
    else if (Container == 1) {
        advAjax("MiddleAdvContainer", _glHomePagePathUrl + "AjaxResponsers/WideAdvLoader.aspx", { cookies: getMyCookies().toString() + str, AdvContainer: Container.toString(), advType: AdvType.toString(), PageType: _PageType });
    }
    else if (Container == 2) {
        advAjax("BottomAdvContainer", _glHomePagePathUrl + "AjaxResponsers/WideAdvLoader.aspx", { cookies: getMyCookies().toString() + str, AdvContainer: Container.toString(), advType: AdvType.toString(), PageType: _PageType });
    }

}
function AdvEmptyHandler() {
    if ($("#" + _trFlashID + " div[advDiv=true]").length == 0) {
        $("#tblFlash").hide();
        $("#tr1").hide();
    }
    else {
        $("#tblFlash").show();
        $("#tr1").show();
    }
    if ($("#ImgAndTxtPart div[advDiv=true]").length == 0) {
        $("#tblImgAndTxt").hide();
        $("#tr2").hide();
    }
    else {
        $("#tblImgAndTxt").show();
        $("#tr2").show();
    }
    if ($("#OnlyTxtPart div[advDiv=true]").length == 0) {
        $("#tblOnlyText").hide();
        $("#tr2").hide();
        $("#tblOnlyText").nextUntil(':not(br)').remove();
        $("#tblOnlyText").nextUntil(':not(br)').remove();
    }
    else {
        $("#tblOnlyText").show();
        $("#tr2").show();
    }
    if ($("#trFlashOverLay").css("display") == "none" && $("#TxtPartOverLay").css("display") == "none" && $("#ImgAndTxtPartOverLay").css("display") == "none" && $("div[advDiv=true]").length == 0) {
        $("#tblAdvHeader").hide();
        $("#tblOnlyText").hide();
        $("#tblImgAndTxt").hide();
        $("#tr2").hide();
        $("#tblFlash").hide();
        $("#tr1").hide();
        $("#tblOnlyText").nextUntil(':not(br)').remove()
    }
}




(function($) {
    var timers = new Array();
    var methods = {
        myContainer: null,
        init: function() {
            ///=========
            (jQuery)(methods.myContainer).children().each(function(index) {
                jQuery(this).hide();
                if (index == 0)
                    jQuery(this).show();
            });
            if (methods.myContainer.children().length > 0)
                methods.myContainer.show();
            var x = (jQuery)(methods.myContainer);
            clearInterval(timers[methods.myContainer.attr("id")]);
            //alert(methods.myContainer.attr("id"));
            timers[methods.myContainer.attr("id")] = setInterval(function() { methods.action(x) }, 5000);
            ///=========
        },
        action: function(Container) {
            ElementNo = Container.children().length;
            curentShowIndex = 0;
            Container.children().each(function(index) {
                if (jQuery(this).is(":visible")) {
                    curentShowIndex = index
                }
            });
            if (ElementNo > 1) {
                jQuery(Container.children()[curentShowIndex]).fadeOut(600);
                if (ElementNo - 1 != curentShowIndex) {
                    jQuery(Container.children()[curentShowIndex + 1]).fadeIn(600);
                }
                else {
                    jQuery(Container.children()[0]).show();
                }
            }
        },
        ClosedItem: function() {
            var x = jQuery(methods.myContainer);
            ElementNo = x.children().length;
            clearInterval(timers[methods.myContainer.attr("id")]);
            if (ElementNo == 1) {
                x.remove();
                try{
                CheckMiddleInGridIsEmpty();}
                catch(err){
                    return;
                };
            }
            else {
                methods.action(x);
                timers[methods.myContainer.attr("id")] = setInterval(function() { methods.action(x) }, 5000);
            }
        },
        AddItem: function() {
            //id4stayClose="15" advDiv="true" afterClose="$('#BottomAdvContainer').urPicFrame('ClosedItem')" style="width:525px;background-color:Black;height:60px;padding:0px;top:0px;left:0px">123</div>
            var NewItem = document.createElement("div");
            jQuery(NewItem).width(jQuery(methods.myContainer).width());
            jQuery(NewItem).css({ 'position': 'absolute', 'padding': '0px', 'margin': '0px', 'top': '0px', 'left': '0px', 'width': '523px', 'display': 'none' });
            jQuery(NewItem).height(jQuery(methods.myContainer).height());
            jQuery(NewItem).appendTo(jQuery(methods.myContainer));
            return NewItem;
        }
    };

    $.fn.urPicFrame = function(method) {
        methods["myContainer"] = jQuery(this);
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            alert("not objective method.");
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.urPagerScroll');
        }
    }
})(jQuery);
