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';
//}


// 04/28/2009 Zebin. Format the date entry.
function setDateFormat(sender) {
    if (checkIfIsNumber()) {
        var inputDate = sender.value;
        var re = /^(0|1)[0-9][0-3][0-9]{3}$/
        if (inputDate.length == 6 && inputDate.search("/") == -1) {
            var outputDate = "";
            if (inputDate.match(re) == null) {
                //	alert("Please input date by 'MM/DD/YY'");
                return;
            }
            outputDate += inputDate.substr(0, 2) + "/";
            outputDate += inputDate.substr(2, 2) + "/";
            var year = inputDate.substr(4, 2);
            if (parseInt(year) >= 20) {
                outputDate += "19" + inputDate.substr(4, 2);
            }
            else {
                outputDate += "20" + inputDate.substr(4, 2);
            }
            sender.value = outputDate;
        }
    }
}

function checkIfIsNumber() {
    var key = event.keyCode;
    if ((key >= 96 && key <= 105) || (key >= 48 && key <= 57) || key == 8 || key == 46 || (key >= 37 && key <= 40)) {
        event.returnValue = true;
        return true;
    }
    else {
        //		alert("Input char is Invlided!");
        event.returnValue = false;
        return false
    }
}


