﻿browserDetect.init();

var docManager =
{
    tabs: [
    //{tabId: 'documentTab', divId: 'documentDiv', className: ''}
    ],

    currentTabId: '',
    mapDivId: '',
    lawMapLinkId: '',
    headerDivId: '',
    documentId: 0,

    ShowLogin: function()
    {
        var iframe = document.getElementById('loginFrame');
        iframe.style.display = '';
        iframe.src = 'Login.aspx';
    },

    // param "isPluginDoc" (bool): Send true to indicate that the document being opened is opened in a browser-plugin
    //      like adobe-reader. If true, opening the folder-popup will hide the document iFrame.
    Init: function(mapDivId, lawMapLinkId, headerDivId, documentId, isLoggedIn, isPluginDoc, publisherDivId)
    {

        if (docManager.currentTabId != '')
        {
            docManager.SetFooterAndSearchArea(docManager.currentTabId);
        }
        else
        {
            docManager.SetFooterAndSearchArea(null, docManager.tabs[0]);

            if (docManager.tabs.length > 0)
                docManager.currentTabId = docManager.tabs[0].tabId;
        }

        this.mapDivId = mapDivId;
        this.documentId = documentId;

        this.GetComments();

        if (isLoggedIn)
        {
            //this.GetComments();
            //this.HideInfoTab(true);
            if ($j("#documentTab").hasClass("selectedTab"))
            {
                $j("#resizeImageContainer").css("display", "block");
            }
            else
            {
                $j("#resizeImageContainer").css("display", "none");
            }
        }
        else
        {
            //this.HideInfoTab(false);
            if ($j("#documentTextDivContainer").css("display") == "block")
            {
                $j("#resizeImageContainer").css("display", "block");
            }
            else
            {
                $j("#resizeImageContainer").css("display", "none");
            }

            $j("#footerDiv").css("display", "none");
        }

        //debugger;
        if ($j("#documentFrame").length > 0)
        {
            if ($j("#documentFrame").attr("src").indexOf('pdf') > -1)
            {
                $j("#resizeImageContainer").css("display", "none");
            }
        }
        else
        {
            $j("#resizeImageContainer").css("display", "none");
        }

        var frames = [];

        if (document.getElementById('documentFrame'))
        {
            if (!isLoggedIn)
            {
                frames = ['documentFrame', mapDivId, 'documentTextDivContainer', 'documentTextDiv'];
            }
            else
            {
                frames = ['documentFrame', mapDivId];
            }
            if (document.getElementById('parentDocumentFrame'))
                frames.push('parentDocumentFrame');

            if (document.getElementById('childDocumentIframe'))
                frames.push('childDocumentIframe');

            // Initialize the window-calculator that manages the height of all resizable frames and divs on the page
            windowCalc.Init(frames, true);
        }

        if (document.getElementById(lawMapLinkId))
        {
            // Save the link-ID
            docManager.lawMapLinkId = lawMapLinkId;

            // Open the document map if there is one
            docManager.ToggleDocumentMap();
        }

        if (document.getElementById(headerDivId))
        {
            // Save header id
            docManager.headerDivId = headerDivId;
        }

        if (document.getElementById(publisherDivId))
        {
            docManager.publisherDivId = publisherDivId;
        }

        if (isPluginDoc && frames.length > 0)
        {
            eventMgr.Register(eventMgr.onBeforeShowPopupEvent, function()
            {
                for (var i = 0; i < frames.length; i++)
                {
                    utility.HideElement(frames[i])
                }
            });

            eventMgr.Register(eventMgr.onAfterHidePopupEvent, function()
            {
                for (var i = 0; i < frames.length; i++)
                {
                    utility.ShowElement(frames[i])
                }
            });
        }

        docManager.SetClickEventToMaxAndMinFontImg();
    },

    SetStartTab: function(tabId)
    {
        this.currentTabId = tabId;
    },

    // Add a tab to the tab-array
    // param "tabId": id of tab.
    // param "divId": id of div associated with the tab.
    // param "className": a class-name to give the tab when it is not selected, or null.
    // param "hasIframe" (optional): true to hide the footer for this tab, else null.
    AddTab: function(tabId, divId, className, hasIframe)
    {
        var tab = { tabId: tabId, divId: divId, className: className };

        if (hasIframe)
            tab.hasIframe = hasIframe;

        this.tabs.push(tab);
    },

    // Hide or show the footer.  Send the tab to check for the hasIframe property, or the tabId by which to get the tab.
    SetFooterAndSearchArea: function(tabId, tab)
    {

        var footer = document.getElementById('footerDiv');

        if (!tab) // Get tab by Id
            tab = docManager.GetTab(tabId);

        if (tab)
        {
            // Hide or show the footer
            footer.style.display = tab.hasIframe ? 'none' : '';

            if (tab.hasIframe)
            //change the inner search area to iframe's window
                ChangeSearchArea(document.getElementById('documentFrame').contentWindow, null, true);
            else
            //change the inner search area to the current tab's div (only if we're not in the iframe tab)
                ChangeSearchArea(window.self, tab.divId, false);
        }
    },

    // Get a tab by its tabId
    GetTab: function(tabId)
    {
        for (i = 0; i < docManager.tabs.length; i++)
        {
            if (docManager.tabs[i].tabId == tabId)
                return docManager.tabs[i];
        }
    },

    SwitchTabs: function(aId)
    {
        //on changing tabs, all inner search markings are removed

        ClearAllMarks();

        // Get requested tab
        var a = document.getElementById(aId);
        a.className = 'selectedTab';

        for (i = 0; i < this.tabs.length; i++)
        {
            var tab = this.tabs[i];

            if (tab.tabId == a.id) // selected tab
            {
                // show matching div
                document.getElementById(tab.divId).style.display = '';

                var iframe = document.getElementById('documentFrame');


                if (iframe !== null && a.id == 'documentTab' && browserDetect.browser == 'Firefox')
                {
                    // Reload iframe for firefox
                    if ($j("#documentTextDiv").html() == "")
                    {
                        iframe.src = iframe.src;
                    }
                }

                // Hide/show the footer
                docManager.SetFooterAndSearchArea(null, tab);
                docManager.currentTabId = tab.tabId;
            }
            else // not selected tab
            {
                //                document.getElementById(tab.tabId).className = tab.className; // set back to default className
                document.getElementById(tab.tabId).className = 'inactiveTab'; // set back to default className
                document.getElementById(tab.divId).style.display = 'none'; // hide div
            }
        }

        // Hide / Show resize Image Container
        if (aId == "documentTab")
        {
            $j("#resizeImageContainer").css("display", "block");
            if ($j("#documentFrame").attr("src").indexOf('pdf') > -1)
            {
                $j("#resizeImageContainer").css("display", "none");
            }
        }
        else
        {
            $j("#resizeImageContainer").css("display", "none");
        }

    },

    ToggleDocumentMap: function()
    {
        var mapCellStyle = document.getElementById('docMapCell').style;

        if (docManager.currentTabId != 'documentTab')
        {
            docManager.SwitchTabs('documentTab');
            mapCellStyle.display = '';
        }
        else
        {
            // Show/hide law-map
            mapCellStyle.display = mapCellStyle.display == 'none' ? '' : 'none';
        }

        var lawMapLink = document.getElementById(docManager.lawMapLinkId);

        // Change link-button text
        lawMapLink.innerHTML = mapCellStyle.display == 'none' ? 'פתח מפת מסמך' : 'סגור מפת מסמך';

    },

    // Jumps to an anchor in the documentFrame
    JumpToAnchor: function(anchorName)
    {
        var iFrame = document.getElementById('documentFrame');
        var regex = /^(.*?)(#.*)?$/;

        iFrame.src = iFrame.src.replace(regex, '$1#' + anchorName);
    },

    CopyHeaderToClipboard: function()
    {
        if (docManager.headerDivId != '')
        {
            /*headerElement = document.getElementById(docManager.headerDivId);
            publisherElement = document.getElementById(docManager.publisherDivId);
            hiddenDateField = document.getElementById('hidShowDate');*/
            hiddenFooterDocBuilderField = document.getElementById('documentHeader_hidFooterDocBuilder');

            //date
            /*showDateString = '';
            if (hiddenDateField != null && hiddenDateField.value != '')
            {
            showDateString = ", " + hiddenDateField.value + ", ";
            }*/

            selectedText = '';

            if (docManager.currentTabId == 'documentTab')
            {
                selectedRange = null;
                // get selected text in iframe
                docFrame = document.frames[0];
                if (docFrame != null)
                {
                    selectedRange = docFrame.document.selection.createRange();
                }

                //put selected text into selectedText
                if (selectedRange != null && selectedRange.text != "")
                {
                    selectedText = selectedRange.text;
                }
            }

            if (hiddenFooterDocBuilderField)
            {
                utility.CopyToClipboard('"' + selectedText + '"' + "\r\n" + "--------------------------------------------" + "\r\n" + hiddenFooterDocBuilderField.value);
                //utility.CopyToClipboard(selectedText + "\n" + headerElement.innerText + showDateString + publisherElement.innerText);
                //utility.CopyToClipboard(selectedText + headerElement.innerText + showDateString + " פורסם בדינים ועוד ");
            }
        }
    },

    GetComments: function()
    {
        ajaxHelper.ShowProgress('GetDocumentComments', 'documentRemarksList');
        SearchEngineService.GetDocumentComments(docManager.documentId, 'documentRemarksList', docManager.GetComments_Complete);
    },

    GetComments_Complete: function(args)
    {
        ajaxHelper.HideProgress('GetDocumentComments');
        if (args)
        {
            var target = document.getElementById(args.Target);

            if (args.Result)
            {
                docManager.HideCommentsTab(false);
                target.innerHTML = args.Result;
            }
            else
            {
                target.innerHTML = '<div style="height: 150px">לא נמצאו הערות המשויכות למסמך זה</div>';
                docManager.HideCommentsTab(true);
            }
        }
        else
        {
            docManager.HideCommentsTab(true);
        }
    },

    DeleteComment: function(folderId, commentId)
    {
        if (confirm("הם ברצונך למחוק את ההערה?"))
            SearchEngineService.DeleteComment(folderId, commentId, docManager.DeleteComment_Complete);
    },

    DeleteComment_Complete: function(args)
    {
        if (args != null)
        {
            if (args)
                docManager.GetComments();
            else
                alert("לא ניתן למחוק הערות שנכתבו על ידי משתמש אחר!");
        }
        else
        {
            alert("!ארעה תקלה בעת מחיקת ההערה, אנא נסה שנית");
        }
    },

    HideCommentsTab: function(doShowComment)
    {
        if (!doShowComment)
        {
            $j("#documentRemarksDiv").removeClass("None");
            $j(".redTabs").find("ul li:last").removeClass("None");
        }
        else
        {
            $j("#documentRemarksDiv").addClass("None");
            $j(".redTabs").find("ul li:last").addClass("None");
        }
    },

    HideInfoTab: function(doShow)
    {
        if (doShow)
        {
            $j("#infoTab").removeClass("None");
            $j("#infoTab").parent().removeClass("None");
        }
        else
        {
            $j("#infoTab").addClass("None");
            $j("#infoTab").parent().addClass("None");
        }
    },

    //Set Click Event To Maximize And Minimize Font Image
    SetClickEventToMaxAndMinFontImg: function()
    {
        var containerType = "";
        //debugger;
        if ($j("#documentTextDivContainer").css("display") == "block")
        {
            containerType = "div";
        }
        else
        {
            containerType = "iframe";
        }

        $j("#maximizeFontImg").click(function()
        {
            docManager.ChangeFontSizeOfTheDocument(containerType, "inc");
        });

        $j("#minimizeFontImg").click(function()
        {
            docManager.ChangeFontSizeOfTheDocument(containerType, "dec");
        });
    },

    //Change Font Size Of The Document
    ChangeFontSizeOfTheDocument: function(documentContainerType, resizeMode)
    {
        var ourText = "";
        if (documentContainerType == "div")
        {
            ourText = $j("#documentTextDivContainer span").not("span:first");
        }
        else
        {
            ourText = $j("#documentFrame").contents().find('span').not("span:first");
        }

        if (ourText != "" && ourText.length > 0)
        {
            var currFontSize = ourText.css('fontSize');
            var test = docManager.GetFontSizeName(currFontSize, resizeMode);
            if (test == "")
            {
                var finalNum = parseFloat(currFontSize, 10);
                var stringEnding = currFontSize.slice(-2);
                if (resizeMode == 'inc')
                {
                    finalNum *= 1.2;
                }
                else if (resizeMode == 'dec')
                {
                    finalNum /= 1.2;
                }
                ourText.css('fontSize', finalNum + stringEnding);
            }
            else
            {
                ourText.css('fontSize', test);
            }
        }
    },

    //Change Font Size Of The Document
    GetFontSizeName: function(currentFontSize, resizeMode)
    {
        if (resizeMode == 'inc')
        {
            if (currentFontSize == "xx-small")
            {
                return "x-small";
            }
            else if (currentFontSize == 'x-small')
            {
                return "small";
            }
            else if (currentFontSize == 'small')
            {
                return "medium";
            }
            else if (currentFontSize == 'medium')
            {
                return "large";
            }
            else if (currentFontSize == 'large')
            {
                return "x-large";
            }
            else if (currentFontSize == 'x-large')
            {
                return "xx-large";
            }
            else if (currentFontSize == 'xx-large')
            {
                return "xx-large";
            }
            else
            {
                return "";
            }
        }
        else if (resizeMode == 'dec')
        {
            if (currentFontSize == "xx-large")
            {
                return "x-large";
            }
            else if (currentFontSize == 'x-large')
            {
                return "large";
            }
            else if (currentFontSize == 'large')
            {
                return "medium";
            }
            else if (currentFontSize == 'medium')
            {
                return "small";
            }
            else if (currentFontSize == 'small')
            {
                return "x-small";
            }
            else if (currentFontSize == 'x-small')
            {
                return "xx-small";
            }
            else if (currentFontSize == 'xx-small')
            {
                return "xx-small";
            }
            else
            {
                return "";
            }
        }
    }
};

function closeWindow()
{
    if (window.opener)
    {
        window.opener.focus();
        window.close();
    }
    else
    {
        history.back();
    }
}

function RemoveSearchMarks(sender)
{
    try
    {
        document.getElementById('documentFrame').contentWindow.$('.markedSpan').css('background-color', '');
        document.getElementById(sender).style.display = 'none';
    }
    catch (e) { }
}

function PrintDocument(docId, doShowDialog)
{
    clearAllDivs();
    if (doShowDialog == 'False')
    {
        sendToPrinter(docId, 1);
    }
    else
    {
        document.getElementById("ChoosePrint").className = "ShowSendToFriendDiv";
    }
}

function printDocumentForm(docId)
{
    var chkBrief, chkDocument, chkParent, PrintType;
    chkBrief = document.getElementById("chkBrief").checked;
    chkDocument = document.getElementById("chkDocument").checked;
    chkParent = document.getElementById("chkParent").checked;
    PrintType = 0;

    if (chkDocument == true)// && chkBrief === true)
    {
        PrintType += 1;
    }

    if (chkBrief == true)
    {
        PrintType += 2;
    }

    if (chkParent == true)
    {
        PrintType += 4;
    }

    if (PrintType == 0)
    {
        alert("לא ניתן להדפיס מסמך ריק");
        return;
    }

    document.getElementById("ChoosePrint").className = "HideMenuDiv";
    sendToPrinter(docId, PrintType);
}

function sendToPrinter(docId, PrintType)
{
    //    window.open("PrintDocument.aspx?docId=" + docId + "&PrintType=" + PrintType, 'dt', 'width=240 height=230 toolbar=0 statusbar=0 scrollbars=1 left=100 top=10');
    window.open("PrintManager.aspx?docId=" + docId + "&PrintType=" + PrintType, 'dt');
}

function ChangeMenuDivs(ToolButtonId)
{
    clearAllDivs();

    if (document.getElementById(ToolButtonId).className == "ShowSendToFriendDiv")
    {
        eventMgr.Raise(eventMgr.onAfterHidePopupEvent);
        document.getElementById(ToolButtonId).className = "HideMenuDiv";
    }
    else
    {
        eventMgr.Raise(eventMgr.onBeforeShowPopupEvent);
        document.getElementById(ToolButtonId).className = "ShowSendToFriendDiv";
    }
    $j("#documentFrame").css("display", "none");
}

function clearAllDivs()
{
    document.getElementById("SendToFreind").className = "HideMenuDiv";
    document.getElementById("ChoosePrint").className = "HideMenuDiv";
}

function showNewRemarkRaw()
{
    if (document.getElementById("newRemarkRaw").className == "ShowMenuDiv")
        document.getElementById("newRemarkRaw").className = "HideMenuDiv";
    else
        document.getElementById("newRemarkRaw").className = "ShowMenuDiv";
}

function Validate(field, regexp, warning)
{
    var element = document.getElementById(field);

    if (element)
    {
        var re = new RegExp(regexp);

        element.value = element.value.trim();

        if (element.value == "" || !element.value.match(re))
        {
            alert(warning);
            element.select();
            return false;
        }
    }

    return true;
}

//---------------------------------------------------
//      Send Mail To A friend
//---------------------------------------------------
function SendToFriend(documentID, sourceUrl)
{
    if (!CheckIsSending())
    {
        DisableSendButtons();
        var reEmail = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;

        var userMail = "";
        if (document.getElementById("txtRecipientMail").value != "") userMail = document.getElementById("txtRecipientMail").value;
        if (userMail == "")
        {
            alert("חובה למלא מייל");
            EnableSendButtons();
            return;
        }

        if (!Validate("txtRecipientMail", reEmail, "מייל לא תקין"))
        {
            EnableSendButtons();
            return;
        }

        var userName = "";
        if (document.getElementById("txtRecipientName").value != "") userName = document.getElementById("txtRecipientName").value;
        if (userName == "")
        {
            alert("חובה למלא שם משתמש");
            EnableSendButtons();
            return;
        }

        var userNote = $j("#message").val();

        //        AjaxService.SendDocument(documentID, userMail, userName, OnSendToFriendComplete, OnSendToFriendTimeOut, OnSendToFriendError);
        AjaxService.SendDocumentWithComment(documentID, userMail, userName, userNote, sourceUrl, OnSendToFriendComplete, OnSendToFriendTimeOut, OnSendToFriendError);
    }
}

function OnSendToFriendComplete(args)
{
    if (args == true)
    {
        document.getElementById("SendToFreind").className = "HideMenuDiv";
        document.getElementById("txtRecipientName").value = "";
        document.getElementById("txtRecipientMail").value = "";
        document.getElementById("message").value = "";
        alert("המסמך נשלח בהצלחה");
        eventMgr.Raise(eventMgr.onAfterHidePopupEvent);
    }
    else
    {
        alert("!ארעה תקלה בעת שליחת המסמך, אנא נסה שנית");
    }
    EnableSendButtons();
    CloseMailToFriend();
}

function OnSendToFriendTimeOut(args)
{
    alert("!ארעה תקלה בעת שליחת המסמך, אנא נסה שנית" + "\n" + args);
    EnableSendButtons();
    CloseMailToFriend();
}

function OnSendToFriendError(args)
{
    alert("!ארעה תקלה בעת שליחת המסמך, אנא נסה שנית" + "\n" + args);
    EnableSendButtons();
    CloseMailToFriend();
}

//disables the  SendToFriend div  buttons
function DisableSendButtons()
{
    var sendButton = document.getElementById("btnSendMail");
    sendButton.src = "Images/send_button_gray.gif";
    sendButton.alt = "שולח לחבר";


    var clearButton = document.getElementById("CloseSendMail");
    clearButton.src = "Images/close_gray.gif";

}

//enables the SendToFriend div buttons
function EnableSendButtons()
{
    var sendButton = document.getElementById("btnSendMail");
    sendButton.src = "Images/send_button.gif";
    sendButton.alt = "שלח לחבר";

    var clearButton = document.getElementById("CloseSendMail");
    clearButton.src = "Images/close.gif";


}

//Checks if a an email is being sent (by checking if the buttons are enabled)
function CheckIsSending()
{
    var sendButton = document.getElementById("btnSendMail");
    //if (sendButton.src == "Images/send_button_gray.gif")
    //if ( sendButton.attributes["sendingMail"] == "true")
    if (sendButton.alt == "שולח לחבר")
    {
        return true;
    }
    else
    {
        return false;
    }
}

//closes div, if close button is enabled
function CloseMailToFriend()
{
    if (!CheckIsSending())
    {
        eventMgr.Raise(eventMgr.onAfterHidePopupEvent);
        clearAllDivs();
    }
    $j("#documentFrame").css("display", "block");
}
//---------------------------------------------------
//      add Favorite
//---------------------------------------------------
//function AddToFavorite(documentID)
//{
//    SearchEngineService.AddDocumentToFavorite(documentID, OnAddDocumentToFavoriteComplete, OnAddDocumentToFavoriteTimeOut, OnAddDocumentToFavoriteError);
//}

//function OnAddDocumentToFavoriteComplete(args)
//{
//    if (args == true)
//        alert("המסמך התווסף למועדפים בהצלחה");
//    else
//        alert("!המסמך כבר קיים במועדפים שלך");
//}

//function OnAddDocumentToFavoriteTimeOut(args)
//{
//    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
//}

//function OnAddDocumentToFavoriteError(args)
//{
//    alert("!ארעה תקלה בעת הוספת המסמך למועדפים, אנא נסה שנית" + "\n" + args);
//}
//---------------------------------------------------


//---------------------------------------------------
//      add Comment
//---------------------------------------------------
//function AddComment(documentID)
//{
//    var title = "";
//    if (document.getElementById("txtRemarkTitle") != null) title = document.getElementById("txtRemarkTitle").value;
//    title = title.trim();
//    if (title == "")
//    {
//        alert("חובה למלא את כותרת ההערה")
//        return false;
//    }

//    var body = "";
//    if (document.getElementById("txtRemarkText") != null) body = document.getElementById("txtRemarkText").value;
//    body = body.trim();
//    if (body == "")
//    {
//        alert("חובה למלא את גוף ההערה")
//        return false;
//    }

//    var type = 0;
//    // if(document.getElementById("CtlShowDocument1$CtlAddComment1$GroupRemark")!=null)
//    // {
//    //    if(document.getElementById("CtlShowDocument1$CtlAddComment1$GroupRemark").checked==true)
//    //        type=0;//GROUP COMMENT
//    //    else
//    //        type=1;//PERSONAL COMMANT
//    //  }  

//    SearchEngineService.AddComment(documentID, type, title, body, OnAddCommentToDocumentComplete, OnAddCommentToDocumentTimeOut, OnAddCommentToDocumentError);

//}

//function OnAddCommentToDocumentComplete(args)
//{
//    if (args == true)
//    {
//        //loadFrame();
//        document.getElementById("txtRemarkTitle").value = "";
//        document.getElementById("txtRemarkText").value = "";
//        window.location.reload(true);
//        //alert("ההערה התווספה למסמך בהצלחה");    
//    }
//    else
//        alert("!ארעה תקלה בעת הוספת הערה למסמך, אנא נסה שנית" + "\n" + args);
//}

//function OnAddCommentToDocumentTimeOut(args)
//{
//    alert("!ארעה תקלה בעת הוספת הערה למסמך, אנא נסה שנית" + "\n" + args);
//}

//function OnAddCommentToDocumentError(args)
//{
//    alert("!ארעה תקלה בעת הוספת הערה למסמך, אנא נסה שנית" + "\n" + args);
//}

//---------------------------------------------------
//      Delete Comment
//---------------------------------------------------
//function DeleteComment(commentId)
//{
//    SearchEngineService.DeleteComment(commentId, OnDeleteCommentComplete, OnDeleteCommentTimeOut, OnDeleteCommentError);
//}

//function OnDeleteCommentComplete(args)
//{
//    if (args == true)
//    {
//        window.location.reload(true);
//    }
//    else
//        alert("!ארעה תקלה בעת מחיקת הערה למסמך, אנא נסה שנית" + "\n" + args);
//}

//function OnDeleteCommentTimeOut(args)
//{
//    alert("!ארעה תקלה בעת מחיקת הערה למסמך, אנא נסה שנית" + "\n" + args);
//}

//function OnDeleteCommentError(args)
//{
//    alert("!ארעה תקלה בעת מחיקת הערה למסמך, אנא נסה שנית" + "\n" + args);
//}



//-------------------------------------------------------------------------------------------------
//  WINDOW CALCULATOR: Makes screen-size calculations
//-------------------------------------------------------------------------------------------------

var windowCalc =
{
    //w: 0, // available browser window width
    h: 0, // available browser window height
    isIE: true, //indicates whether the browser is IE or not
    elementIds: [],
    notFrameHeight: 181,

    // param "iframeId": ID of document.aspx's iframe
    Init: function(elementIds, flag)
    {
        if (elementIds)
        {
            if (elementIds.length > 0)
            {
                this.elementIds = elementIds;
            }
        }

        this.SetElementHeights();

        if (!browserDetect.initialized)
            browserDetect.init();

        //
        // Attach resize event
        //
        if (!(browserDetect.browser == 'Explorer' && browserDetect.version < 7))
        {
            if (window.addEventListener)
                window.addEventListener("resize", windowCalc.SetElementHeights, false);
            else if (window.attachEvent)
                window.attachEvent("onresize", windowCalc.SetElementHeights);
            else if (document.getElementById)
                window.onresize = windowCalc.SetElementHeights;
        }
    },

    // Gets width and height of window and saves them to h and w fields
    GetWindowDimensions: function()
    {
        //
        // get w and h (width and height)
        //
        if (window.innerWidth)
        {
            //Non-IE
            //w = window.innerWidth;
            h = window.innerHeight;
            windowCalc.isIE = false;
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
        {
            //IE 6+ in 'standards compliant mode'
            //w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
            windowCalc.isIE = true;
        }
        else if (document.body && (document.body.clientWidth || document.body.clientHeight))
        {
            //IE 4 compatible
            //w = document.body.clientWidth;
            h = document.body.clientHeight;
            windowCalc.isIE = true;
        }

        //windowCalc.w = w;
        windowCalc.h = h;
    },

    // Sets document Iframe height
    SetElementHeights: function()
    {
        windowCalc.GetWindowDimensions();

        var notFrameHeight = windowCalc.notFrameHeight; // header: 163 + 17 +26 documnet-info + 11px scroll-buffer [footer: 65px, margin above footer: 6px]

        if (browserDetect.browser == 'Explorer' && browserDetect.version < 7)
            notFrameHeight -= 20; // IE6: make higher
        else if (browserDetect.browser == 'Firefox')
            notFrameHeight -= 10; // firefox: make higher

        var height = windowCalc.h - notFrameHeight;

        if (height < 150) // minimum height is 150px
            height = 150;

        // Run through all elements and set their sizes
        var fixedHeight = 0;
        for (var i = 0; i < windowCalc.elementIds.length; i++)
        {
            // Get element
            var element = document.getElementById(windowCalc.elementIds[i]);
            var isIframe = element.tagName.toLowerCase() == 'iframe';

            fixedHeight = isIframe ? height - 41 : height; // take off another 26px for documentHeader for iframes
            if (!(isIframe) && (element.id == 'documentTextDivContainer' || element.id == 'documentTextDiv'))
            {
                fixedHeight = height - 41;
            }
            // Set its height
            element.height = fixedHeight.toString() + 'px';
            element.style.height = fixedHeight.toString() + 'px';
        }

    }
};

function DocumentFullScreen()
{
    utility.ToggleElementById('header');
    var image = document.getElementById('docBehaive');

    if (windowCalc.notFrameHeight == 43)//full screen
    {
        windowCalc.notFrameHeight = 217;
        image.src = 'Images/DocumentIcons/icon_fullscreen.gif';
        image.alt = 'תצוגת מסך מלאה';
    }
    else
    {
        windowCalc.notFrameHeight = 43;
        image.src = 'Images/DocumentIcons/icon_defaultscreen.gif';
        image.alt = 'תצוגת מסך רגילה';
    }

    windowCalc.SetElementHeights();
}


