﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

function OnLoadEvents() {
    $(document).ready(function () {

        FixSideNavIE7();

        SetTwitterTargetBlank();

        setTextByLang();

        FixAudience();

        SetImageGallery();

        SetTextAreaCounter();

        FixBreadCrumb();

        setDatePicker();

        FixFaq();

        HideAudienceFields();

        SetQuickNav();

        SetEntities();

        SetABC();

        FixAccesability();

        SetAltsAndTitles();

        SetTopNav4IE7();

        $(".txtTable").attr("cellpadding", "0");
        $(".txtTable").attr("cellspacing", "0");
            
    });
}

function SetTwitterTargetBlank() {
    for (var i = 1; i < 20; i++) {

        setTimeout("$('.TwitterDiv a').attr('target', '_blank')", 700 * i);

    }
}

function SetTopNav4IE7() {
    if (navigator.appName != "Microsoft Internet Explorer") {
        if ($("body").hasClass("English") != 'true') {
            $(".mopsTopNavMainDiv> .SiteDataDiv:last").find(".Level2Node").css("left", $(".mopsTopNavMainDiv> .SiteDataDiv:last").position().left);
        }
    }
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieversion = new Number(RegExp.$1);
        if (ieversion >= 8) {

            if ($("body").hasClass("English")) {
                return;
            }

            $(".mopsTopNavMainDiv> .SiteDataDiv:last").find(".Level2Node").css("left", $(".mopsTopNavMainDiv> .SiteDataDiv:last").position().left);

            return;
        }
        else {

            //IE7 
            var direction;
            var lastElementDirection;
            var startIndent = 0;

            if ($("body").hasClass("English")) {
                direction = "left";
                lastElementDirection = "right";
                startIndent = $(".mopsTopNavMainDiv> .SiteDataDiv:first").position().left;
            }
            else {
                direction = "right";
                lastElementDirection = "left";
                startIndent = $(window).width() - $(".mopsTopNavMainDiv> .SiteDataDiv:first").position().left - $(".mopsTopNavMainDiv> .SiteDataDiv:first").width();
            }



            var W = -1;

            $(".mopsTopNavMainDiv> .SiteDataDiv").each(function (i) {
                $(this).find(".Level2Node").css(direction, W + startIndent + "px");
                W = W + $(this).width() + 1;
            })

            $(".mopsTopNavMainDiv> .SiteDataDiv:last").find(".Level2Node").css(direction, W + startIndent - 165);

        } 
    } 
}

function SetAltsAndTitles() {

    $("a").each(function (i) {
        if (($(this).attr('title') == null || ($(this).attr('title') == '')
                    && $(this).attr('alt') == null || $(this).attr('alt') == '')) {

            $(this).attr("alt", $(this).text())
            $(this).attr("title", $(this).text())
        }
        else if ($(this).attr('title') == null || ($(this).attr('title') == '')) {
            var strALT = $(this).attr("alt");
            $(this).attr("title", strALT);
        }
    });

    $("img").each(function (i) {

        if (($(this).attr('title') == null || ($(this).attr('title') == '')
                                && $(this).attr('alt') == null || $(this).attr('alt') == '')) {

            $(this).attr("alt", $(this).text())
            $(this).attr("title", $(this).text())
        }
        else if ($(this).attr('title') == null || $(this).attr('title') == '') {
            var strALT = $(this).attr("alt");
            $(this).attr("title", strALT);
        }
    });

}

function FixPagerWP() {

    if ($(".srch-Page").html() != null) {

        var w = 0;

        //add prev arrows

        var pageURL = document.location.href;
        var endIndex = pageURL.lastIndexOf("&start1=");
        var newURL4firstPage = pageURL.substring(0, endIndex + 8) + "1";

        var firstPageTitle = "לדף הראשון";
        var prevPageTitle = "לדף הקודם";
        var nextPageTitle = "לדף הבא";
        var lastPageTitle = "לדף האחרון";

        //if not first page
        if ($("#SRP_Prev").html() != null) {

            var href = $("#SRP_Prev").attr("href");
            var title = $("#SRP_Prev").html();

            $("#SRP_Prev").before("<a title='" + firstPageTitle + "' alt='" + firstPageTitle + "' style='color:transparent !important' href='" + newURL4firstPage + "'><img src='/WebResources/Images/bullets/gallery-two-arrows-previous.gif' title='" + firstPageTitle + "' alt='" + firstPageTitle + "'/></a>");
            $("#SRP_Prev").before("<a title='" + title + "' alt='" + title + "' style='color:transparent !important' href='" + href + "'><img src='/WebResources/Images/bullets/gallery-arrow-previous.gif' title='" + title + "' alt='" + title + "'/></a>");
        }
        else {
            $("#.srch-Page strong").before("<img class='floatRight two-arrows-previous-off' src='../WebResources/Images/bullets/gallery-two-arrows-previous-off.gif' /><img class='floatRight arrow-previous-off' src='../WebResources/Images/bullets/gallery-arrow-previous-off.gif' /><span class='grayOff floatRight prevPageTitle'>" + prevPageTitle + "</span>");
            w = w + 70;
        }


        //add next arrows

        //if not last page
        if ($("#SRP_Next").html() != null) {

            href = $("#SRP_Next").attr("href");
            title = $("#SRP_Next").html();

            $("#SRP_Next").after("<a title='" + lastPageTitle + "' alt='" + lastPageTitle + "' style='color:transparent !important' href='" + href + "'><img src='/WebResources/Images/bullets/gallery-two-arrows-next.gif' title='" + lastPageTitle + "' alt='" + lastPageTitle + "'/></a>");
            $("#SRP_Next").after("<a title='" + title + "' alt='" + title + "' style='color:transparent !important' href='" + href + "'><img src='/WebResources/Images/bullets/gallery-arrow-next.gif' title='" + title + "' alt='" + title + "'/></a>");
        }
        else {
            $("#.srch-Page strong").after("<span class='floatRight grayOff nextPageTitle'>" + nextPageTitle + "</span><img class='floatRight arrow-next-off' src='../WebResources/Images/bullets/gallery-arrow-next-off.gif' /><img class='floatRight two-arrows-next-off' src='../WebResources/Images/bullets/gallery-two-arrows-next-off.gif'/>");
            w = w + 110;

        }

        //calc width
        var w = w + 45 + $(".srch-Page a").size() * 36;
        w = w + $(".srch-Page #SRP_Prev").width();
        w = w + $(".srch-Page #SRP_Next").width();

        $(".srch-Page").width(w);

        $(".srch-Page").wrap("<div class='srch-Page-wrap'>");
        $(".srch-Page").css("margin", "auto");
        //$(".srch-Page").css("border", "1px solid red");
        $(".srch-Page").show();
        //$(".srch-Page").css("display", "inline");
    }
}

function SetEntities() {

    $(".entityMoreDetails").each(function (i) {

        if ($(this).text().length > 24) {

            $(this).addClass("entitySeparator");
        }

    });
}
function SetABC() {
    $(".ln-letters a").each(function (j) {

        $(this).click(function () {
            GetLetter($(this).text())
        })
    })

    if ($(".abcOpenCloseAll").html() != null) {

        $(".abcOpenCloseAll").before("<div class='selectedLetter'></div>")
    }
}

function FixAccesability() {

    //    var str = $("html").html();
    //    if (str.search(/UniversalB1.css/i) < 0)
    //        return;

    if ($(".topNavFont").css("font-size") != "17px")
        return;

    //fix phones
    if ($(".cqwpGridViewTable").html() != null) {

        for (var i = 0; i <= 6; i++) {

            var divWidth;

            switch (i) {

                case 0:
                    divWidth = 100;
                    break;
                case 1:
                    divWidth = 100;
                    break;
                case 2:
                    divWidth = 110;
                    break;
                case 3:
                    divWidth = 110;
                    break;
                case 4:
                    divWidth = 160;
                    break;
                case 5:
                    divWidth = 130;
                    break;
                default:
                    divWidth = 100;
                    break;
            }
            var className = ".PhoneBookInnerRow" + i;

            $(className).each(function () {
                if ($(this).width() > divWidth) {
                    $(this).css("overflow-x", "scroll");
                    $(this).width(divWidth - 13);
                }
            });

            $(".cqwpGridViewTable").show();
        }
    }


    $(".Toolsgroupheader").each(function () {
        if ($(this).height() > 33) {
            $(this).css("background-image", "url('/WebResources/Images/MasterPage/box2-bg-acc.gif')");
        }
    })

    if ($(".quickNav .QuickNavTitle").height() > 33) {
        $(".quickNav .QuickNavTitle").css("background-image", "url('/WebResources/Images/MasterPage/box3-bg-acc.gif')");
    }

    $(".Grayboxtitle").each(function () {
        if ($(this).height() > 33) {

            $(this).parent(".Grayboxheader").css("height", "60px");
        }
    })

    $(".GrayboxtitleSummaryLinks").each(function () {
        if ($(this).height() > 33) {
            $(this).css("padding-top", "0px");
            $(this).closest(".Grayboxheader").css("height", "60px");
        }
    })


}

function SetQuickNav() {

    if ($(".qNavUl").children().length == 0) {

        $(".QuickNavTitle").addClass("ToolsBoxInfo");
        $(".QuickNavTitle").removeClass("QuickNavTitle");
        $(".qNavUl").removeClass("qNavUl");
    }
    else {
        $(".QuickNavTitle").css("display", "block");
        $(".qNavUl").css("display", "block");
        $(".qNavUl").css("margin-bottom", "15px");
    }

}
function setMailingListsCBs() {

    if ($(".AllSubjectCheckBoxStatus").html() == '1') {

        $(".AllSubjectCheckBoxStatus").html('0');

        $(".NoteDiv .mailingSubject input").each(function () {
            $(this).attr("checked", "");
        })
    }
    else {

        $(".AllSubjectCheckBoxStatus").html('1');

        $(".NoteDiv .mailingSubject input").each(function () {
            $(this).attr("checked", "checked");
        })
    }
}
function GetLetter(letter) {


    $(".selectedLetter").text(letter)

}
function ShowContent(GroupId, Id) {


    $(GroupId).children().each(function (i) {


        if ($(this).hasClass("HideRow") && $(this).css("display") == "none") {

            $(this).show();
            $(Id).text(closeText);
        }
        else {
            if ($(this).hasClass("HideRow")) {

                $(this).hide();
                $(Id).text(openText);
            }
        }


    });


}
function HideAudienceFields() {

    if ($(".Hebrew").html() != null) {

        $(".HebrewFields ").css("display", "block");
    }
    if ($(".English").html() != null) {

        $(".EnglishFields").css("display", "block");
    }
    if ($(".Arabic").html() != null) {

        $(".ArabicFields").css("display", "block");
    }

}

function setTextByLang() {

    if ($(".Hebrew").html() != null) {

        openText = "פתח פרטי מידע נוספים";
        closeText = "סגור פרטי מידע נוספים";
        ArrowIcon = "/WebResources/Images/bullets/arrow-link.gif";
        NewsCount = "הודעות במאגר"


    }
    if ($(".English").html() != null) {

        openText = "Open Information";
        closeText = "Close Information";
        ArrowIcon = "/WebResources/Images/bullets/arrow-link-eng.gif";
        NewsCount = "הודעות במאגר"
    }
    if ($(".Arabic").html() != null) {

        openText = "ערבית פרטי מידע נוספים";
        closeText = "סגור פרטי מידע נוספים ערבית";
        ArrowIcon = "/WebResources/Images/bullets/arrow-link.gif";
        NewsCount = "הודעות במאגר"
    }

}

function FixAudience() {
    var id;
    var Newid;

    $(".AudienceSubject").each(function (i) {

        if ($(".AudienceSubject").length - i > 1) {
            $(this).after("<div class='AudienceSepartor'></div>")
        }
        $(this).attr("id", "AudienceSubject" + i);
        $(this).find("div.AudienceInnerTitle").html($(this).find("div.AudienceInnerTitle").text() + "  " + "(" + $(this).find(".AudienceItem").length + ")");
        var TootalCount = $(this).find(".AudienceItem").length;

        $(this).find(".AudienceItem").each(function (j) {

            if (j < 4) {
                $(this).show();
            }
            else {

                if (j = 5) {


                    id = $(this).parent().attr("id");

                    if (id != Newid) {
                        $(this).before("<div class='OpenMore  mopsBlueLink' id='open" + id + j + "'  onclick=ShowContent('#" + id + "','#open" + id + j + "') >" + openText + " <span>(" + (TootalCount - 4) + ")</span></div> ");
                        Newid = $(this).parent().attr("id");
                    }


                }

                $(this).addClass("HideRow");
                $(this).attr("hide", "true");
                $(this).hide();
            }
        });
    })

    if ($(".AudienceSubject .HideRow").length > 0) {

        $(".AudienceOpenCloseButton").css("display", "block")
    }
}


function FixSideNavIE7() {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1); // capture x.x portion and store as a number
        if (ieversion < 8)
            setTimeout("$('.quickNav .openArrow').css('display', 'inline-block')", 1);
    }
}

function SetTopNav() {

    var direction;
    var lastElementDirection;
    var startIndent = 0;

    if ($("body").hasClass("English")) {
        direction = "left";
        lastElementDirection = "right";
    }
    else {
        direction = "right";
        lastElementDirection = "left";
    }

    //IE7 הזבל
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieversion = new Number(RegExp.$1);
        if (ieversion < 8) {
            setTimeout("$('.quickNav .openArrow').css('display', 'inline-block')", 1);
            startIndent = $(window).width() - $(".mopsTopNavMainDiv> .SiteDataDiv:first").position().left - $(".mopsTopNavMainDiv> .SiteDataDiv:first").width();
        }
    }

    var W = -1;

    $(".mopsTopNavMainDiv> .SiteDataDiv").each(function (i) {
        $(this).find(".Level2Node").css(direction, W + startIndent + "px");
        W = W + $(this).width() + 1;
    })

    $(".mopsTopNavMainDiv> .SiteDataDiv:last").find(".Level2Node").css(direction, W + startIndent - 165);

    //IE7 הזבל
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieversion = new Number(RegExp.$1);
        if (ieversion < 8)
            setTimeout("$('.quickNav .openArrow').css('display', 'inline-block')", 1);
    }
}



function ClearSearchInput() {
    $(".SearchInSiteInput").val('');
}
function FixFaq() {

    if ($(".FaqHeader").html() == null)
        return;

    $(".searchBoxPredefinedTableMainFAQ").closest("table").closest("td").css("background-image", "url('/WebResources/Images/Boxes/form-bg.gif')");
    $(".searchBoxPredefinedTableMainFAQ").closest("table").closest("td").css("background-repeat", "repeat-x");
    $(".searchBoxPredefinedTableMainFAQ").closest("table").closest("td").css("border", "1px solid #CCC");

    //$(".searchBoxPredefinedTableMainFAQ").closest("table").closest("td").css("background", "url('/WebResources/Images/Boxes/form-bg.gif') repeat-y')");


    $(".searchBoxPredefinedTableMainFAQ").after("<div class='faqTotalCount floatLeft '>" + $('span.ViewItemsCountMsg').html() + "</div>")


    $(".LinkToSubject").css("display", "none")
    $(".FaqHeader").css("display", "none")

    if ($(".LinkToSubject").length == 1) {
        $(".LinkToSubject").css("display", "none")
        $(".FaqHeader").css("display", "none")
    }
    else {

        $(".LinkToSubject").css("display", "block")
        $(".FaqHeader").css("display", "block")
    }



    if ($(".FaqHeader").size() == 1) {

        $(".faqOpenCloseAll").css("padding-bottom", "28px");

        $(".FaqGroup li").each(function (i) {

            $(this).show();
        })
    }
    else {

        $(".FaqGroup").parent("li").each(function (i) {
            $(this).after("<li>" + $(this).find(".LinkToSubjectWrap").html() + "</li>");
        });

        $(".LinkToSubject").show();

        $(".FaqGroup").each(function (i) {
            $(this).find("li").each(function (j) {
                if (j < 3) {
                    $(this).show();
                }
            });
        });

    }
    $(".FaqGroup li.dfwp-item").each(function (i) {
        $(this).after("<li class='sepLI'>&nbsp;</li>");
    });
    $(".sepLI").show();
}
function PrintFaq(classNmae, id) {


    try {
        var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
        disp_setting += "scrollbars=yes,width=850, height=250, left=100, top=25";
        var PHMC = $("." + classNmae + id).html();
        var BodyClass = "Print";
        var ImageSrc = "/WebResources/Images/logo-mops-print-page.jpg";
        if ($("body").hasClass("English")) {
            BodyClass = "English";
            ImageSrc = "/WebResources/Images/logo-mops-print-page-eng.gif";
        }

        // var HD = document.getElementById("logo");

        if (PHMC != null) {

            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>Print</title>');
            docprint.document.write('<link rel="stylesheet" type="text/css" href="/Style Library/CustomToPrint.css"/>');
            docprint.document.write('<link rel="stylesheet" type="text/css" href="/Style Library/Custom.css"/>');
            docprint.document.write('</head><body onLoad="self.print()">');
            docprint.document.write('<div class=' + BodyClass + ' >');
            docprint.document.write("<img src='" + ImageSrc + "' alt='' title='' />")
            docprint.document.write(PHMC);
            docprint.document.write('</div>');
            docprint.document.write('</body></html>');
            if (navigator.appName != "Microsoft Internet Explorer") {
                docprint.document.close();
            }
            else {
                docprint.location.reload(false);
            }
            docprint.focus();
        }
        else {
            window.print();
        }
    }
    catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }



}
function FPBtn_onclick() {
    try {
        var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
        disp_setting += "scrollbars=yes,width=800, height=600, left=100, top=25";
        var PHMC;
        var BodyClass = "Print";
        var ImageSrc = "/WebResources/Images/logo-mops-print-page.jpg";
        if ($(".ContentToPrint").html() != null) {

            PHMC = $(".ContentToPrint").html();
            BodyClass = "Print"
        }
        else {

            PHMC = $(".ArticlContentToPrint").html()
            BodyClass = "ArticlContentToPrint"
        }


        if ($("body").hasClass("English")) {


            BodyClass = "English"
            ImageSrc = "/WebResources/Images/logo-mops-print-page-eng.gif";
        }
        // var HD = document.getElementById("logo");

        if (PHMC != null) {

            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<html><head><title>Print</title>');
            docprint.document.write('<link rel="stylesheet" type="text/css" href="/Style Library/CustomToPrint.css"/>');
            docprint.document.write('<link rel="stylesheet" type="text/css" href="/Style Library/Custom.css"/>');
            docprint.document.write('</head><body onLoad="self.print()">');
            docprint.document.write('<div class=' + BodyClass + ' >');
            docprint.document.write("<img src='" + ImageSrc + "' alt='' title='' />")
            docprint.document.write(PHMC);
            docprint.document.write('</div>');
            docprint.document.write('</body></html>');
            if (navigator.appName != "Microsoft Internet Explorer") {
                docprint.document.close();
            }
            else {
                docprint.location.reload(false);
            }
            docprint.focus();
        }
        else {
            window.print();
        }
    }
    catch (err) {
        txt = "There was an error on this page.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(txt);
    }
}

function FixBreadCrumb() {
    if ($(".English").html() != null || $(".Arabic").html() != null) {
        $(".breadcrumb span span a").first().remove();
        $(".breadcrumb span span").first().next().remove();

        if ($(".breadcrumb span span").length == 2) {
            $(".breadcrumb").remove();
        }
    }
    else {
        if ($(".breadcrumb span span").length == 1) {
            $(".breadcrumb").remove();
        }
    }
    $(".breadcrumb").css("display", "block");
}

function RestAbcControl() {

    if ($(".MopsCqwpABC").html() != null) {
        $(".ln-letters a").click(function () {
            CloseAllAbcDivs();
        });

    }

}

function OpenAllContent(className, linkid) {

    $(linkid).text(closeText)
    $("." + className).children().each(function () {
        if ($(this).css("display") == "none") {

            $(this).show();
        }
    });
}

function CloseAllContent(className, linkid) {
    $(linkid).text(openText)
    $("." + className).children().each(function () {
        if ($(this).hasClass("HideRow")) {
            $(this).hide();
        }
    });
}




function OpenAllDivs(className) {


    $("." + className).each(function () {
        if ($(this).css("display") == "none") {

            ShowData(className, $(this).attr("num"));
        }
    });
}

function CloseAllDivs(className) {

    $("." + className).each(function () {

        if ($(this).css("display") == "block") {
            HideData(className, $(this).attr("num"));
        }
    });
}

function ToggleData(ClassName, num) {
    if ($("." + ClassName + num).css("display") == "none") {
        ShowData(ClassName, num);
    }
    else {
        HideData(ClassName, num);

    }
}

function ShowData(ClassName, num) {

    $("." + ClassName + num).show();

    $("." + ClassName + num).parent().find("img.ArrowImage").attr("src", "/WebResources/Images/bullets/arrow-link-down.gif");

    //swicth tooltips
    $("." + ClassName + num).parent().find("img.ArrowImage").attr("alt", $(".HideItemText").html());
    $("." + ClassName + num).parent().find("img.ArrowImage").attr("title", $(".HideItemText").html());
    $("." + ClassName + num).parent().find("div").attr("alt", $(".HideItemText").html());
    $("." + ClassName + num).parent().find("div").attr("title", $(".HideItemText").html());

}
function HideData(ClassName, num) {

    $("." + ClassName + num).hide();
    if ($(".English").html() != null)
        $("." + ClassName + num).parent().find("img.ArrowImage").attr("src", "/WebResources/Images/bullets/arrow-link-eng.gif");
    else
        $("." + ClassName + num).parent().find("img.ArrowImage").attr("src", "/WebResources/Images/bullets/arrow-link.gif");

    //swicth tooltips
    $("." + ClassName + num).parent().find("img.ArrowImage").attr("alt", $(".ShowItemText").html());
    $("." + ClassName + num).parent().find("img.ArrowImage").attr("title", $(".ShowItemText").html());
    $("." + ClassName + num).parent().find("div").attr("alt", $(".ShowItemText").html());
    $("." + ClassName + num).parent().find("div").attr("title", $(".ShowItemText").html());

}

/***********************    for SiteMapPage    ***********************************/
function OpenAllSiteMapDivs() {

    $(".siteMapPageMainDiv .childnum").each(function () {
        if ($(this).css("display") == "none") {

            ShowSiteMapData($(this).attr("num"));
        }
    });
}

function CloseAllSiteMapDivs() {

    $(".siteMapPageMainDiv .childnum").each(function () {

        if ($(this).css("display") != "none") {
            HideSiteMapData($(this).attr("num"));
        }
    });
}
function ToggleSiteMapData(num) {
    if ($(".siteMapPageMainDiv .childnum" + num).css("display") == "none") {
        ShowSiteMapData(num);
    }
    else {
        HideSiteMapData(num);

    }
}
function ShowSiteMapData(num) {

    $(".siteMapPageMainDiv .childnum" + num).css("display", "inline-block");

    $(".siteMapPageMainDiv .ArrowImage" + num).attr("src", "/WebResources/Images/bullets/arrow-link-down.gif");

    //swicth tooltips
    $(".siteMapPageMainDiv .ArrowImage" + num).attr("alt", $(".HideItemText").html());
    $(".siteMapPageMainDiv .ArrowImage" + num).attr("title", $(".HideItemText").html());

}
function HideSiteMapData(num) {

    $(".childnum" + num).hide();
    if ($(".English").html() != null)
        $(".siteMapPageMainDiv .ArrowImage" + num).attr("src", "/WebResources/Images/bullets/arrow-link-eng.gif");
    else
        $(".siteMapPageMainDiv .ArrowImage" + num).attr("src", "/WebResources/Images/bullets/arrow-link.gif");

    //swicth tooltips
    $(".siteMapPageMainDiv .ArrowImage" + num).attr("alt", $(".ShowItemText").html());
    $(".siteMapPageMainDiv .ArrowImage" + num).attr("title", $(".ShowItemText").html());

}
/***********************    end for SiteMapPage    ***********************************/
function SetTextAreaCounter() {
    $(document).ready(function () {

        $("textarea").each(function (i) {
            $(this).attr("maxlength", "255");
        });

        $(".ArticleSummary .ms-formfieldvaluecontainer span textarea[id*=TextField]").addClass("TextareaCounter");
        $(".TextareaCounter").before("<div id='Counter' style='color:red'></div>")

        var texta = $('.ArticleSummary div .ms-formfieldvaluecontainer span textarea[maxlength]');

        $(texta).keyup(function () {

            //get the limit from maxlength attribute
            var limit = parseInt($(this).attr('maxlength'));
            //get the current text inside the textarea
            var text = $(this).val();
            //count the number of characters in the text
            var chars = text.length;
            $("#Counter").text("נשארו עוד " + (255 - $(".TextareaCounter").val().length) + " תווים ")
            //$(".TextareaCounter").val().length
            //check if there are more characters then allowed
            if (chars > limit) {
                //and if there are use substr to get the text before the limit
                var new_text = text.substr(0, limit);

                //and change the current text with the new text
                $(this).val(new_text);
            }
        });

    });
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}


function ShowShadowBox(show, className, isAutoWidth, objwidh, objHeight) {

    var popupDiv = $("." + className);
    var opacityDiv = $("#opacityMask");

    if (show == "false") {
        $("html").css("overflow", "auto");
        opacityDiv.fadeOut(555);
        popupDiv.fadeOut(555);
        return false;
    }

    $("html").css("overflow", "hidden");

    opacityDiv.css("opacity", "0.8");
    opacityDiv.css("filter", "alpha(opacity=40)");

    opacityDiv.width(getDocWidth());
    opacityDiv.height(getDocHeight());
    opacityDiv.fadeIn(555);
    popupDiv.fadeIn(555);

    var imageWidth;
    var imageHeight;
    var newImageWidth;
    var newImageHeight;
    var topOffset;
    var leftOffset;
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;

    //if enlarge image
    if (objwidh == "700") {

        imageWidth = $(".zoomBoxImg").width();
        imageHeight = $(".zoomBoxImg").height();

        var PopUpImage = $("#ctl00_PlaceHolderMain_EnlargeImage_PopUpImage");

        if (imageWidth > imageHeight) {

            newImageWidth = (windowWidth / 2);
            newImageHeight = newImageWidth * imageHeight / imageWidth;
            topOffset = (windowHeight - newImageHeight) / 2;
            leftOffset = (windowWidth - newImageWidth) / 2;

            PopUpImage.width(newImageWidth);

            popupDiv.width(newImageWidth);
            popupDiv.css("top", topOffset);
            popupDiv.css("left", leftOffset);
        }
        else {
            newImageHeight = (windowHeight * 6 / 10);
            newImageWidth = imageWidth * newImageHeight / imageHeight;
            topOffset = (windowHeight - newImageHeight) / 2;
            leftOffset = (windowWidth - newImageWidth) / 2;

            PopUpImage.height(newImageHeight);

            popupDiv.height(newImageHeight);
            popupDiv.css("top", topOffset);
            popupDiv.css("left", leftOffset);
        }

    } //if not enlarge image
    else {

        topOffset = (windowHeight - objHeight) / 2;
        leftOffset = (windowWidth - objwidh) / 2;

        if (objwidh > objHeight) {

            //PopUpImage.width(objwidh);
            popupDiv.width(objwidh);
            popupDiv.css("top", topOffset);
            popupDiv.css("left", leftOffset);
        }
        else {
            //PopUpImage.height(objHeight);
            popupDiv.height(objHeight);
            popupDiv.css("top", topOffset);
            popupDiv.css("left", leftOffset);
        }

        FixSendToFrindInGallery("");
    }

    return false;
}


function FixSendToFrindInGallery(Cssproperty) {

    if ($(".EilatMainImageDivNoBorder0").html() != null) {
        $(".EilatMainImageDivNoBorder").css("position", "" + Cssproperty + "")
    }
}

function ShowPopUp(show, className, isAutoWidth, objwidh, objHeight) {
    var popup = $("." + className);
    popup.css("top", "120px");
    if (show == 'false') {
        $("#opacityMask").animate({ width: 0, height: 0 }, 1500);
        popup.css("left", "-" + objwidh + "px");
        popup.css("display", "none");
        setTimeout("FixSendToFrindInGallery('absolute')", 1000);
    }

    else {

        if (isAutoWidth == 'true') {

            if (imageWidth != "") {
                if (imageWidth > imageHeight) {

                    popup.animate({ left: 27 + "%", width: popup.width(), height: popup.height() }, 500);
                }
                else {
                    popup.animate({ left: 36 + "%", width: popup.width(), height: popup.height() }, 500);
                }

            }

            else {
                popup.animate({ left: ($("#s4-bodyContainer").width() - imageWidth) / 2, width: popup.width(), height: popup.height() }, 500);
            }

        }
        else {
            popup.animate({ left: ($("#s4-bodyContainer").width() - objwidh) / 2, width: objwidh, height: objHeight }, 500);
        }

    }
}
function setPagerMarginAUTO() {

    $(".resultsPaging").css("margin", "auto");

    if ($(".fastResultsPaging").html() != null) {


        var FASTwidth = 0;

        $(".fastResultsPaging .pages>*").each(function () {
            FASTwidth = FASTwidth + $(this).width() + 10;
        });

        $(".resultsPaging").width(FASTwidth);

        return;
    }

    var W;
    //case double arrows exist
    if ($(".resultsPaging .aRightArrows").html() != null) {

        W = getPagerWidth();
        $(".resultsPaging > div").width(W);
    }
    else {



        $(".resultsPaging div").first().css("margin-top", "4px");

        if (navigator.appName == "Microsoft Internet Explorer") {
            if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
                var ieversion = new Number(RegExp.$1); // capture x.x portion and store as a number

                if (ieversion > 7) {
                    W = getPagerWidth();
                    $(".resultsPaging").width(W);
                }
                else { //IE7 הזבל

                    $(".resultsPaging .pages").width(320);
                    $(".resultsPaging .aPreviousLabelStyle").width(110);

                    W = 150;
                    $(".resultsPaging .NumbersPanel").width(W);

                    while ($(".resultsPaging .NumbersPanel").height() < 20 && W > 16) {
                        W = -16 + W;
                        $(".resultsPaging .NumbersPanel").width(W);
                    }
                    $(".resultsPaging .NumbersPanel").width(16 + W);

                    $(".resultsPaging .aNextLabelStyle").width(110);

                    W = getPagerWidth();
                    $(".resultsPaging .pages").css("padding-right", (680 - W) / 2 + "px");
                }
            }
        }
        else {
            W = getPagerWidth();
            $(".resultsPaging").width(W);
        }

    }
}

function getPagerWidth() {
    var W1;


    var W2 = $(".resultsPaging .aPreviousLabelStyle").width();

    var W4 = $(".resultsPaging .aNextLabelStyle").width();
    var W5 = $(".resultsPaging .aLeftArrows").width();

    var W = W2 + W4 + W5;

    return (W + 200);


}


function setDatePicker() {

    //check Language
    var strAltText = "בחרו תאריך מתוך לוח השנה";

    if ($(".English").html() != null) {
        strAltText = "Choose a date from the Calender";
    }
    if ($(".Arabic").html() != null) {
        strAltText = "حدد تاريخ";
    }

    var index = 1;
    if ($(".ms-dtinput").length > 0) {
        $(".ms-dtinput img").each(function (i) {
            var DatePicker = "DatePicker" + i;
            var DatePickerContainer = "DatePickerContainer" + i;
            if (i > 0)
                index = i - 1;
            $(this).parent().parent().html("<A style='cursor:pointer'  onclick=ShowDatePicker('" + DatePicker + "','DatePicker" + index + "') ><IMG id=FromCalculatedPublishDate src='/_layouts/images/calendar.gif' border='0' alt='" + strAltText + "' title='" + strAltText + "'style='margin-left:0px; '></IMG></A><div id='" + DatePicker + "'  style='position:absolute;display:none;' class='datepicker' type='text'></div>");
        });
        $(".datepicker").datepicker({
            onSelect: function (dateText, inst) {
                var PickerID = $(this).attr("id");
                PickerID = PickerID.substring(10);
                var NewID = "DatePickerContainer" + PickerID;
                $(this).parent().prev().find("input").val(dateText)
                $(this).css("display", "none");
            }
        });
    }
}


function ShowDatePicker(id, idToHide) {
    if ($("div [id='" + id + "']").css("display") == "none") {
        $("div [id='" + id + "']").css("display", "block");

        if ($("div [id='" + id + "']").css("display") == "block") {
            $("div [id='" + idToHide + "']").css("display", "none")
        }
    }
    else {
        $("div [id='" + id + "']").css("display", "none");

    }
}

function SetImageGallery() {

    if ($(".ImageGallery").html() == null || $(".EIG_EditModeMainSortPanel").html() != null) {
        return;
    }

    $(".ImageGallery").show();

    $(window).resize(function (event) {
        event.preventDefault();
    });

    setInitialEffects();

    setSmallPicsHeight();

    setBreadcrumbLink();
}
function setBreadcrumbLink() {

    var LinkToGallery = document.location.href;
    var ImageGalleryName = $(".breadCrumbCurrent:last").text();

    if ($(".EilatConferenceWP img").attr("src") != undefined) {
        $(".EilatConferenceWP").css("display", "block");
        $(".EilatConferenceWP").css("padding-bottom", "10px");
    }
    if ($(".ImageGallery").html() != null) {

        $(".breadCrumbCurrent:last").html("<a class='breadCrumbCurrent' href=" + LinkToGallery + ">" + ImageGalleryName + "</a>")
    }
}
function setSmallPicsHeight() {

    var i = 0;

    var panel;
    var panelBaseStr;
    var panelMaxHeight;

    var img;
    var imgBaseStr = ".imgGallerySmallImg";
    var imgMaxHeight;

    var imgDivWrap;
    var imgDivWrapBaseStr = ".secondPicDiv";
    var imgDivWrapMaxHeight;

    if ($(".smallAlbumsPanel").html() != null) {
        panelBaseStr = ".smallImagePanel";
    }
    else {
        panelBaseStr = ".smallPicPanel";
    }

    panel = panelBaseStr + "0";
    imgDivWrap = imgDivWrapBaseStr + "0";

    while ($(panel).html() != null) {

        //get image max height
        imgMaxHeight = 0;
        var j;
        for (j = i; j < i + 4; j = j + 1) {

            img = imgBaseStr + j;

            if ($(img).height() > imgMaxHeight) {
                imgMaxHeight = $(img).height();
            }
        }

        //set image padding-top 
        for (j = i; j < i + 4; j = j + 1) {

            img = imgBaseStr + j;

            if ($(img).height() < imgMaxHeight) {

                imgDivWrap = imgDivWrapBaseStr + j;
                var hefresh = Math.floor((imgMaxHeight - $(img).height() - 1));
                $(imgDivWrap).css("padding-top", hefresh + "px");
            }
        }

        panelMaxHeight = 0;

        //get panel max height
        for (j = i; j < i + 4; j = j + 1) {

            panel = panelBaseStr + j;
            img = imgBaseStr + j;

            if ($(panel).height() > panelMaxHeight) {
                panelMaxHeight = $(panel).height();
            }
            if ($(img).height() > imgMaxHeight) {
                imgMaxHeight = $(img).height();
            }
        }
        //set panel height
        for (j = i; j < i + 4; j = j + 1) {

            panel = panelBaseStr + j;
            //imgDivWrap = imgDivWrapBaseStr + j;

            if ($(panel).html() == null) {
                break;
            }
            $(panel).height(panelMaxHeight);
            //$(imgDivWrap).height(imgMaxHeight);
        }
        i = i + 4;




    }
}
function setInitialEffects() {

    if ($(".bigImgAndAnchorsDiv").html() != null) {

        var effectTime = $(".InitialEffectTimeDiv").html();
    }

    $(document).ready(function () {

        if ($(".bigImgAndAnchorsDiv").html() != null) {

            if ($(".ImageNumDiv").html() != null && $(".ImageNumDiv").html() != '' && $(".ImageNumDiv").html() != '\n') {
                SetMainImage(effectTime, $(".ImageNumDiv").html(), "false");
            }
            else {
                SetMainImage(effectTime, 0, "false");
            }
        }

        $(".bigImgAndAnchorsDiv").css("display", "block");
        $(".ajaxLoaderDiv").css("display", "none");


        $(".bigImgAndAnchorsDivInner").fadeIn(effectTime);
        $(".EilatMainImageDivWithBorder").fadeIn(effectTime);
        $(".AllPicsDiv").fadeIn(effectTime);
        $(".smallImagePanel").fadeIn(effectTime);
        $(".smallPicPanel").fadeIn(effectTime);

    });
}

