function TrapKeyDown ( zButton )
{
	if (document.all)
	{
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			var oTarget = GetById(zButton);
			if ( oTarget != null )
			{
				oTarget.click();
			}
		} 
	}
}

function XsltFind ( zControl )
{
	var oObj = document.forms[0].elements[zControl];
	if ( oObj == null )
	{
		zControl = zControl.replace('$','_');
		oObj = document.forms[0].elements[zControl];
	}
	if ( oObj == null )
	{
		zControl = null;
	}
	return zControl;
}

function XsltAutoPost ( zControl, iSort )
{
	zControl = XsltFind ( zControl + "_Sort_" + iSort );
	if ( zControl != null )
	{
		document.forms[0].elements[zControl].checked=true;
		__doPostBack(zControl+'$Submit','');
	}
}
function XsltSortPost ( zControl, iSort )
{
	zControl = XsltFind ( zControl + "_Sort_" + iSort );
	if ( zControl != null )
	{
		document.forms[0].elements[zControl].checked=true;
		__doPostBack(zControl + '$Submit','');
	}
}
function XsltFilter ( zControl, iFilter, zFilter )
{
	zControl = XsltFind ( zControl + "_Filter_" + iFilter );
	if ( zControl != null )
	{
		document.forms[0].elements[zControl].value = zFilter;
	}
	//__doPostBack(zControl + '$Submit','');
	return zControl;
}
function XsltFilterPost ( zControl, iFilter, zFilter )
{
	zControl = XsltFilter ( zControl, iFilter, zFilter );
	if ( zControl != null )
	{
		__doPostBack(zControl + '$Submit','');
	}
}
function XsltNavToPage ( zControl, iPageNumber )
{
	zControl = XsltFind ( zControl + "_PageCurrent");
	if ( zControl != null )
	{
		document.forms[0].elements[zControl].value = iPageNumber;
	}
	return zControl;
}
function XsltNavToPagePost ( zControl, iPageNumber )
{
	zControl = XsltNavToPage( zControl, iPageNumber );
	if ( zControl != null )
	{
		__doPostBack(zControl + '$Submit','');
	}
}


function getTargetFieldJScript( zParam )
{
    var fld;
    fld = getTargetSub( zParam );
    if ( fld == null )
    {
		zParam = zParam.replace(":","_");
    }
    return fld;
}
function getTargetSub ( zParam )
{
    var targets = zParam.split(";");
    var fld;
    try
    {
		if (targets.length == 1)
		{
			fld = parent.opener.document.forms[0].elements[targets[0]];
		}
		else
		{
			fld = parent.opener.document.forms[targets[0]].elements[targets[1]];
		}
    }
    catch(e)
    {
    }
    return fld;
}

function CheckForPopup()
{
	var zLoc = window.location.href;
	if ( document.referrer != zLoc )
	{
		var bDoit = false;
		if ( zLoc.indexOf("PopupAs=1") != -1 )	// AS=AutoSize
		{
			window.resizeTo(100,100);
			bDoit = true;
		}

		var iWidth = document.body.clientWidth;
		var iHeight = document.body.clientHeight;
		
		if ( (iWidth == 100 && iHeight == 100) || bDoit )
		{
			ResizeDialogWindow();
		}
		//window.focus();
		//window.document.focus();
		//window.document.body.focus();
		
		if ( zLoc.indexOf("PopupSb=1") != -1 )		// Sb = Scroll Bar
		{
			var iWidth = GetDocWidth();
			var iHeight = GetDocHeight();
			//alert(iWidth);
			//alert(iHeight);

			//alert(document.body.clientWidth);
			//alert(document.body.clientHeight);
			if ( iWidth > document.body.clientWidth || iHeight > document.body.clientHeight )
			{
				//alert(document.body.scroll);
				document.body.scroll = "auto";
				//alert(document.body.scroll);
			}
		}
	}
}

function SizeBody ( iWidth, iHeight )
{
	window.resizeTo ( iWidth, iHeight );
}

function DivDisplayer ( zExpandId, zContractId, zDivId, bOpen )
{
	if ( bOpen )
	{
		zExpandId.style.visibility = 'hidden';
		zExpandId.style.display = 'none';
		zContractId.style.visibility = 'visible';
		zContractId.style.display = '';
		zDivId.style.visibility = 'visible';
		zDivId.style.display = '';
	}
	else
	{
		zExpandId.style.visibility = 'visible';
		zExpandId.style.display = '';
		zContractId.style.visibility = 'hidden';
		zContractId.style.display = 'none';
		zDivId.style.visibility = 'hidden';
		zDivId.style.display = 'none';
	}
}

function DropRowHider ( iTest, bEqual, DropId, Row1Id )
{
	if ( (bEqual && DropId.value == iTest) || (!bEqual && DropId.value != iTest) )
	{
		Row1Id.style.visibility = "hidden";
		Row1Id.style.display = "none";
	}
	else
	{
		Row1Id.style.visibility = "visible";
		Row1Id.style.display = "";
	}
}
function CheckRowHider ( iTest, bEqual, CheckId, Row1Id )
{
	if ( (bEqual && CheckId.checked == iTest) || (!bEqual && CheckId.checked != iTest) )
	{
		Row1Id.style.visibility = "hidden";
		Row1Id.style.display = "none";
	}
	else
	{
		Row1Id.style.visibility = "visible";
		Row1Id.style.display = "";
	}
}


function ChangeParentPopUpInput ( zId, zValue )
{
    var fld;
    fld = getTargetFieldJScript(zId);

	if ( fld != null )
	{
		fld.value = zValue;
		fld.fireEvent("onChange");
	}
    window.close();
}

function changeImageFromHidden( zHidden, zImage )
{
	var t = document.forms[0].elements[zHidden].value;
	var p = t.split(':');
	var o = document.images[zImage]; 
	o.src = p[1] + ':' + p[2];
	o.style.visibility = 'visible';
	o.style.display = '';
}

var g_oMyPopup = null;
var iTest = 0;
var g_zFrameList = "";

function UrlParamAdd ( zUrl, zKey, zValue )
{
	var iIdx = zUrl.indexOf(zKey+"=");
	if ( iIdx == -1 )
	{
		if ( zUrl.indexOf("?") == -1 )
		{
			zUrl += "?";
		}
		else
		{
			zUrl += "&";
		}
		zUrl += zKey + "=" + zValue;
	}
	else
	{
		var zTemp = zUrl.substring(iIdx+zKey.length+1, zUrl.length);
		zUrl = zUrl.substring(0,iIdx+zKey.length+1) + zValue;
		var iNext = zTemp.indexOf("&");
		if ( iNext != -1 )
		{
			zUrl += zTemp.substring(iNext,zTemp.length);
		}
	}
	
	return zUrl;
}

function WinPopup(url, winname, iWidth, iHeight, fScroll, zFrameName, iPopupType, bIsOffSite )
{
	var iParentWidth = document.body.clientWidth/2+ window.screenLeft/1-iWidth/2;
	var iParentHeight = document.body.clientHeight/2+window.screenTop/1-iHeight/2;

	var fResize = false;

	if ( !bIsOffSite )
	{
		if ( g_oMyPopup != null )
		{
			if ( iWidth <= 100 && iHeight <= 100 )
			{
				url = UrlParamAdd ( url, "PopupAs", "1" );
			}
		}
		if ( fScroll )
		{
			url = UrlParamAdd ( url, "PopupSb", "1" );
		}
		url = UrlParamAdd ( url, "Popup", "1" );
	}
	
	//zFrameName = "BodyIFrame"
	var bDoPopup  = true;
	
	// This check will verify that the browser is IE and therefore can
	// user iframes, otherwise force the browser to do a popup.
	if ( navigator.appName != "Microsoft Internet Explorer" )
	{
		zFrameName = "";
	}
	
	// don't execute on window
	if ( (zFrameName.length > 0) && (iPopupType != 4) )
	{
		if ( iPopupType == 3 )
		{
			g_zFrameList = zFrameName;
		}
		// Handle the inframe body calls
		var oTransContainer = document.getElementById("div"+zFrameName);
		if ( oTransContainer != null )
		{
			oTransContainer.style.visibility = 'visible';
			oTransContainer.style.display = '';
			
			var oFrame = document.getElementById(zFrameName);
			if ( oFrame != null )
			{
				oFrame.src = url;
				oFrame.style.visibility = 'visible';
				oFrame.style.display = '';
				oFrame.focus();
				
				bDoPopup  = false;
				if ( iWidth != 100 && iHeight != 100 )
				{
					var oObj = window.document.getElementById('MyBody')
					var iParentWidth = oObj.clientWidth;
					iWidth = Math.min(iParentWidth,iWidth);
					var iParentHeight = oObj.clientHeight;
					iHeight = Math.min(iParentHeight,iHeight);
					
					oTransContainer.style.width = iWidth;
					oTransContainer.style.height = iHeight;
					oFrame.style.width = iWidth;
					oFrame.style.height = iHeight;
					
					if ( oObj.style.textAlign == 'center' )
					{
						oTransContainer.style.posLeft = 0;
						oTransContainer.style.posTop = iParentHeight/2-iHeight/2+oObj.scrollTop;
					}
					else
					{
						oTransContainer.style.posLeft = iParentWidth/2-iWidth/2;
						oTransContainer.style.posTop = iParentHeight/2-iHeight/2+oObj.scrollTop;
					}

					//oFrame.moveTo(iParentLeft-iWidth/2,iParentTop-iHeight/2);
				}
				else
				{
					oTransContainer.style.posTop = 0;
					oTransContainer.style.posLeft = 0;
				}
				iTest = 1;
			}
		}
	}
	
	// make winname useable by removing extra characters	
	winname = winname.replace(/[^a-z^A-Z]/g, "")
	if ( winname.length > 20 )
	{
		winname = winname.substr(0,20);
	}
	
	// check to see if a window should be displayed (4 is window type)
	if (iPopupType == 4)
	{
		//Get window manager
        var windowManager = GetRadWindowManager();
              
        // attempt to get the window by name
        var popupWindow = windowManager.GetWindowByName(winname);
        
        // check to see if window already exists
        if (popupWindow)
        {
			// set the new url
			popupWindow.SetUrl(url);
			
			// set the size
			popupWindow.SetSize(iWidth, iHeight);
			
			// show the window and make it active
			popupWindow.Show();
			popupWindow.SetActive(true);
        }
        else
        {
			// open the window
			var popupWindow = window.radopen(url, winname);
			
			// set the size
			popupWindow.SetSize(iWidth, iHeight);
			
			// probably need to set the initial position too
        }
        
        // turn off popup code
        bDoPopup = false;
	}
	else if ( bDoPopup )
	{
		// Handle pure popup's
		var win = "width=" + iWidth + ",height=" + iHeight;
		win = win + ",top=" + iParentHeight + ",left=" +iParentWidth;
		if ( fScroll )
		{
			win = win + ",scrollbars="+(iHeight>screen.availHeight ? 'yes' : 'no');
		}
		else
		{
			win = win + ",scrollbars=no";
		}
		win = win + ",menubar=no";
		win = win + ",toolbar=no,location=no,status=no;directories=no";
		win = win + ",resizeable=no";
		
		winname = winname.replace(/[^a-z^A-Z]/g, "")
		if ( winname.length > 20 )
		{
			winname = winname.substr(0,20);
		}
		g_oMyPopup = window.open(url, winname, win);
		g_oMyPopup.focus();
	}
}

var g_oMyFPopup = null;
function WinPopupFPicker(url, winname, iWidth, iHeight, fScroll, zFrameName, iPopupType)
{
	var iParentWidth = document.body.clientWidth/2+ window.screenLeft/1-iWidth/2;
	var iParentHeight = document.body.clientHeight/2+window.screenTop/1-iHeight/2;

	var win = "width=" + iWidth + ",height=" + iHeight;
	win = win + ",top=" + iParentHeight + ",left=" +iParentWidth;
	if ( fScroll )
	{
		win = win + ",scrollbars="+(iHeight>screen.availHeight ? 'yes' : 'no');
	}
	else
	{
		win = win + ",scrollbars=no";
	}
	win = win + ",menubar=no";
	win = win + ",toolbar=no,location=no,status=no;directories=no";
	win = win + ",resizeable=no";
	var fResize = false;
	if ( g_oMyPopup != null )
	{
		url = UrlParamAdd ( url, "PopupAs", "1" );
	}
	winname = winname.replace(/[^a-z^A-Z]/g, "")
	if ( winname.length > 20 )
	{
		winname = winname.substr(0,20);
	}
	g_oMyPopup = window.open(url, winname, win);
	//g_oMyFPopup.focus();
}

function ClosePopupWindow ( bRefreshParent )
{
	if ( window.opener == null )
	{
		if ( bRefreshParent == 'True' )
		{
			window.parent.execScript('window.location.replace( window.location.href );');
		}
		window.document.body.style.visibility = 'hidden';
		window.document.body.style.display = 'none';
		window.resizeTo(0,0);
		window.moveTo(0,0);
	}
	else
	{
		if ( bRefreshParent == 'True' )
		{
			window.opener.execScript('window.location.replace( window.location.href );');
		}
		window.close();
	}
}

function ResizeDialogWindow()
{
	var iWidth = GetDocWidth();
	var iHeight = GetDocHeight();

	ResizeDialogFromSize ( iWidth, iHeight );
}

function ClickTest()
{
	if ( window.opener != null )	// This is a popup.
	{
		//alert ( "popup lost focus" );
	}
	else if ( document.parentWindow != null && g_zFrameList != "" ) // this is a inframe element.
	{
		var zLoc = window.location.href;
		if ( zLoc.indexOf("Popup=1") == -1 )	// If this is not a popup
		{
			if ( iTest == 1 )
			{
				iTest = 2;
			}
			else if ( iTest == 2 )
			{
				var oFrame = document.getElementById(g_zFrameList);
				if ( oFrame != null )
				{
					oFrame.contentWindow.document.body.style.visibility = 'hidden';
					oFrame.contentWindow.document.body.style.display = 'none';
					oFrame.contentWindow.resizeTo(0,0);
					oFrame.contentWindow.moveTo(0,0);
				}
				iTest = 0;
			}
		}
	}
}

function ResizeDialogFromSize(iWidth,iHeight)
{
	var oParent = window.opener;

	if ( oParent != null )	// This is a popup.
	{
		if ( navigator.appName == "Microsoft Internet Explorer" )
		{
			iWidth += document.body.leftMargin/1+document.body.rightMargin/1;
			iWidth += -(document.body.clientLeft*2);
			//iHeight += document.body.topMargin/1+document.body.bottomMargin/1;
		}
		window.resizeTo(iWidth,iHeight);
		
		var iParentLeft = oParent.document.body.clientWidth/2;
		var iParentTop = oParent.document.body.clientHeight/2;
		if ( navigator.appName == "Microsoft Internet Explorer" )
		{
			iParentLeft += oParent.screenLeft;
			iParentTop += oParent.screenTop;
		}
		
		window.moveTo(iParentLeft-iWidth/2,iParentTop-iHeight/2);
		//window.focus();
	}
	else if ( document.parentWindow != null ) // this is a inframe element.
	{
		var oObj = window.parent.document.getElementById('MyBody')
		var iParentWidth = oObj.clientWidth;
		iWidth = Math.min(iParentWidth,iWidth);
		var iParentHeight = oObj.clientHeight;
		iHeight = Math.min(iParentHeight,iHeight);
		
		window.resizeTo(iWidth,iHeight);
		
		iWidth			= iWidth/2;
		iHeight			= iHeight /2;
		iParentHeight	= iParentHeight /2;
		iParentWidth	= iParentWidth /2;
		
		if ( oObj.style.textAlign == 'center' )
		{
			window.moveTo(iParentWidth - iWidth,iParentHeight-iHeight+oObj.scrollTop);
		}
		else
		{
			window.moveTo(iWidth,iParentHeight-iHeight+oObj.scrollTop);
		}

		//oObj.focus();
		//var oObj = window.document.getElementById('MyBody');
		//window.document.focus();
		//oObj.parent.focus();
		//	alert (oObj);
		//oObj.attachEvent( "onblur" , OnWindowBlur );
	}
}

function GetDocWidth()
{
	//var iWidth = document.body.scrollWidth/1;
	var iWidth = document.getElementById('BodyDiv').offsetWidth/1;
	//test iWidth += document.body.leftMargin/1+document.body.rightMargin/1;
	//test iWidth += -(document.body.clientLeft*2);
	//iWidth += document.body.offsetWidth;
	//iWidth += -document.body.clientWidth;
	//iWidth -= 6;
	
	if ( document.body.clientWidth < 100 )
	{
		iWidth += (100 - document.body.clientWidth);
	}
	
	iWidth = Math.min ( window.screen.availWidth * .90, iWidth );

	return iWidth;
}

function GetDocHeight()
{
	//var iHeight = document.body.scrollHeight/1;
	var iHeight = document.getElementById('BodyDiv').offsetHeight;
	//test iHeight += document.body.topMargin/1+document.body.bottomMargin/1;
	//iHeight += -document.body.clientTop*2;
	//iHeight += document.body.offsetHeight;
	if ( document.body.clientHeight < 100 )
	{
		iHeight += (100 - document.body.clientHeight);
	}
	//iHeight += -document.body.clientHeight;
	//iHeight += 20;

	iHeight = Math.min(window.screen.availHeight * .90 ,iHeight);
	return iHeight;
}

function getObjectLeft(obj)
{
	var offset=0;
	while (obj != null && obj != document.body)
	{
		offset += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return offset + window.screenLeft;
}


function getObjectTop(obj)
{
	var offset=0;
	while (obj != null && obj != document.body)
	{
		offset += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return offset + window.screenTop;
}

//var zLoc;
//zLoc = new String(document.location);

function GetUrlParam ( zLoc, zName )
{
	iStart = zLoc.indexOf ( zName )
	iStart = zLoc.indexOf ( "=", iStart )
	//alert ( iStart );
	iEnd = zLoc.indexOf ( "&", iStart )
	//alert ( iEnd );
	zSub = new String(zLoc.substr(iStart+1,iEnd-iStart-1));
	
	zSub = zSub.replace("+", " ")
	return (zSub);
}

function IssuePostBack( zPostBack )
{
	//Main_form.action = Main_form.substr(0,Main_form.indexOf("&PostBack="));
	zSub = new String(Main_form.action);
	zSub = zSub.substr(0,zSub.indexOf("&PostBack="));
	Main_form.action = zSub+"&Poster";
	eval(zPostBack);
}

function PrintPage ( zPrintDiv )
{
	//alert ( window.document.all[zPrintDiv] );
	window.document.all[zPrintDiv].style.visibility = "hidden";
	window.document.all[zPrintDiv].style.display = "none";
	ResizeDialogWindow();
	window.print();
	window.document.all[zPrintDiv].style.display = "inline";
	window.document.all[zPrintDiv].style.visibility = "";
	ResizeDialogWindow();
}

function GetById(sID)
{
	if (document.all == null)
	{
		return document.getElementById(sID);
	}
	else
	{
		return document.all(sID);
	}
}

function ToggleVisibility ( sID )
{
	if ( sID.style.visibility == "visible" )
	{
		sID.style.visibility = "hidden";
		sID.style.display = "none";
	}
	else
	{
		sID.style.visibility = "visible";
		sID.style.display = "";
	}
}

function AdOnLoad ( sID )
{
	var oId = GetById(sID);
	if ( oId != null )
	{
		try
		{
			oId.style.visibility = '';
		}
		catch(e)
		{
		}
	}
}


function Search_Setup ( zSource )
{
	var oSearchText;
	var oTarget;
	
	oSearchText		= GetById(zSource + "_SearchText");
	oTarget			= GetById(g_zSearchSource + "_SearchText" );
	if ( oSearchText != null && oTarget != null )
	{
		oTarget.value	= oSearchText.value;
	}

	oSearchText		= GetById(zSource + "_AllWords");
	oTarget			= GetById(g_zSearchSource + "_AllWords" );
	if ( oSearchText != null && oTarget != null )
	{
		oTarget.checked	= oSearchText.checked;
	}

	oSearchText		= GetById(zSource + "_AnyWords");
	oTarget			= GetById(g_zSearchSource + "_AnyWords" );
	if ( oSearchText != null && oTarget != null )
	{
		oTarget.checked	= oSearchText.checked;
	}

	oSearchText		= GetById(zSource + "_ExactPhrase");
	oTarget			= GetById(g_zSearchSource + "_ExactPhrase" );
	if ( oSearchText != null && oTarget != null )
	{
		oTarget.checked	= oSearchText.checked;
	}
	
	oTarget			= GetById(g_zSearchSource + "_SubmitButton" );
	if ( oTarget != null )
	{
		oTarget.click();
	}
}

function Search_Launch ( zSource )
{
	var oTarget;
	var zSMode = 2;
	oTarget			= GetById(zSource + "_AllWords" );
	if ( oTarget != null )
	{
		if ( oTarget.checked )
		{
			zSMode = 1;
		}
		else
		{
			oTarget			= GetById(zSource + "_ExactPhrase" );
			if ( oTarget != null )
			{
				if ( oTarget.checked )
				{
					zSMode = 3;
				}
			}
		}
	}

	oTarget		= GetById(zSource + "_SearchText");
	if ( oTarget != null )
	{
		var zAdd	= "&Search=" + escape(oTarget.value) + "&SMode=" + zSMode;
		Auto_Launch ( zSource + "_LaunchLink", zAdd );
	}
}

function Auto_Launch ( zTarget, zParams )
{
	var oTarget = GetById(zTarget);
    
    if ( oTarget != null )
    {
		if ( oTarget != "" )
		{
			// We are a simple href so just augment the url.
			var oAttrib = oTarget.attributes["href"];
			oAttrib.value = oAttrib.value + zParams;
			oTarget.click();
		}
		else
		{
			var oAttrib = oTarget.attributes["onclick"];
			var zTemp = oAttrib.value;
			var iIdx = zTemp.indexOf ( "?T0=" );
			if ( iIdx > -1 )
			{
				iIdx = zTemp.indexOf ( "'", iIdx );
				zTemp = zTemp.substring(0,iIdx) + zParams + zTemp.substring(iIdx);
				eval (zTemp);
			}
		}
	}
}