
/**************************************************************************************
 *  Description : Global variables used by the following functions:                   * 
 *                    setCurrentBrowserCoordinates()                                  *
 *                    goToCurrentBrowserCoordinates()                                 *
 *  ISD Feature : ""                                                                  *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
var justDoIt = true;

/**************************************************************************************
 *  Function    : setCurrentBrowserCoordinates()                                      *
 *  Description : Records current browser focus location based upon user input        *
 *                    (scroll, click, or keypress).                                   *
 *  Parameters  : None.                                                               *
 *  ISD Feature : "Maintain position in tables"                                       *
 *  Authors     : Akesh Gupta, Light Speed Solutions                                  *
 **************************************************************************************/
 function setCurrentBrowserCoordinates() {
    var scrollX, scrollY;
    
    if (justDoIt == true) {
		var pageLeftCoordinate = document.getElementById("pageLeftCoordinate");
		var pageTopCoordinate = document.getElementById("pageTopCoordinate");

		// do not scroll in pre-v3.2.1 apps (which do not contain the hidden scroll coordinates fields)			
		if (!pageLeftCoordinate || !pageTopCoordinate) return;
    
		if (document.all)
		{
			if (!document.documentElement.scrollLeft)
				scrollX = document.body.scrollLeft;
			else
				scrollX = document.documentElement.scrollLeft;
		 
			if (!document.documentElement.scrollTop)
				scrollY = document.body.scrollTop;
			else
				scrollY = document.documentElement.scrollTop;
		}
		else
		{
			scrollX = window.pageXOffset;
			scrollY = window.pageYOffset;
		}
	    	
	    // alert("setCurrentBrowserCoordinates(x=" + scrollX + ",y=" + scrollY + ")");
		pageLeftCoordinate.value = scrollX;
		pageTopCoordinate.value = scrollY;
    }
}
  
/**************************************************************************************
 *  Function    : goToCurrentBrowserCoordinates()                                     *
 *  Description : Moves to the browser coordinates previously saved by                *
 *                    setCurrentBrowserCoordinates().                                 *
 *  Parameters  : None.                                                               *
 *  ISD Feature : "Maintain position in tables"                                       *
 *  Authors     : Akesh Gupta, Light Speed Solutions                                  *
 **************************************************************************************/
 function goToCurrentBrowserCoordinates() {
	if (justDoIt == true) {
		var pageLeftCoordinate = document.getElementById("pageLeftCoordinate");
		var pageTopCoordinate = document.getElementById("pageTopCoordinate");

		// do not scroll in pre-v3.2.1 apps (which do not contain the hidden scroll coordinates fields)	
		if (!pageLeftCoordinate || !pageTopCoordinate) return;
		
		// do not scroll if not a doPostBack() reload of page
		if ((pageLeftCoordinate.value == "") && (pageTopCoordinate.value == "")) return;

		var scrollX = pageLeftCoordinate.value;
		var scrollY = pageTopCoordinate.value;
		// alert("goToCurrentBrowserCoordinates(x=" + scrollX + ",y=" + scrollY + ")");
		window.scrollTo(scrollX, scrollY);
	}
 }

/**************************************************************************************
 *  Description : Event handlers (scroll, click, and keypress) active for all pages.  *
 *  Parameters  : None.                                                               *
 *  ISD Feature : "Maintain position in tables"                                       *
 *  Authors     : Akesh Gupta, Light Speed Solutions                                  *
 **************************************************************************************/
  window.onload = goToCurrentBrowserCoordinates;
  window.onscroll = setCurrentBrowserCoordinates;
  window.onclick = setCurrentBrowserCoordinates;
  window.onkeypress = setCurrentBrowserCoordinates;

/**************************************************************************************
 *  Function    : ShowDetails()                                                       *
 *  Description : Hide or Shows the specified table row                               *
 *                    (scroll, click, or keypress).                                   *
 *  Parameters  : link : the link to change from + to - and back.                     *
 *                tableRow : tha table row to show or hide                            *
 *  ISD Feature : none                                                                *
 *  Authors     : Ariel Serrano, Informatica Ambientale S.r.l.                        *
 **************************************************************************************/
 function ShowDetails(link, tableRow){
    var tableRowCtrl = document.getElementById(tableRow);
	
	// verify the link and row isn't null
	if (link && tableRowCtrl)
	{
//	    if(document.all){
//             alert("Inside " + link.innerText + " " + tableRowCtrl.style.display);
//        } else{
//            alert("Inside " + link.textContent + " " + tableRowCtrl.style.display);
//        }
	    
        if (tableRowCtrl.style.display=="none")
        {
            // is hidden, then show it
            tableRowCtrl.style.display="";
            
            if(document.all){
                 link.innerText = "-";
            } else{
                link.textContent = "-";
            }

            link.style.paddingRight = "4px";
            link.style.paddingLeft = "4px";
        }
        else
        {
            // is visible, then hide it
            tableRowCtrl.style.display="none";
            
            if(document.all){
                 link.innerText = "+";
            } else{
                link.textContent = "+";
            }
            
            link.style.paddingRight = "2px"; 
            link.style.paddingLeft = "2px";
        }
	}
 }
 
function FlagInactive ( flagname )
{
    var imageCtrl = document.getElementById(flagname);
	
    if (imageCtrl) {
        var imagepath = "../Images/" + flagname + "Inactive.jpg";
        imageCtrl.src = imagepath;
    }
}
function FlagActive ( flagname )
{
    var imageCtrl = document.getElementById(flagname);
	
    if (imageCtrl) {
        var imagepath = "../Images/" + flagname + "Active.jpg";
        imageCtrl.src = imagepath;
    }
}
