﻿var LawRoom = 
{
    onError: function(dispDivText, parentDivID)     // DON'T CHANGE THE ARGUMENT NAMES. IF YOU MUST DO THE SAME CHANGE IN .vb PAGES ALSO
    {
        //Displaying a pop-up box if any error occurred
        alert("Exception :\n" + dispDivText);
        window.status="An error has occurred.";
    },

    ReceiveChildDataFromServer: function(dispDivText, parentDivID)      // DON'T CHANGE THE ARGUMENT NAMES. IF YOU MUST DO THE SAME CHANGE IN .vb PAGES ALSO
    {
        if (parentDivID == "TB")      // TITLE BROWSE. IN THIS CASE DIV ID IS divAns
        {
            var divAns = document.getElementById("divAns");
            $(divAns).setProperty("margin-top", "0px");
            $(divAns).setProperty("margin-bottom", "0px");
            $(divAns).setProperty("margin-left", "0px");
            $(divAns).setProperty("margin-right", "0px");
            $(divAns).setProperty("vertical-align", "top");
            $(divAns).setProperty("display", "inline");
            $(divAns).setProperty("padding-bottom", "0px");
            $(divAns).setProperty("padding-top", "0px");
            $(divAns).setProperty("padding-right", "0px");
            $(divAns).setProperty("padding-left", "0px");
            $(divAns).setProperty("class", "f2");
            //$(childDiv).setProperty("innerHTML", dispDivText);        THIS LINE DOES NOT SUPPORT IN FIREFOX
            divAns.innerHTML = dispDivText;
        } else {
  
            var i;
            var showChildDiv;
            var parentDiv;
            var parentImgID;
            var parentImg;
            var childLevel;         // LEVEL OF NEW DIV IN THE TREE
            var childDivID;
            var childDiv;
            var currOpenedLevel;
            var slcOpenedLevel;     // SUB LEVEL OF CURRENTLY OPENED LEVEL
            var slcOpenedDivID;
            var slcOpenedDiv;
            var arcchTID;           // arcchTID --> AFTER REMOVED UNNEEDED CHILDS, CURRENTLY HIGHLIGHTED TOPIC ID
            var arcchImgID;
            var arcchImg;
            var arcchDivID;
            var arcchDiv;
            
            i = 0;
            showChildDiv = true;
            parentDiv = document.getElementById(parentDivID);
            parentImgID = "img" + parentDivID.substr(3, parentDivID.length);
            parentImg = document.getElementById(parentImgID)
            childLevel = parentDivID.length-4;
            childDivID = "divM" + childLevel;

            // divM --> div MooTools  old openedTIDs
            openedTIDs = document.getElementById("openedTIDs");

            if (openedTIDs == null) {
                openedTIDs = document.getElementById("ctl00_cphCenterContent_openedTIDs");
            }

            openedTIDsArr = openedTIDs.value.split("_");

            if (openedTIDsArr.length > 1) {
                currOpenedLevel = openedTIDsArr.length - 1;
                if (parseInt(childLevel) <= parseInt(currOpenedLevel))
                {
                    for (i=parseInt(currOpenedLevel); i>= parseInt(childLevel); i--) {
                        // GET OPENED CHILD DIVS (DIVS CREATED BY MOOTOOLS) AND REMOVE THOSE
                        slcOpenedLevel = i;
                        slcOpenedDivID = "divM" + slcOpenedLevel;
                        slcOpenedDiv = document.getElementById(slcOpenedDivID);
                        if (slcOpenedDiv == null) {
                            slcOpenedDiv = document.getElementById("ctl00_cphCenterContent_slcOpenedDiv");
                        }
                        $(slcOpenedDiv).setProperty("innerHTML", "");
                        $(slcOpenedDiv).remove();
                    }
                    // DEHIGHLIGHTING PERVIOUSLY SELECTED IMG AND TEXT
                    arcchTID = openedTIDsArr[parseInt(childLevel)];
                    arcchImgID = "img" + arcchTID;
                    arcchImg = document.getElementById(arcchImgID);
                    arcchDivID = "div" + arcchTID;
                    arcchDiv = document.getElementById(arcchDivID);
                    $(arcchImg).setProperty("src", "/images/arrow_r.gif");
                    $(arcchDiv).setProperty("class", "f2");
                    // RESTORING OPENED TIDS
                    $(openedTIDs).setProperty("value", "");
                    for (i=1; i<parseInt(childLevel); i++)
                    {
                       $(openedTIDs).setProperty("value", openedTIDs.value + "_" +  openedTIDsArr[i]);
                    }
                    if (arcchDivID == parentDivID)
                    {
                        showChildDiv = false;
                    }
                    
                }
            }
            if (showChildDiv)
            {
                // APPEND OPENED TID
                $(openedTIDs).setProperty("value", openedTIDs.value + "_" + parentImg.id.substr(3, parentImg.id.length));
                
                // HIGHLIGHTING SELECTED IMG AND TEXT
                $(parentImg).setProperty("src", "/images/arrow_d.gif");
                $(parentDiv).setProperty("class", "f2bc");
                
                // CREATE CHILD DIV
                childDiv = new Element("div");
                $(childDiv).setProperty("id", childDivID);
                $(childDiv).setProperty("margin-top", "0px");
                $(childDiv).setProperty("margin-bottom", "0px");
                $(childDiv).setProperty("margin-left", "0px");
                $(childDiv).setProperty("margin-right", "0px");
                $(childDiv).setProperty("vertical-align", "top");
                $(childDiv).setProperty("display", "inline");
                $(childDiv).setProperty("padding-bottom", "0px");
                $(childDiv).setProperty("padding-top", "0px");
                $(childDiv).setProperty("padding-right", "0px");
                $(childDiv).setProperty("padding-left", "0px");
                $(childDiv).setProperty("class", "f2");
                //$(childDiv).setProperty("innerHTML", dispDivText);        THIS LINE DOES NOT SUPPORT IN FIREFOX
                childDiv.innerHTML = dispDivText;
                $(childDiv).injectAfter(parentDiv);
            }
        }
    },
    
    ShowMemoDiv: function(pMeomID, pTopicID, pPageType)
    {
        var cook;
        if (pPageType == "FA")  // FIND ANSWER
        {
            cook = this.GetCookie("TOPICIDFA");
        }
        else if (pPageType == "FF") // FIND FORM
        {
            cook = this.GetCookie("TOPICIDFF");
        }        
        var blnDup = false;
        if(cook == null) {cook="";}
    	
        if(cook == "")
        {
            if (pPageType == "FA")
            {
                document.cookie = "TOPICIDFA=" + pTopicID;
            }
            else if (pPageType == "FF")
            {
                document.cookie = "TOPICIDFF=" + pTopicID;
            }
        }
        else
        {
            var ArrayCook =cook.split(",");
            for(i=0;i<ArrayCook.length;i++)
            {
	            if(ArrayCook[i] == pTopicID)
	            {
		            blnDup = true;
		            break;
	            }
            }
            if(!blnDup)
            {
	            cook = cook + "," + pTopicID;
	            if (pPageType == "FA")
                {
	                document.cookie = "TOPICIDFA="+cook;
                }
                else if (pPageType == "FF")
                {
                    document.cookie = "TOPICIDFF="+cook;
                }
            }
        }
        window.location.href = "Memo_Redirect.aspx?txtMemoID=" + pMeomID ;
    },
    
    GetCookie: function(pName)
    {
        var cname = pName + "=";
        var dc = document.cookie;
        if (dc.length > 0)
        {
            begin = dc.indexOf(cname);
            if (begin != -1)
            {
                begin += cname.length;       
                end = dc.indexOf(";", begin);
                if (end == -1) end = dc.length;
                return unescape(dc.substring(begin, end));
            }
        }
        return null;
    },
    
    OnSearchTxtKeyPress: function(e, pType)
    {
        var keyCode;
        if (window.event)
        {
            keyCode = e.keyCode;
        }
        else if (e.which)
        {
            keyCode = e.which;
        }
        if(keyCode == 13)
        {
            this.SearchAns(pType);
            return false;
        }
    },
    
    SearchAns: function(pType)
    {
        var txtSearch;
        txtSearch = LRUtil.Trim(document.getElementById("txtSearch").value);
        if (txtSearch.length == 0)
        {
            alert("Enter search text");
            document.getElementById("txtSearch").focus(); 
        }
        else
        {
            if (pType == "M")
            {
                window.location.href = "Search.aspx?SER=" + txtSearch;
            }
            else if (pType == "F")
            {
                window.location.href = "Search_F.aspx?SER=" + txtSearch;
            }
        }
        return false;
    },
    
    GoMemoList: function(pType, pTopicID)
    {
        window.location.href = "MemoList.asp?MM=" + pType + "&TID=" + pTopicID;
    },
    
    GoHrefPage: function(pPage, pQryStr)
    {
        window.location.href = pPage + "?" + pQryStr;
    },
    
    SelectInd: function(pPage)
    {
        if (pPage == "ISG")     // INDUSTRY_SG
        {
            alert("You have to continue selecting a sub industry until you see your industry displayed.")
        }
        else if (pPage == "ITSG")       // INDUSTRYTITLE_SG
        {
            alert("You have to select an industry");
        }
        else
        {
            alert("ERROR");
        }
    },
    
    ShowDivProgress: function ()
    {
        var scrollWidth;
        var scrollHeight;
        var divProgress;

        scrollWidth = document.body.scrollWidth;
        scrollHeight = document.body.scrollHeight;
        
        if (scrollHeight == 0)
        {
            scrollHeight=(window.innerHeight/2)-150;
        }
        else
        {
            scrollHeight=scrollHeight/2;	   
        }
        
        divProgress = document.getElementById("divProgress");
        with(divProgress.style)
        {
            left = (scrollWidth/2)-150 + 'px' ;
            top = scrollHeight + 'px';
            position = 'absolute';
            display = 'block';
            zIndex = 101;
        }
    },

    HideDivProgress: function ()
    {
        var divProgress = document.getElementById("divProgress");
        divProgress.style.display = 'none';
    }	
}
