/*******************************/
/* Courtesy www.quirksmode.org           */
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
				obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
				obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//Gets an array of the selected items in a checkboxlist.
//Please note that the values in the array are the text values in the checkboxlist,
//not the ID values, because the ID values are not rendered on the client.
function GetSelectedValuesFromCheckBoxList(checkBoxListClientID)
{
	var selectedValues = new Array();
	var checkBoxList = $get(checkBoxListClientID);
	var arrayOfCheckBoxes = checkBoxList.getElementsByTagName("input");
    
	for(var i=0; i < arrayOfCheckBoxes.length; i++)
	{
		if(arrayOfCheckBoxes[i].checked)
		{
			var label = arrayOfCheckBoxes[i].parentNode.childNodes[1];
			
			//We can't get at the value of the checkbox item, so we'll need to get at the text,
			//and do a reverse-lookup on the server.
			if (label.innerText)
				// For IE-type browsers
				selectedValues.push(label.innerText);  
			else if (label.textContent)
				// For Mozilla-based browsers
				selectedValues.push(label.textContent); 
			else
				alert("Unsupported browser.");
			
		}
	}
   
	return selectedValues;
}

//Checks all check boxes in a checkboxlist.
function SelectAllValuesInCheckBoxList(checkBoxListClientID)
{
	var checkBoxList = $get(checkBoxListClientID);
	var arrayOfCheckBoxes = checkBoxList.getElementsByTagName("input");
    
	for(var i=0; i < arrayOfCheckBoxes.length; i++)
	{
		arrayOfCheckBoxes[i].checked = true;
	}
   
	return;
}


//Gets the selected item in a radiobutton list.
//Please note that the value returned is the text value in the radiobuttonlist,
//not the ID value, because the ID value is not rendered on the client.
function GetSelectedValueFromRadioButtonList(radioButtonListClientID)
{
	var selectedValue = "";
	var radioButtonList = $get(radioButtonListClientID);
	
	if(radioButtonList)
	{
	    var arrayOfRadioButtons = radioButtonList.getElementsByTagName("input");
        
	    for(var i=0; i < arrayOfRadioButtons.length; i++)
	    {
		    if(arrayOfRadioButtons[i].checked)
		    {
			    var label = arrayOfRadioButtons[i].parentNode.childNodes[1];
    			
			    //We can't get at the value of the checkbox item, so we'll need to get at the text,
			    //and do a reverse-lookup on the server.
			    if (label.innerText)
				    // For IE-type browsers
				    selectedValue = label.innerText; 
			    else if (label.textContent)
				    // For Mozilla-based browsers
				    selectedValue = label.textContent; 
			    else
				    alert("Unsupported browser.");
    			
			    break;
		    }
	    }
    }
    else
    {
        alert("Radio Button List not found.");
    }
    
	return selectedValue;
}


//Gets the selected index in a radiobutton list.
function GetSelectedIndexFromRadioButtonList(radioButtonListClientID)
{
	var selectedIndex = 0;
	var radioButtonList = $get(radioButtonListClientID);
	
	if(radioButtonList)
	{
	    var arrayOfRadioButtons = radioButtonList.getElementsByTagName("input");
        
	    for(var i=0; i < arrayOfRadioButtons.length; i++)
	    {
		    if(arrayOfRadioButtons[i].checked)
		    {
		        selectedIndex = i;
    			
			    break;
		    }
	    }
    }
    else
    {
        alert("Radio Button List not found.");
    }
    
	return selectedIndex;
}


//Gets an array of the selected items in a duallist.
function GetSelectedValuesFromDualList(dualListClientID)
{
	var selectedValues = new Array();
	
	var selectedBox = DynamicListBox_FindControl(dualListClientID + "_RightBox");
	for(var i=0; i < selectedBox.options.length; i++)
	{
		selectedValues.push(selectedBox.options[i].value);
	}
	
	return selectedValues;
}


//Returns the top-most selected item in a duallist.
function GetTopMostSelectedValueFromDualList(dualListClientID)
{
    var selectedValue;
    
    var selectedBox = DynamicListBox_FindControl(dualListClientID + "_RightBox");
	
	if(selectedBox.options.length > 0)
	{
	    selectedValue = selectedBox.options[0].value;
	}
	
	return selectedValue;
}


function ShowUpdateProgress(updateProgressClientID) {
	$get(updateProgressClientID).style.display = 'block';
}

function HideUpdateProgress(updateProgressClientID) {
	$get(updateProgressClientID).style.display = 'none';
}

//Displays the report
function OnViewReportRequestComplete(result)
{
	HideUpdateProgress(reportUpdateProgressClientID);

    eval(result);
    
    if(!childWindow)
    {
        alert('In order to view the report, please allow pop-ups from this site.\n' + 
        '(Alternatively, some pop-up blockers allow a pop-up if you to hold the CONTROL key while clicking the button.)');
    }
}

