﻿//**************************************************************************************
//**************************************************************************************
//*  Copyright (c) 2004-2009 Swip Systems Incorporated.  All Rights Reserved.          *
//*  Warning:  This computer program is protected by copyright laws as described       *
//*  in the License Agreement.  Unauthorized reproduction or distribution of this      *
//*  program, or any portion of this program may result in severe civil and criminal   *
//*  penalties.  Violators will be prosecuted to the fullest extent of the law.        *
//**************************************************************************************
//**************************************************************************************


function ShowHideDivWithIFrame(strDivControlID, strIFrameControlID, blnDisplay, blnRepositionPopupToUpperLeft)
/*********************************************************************
Developer:	TJ McDowell
Date:		9/26/07
Purpose:	show / hide the div control and iframe handed in
Inputs:		div control, iframe control, boolean to show / hide the div control
Returns:	nothing
Note:      
********************************************************************
Developer:	TJ McDowell
Date:		2/23/09
Note:       added the reposition popup to upper left flag
********************************************************************/
{
    var intMainTableHeight;
    var intMainTableWidth;
    var intClientHeight;
    var intClientWidth;
    var intMaxHeight;
    var intMaxWidth;

	// if true was handed in (we want to show the div control)...
	if (blnDisplay == true)
	{
		// show the div control
		document.getElementById(strDivControlID).style.display = "";
		// iframe's width and height should be the same as the div
		document.getElementById(strIFrameControlID).style.height = document.getElementById(strDivControlID).clientHeight + "px";
		// changed to not subtract 30 off the client width  TLM 3/19/09
		document.getElementById(strIFrameControlID).style.width = document.getElementById(strDivControlID).clientWidth + "px";
		// subtracted 30 off the client width calculation  TLM 4/2/08
        // get the main table height and width (plus a little extra to compensate for padding)  TLM 3/19/08
        intMainTableWidth = document.getElementById("divContentPlaceHolder").clientWidth + 15;
        intMainTableHeight = document.getElementById("divContentPlaceHolder").clientHeight + 30;
        // get the height and width of the browser window  TLM 3/19/08
        intClientWidth = document.documentElement.clientWidth;
        intClientHeight = document.documentElement.clientHeight;
        // if the main table height is greater than the client height...  TLM 3/19/08
        if (intMainTableHeight > intClientHeight)
        {
            // set the max height to the main table height  TLM 3/19/08
            intMaxHeight = intMainTableHeight;
        }
        // if the main table height is NOT greater than the client height...  TLM 3/19/08
        else
        {
            // set the max height to the client height  TLM 3/19/08
            intMaxHeight = intClientHeight;
        }
        // if the main table width is greater than the client width...  TLM 3/19/08
        if (intMainTableWidth > intClientWidth)
        {
            // set the max width to the main table width  TLM 3/19/08
            intMaxWidth = intMainTableWidth;
        }
        // if the main table width is NOT greater than the client width...  TLM 3/19/08
        else
        {
            // set the max width to the client width  TLM 3/19/08
            intMaxWidth = intClientWidth;
        }
        // set the disable background so it covers the entire screen  TLM 3/19/08
		document.getElementById("ifrmDisableBackground").style.width = intMaxWidth + "px";
		document.getElementById("ifrmDisableBackground").style.height = intMaxHeight + "px";
		document.getElementById("divDisableBackground").style.width = intMaxWidth + "px";
		document.getElementById("divDisableBackground").style.height = intMaxHeight + "px";
		// if the popup DOES need to be repositioned to the upper left...  TLM 2/23/09
		if (blnRepositionPopupToUpperLeft)
		{
            // display the div in the upper left hand corner of the browser  TLM 3/17/08
            document.getElementById(strDivControlID).style.left = "30px";
            document.getElementById(strDivControlID).style.top = "115px";
            document.getElementById(strIFrameControlID).style.left = "30px";
            document.getElementById(strIFrameControlID).style.top = "115px";
        }
		// if the popup does NOT need to be repositioned to the upper left...  TLM 2/23/09
        else
        {
            // do nothing - do NOT reposition the popup or iframe  TLM 2/23/09
            // display the div in the upper left hand corner of the browser  TLM 3/17/08
            document.getElementById(strDivControlID).style.left = ((intClientWidth/2) - 300) + "px";
            document.getElementById(strDivControlID).style.top = "300px";
            document.getElementById(strIFrameControlID).style.left = ((intClientWidth/2) - 300) + "px";
            document.getElementById(strIFrameControlID).style.top = "300px";
        }
	}
	// if false was handed in (we want to hide the div control)...
	else
	{
		// hide the div control
		document.getElementById(strDivControlID).style.display = "none";
		document.getElementById(strIFrameControlID).style.width = "0px";
		document.getElementById(strIFrameControlID).style.height = "0px";
		// hide the disable background by setting its width and height to 0  TLM 2/23/09
		document.getElementById("ifrmDisableBackground").style.width = "0px";
		document.getElementById("ifrmDisableBackground").style.height = "0px";
		document.getElementById("divDisableBackground").style.width = "0px";
		document.getElementById("divDisableBackground").style.height = "0px";
	}
}

function DisableBackground()
/*********************************************************************
Developer:	TJ McDowell
Date:		11/13/08
Purpose:	disable the background so the user can only interact with
the popup
Inputs:		none
Returns:	nothing
Note 1:     copied from ShowHideDivWithIFrameForSSIPromptControl and modified
Note 2:     extra steps need to be taken if the user should not be able
            to get to background content - this disable is only to make
            it clear which part of the page the user should be interacting with
********************************************************************
Developer:	Scott Smith
Date:		6/25/09
Note:       copied from Nexus SSIGlobalJavaScript.js
********************************************************************/
{
	var intMainTableWidth;
	var intMainTableHeight;
	var intClientWidth;
	var intClientHeight;
	var intMaxWidth;
	var intMaxHeight;

	// get the main table height and width (plus a little extra to compensate for padding)  TLM 3/19/08
	intMainTableWidth = document.getElementById("container").clientWidth + 15;
	intMainTableHeight = document.getElementById("container").clientHeight + 30;
	// get the height and width of the browser window  TLM 3/19/08
	intClientWidth = document.documentElement.clientWidth;
	intClientHeight = document.documentElement.clientHeight;
	// if the main table height is greater than the client height...  TLM 3/19/08
	if (intMainTableHeight > intClientHeight) {
		// set the max height to the main table height  TLM 3/19/08
		intMaxHeight = intMainTableHeight;
	}
	// if the main table height is NOT greater than the client height...  TLM 3/19/08
	else {
		// set the max height to the client height  TLM 3/19/08
		intMaxHeight = intClientHeight;
	}
	// if the main table width is greater than the client width...  TLM 3/19/08
	if (intMainTableWidth > intClientWidth) {
		// set the max width to the main table width  TLM 3/19/08
		intMaxWidth = intMainTableWidth;
	}
	// if the main table width is NOT greater than the client width...  TLM 3/19/08
	else {
		// set the max width to the client width  TLM 3/19/08
		intMaxWidth = intClientWidth;
	}
	// set the disable background so it covers the entire screen  TLM 3/19/08
	document.getElementById("ifrmDisableBackground").style.width = intMaxWidth + "px";
	document.getElementById("ifrmDisableBackground").style.height = intMaxHeight + "px";
	document.getElementById("divDisableBackground").style.width = intMaxWidth + "px";
	document.getElementById("divDisableBackground").style.height = intMaxHeight + "px";
}

function ShowHideDivWithIFrameForSSIPromptControl(strDivControlID, strIFrameControlID)
/*********************************************************************
Developer:	TJ McDowell
Date:		8/27/08
Purpose:	show / hide the div control and iframe handed in
Inputs:		div control, iframe control
Returns:	nothing
Note:       copied from ShowHideDivWithIFrame and modified
********************************************************************
Developer:	Scott Smith
Date:		6/25/09
Note:       copied from Nexus SSIGlobalJavaScript.js
********************************************************************/
{
	// show the div control
	document.getElementById(strDivControlID).style.display = "";
	// iframe's width and height should be the same as the div
	document.getElementById(strIFrameControlID).style.height = (document.getElementById(strDivControlID).clientHeight - 10) + "px";
	// subtracted 30 off the client width calculation  TLM 4/2/08
	document.getElementById(strIFrameControlID).style.width = (document.getElementById(strDivControlID).clientWidth - 10) + "px";
	// disable the background so the user can only interact with the popup  TLM 11/13/08
	DisableBackground();
}

function SetUniqueRadioButton(strControlGroupRegEx, strSelectedRadioButton)
/*********************************************************************
Developer:	Scott Smith
Date:		7/7/09
Purpose:	set one unique radio button in a group 
Inputs:		control name/group name regular expression, selected 
			radiobutton
Returns:	nothing
Note:       this is a workaround for a bug in .NET that doesn't allow
			you to specify GroupName within a datalist/repeater 
			control - it unchecks all of the radio buttons in the
			group and then checks the one you selected
QA:         TMS 8/24/09
*********************************************************************/
{
	// get a regular expression object using the handed in control/group reg ex
	rgxRegEx = new RegExp(strControlGroupRegEx);
	// for each element in the form...
	for (i = 0; i < document.forms[0].elements.length; i++) {
		// get the current element
		elmElement = document.forms[0].elements[i]
		// if the element IS a radio button...
		if (elmElement.type == 'radio') {
			// if the current element IS part of the specified group...
			if (rgxRegEx.test(elmElement.name)) {
				// uncheck the element
				elmElement.checked = false;
			}
			// if the current element is NOT part of the specified group...
			else {
				// do nothing
			}
		}
		// if the element is NOT a radio button...
		else {
			// do nothing
		}
	}
	// check the selected radio button
	strSelectedRadioButton.checked = true;
}
