//Opens a new window to display a report in.
function openRptWindow(intDocID)
{
    var strFeatures
	var strURL
	
	strFeatures = 'resizable=1,toolbar=0,location=0,directories=0,addressbar=0,scrollbars=1,status=1,menubar=0,top=0,left=0,width='
	//strFeatures = 'resizable=1,toolbar=0,location=0,directories=0,addressbar=0,scrollbars=1,status=1,menubar=0,top=0,left=0,width='
	    
	strFeatures += (window.screen.availWidth)+ ',height=' +(window.screen.availHeight) + ',screenX=' + (window.screen.availWidth) + 'screenY=' + (window.screen.availHeight)
	strURL = 'CRViewer.aspx?DocID=' + escape(intDocID)
	var newWindow = window.open(strURL,'DisplayReport',strFeatures);
	newWindow.resizeTo(screen.availWidth, screen.availHeight);
}

//Opens a new window to display the output from a scheduled report.
function openScheduleWindow(strFileName, intFolderID, strType)
{
	var strFeatures
	var strURL

	strFeatures = 'resizable=1,toolbar=0,location=1,directories=1,addressbar=0,scrollbars=1,status=1,menubar=0,top=0,left=0,width='
	strURL = 'ScheduledFile.aspx?Rpt=' + escape(strFileName) + '&FolderID=' + escape(intFolderID) + '&FileType=' + escape(strType)
	
	strFeatures += (window.screen.availWidth)+ ',height=' +(window.screen.availHeight) + ',screenX=' + (window.screen.availWidth) + 'screenY=' + (window.screen.availHeight)
	var newWindow = window.open(strURL,'DisplayReport',strFeatures);
	newWindow.resizeTo(screen.availWidth, screen.availHeight);
}

//Opens a new window to display help
function callHelp(Page)
{
	var URL = 'help/index.html?page=source/' + Page
	var newWindow = window.open(URL,'Help','HEIGHT=600,WIDTH=950,LEFT=150,TOP=75,SCROLLBARS,RESIZABLE');
}

//Ok button action on some admin lists that are not html forms
function ReturnToAdministration()
{
	window.location = 'AdministrationLinks.aspx';
}

// This is used by the parameter user control to add a custom value to the Selected Parameters listbox
function addCustomValue(from,to)
{
	// First check for a duplicate
	var itemFound;
	
	itemFound = false;
	for (var i=0; i<to.options.length; i++) 
		{
			if (from.value == to.options[i].value)
			{
				itemFound = true;
				alert("Value has already been added.");
			}
		}

	if (itemFound == false)
	{
		// Add the custom value to the listbox
		addOption(to, from.value, from.value, false);
	}
	
	// remove the custom value from the text box
	from.value = "";

}

// This is used by the parameter user control to add a selected value from a select element and add it to a text element
function addSelectedValue(from,to)
{
	var selectedValue;

	selectedValue = "";
	
	for (var i=0; i<from.options.length; i++) 
		{
			if (from.options[i].selected == true)
			{
				selectedValue = from.options[i].value;
			}
		}
	
	to.value = selectedValue;
}

// This is used by the parameter user control to add a Range Value to a listbox
function addRangeValues(beginRange, endRange, to)
{
	// First check for a duplicate
	var itemFound;
	var rangeText;
	var rangeValue;
	
	rangeText = "[" + beginRange.value + " .. " + endRange.value + "]"
	rangeValue = beginRange.value + "~" + endRange.value
	
	itemFound = false;
	for (var i=0; i<to.options.length; i++) 
		{
			if (rangeText == to.options[i].value)
			{
				itemFound = true;
				alert("Range has already been added.");
			}
		}

	if (itemFound == false)
	{
		// Add the custom value to the listbox
		addOption(to, rangeText, rangeValue, false);
	}
	
	// remove the custom value from the text box
	beginRange.value = "";
	endRange.value = "";

}

// This is used by the CRViewer and EditSchedule to select values in the HTML select 
// elements located in the Parameters control
function prepareForm()
{
	var fieldCount = document.getElementById("Count");
	
	if (fieldCount != null)
	{
	var paramCount = parseInt(fieldCount.value + 1);
	
	for (var i=0; i<paramCount; i++) 
		{
			var paramName = "P" + i;
			var elementTypeName = "P" + i + "ElementType"
			var elementTypeControl = document.getElementById(elementTypeName);
			
			if (elementTypeControl != null)
			{
				if (elementTypeControl.value=="SelectMultiple") 
				{
					var elementControl = document.getElementById(paramName);
					selectAllOptions(elementControl);
					
					// Look for a Range SelectBox
					var rangeSelect = document.getElementById("lstRangeValuesP" + i)
				
					if (rangeSelect != null)
					{
						selectAllOptions(rangeSelect)
					}
				}
			}
		}
	}
}
