var sDebugSQL = '';
// 02/29/2008 Paul.  startHighlight is no longer used, so remove. 

var ChangeDate = null;

function CalendarPopup(ctlDate, clientX, clientY)
{
	clientX = window.screenLeft + parseInt(clientX);
	clientY = window.screenTop  + parseInt(clientY);
	if ( clientX < 0 )
		clientX = 0;
	if ( clientY < 0 )
		clientY = 0;
	return window.open('../Calendar/Popup.aspx?Date=' + ctlDate.value,'CalendarPopup','width=193,height=155,resizable=1,scrollbars=0,left=' + clientX + ',top=' + clientY);
	/*
	var sFeatures = 'dialogHeight:215px ;dialogWidth:253px;resizable:yes;center:yes;status:no;help:no;scroll:no;';
	var sUrl = '<%= Application["rootURL"] %>Calendar/CalendarPopup.aspx?Date=' + ctlDate.value;
	var lookupItems = window.showModalDialog(sUrl, null, sFeatures);
	if ( lookupItems != null )
	{
		ctlDate.value = lookupItems;
	}
	*/
}

function SelectOption(sID, sValue)
{
	var lst = document.forms[0][sID];
	if ( lst != null )
	{
		if ( lst.options != null )
		{
			for ( i=0; i < lst.options.length ; i++ )
			{
				if ( lst.options[i].value == sValue )
				{
					lst.options[i].selected = true;
					break;
				}
			}
		}
	}
}

// 02/28/2008 Paul.  Replace the SugarCRM implementation with one that is more efficient. 
// There is simply no need to iterate through all elements. 
//function checkAll(form, sFieldID, value)
//{
//    var fld = document.forms[0][sFieldID];
//    if (fld == null) return;
//    
//	for (i = 0; i < fld.length; i++)
//	{
//		fld[i].checked = value;
//	}
//}
//TODO: modify the fuction checkAll and toggleDisplay (when only one in the list this fuction is uneffective). allen 02/24/2009
//start:
//remark: Ln 47 -- Ln 56, ln: 83 -- Ln87: 
function checkAll(form, field, value) {
    for (i = 0; i < form.elements.length; i++) {
        if (form.elements[i].name == field)
            form.elements[i].checked = value;
    }
}
function toggleDisplay(sID)
{
	var fld = document.getElementById(sID);
	if (fld == null) return;
    
	fld.style.display = (fld.style.display == 'none') ? 'inline' : 'none';
}

//end

// 02/28/2008 Paul.  Simplify toggleDisplay() and move the linked toggling to AccessView. 
//function toggleDisplay(sID)
//{
//	var fld = document.getElementById(sID);
//	fld.style.display = (fld.style.display == 'none') ? 'inline' : 'none';
//}

function FormatCurrency(ctl) {
    var num = ctl.value;
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
//    ctl.value = (((sign) ? '' : '-') + '$' + num);
    ctl.value=(((sign) ? '' : '-') + '$' + num + '.' + cents);
}
