/* FigWeb : Web UI Functions */


/*
	HISTORY
	===========================================================================================
	date               who               what                                version
	===========================================================================================
	13/01/2005         Sean              Modified                              1.0.1
                                              -setPopupField only sets fields
                                                that exist.

	02/03/2005         Toby              Added                                 1.0.2
                                              -dashboardClick
                                              -checkBoxClick                       

	13/05/2005         Sean              Added                                 1.0.3
	                                      -getFieldValues
	                                      -getField

	09/09/2005         Toby              Modified                              1.0.4
                                              - doLookUp .. arg list

	15/09/2005         Sean              Added                                 1.0.5
                                              - multiSelectGetSelectedItems
	                                      
	29/09/2005         Sean              Modified                              1.0.6
                                              - focusFirstFormControl() only 
                                                 attempts to focus the first
                                                 control when the mode is not
                                                 'view' or 'list'

        22/11/2005         Sean              See version markers                   1.0.7

        21/12/2005         Sean              See version markers                   1.0.8

	23/03/2006         Sean              Added                                 1.0.9
                                              - imageClick function for
                                                "coodinate_select" drawings
                                              - getObjectByID function

	26/05/2006         Toby              Added                                 1.0.10
                                              - graphicsPrint function

	25/07/2006         Sean              See version markers                   1.0.11

	16/08/2006         Sean              See version markers                   1.0.12

	08/09/2006         Sean              See version markers                   1.0.13

	25/10/2006         Toby              Debug utility                         1.0.14

	16/04/2007         Sean              Auto delimit dates                    1.0.15

	10/05/2007         Toby              Alpha image loading                   1.0.16

	14/08/2007         Sean              Bug with combos in getFieldValues     1.0.17

        05/11/2007         Sean              Modified                              1.0.18
                                              - Enhancements to calcs and ifs

*/

// Naming Conventions:
// s  = string
// b  = boolean
// v  = variant (arb type)
// i  = integer
// rx = regular expression
// o  = object
// a  = array

var IE  = (document.all)            ? 1 : 0;
var NS  = (document.getElementById) ? 1 : 0;


/*
selectAllCheckbox
Select all the checkboxes on a form
in:
	vForm -- the name or index number of the form on which the checkboxes to be checked reside
out:
	the checkboxes are selected
*/
function selectAllCheckbox(vForm)
{
	var oForm = document.forms[vForm];
	var i;
	
	for (i=0;i<oForm.length;i++)
	{
		if (oForm.elements[i].type == "checkbox")
		{
			oForm.elements[i].checked = true;
		}
	}
}


/*
setFocus
Set focus to a form element
in:
	sItem -- the name of a form element to set focus to
	vForm -- the name or index number of the form on which sItem resides
out:
	the form element receives focus
*/
function setFocus(sItem,vForm) {
	var oForm;
	if (sItem != "") {
		oForm = document.forms[vForm];
		oForm.elements[sItem].focus();
	}
}


/*
newWindow
Opens a new browser window at a given URL
in:
	sURL     -- the URL to open
	sWinName -- a name for the window (defaults to 'new' if blank)
	sWinOpts -- options for the new window
out:
	the new window opened at sURL
*/
function newWindow(sURL,sWinName,sWinOpts) {
	if (sURL != "") {
		if (sWinName == "") { 
			sWinName = "new"; 
		}
		window.open(sURL,sWinName,sWinOpts);
	}
}


/*
browseToURL
Send the browser to URL
in:
	sURL        -- the URL to browse to
	bSameWindow -- open the URL in the current browser window or a new one?
	sNewWinName -- if bSameWindow==false then specify a name for the new window (if '' defaults to 'new')
	sNewWinOpts -- if bSameWindow==false then this is the options for the new window (defualts to '')
out:
	browser navigates to sURL
*/
function browseToURL(sURL,bSameWindow,sNewWinName,sNewWinOpts) {
	if (sURL != "") {
		if (bSameWindow) {
			location.href = sURL;
		}
		else {
			newWindow(sURL,sNewWinName,sNewWinOpts);
		}
	}
}


/*
browseToURL2 -- 1.0.7
Scrapes the screen for values denoted in the sFormFields argument.  Then newWindow is called as normal.
in:
	sURL        -- the URL to browse to
	bSameWindow -- open the URL in the current browser window or a new one?
	sNewWinName -- if bSameWindow==false then specify a name for the new window (if '' defaults to 'new')
	sNewWinOpts -- if bSameWindow==false then this is the options for the new window (defualts to '')
        sFormFields -- list of form fields whose values will be appended to sURL
out:
	browser navigates to sURL
*/
function browseToURL2(sURL,bSameWindow,sNewWinName,sNewWinOpts, sFormFields)
{
	if (sURL != "")
	{
		if (sFormFields != '')
		{
			var aFormFields = sFormFields.split(",");
			var oForm       = document.forms[0];

			for (var i=0; i<aFormFields.length; i++)
			{
				sURL += "&" + aFormFields[i] + "=" + encodeURIComponent(oForm.elements[aFormFields[i]].value);
			}
		}

		//alert(sURL);

		if (bSameWindow)
		{
			location.href = sURL;
		}
		else
		{
			newWindow(sURL,sNewWinName,sNewWinOpts);
		}
	}
}


/*
selectComboItem
Select a combo item.
in:
	sItem  -- the name of the combo-box.
	sValue -- the value to select.
	vForm  -- the index number or name of the form on which sItem resides.
out:
	selects the combo item
*/
function selectComboItem(sItem,sValue,vForm) {
	var oCombo;
	var i;
	if (sItem != "") {
		oCombo = document.forms[vForm].elements[sItem];
		if (oCombo != null) {
			for (i=0;i<oCombo.options.length;i++) {
				if (sValue == oCombo.options[i].value) {
					oCombo.selectedIndex = i;
				}
			}
		}
	}
}


/*
selectComboItems
Selects combo items.
Programmer note: this function uses the SelectComboItem function
in:
	sItemList  -- delimited list of combo-box names and the value to select where delimiter is sDelimiter.
	sDelimiter -- sItemList delimiter eg. '|', ',' etc.
 	              eg. sItemList = 'person.country_code=AUS|person.sex=M';
	vForm      -- the index number or name of the form on which the combo-boxes reside.
out:
	selects the combo item.
*/
function selectComboItems(sItemList,sDelimiter,vForm) {
	var bContinue = true;
	var aPairs, aPair;
	var i;

	var sItem, sValue;
	if (sItemList != "") {
		if (sItemList.indexOf(sDelimiter) == -1) {
			bContinue = false;
		}
		if (bContinue) {
			aPairs = sItemList.split(sDelimiter);
			for (i=0;i<aPairs.length;i++) {
				aPair  = aPairs[i].split("=");
				sItem  = aPair[0];
				sValue = aPair[1];
				selectComboItem(sItem,sValue,vForm);
			}
		}
		else {
			alert("Programmer: the specified delimiter '" + sDelimiter + 
			      "' was not found in '" + sItemList + 
			      "'\nUse the function SelectComboItem for single item selection."
			);
		}
	}
}



function statusHelp(sText)
{
	window.status = sText;
}

function statusClear()
{
	window.status = '';
}

function setToolTip(oField, sTip)
{
	oField.title = sTip;
}



function commify(Field)
{

	var amount = Field.value;

	amount = amount.replace(/,/g, '');

	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)

	var d;

	if (a[1] == null)
	{
		d = '';
	}
	else
	{
		d = a[1];
	}

	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;

	//return amount;
	//alert(amount);

	Field.value = amount;

}

function dateDelimit(control,formIndex,dateDelimiter,dateFormat)
{
	dateFormat = dateFormat.toUpperCase();

	var dateValue = document.forms[formIndex].elements[control].value;
	var aDateFormat = dateFormat.split(dateDelimiter);

	if (dateValue.indexOf(dateDelimiter) != -1)
	{
		return;
	}
	if (dateValue.length < 6)
	{
		return;
	}

	if ((dateValue.length > 6) && (aDateFormat[0].indexOf('Y') != -1))
	{
		dateValue = dateValue.substr(0, 4) + dateDelimiter + dateValue.substr(4, 2) + dateDelimiter +  dateValue.substr(6);
	}
	else if ((dateValue.length > 6) && (aDateFormat[1].indexOf('Y') != -1))
	{
		dateValue = dateValue.substr(0, 2) + dateDelimiter + dateValue.substr(2, 4) + dateDelimiter +  dateValue.substr(6);
	}
	else
	{
		dateValue = dateValue.substr(0, 2) + dateDelimiter + dateValue.substr(2, 2) + dateDelimiter +  dateValue.substr(4);
	}
	
	document.forms[formIndex].elements[control].value = dateValue;
}

function focusFirstFormControl(vForm)
{
	
	var oForm;
	var i;

	var sMode = ""; //v1.0.6

	oForm = document.forms[vForm];

	//v1.0.6
	if (oForm.elements['mode'] != null)
	{ sMode = oForm.elements['mode'].value; }
	else { return; }

	if (sMode.toUpperCase() == "VIEW" || sMode.toUpperCase() == "LIST")
	{ return; }
	// /v1.0.6

	for (i=0; i<oForm.length; i++)	
	{
		//v1.0.11 the two lines below...
		//if (oForm.elements[i].style.display == ""
		//if (oForm.elements[i].parentElement.parentElement.style.display == "" 
		//v1.0.13 bug fixes...
		if (oForm.elements[i].parentNode.parentNode.style.display == "" 
			&& oForm.elements[i].type != "hidden" 
			&& oForm.elements[i].className != "input-type-label")
		{
			oForm.elements[i].focus();
			break;
		}
	}

	
}


function itemSelectorAdd(sList1,sList2)
{
// Add (move) selected item from list1 to list2

	var oList1, oList2;
	var oSelectedOption;
	var oNewOption;
	var aNewItem;

	if (IE)
	{
		oList1 = document.all(sList1);
		oList2 = document.all(sList2);
	}
	if (NS)
	{
		oList1 = document.getElementsByName(sList1)[0];
		oList2 = document.getElementsByName(sList2)[0];
	}


	if (oList2.options.length == 30)
	{
		alert('Maximum number of items exceeded, Maximum = 30.');
	}
	else
	{
	
		if (oList1.selectedIndex != -1)
		{
			oSelectedOption = oList1.options[oList1.selectedIndex];	
			oNewOption = new Option(oSelectedOption.text, oSelectedOption.value);
			oList2.options[oList2.length] = oNewOption;
			oList1.options[oList1.selectedIndex] = null;

			if (aItemDisplay != null) 
			{
				aNewItem = new Array(oNewOption.value, '');	
				aItemDisplay.push(aNewItem);
			}

		}
	}
}

function itemSelectorDelete(sList1,sList2)
{
// Delete item from list2 (move to list1)

	var oList1, oList2;
	var oSelectedOption;
	var oNewOption;
	var iItemIndex;
	
	if (IE)
	{
		oList1 = document.all(sList1);
		oList2 = document.all(sList2);
	}
	if (NS)
	{
		oList1 = document.getElementsByName(sList1)[0];
		oList2 = document.getElementsByName(sList2)[0];
	}
	
	if (oList2.selectedIndex != -1)
	{
		oSelectedOption = oList2.options[oList2.selectedIndex];	
		oNewOption = new Option(oSelectedOption.text, oSelectedOption.value);
		oList1.options[oList1.length] = oNewOption;
		oList2.options[oList2.selectedIndex] = null;


		if (aItemDisplay != null) 
		{
			iItemIndex = getItemDisplayArrayIndex(oNewOption.value);
			if (iItemIndex != -1)
			{	
				aItemDisplay.splice(iItemIndex, 1);
			}
		}
	}
}

function itemSelectorUp(sList)
{
// move the selected item up

	var oList;
	
	var oSelectedItem;
	var sSelectedItemText;
	var sSelectedItemValue;
	
	var oItemAbove;
	var sItemAboveText;
	var sItemAboveValue;

	var aTemp;
	var iItemIndex;
	
	if (IE) { oList = document.all(sList); }
	if (NS) { oList = document.getElementsByName(sList)[0]; }

	if (oList.selectedIndex != -1 && oList.selectedIndex != 0)
	{
	
		oSelectedItem = oList.options[oList.selectedIndex];
		oItemAbove    = oList.options[oList.selectedIndex - 1];

		sSelectedItemText = oSelectedItem.text;
		sSelectedItemValue = oSelectedItem.value;

		sItemAboveText = oItemAbove.text;
		sItemAboveValue = oItemAbove.value;
	
		oList.options[oList.selectedIndex].text = sItemAboveText;
		oList.options[oList.selectedIndex].value = sItemAboveValue;

		oList.options[oList.selectedIndex - 1].text = sSelectedItemText;
		oList.options[oList.selectedIndex - 1].value = sSelectedItemValue;

		oList.selectedIndex = oList.selectedIndex - 1;

		/*
		if (aItemDisplay != null) 
		{
			iItemIndex = getItemDisplayArrayIndex(sSelectedItemValue);
			if (iItemIndex != -1)
			{
				aTemp = aItemDisplay[iItemIndex];
				aItemDisplay[iItemIndex] = aItemDisplay[iItemIndex - 1];
				aItemDisplay[iItemIndex - 1] = aTemp;
			}
		}
		*/
	}
}

function itemSelectorDown(sList)
{
// move the selected item down

	var oList;
	
	var oSelectedItem;
	var sSelectedItemText;
	var sSelectedItemValue;
	
	var oItemBelow;
	var sItemBelowText;
	var sItemBelowValue;

	var aTemp;
	var iItemIndex;
	
	if (IE) { oList = document.all(sList); }
	if (NS) { oList = document.getElementsByName(sList)[0]; }
	
	if (oList.selectedIndex != -1 && oList.selectedIndex != oList.length - 1)
	{
	
		oSelectedItem = oList.options[oList.selectedIndex];
		oItemBelow    = oList.options[oList.selectedIndex + 1];

		sSelectedItemText = oSelectedItem.text;
		sSelectedItemValue = oSelectedItem.value;

		sItemBelowText = oItemBelow.text;
		sItemBelowValue = oItemBelow.value;
	
		oList.options[oList.selectedIndex].text = sItemBelowText;
		oList.options[oList.selectedIndex].value = sItemBelowValue;

		oList.options[oList.selectedIndex + 1].text = sSelectedItemText;
		oList.options[oList.selectedIndex + 1].value = sSelectedItemValue;

		oList.selectedIndex = oList.selectedIndex + 1;

		/*
		if (aItemDisplay != null) 
		{
			iItemIndex = getItemDisplayArrayIndex(sSelectedItemValue);
			if (iItemIndex != -1)
			{
				aTemp = aItemDisplay[iItemIndex];
				aItemDisplay[iItemIndex] = aItemDisplay[iItemIndex + 1];
				aItemDisplay[iItemIndex + 1] = aTemp;
			}
		}
		*/
	}
	
}

function getItemDisplayArrayIndex(sItemName)
{
	var i;
	var iReturnIndex = -1;

	for (i=0; i < aItemDisplay.length; i++)
	{
		if (aItemDisplay[i][0].toUpperCase() == sItemName.toUpperCase())
		{
			iReturnIndex = i;
			break;
		}
	}

	return iReturnIndex;
}

                                                                          //v1.0.5
function itemSelectorGetSelectedItems(sSelectedListName, sPopupFieldName, sDescriptionDelimiter)
{
//Get selected items from an item selectors selected list 
//and write value back to parent via setPopupField();

	var oSelectedList;
	var sPopupFieldValue = "";
	var sPopupFieldDescription = "";
	var oOption;
	var iItemIndex;

	if (IE) { oSelectedList = document.all(sSelectedListName); }
	if (NS) { oSelectedList = document.getElementsByName(sSelectedListName)[0]; }

	if (oSelectedList.options.length > 0)
	{
		for (i=0; i < oSelectedList.options.length; i++)
		{
			oOption = oSelectedList.options[i];

			                          //v1.0.12
			sPopupFieldDescription += (bReturnDescAsValueList) ? oOption.value : oOption.text;

			if (aItemDisplay != null) 
			{
				iItemIndex = getItemDisplayArrayIndex(oOption.value);
				if (iItemIndex != -1)
				{
					sPopupFieldValue += aItemDisplay[iItemIndex][0] + "=" + aItemDisplay[iItemIndex][1];
					aItemDisplay.splice(iItemIndex, 1);
				}
				else
				{
					sPopupFieldValue += oOption.value + '=';
				}
			}
			else
			{
				sPopupFieldValue += oOption.value + '=';
			}			

			if (i < oSelectedList.options.length - 1)  
			{
				//v1.0.5
				//sPopupFieldDescription += String.fromCharCode(10);
				sPopupFieldDescription += sDescriptionDelimiter;
				sPopupFieldValue += ",";
			}
		}

		if (aItemDisplay != null && aItemDisplay.length > 0)
		{

			for (i=0; i < aItemDisplay.length; i++)
			{
				if (sRemoveItemsFromItemValue.indexOf(',' + aItemDisplay[i][0] + ',') == -1) //v1.0.12
				{
					sPopupFieldValue += ',' + aItemDisplay[i][0] + "=" + aItemDisplay[i][1];
					if (i < aItemDisplay.length - 1)  
					{
						sPopupFieldValue += ',';
					}
				}
			}
		}

		/*
		if (aItemDisplay != null) 
		{
			sPopupFieldValue = '';
			for (i=0; i < aItemDisplay.length; i++)
			{
				sPopupFieldValue += aItemDisplay[i][0] + "=" + aItemDisplay[i][1];
				if (i < aItemDisplay.length - 1)  
				{
					sPopupFieldValue += ',';
				}
			}
		}
		*/
	}

	//setPopupField(sPopupFieldValue, sPopupFieldDescription);
	setPopupField(sPopupFieldValue, sPopupFieldDescription, sPopupFieldName, sPopupFieldName.replace("\.", "_") + "_description");

}

                                                              //v1.0.5
function validateCriteria(sSelectedListName, sPopupFieldName, sDescriptionDelimiter)
{

	var oSelectedList;
	var oOption;
	var sQuery;
	var bQueryOK;
	var iOpenBracketCount = 0;
	var iCloseBracketCount = 0;

	if (IE) { oSelectedList = document.all(sSelectedListName); }
	if (NS) { oSelectedList = document.getElementsByName(sSelectedListName)[0]; }

	sQuery = '';

	if (oSelectedList.options.length > 0)
	{
		for (i=0; i < oSelectedList.options.length; i++)
		{
			oOption = oSelectedList.options[i];
			switch (oOption.value.toUpperCase())
			{
				case '('  :
					sQuery += ' ( ';
					iOpenBracketCount++;
					break;

				case ')'  :
					sQuery += ' ) ';
					iCloseBracketCount++;
					break;

				case 'AND':
					sQuery += ' && ';
					break;

				case 'OR' :
					sQuery += ' || ';
					break;

				case 'NOT':
					sQuery += ' ! ';
					break;

				default   :
					sQuery += ' true ';
					break;
			}

		}

		//alert(sQuery);

		bQueryOK = true;
		if (sQuery.match(/\s\(\s|\s\)\s|\s&&\s|\s\!\s|\s\|\|\s/))
		{
			if (iOpenBracketCount != iCloseBracketCount)
			{
				bQueryOK = false;
				iOpenBracketCount > iCloseBracketCount ? alert("Expecting ')'") : alert("Expecting '('");
			}
			else
			{
				try
				{
					bQueryOK = eval(sQuery);
					bQueryOK = true;
				}
				catch (e) 
				{ 
					alert('Invalid Criteria');		
					bQueryOK = false; 
				}
			}
		}
	}

	if (bQueryOK)
	{
                                                                                 //v1.0.5
		itemSelectorGetSelectedItems(sSelectedListName, sPopupFieldName, sDescriptionDelimiter);		
	}
}

function performCFCalculations()
{
	var i;
	var aCalculation;
	var sField;
	var sCalculation;	
	var oField;

	if (typeof(aCFCalculations)!="undefined") {
	
		for(i=0; i<aCFCalculations.length; i++)
		{
			aCalculation = aCFCalculations[i].split(String.fromCharCode(31));
			sField = aCalculation[0];
			sCalculation = aCalculation[1];
			document.forms[0].elements[sField].value = eval(sCalculation);
			commify(document.forms[0].elements[sField]);
		}
	}
	    
	if (initCFCalcs) { updateControls(); } //initCFCalcs defined in fw-main.js
}

function DateDiff(date1, date2, dateFormat, bInclusive)
{
	var d1 = new Date();
	var d2 = new Date();
	
	var aDate1 = date1.split("/");
	var aDate2 = date2.split("/");

	// todo handle date format

	d1.setDate(aDate1[0]);
	d1.setMonth(aDate1[1]);
	d1.setYear(aDate1[2]);

	d2.setDate(aDate2[0]);
	d2.setMonth(aDate2[1]);
	d2.setYear(aDate2[2]);
	
	if (isNaN (d1) || isNaN (d2))
	{
		return 0;
	}
	else
	{
		var n  = d1 - d2;

		if (bInclusive)
		{
			return parseInt(n / 86400000) + 1;
		}
		else
		{
			return parseInt(n / 86400000);	
		}
	}
}


function setPopupField(sFieldValue, sFieldLabel, sPopupFieldName, sPopupFieldLabel)
{
	var aTemp;
		
	var oParent = window.opener.document;
	var oField = null;	

	//alert("sFieldValue=" + sFieldValue + "\n\nsFieldLabel=" + sFieldLabel + "\n\nsPopupFieldName=" + sPopupFieldName + "\n\nsPopupFieldLabel=" + sPopupFieldLabel);

	aTemp = sFieldLabel.split("[|]");
	sFieldLabel = aTemp.join(String.fromCharCode(10));

	//alert("sFieldValue=" + sFieldValue + "\n\nsFieldLabel=" + sFieldLabel + "\n\nsPopupFieldName=" + sPopupFieldName + "\n\nsPopupFieldLabel=" + sPopupFieldLabel);

	if (IE)
	{

		if (oParent.all(sPopupFieldName) != null)  // v1.0.1 
		{
			// v1.0.3 fixed bug where parent fields were not setting. Uses forms[0] rather than document.all()
			oParent.forms[0].elements[sPopupFieldName].value = sFieldValue;
		}

		if (oParent.all(sPopupFieldLabel) != null) // v1.0.1 
		{
			if ((oParent.all(sPopupFieldLabel).tagName == 'DIV') || (oParent.all(sPopupFieldLabel).tagName == 'DIV'))
			{
				oParent.all(sPopupFieldLabel).innerHTML = sFieldLabel;
			}
			else
			{
				oParent.all(sPopupFieldLabel).value = sFieldLabel;
			}
		}
	}

	else if (NS)
	{
		if (oParent.getElementsByName(sPopupFieldName)[0] != null)  // v1.0.1
		{
			oParent.getElementsByName(sPopupFieldName)[0].value = sFieldValue;
		}

		if (oParent.getElementsByName(sPopupFieldName)[0] != null)  // v1.0.1
		{
			if ((oParent.getElementsByName(sPopupFieldName)[0].tagName == 'DIV') || (oParent.getElementsByName(sPopupFieldName)[0].tagName == 'DIV'))
			{
				oParent.getElementById(sPopupFieldLabel).innerHTML  = sFieldLabel;	
			}
			else
			{
				oParent.getElementsByName(sPopupFieldLabel)[0].value  = sFieldLabel;	
			}
		}
	}

	self.close();

}

function getRadioValue(oRadio)
{
	var i;
	var sValue;

	for(i=0; i<oRadio.length; i++)
	{
		if (oRadio[i].checked)
			sValue = oRadio[i].value;
	}

	return sValue;
}

function selectRadioValue(oRadio, sValue)
{
	var i;

	for(i=0; i<oRadio.length; i++)
	{
		if (oRadio[i].value == sValue)
			oRadio[i].checked = true;
	}
}

function copyInnerHTML(source, destination, bFromOpener)
{
	// copy the innerHTML from source to destination
	// if bFromOpener == true, the source is the parent (opener) window

	// source is the name of the source control
	// source is the name of the destination control
	
	var oSource, oDestination;

	if (IE)
	{
		oSource = (bFromOpener) ? window.opener.document.all(source) : document.all(source);
		oDestination = document.all(destination);
		oDestination.innerHTML = oSource.innerHTML;
	}
	else if (NS)
	{
		oSource = (bFromOpener) ? window.opener.document.getElementById(source) : document.getElementById(source);
		oDestination = document.getElementById(destination);
		oDestination.innerHTML = oSource.innerHTML;
	}
	else
	{
	}
}

//1.0.2


function dashboardClick(areaId, dashboardId)
{
	var sClickUrl;
	var oDashboardDataView;

	if (IE) { oDashboardDataView = eval("document.all(\"dashboard_frame_" + dashboardId + "\");"); }
	if (IE) { oDashboardDataView = eval("document.getElementsByName(\"dashboard_frame_" + dashboardId + "\")[0];"); }

	//if (IE) { oDashboardDataView = document.all("dahsboardDataView"); }
	//if (NS) { oDashboardDataView = document.getElementsByName("dahsboardDataView")[0]; }

	areaId++;
	
	var aDashboardParams = eval("aDashboardParams" + dashboardId);

	for (i=0; i<aDashboardParams.length; i++)
	{
		if(areaId == aDashboardParams[i][0])
		{
			sClickUrl = aDashboardParams[i][1];
			oDashboardDataView.src = sClickUrl;
			break;
		}
	}

	//alert(sParams);
}


//v1.0.7 imageMapClick replaces dashboardClick
function imageMapClick(areaId, imageMapId)
{
	var sClickUrl;
	var sClickTargetControlName;
	var aImageMapParams = eval("aImageMapParams" + imageMapId);

	areaId++;

	for (i=0; i<aImageMapParams.length; i++)
	{
		if(areaId == aImageMapParams[i][0])
		{
			sClickTargetControlName = aImageMapParams[i][2];
			sClickUrl = aImageMapParams[i][1];

			setSrc(sClickTargetControlName, sClickUrl);
			break;
		}
	}

}
function checkBoxClick(sCheckBoxName, sHiddenFieldName)
{
	var oCheckBox;
	var oHidden;

	if (IE) 
	{ 
		oCheckBox = document.all(sCheckBoxName); 
		oHidden = document.all(sHiddenFieldName); 
	}
	if (NS) 
	{
		oCheckBox = document.getElementsByName(sCheckBoxName)[0]; 
		oHidden = document.getElementsByName(sHiddenFieldName)[0]; 
	}

	if (oCheckBox != null && oHidden != null)
	{
		if (oCheckBox.checked)
		{
			oHidden.value = 'on';
			oCheckBox.value = 'on';
		}
		else
		{
			oHidden.value = 'off';
			oCheckBox.value = 'off';
		}

		updateControls();
	}

}
//1.0.2

//1.0.3
function getFieldValues(sFields)
{
	var aFields = sFields.split(",");
	var sReturn = "";
	var sValue = "";
	var oField = null;


	for (var i=0; i<aFields.length; i++)
	{
		//oField = getField(aFields[i]);
		oField = document.forms[0].elements[aFields[i]];
		sValue = "";	

		//For RadioSets

		if (oField != null)
		{
			if (oField[0] != null && oField[0].tagName.toUpperCase() == "INPUT")
			{
				sValue = getRadioValue(oField);
			}
			else
			{
				sValue = oField.value;
			}
		}	
	
		sReturn += aFields[i] + '=' + sValue;
		//alert(aFields[i] + '=' + sValue);
		if (i<aFields.length)
		{
			sReturn += ",";
		}

		//alert(sReturn);
	}

	return encodeURIComponent(sReturn);
}

function getField(sName)
{
	var oReturn = null;
	
	if (NS) 
	{
		oReturn = document.getElementsByName(sName)[0]; 
	}
	else
	{
		oReturn = document.all(sName);
	}

	return oReturn;
}

//function doLookUp(sUrl, sFields)
function doLookUp(sUrl, sFields, sNewWindowName) // 1.0.4
{
	if (sFields != '')
	{
		sUrl += '&form_info=' + getFieldValues(sFields);
	}

	//openModalWindow(sUrl,'winLookup','width=567,height=526,titlebar=no,scrollbars=no,resizable=yes');
	openModalWindow(sUrl,sNewWindowName,'width=567,height=526,titlebar=no,scrollbars=no,resizable=yes'); // 1.0.4
}
//1.0.3

//v1.0.5
function multiSelectGetSelectedItems(multiSelectName)
{

	var multiSelect = getField(multiSelectName);
	var returnString = "";
	var i;

	if (multiSelect == null)
	{
		return "";   
	}
	else
	{
		for (i=0; i <  multiSelect.options.length; i++)
		{
			returnString += multiSelect.options.item(i).value;
			
			if (i < (multiSelect.options.length - 1))
			{
				returnString += ',';
			}
		}

		return returnString;
	}
}
//v1.0.5

//v1.0.7
function setSrc(asControl, asSrc)
{

	var oControl = getField(asControl);

	if (oControl != null)
	{
		oControl.src = asSrc;
	}
	else
	{
		browseToURL(asSrc, (asControl.toUpperCase() == "THIS"), 'win_' + asControl , ''); //v1.0.8
	}

}
// /v1.0.7


//v1.0.9
function imageClick(imageName)
{
	var oForm = document.forms[0];

	oForm.elements[imageName + '.x'].value = event.offsetX;
	oForm.elements[imageName + '.y'].value = event.offsetY;

	oForm.submit();
}

function getObjectById(sId)
{
	var oReturn = null;
	
	if (NS) 
	{
		oReturn = document.getElementById(sId); 
	}
	else
	{
		oReturn = document.all(sId);
	}

	return oReturn;
}
//

// v1.0.10 altered for v1.0.13
function graphicsPrint(oCheckBox)
{
	var setDisplayTo = '';
	var exportIcons = null;

	if (oCheckBox.checked)
	{
		setDisplayTo = 'none';
	}

	getObjectById('folder_tabs').style.display = setDisplayTo;
	
	exportIcons = (IE) ? document.all('csv_export_icon') : document.getElementsByName('csv_export_icon');

	if (exportIcons != null) 
	{
		if (exportIcons[0] != null)
		{
			for (var i=0; i<exportIcons.length; i++)
			{
				exportIcons[i].style.display = setDisplayTo;
			}	
		}
		else
		{
				exportIcons.style.display = setDisplayTo;
		}
	}

	if (setDisplayTo == 'none')
	{
		window.print();
	}

}
//



window.document.onkeydown=debug;
function debug()
{
	var iKeyStartDebug = 118; //F7
	var iKeyStopDebug  = 119; //F8

	var sDebugServlet  = 'FWDebug';

	
	if (window.event.ctrlKey && window.event.shiftKey && window.event.keyCode == iKeyStartDebug)
	{
		if (confirm("!!! START DEBUG DETECTED !!!\n\nWould you like to START debug mode?"))
		{
			browseToURL(sDebugServlet + '?mode=start', false, 'winDebug', 'width=480,height=640,titlebar=no');
		}
	}

	if (window.event.ctrlKey && window.event.shiftKey && window.event.keyCode == iKeyStopDebug)
	{
		if (confirm("!!! STOP DEBUG DETECTED !!!\n\nWould you like to STOP debug mode?"))
		{
			browseToURL(sDebugServlet + '?mode=stop', false, 'winDebug', 'width=1,height=1,titlebar=no');
		}
	}

}


function alphaImageLoad(span,imageName)
{
	
	span.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imageName + "');";
	var img = span.firstChild;
	img.src = imageName;

}
