﻿// JScript File

    function setCookie(c_name,value,expiredays)
    {
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    } 
    
    function getCookie(c_name)
    {
        if (document.cookie.length>0)
          {
          c_start=document.cookie.indexOf(c_name + "=");
          if (c_start!=-1)
            { 
            c_start=c_start + c_name.length+1 ;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1)
                {
                 c_end=document.cookie.length;
                 }

            //alert("Get Cookie Value = " + unescape(document.cookie.substring(c_start,c_end)));    
            return unescape(document.cookie.substring(c_start,c_end));
            
            
            } 
          }
        return "";
    }

    // Advanced cookie storage system
    
    
    
    
    // End
    
    function NavigateToURL(url)
    {
        javascript:window.open('http://' + url );
        
    } 

    function AdjustColumnsHeight()
        {
            // get a reference to the three DIVS that make up the columns
            var centerCol = window.document.getElementById('maincol');
            var leftCol = window.document.getElementById('leftcol');
            //var rightCol = window.document.getElementById('rightcol');
            var footer = window.document.getElementById('footer');
            var qasnav = window.document.getElementById('QasNav');
            // calculate the max height
            var hCenterCol = centerCol.offsetHeight;
            var hLeftCol = leftCol.offsetHeight;
            //var hRightCol = rightCol.offsetHeight;
            var maxHeight = Math.max(hCenterCol, hLeftCol);
            
            //alert(maxHeight);
            
            var footerHeight = maxHeight + 200;
            
            // add anset object to MyActiveAnswerSet.aspx
            if (qasnav != null && maxHeight < 760) {
                footerHeight = 863;
            }
            // set the height of all 3 DIVS to the max height
            centerCol.style.height = maxHeight + 'px';
            leftCol.style.height = maxHeight + 'px';
            //rightCol.style.height = maxHeight + 'px';
            // Adjust footer to suit
            if (footer != null) {
                footer.style.visibility = 'visible';
                
                var height = document.compatMode=='CSS1Compat' &&
                !window.opera?document.documentElement.clientHeight:
                document.body.clientHeight;
                
                if (footerHeight > height) 
                {
                        //Footerheight already set is greater than the current window height (window not maximised!)
                        //then place footer below the main/left col data
                        footer.style.top = footerHeight + 'px'; 
                }
                else
                {
                    height = height - 50; //take off the footer height
                    footer.style.top = height + 'px'; 
                }
                    
                footer.style.zIndex=10;
                }       
            
            window.footerHeight = footerHeight;
            // Show the footer
            //window.document.getElementById('footer').style.visibility = 'inherit';
            CollateFormInfo();
        }
   
        
    function AdjustLeftColumn(newWidth)
        {        
            objleftCol = window.document.getElementById('leftcol');
            objcenterCol = window.document.getElementById('maincol');
            
            var mainColWidth;
            var maxWidth = 995;
            
            mainColWidth = maxWidth - newWidth
            
            objleftCol.style.width = newWidth + 'px'; 
            objcenterCol.style.width = mainColWidth + 'px'; 
            objcenterCol.style.left = newWidth + 'px';
            
        }
   
   function HideFooter()
        {
            var footer = window.document.getElementById('footer');
            footer.style.visibility = 'hidden' ;
        }

   function LightMode(light)
   {
        if(light == true){
           document.getElementById('ctl00_LeftNav_ibtnQasNav').style.top = 25 +'px';
           document.getElementById('ctl00_LeftNav_ibtnQasNav').className="lbtn_Current";
                    
        }
   
   }
   // Swap the left nave to display either 'QasNav Navigator' or 'Element Evidence' 
   function SwitchMode(div, light)
        {
        //div = "Evidence";
        
        
            // If the cookie has never been set the default to the Navigation screen
            if (div == null || div == "" || light == "true") { div == "QasNav";}
        
            //if (document.getElementById('QasNav'))
            //{
            var option=["QasNav","QasSearch","Evidence"];
            for(var i=0; i<option.length; i++)
                { 
                obj=document.getElementById(option[""+i+""]);
                obj.style.display=(option[""+i+""]==div)? "block" : "none";
                
                if(light == "true"){
                    obj.style.top = 0 + 'px';
                    obj.style.height = 728 + 'px';
                }
                
                // Extra Functionality
                setCookie("NavViewIndex",div,1);
                   
                }
            //}
            // Switch button state
            if(light == "true"){
                    //document.getElementById('ctl00_LeftNav_ibtnQasNav').style.top = 25 +'px';
                    document.getElementById('ctl00_LeftNav_ibtnQasNav').className="lbtn_Current";
                   
                } else {
                    if (div =="QasNav")
                    {

                        document.getElementById('ctl00_LeftNav_ibtnQasNav').className="lbtn_Current";
                        document.getElementById('ctl00_LeftNav_ibtnSearch').className="lbtn_Standard";
                        document.getElementById('ctl00_LeftNav_ibtnEvidence').className="lbtn_Standard";  
                    }
                    if (div =="QasSearch")
                    {
                        document.getElementById('ctl00_LeftNav_ibtnQasNav').className="lbtn_Standard";
                        document.getElementById('ctl00_LeftNav_ibtnSearch').className="lbtn_Current";
                        document.getElementById('ctl00_LeftNav_ibtnEvidence').className="lbtn_Standard";
                        
                    }
                    if (div =="Evidence")
                    {
                        document.getElementById('ctl00_LeftNav_ibtnQasNav').className="lbtn_Standard";
                        document.getElementById('ctl00_LeftNav_ibtnSearch').className="lbtn_Standard";
                        document.getElementById('ctl00_LeftNav_ibtnEvidence').className="lbtn_Current";
                    }
                }

        }
    
    
    
//    function YesNoMessageBox(question)
 //       {
            
 //       }



     
    // Currently not used   
    function AdjustLeftNav(offset)
        {
            var centerCol = window.document.getElementById('maincol');
            var leftCol = window.document.getElementById('leftcol');
            var ucClientTree = window.document.getElementById('ucClientTree');
            
            centerCol.style.left = (180 + offset) + 'px';
            centerCol.style.width = (815 - offset) + 'px';
            leftCol.style.width = (180 + offset) + 'px';
        }
        

    function refreshParent() {
          window.opener.location.href = window.opener.location.href;
          if (window.opener.progressWindow){ window.opener.progressWindow.close()}
          window.close();
        }


    var highlightedText = "";
    var timerId = -1;
    var counter = 0;
    
    function trackChanges(p_textBoxId, p_postBackScript)
    {
        var l_elem = document.getElementById(p_textBoxId);
        if(l_elem)
        {
            var currentText = l_elem.value;
            
            if(highlightedText != currentText)
            {
                highlightedText = currentText;
                counter = 1;                    
            } else
            {
                if(counter == 1)
                {
                    counter = 0;
                    eval(p_postBackScript);
                }
            }
        }
    }
    
    function startTrackChanges(p_textBoxId, p_postBackScript)
    {
        if(timerId == -1)
        {
            timerId = setInterval("trackChanges(\""+p_textBoxId+"\", \""+p_postBackScript+"\");", 300);
        }
    }
    
    function intTabClick() { 
       _clickDelegate = Function.createDelegate(this, onTabClick); 
       tabP_beh = $find(tabPanelBehaviorId);
       tabP_beh.add_click(_clickDelegate);
    }

    function onTabClick() {
        alert("you clicked me");
    }


    function CollateFormInfo()
    {
        // Steps through form elements on page 
        if (!document.getElementsByTagName) return false;
        var elementsForms = document.getElementsByTagName("form");
        for (var intCounter = 0; intCounter < elementsForms.length; intCounter++) 
            { 
            // Tab Array is required for adjusting footer height when using AJAX tabs 
            CreateTabArray(elementsForms[intCounter])
            }
     }


    function CreateTabArray(currentForm)
    {
        var msg = "ok";
        var elementsDivs = currentForm.getElementsByTagName("div");
        //alert("Number of Div Tags:" + elementsDivs.length);
        var aryDivs = new Array(2);
         
            for (var intCounter = 0; intCounter < elementsDivs.length; intCounter++) 
            {
                // 3D array 
                aryDivs [intCounter] = new Array(2);
                
                // admintab_theme ajax__tab_container ajax__tab_default (must match css)
                if (elementsDivs[intCounter].className == "admintab_theme ajax__tab_container ajax__tab_default")
                    {
                        aryDivs [intCounter] [0] = elementsDivs[intCounter].id;
                        aryDivs [intCounter] [1] = elementsDivs[intCounter].offsetHeight;
                        //aryDivs [intCounter] [2] = elementsDivs[intCounter].className;
                    } else{
                        aryDivs [intCounter] [0] = "";
                        aryDivs [intCounter] [1] = 0;
                        //aryDivs [intCounter] [2] = elementsDivs[intCounter].className;
                    }
            }
        // Save Array Of Div's used by Tab containers to adjust footer offset
        window.aDivs = aryDivs;
    }
    
    
    
    function Tab_SelectionChanged(sender,e) 
    {
        var aryDivs = window.aDivs; // The Array of Div's is storred in the Windows object
        var tabButtonId = sender.get_activeTab().get_id(); // Selected tab button id
        var tabContainer_OldHeight = 0;
        var tabButtonParentId = "";
        var tabContainer = ""; // Parent Tab Container Object
        var tabContainer_NewHeight = 0;
    
            for (var intCounter = 0; intCounter < aryDivs.length; intCounter++) 
                {
                    if ("" != aryDivs[intCounter][0]){    
                        // looks for the parent control id in the child control id        
                        if(tabButtonId.indexOf(aryDivs[intCounter][0]) != -1)
                            {
                             tabButtonParentId = aryDivs[intCounter][0];
                             tabContainer_OldHeight = aryDivs[intCounter][1];
                             
                             // Gets Height of currently selected tab Container
                             tabContainer = window.document.getElementById(tabButtonParentId);
                             tabContainer_NewHeight = tabContainer.offsetHeight;
                             
                             // Update Div Array with new tab Container Height
                             window.aDivs[intCounter][1] = tabContainer_NewHeight;
                            } 
                    }
                }   
    
      // Gets footer height from AdjustColumnsHeight()
      var footerHeight = window.footerHeight;
      // Calculates footer height by difference between the tab container befor and after selection of new tab     
      var newfooterHeight = footerHeight + (tabContainer_NewHeight - tabContainer_OldHeight); 
      // Adjusts Footer
      if (footer != null) {footer.style.top = newfooterHeight + 'px'}

      // Modifies the current overal footer position.
      window.footerHeight = window.footerHeight + (tabContainer_NewHeight - tabContainer_OldHeight);

    }
    
