// JScript File

// Changes the image source for an image tag
function SwapImage(ID, ImageURL)
{
    document.getElementById(ID).src = ImageURL;
}    
    
// Changes the style sheet class on an element    
function SwapClass(ID, ClassName)
{
    document.getElementById(ID).className = ClassName;            
}

// Toggles the visibility of an object
function ToggleHiddenObject(ID)
{
    if(document.getElementById(ID).style.display == "")
    {
        document.getElementById(ID).style.display = "none";
    }
    else
    {
        document.getElementById(ID).style.display = "";
    }
        
}

// Shows a hidden object
function ShowHiddenObject(ID)
{
    if(document.getElementById(ID).style.display != "")
        {
            document.getElementById(ID).style.display = "";
        }
}

// Hides a visible object
function HideVisibleObject(ID)
{
    if(document.getElementById(ID).style.display != "none")
        {
            document.getElementById(ID).style.display = "none";
        }
}
    
// Indicates whether the current browser is Internet Explorer
function IsIE()
    {
    if (window.navigator.appName == "Microsoft Internet Explorer")
        {
            return true;
        }
    else
        {
            return false;
        }
    }   
    
// Toggles the visibility of an object and swaps images for between a show and 
// hide image.
function ToggleHiddenObjectAndSwapImage(ID, ImageID, ShowImageURL, HideImageURL)
{
    if(document.getElementById(ID).style.display == "")
    {
        document.getElementById(ID).style.display = "none";
        SwapImage(ImageID, ShowImageURL);
    }
    else
    {
        document.getElementById(ID).style.display = "";
        SwapImage(ImageID, HideImageURL);
    }
        
}
    
// Finds the leftmost position of the current monitor
    function GetLeftMostPosition(ScreenX)
        {
        // Establish Locals
        var nLeftOffset = 0;
        var nLeftMost = 0;
        
        // Always add 10 in case the screen is maximized.  The reason 10 is used instead of a single
        // pixel is because when Mozilla is maximized, the left position is negative.  This is done
        // because the client window would show up one screen to the left.
        ScreenX = ScreenX + 10;

        // If the screen being used is the main screen (has a 0 left position)
        // do not calculate the offset and just set the position to 0
        if ((ScreenX >= 0) && (ScreenX <= window.screen.availWidth))
            {
            return 0;
            }
            
        // See if the window position is negative (i.e. a far left monitor)        
        if (ScreenX < 0)
            {
            nLeftOffset = ScreenX * -1;
            }
        else
            {
            nLeftOffset = ScreenX;
            }
        
        // Determine how far from the left position of the screen the window is sitting
        nLeftOffset = window.screen.availWidth - nLeftOffset;
            
        // Now find the left most X position of the screen using the offset
        if (ScreenX < 0)
            {
                nLeftMost = (nLeftOffset * -1) + ScreenX;
            }
        else
            {
                nLeftMost = nLeftOffset + ScreenX;
            }
            
            return nLeftMost;
        }
        
// Launches the image viewer and dynamically sizes the window for the image
function ZoomImage(SessionName)
{	
//    // Establish Locals
//    var loImage = new Image();
//    var nLeft = 0;
//    var nTop = 0;
//    var xOffset = 0;

//    // Load the image
//    loImage.src = imgName;

//    // Get the width and height from the image
//    var nWidth = loImage.width + 10;
//    var nHeight = loImage.height + 10;

//    // Determine the window position and launch the image viewer
//    if (window.navigator.appName == "Microsoft Internet Explorer")
//    {
//        nLeft = GetLeftMostPosition(window.screenLeft) + ((window.screen.availWidth - nWidth) / 2);
//        nTop = (window.screen.availHeight - nHeight) / 2;

//        window.open("enlargeimageview.aspx?img=" + imgName,"zoomScreenShot","width=" + nWidth + ",height=" + nHeight + ",left=" + nLeft + ",top=" + nTop + ",resizable=1,scrollbars=no,menubar=no,toolbar=0,status=0");
//    }
//    else
//    {
//        nLeft = GetLeftMostPosition(window.screenX) + ((window.screen.availWidth - nWidth) / 2);
//        nTop = (window.screen.availHeight - nHeight) / 2;

//        window.open("enlargeimageview.aspx?img=" + imgName,"zoomScreenShot","width=" + nWidth + ",height=" + nHeight + ",left=" + nLeft + ",top=" + nTop + ",resizable=1,scrollbars=no,menubar=no,toolbar=0,status=0");
//    }
    var lcOptions = "width=1000, height=700, resizable=0, scrollbars=0, menubar=0, toolbar=0, status=0";

    window.open('zoomsingleimage.aspx?vname=' + SessionName + '&index=0','ViewLargerImage_Window',lcOptions);
}

// Shows/Hides the given element and changes the inner html of the given TD element to the appropriate
// given InnerHtml
function ShowHide(ElementID, TdElementID, ExpandedInnerHtml, CollapsedInnerHtml)
{
	// Establish locals
	var element;
	var tdElement;
	
	// Get the element to show/hide
	element = document.getElementById(ElementID);
    
	// Get the element to change the class
	tdElement = document.getElementById(TdElementID);
    
	// Show/Hide the element and change the css class on the parent
	if(element.style.display == 'none')
	{
	    // Show the display and change the CssClass
		element.style.display = '';
		tdElement.innerHTML = ExpandedInnerHtml;
	}
	else
	{
	    // Hide the display and change the CssClass
		element.style.display = 'none';
	    tdElement.innerHTML = CollapsedInnerHtml;
	}		
}

function Show(ElementID, TdElementID, ExpandedInnerHtml, CollapsedInnerHtml)
{
    // Establish locals
	var element;
	var tdElement;
	
	// Get the element to show/hide
	element = document.getElementById(ElementID);
    
	// Get the element to change the class
	tdElement = document.getElementById(TdElementID);
    
	// Show the display and change the CssClass
	element.style.display = '';
	tdElement.innerHTML = ExpandedInnerHtml;
}

function Hide(ElementID, TdElementID, ExpandedInnerHtml, CollapsedInnerHtml)
{
    // Establish locals
	var element;
	var tdElement;
	
	// Get the element to show/hide
	element = document.getElementById(ElementID);
    
	// Get the element to change the class
	tdElement = document.getElementById(TdElementID);
    
	// Hide the display and change the CssClass
	element.style.display = 'none';
	tdElement.innerHTML = CollapsedInnerHtml;
}

// Starts a slide show within a bullet detail control
function StartSlideShow(SessionName)
{
    var lcOptions = "width=800, height=640, resizable=0, scrollbars=0, menubar=0, toolbar=0, status=0";

    window.open('ImageSlideShow.aspx?vname=' + SessionName + '&index=0','ViewLargerImage_Window',lcOptions);
}

// Starts the online demo    
function StartOnlineDemo(StartPage)
{
    var lcOptions = "width=800, height=662, resizable=1, scrollbars=0, menubar=0, toolbar=0, status=0";

    window.open(StartPage,'OnlineDemo_Window',lcOptions);
}
    
function ShowPopUp(ImageUrl, Title, Width, Height)
{
    // Set the max values
    var MaxHeight = 600;
    var MaxWidth = 800;
    var HeightPadding = 20;
    var WidthPadding = 20;
    var AddPadding = true;
    
    var WindowHeight;
    var WindowWidth;

    // Check to make sure that the height of the popup is not too large
    if(Height > MaxHeight)
    {
        WindowHeight = MaxHeight;
        AddPadding = true;
    }
    else
    {
        WindowHeight = parseInt(Height);
    }
    
    // Check the width to make sure it is not too large
    if(Width > MaxWidth)
    {
        WindowWidth = MaxWidth;
        AddPadding = true;
    }
    else
    {
        WindowWidth = parseInt(Width);
    }
    
    // if either the height or width is going to scroll, add padding for the scroll bars
    if(AddPadding)
    {
        WindowWidth = WindowWidth + WidthPadding;
        WindowHeight = WindowHeight + HeightPadding;
    }
    
    // Show the window
    window.open('PopupImage.aspx?ImgUrl=' + ImageUrl + '&Title=' + Title + '&Width=' + WindowWidth + '&Height=' + WindowHeight, 'Title', 'width=' + WindowWidth + ', height=' + WindowHeight + ', resizable=1, scrollbars=1, menubar=0, toolbar=0, status=0');
}

function CenterPopupWindow(Url, Title, Width, Height)
{
    // Set the max values
    var MaxHeight = 600;
    var MaxWidth = 800;
    var HeightPadding = 20;
    var WidthPadding = 20;
    var AddPadding = true;
    
    var WindowHeight;
    var WindowWidth;

    // Check to make sure that the height of the popup is not too large
    if(Height > MaxHeight)
    {
        WindowHeight = MaxHeight;
        AddPadding = true;
    }
    else
    {
        WindowHeight = parseInt(Height);
    }
    
    // Check the width to make sure it is not too large
    if(Width > MaxWidth)
    {
        WindowWidth = MaxWidth;
        AddPadding = true;
    }
    else
    {
        WindowWidth = parseInt(Width);
    }
    
    // if either the height or width is going to scroll, add padding for the scroll bars
    if(AddPadding)
    {
        WindowWidth = WindowWidth + WidthPadding;
        WindowHeight = WindowHeight + HeightPadding;
    }
    
    // Show the window
    window.open(Url + '?Title=' + Title + '&Width=' + WindowWidth + '&Height=' + WindowHeight, 'Title', 'width=' + WindowWidth + ', height=' + WindowHeight + ', resizable=1, scrollbars=1, menubar=0, toolbar=0, status=0');
}

function PopupWindow(Url, Title, Width, Height)
{
    // Set the max values
    var MaxHeight = 600;
    var MaxWidth = 800;
    var HeightPadding = 20;
    var WidthPadding = 20;
    var AddPadding = true;
    
    var WindowHeight;
    var WindowWidth;

    // Check to make sure that the height of the popup is not too large
    if(Height > MaxHeight)
    {
        WindowHeight = MaxHeight;
        AddPadding = true;
    }
    else
    {
        WindowHeight = parseInt(Height);
    }
    
    // Check the width to make sure it is not too large
    if(Width > MaxWidth)
    {
        WindowWidth = MaxWidth;
        AddPadding = true;
    }
    else
    {
        WindowWidth = parseInt(Width);
    }
    
    // if either the height or width is going to scroll, add padding for the scroll bars
    if(AddPadding)
    {
        WindowWidth = WindowWidth + WidthPadding;
        WindowHeight = WindowHeight + HeightPadding;
    }
    
    // Show the window
    window.open(Url + '?Title=' + Title + '&Width=' + WindowWidth + '&Height=' + WindowHeight, 'Title', 'width=' + WindowWidth + ', height=' + WindowHeight + ', resizable=1, scrollbars=1, menubar=0, toolbar=0, status=0');
}


