function setFormValue(aform, column_name, column_value, need_submit)
{//	asubmit = true, false
	index = findFormIndex(aform, column_name);
	if (index >= 0)
	{
		aform[index].value = column_value;
		if (need_submit == true)
			aform.submit();
	}
}


function findFormIndex(aform, column_name)
{
	if (aform.length > 0)
	{
		for (i = 0; i < aform.length; i++)
		{
			if (aform[i].name == column_name)
				return i;
		}
		return -2;	// not found
	}
	else
		return -1;	// no index
}


function listFormSelect(dest_form, dest_column, array_data_name, array_data_value, default_data_value)
{//	dest_form : Form Object
//	dest_column_name : String name of column
//	array_data_name : Array of date-name
//	array_data_value : Array of date-value
//	default_data_value : String data-value to be selected

	dest_column_index  = findFormIndex(dest_form, dest_column);

	if (dest_column_index >= 0) 
	{
		column_length = dest_form[dest_column_index].length;
		for (i = (dest_form[dest_column_index].length - 1); i >= 0 ; i--)
		{
			dest_form[dest_column_index].options[i] = null;
		}
		if ((array_data_name.length > 0) && (array_data_value.length == array_data_name.length))
		{
			for (i = 0; i < array_data_name.length; i++)
			{
				dest_form[dest_column_index].options[i] = new Option(array_data_name[i], array_data_value[i]);
			}
			dest_form[dest_column_index].style.width = '72px';
			defaultFormSelect(dest_form, dest_column, default_data_value);
		}
		return true;
	}
	else
		return false;
}


function defaultFormSelect(dest_form, dest_column, default_data_value)
{//	dest_form : Form Object
//	dest_column_name : String name of column
//	default_data_value : String data-value to be selected

	dest_column_index  = findFormIndex(dest_form, dest_column);

	if (dest_column_index >= 0) 
	{
		column_length = dest_form[dest_column_index].length;
		for (i = 0; i < dest_form[dest_column_index].length; i++)
		{
			if (dest_form[dest_column_index].options[i].value == default_data_value)
			{
				dest_form[dest_column_index].options[i].selected = true;
				break;
			}
		}
		return true;
	}
	else
		return false;
}








function checkValidDate()
{  
    aform = document.form_body;
    
    sd = parseInt(aform.from_date.selectedIndex+1);
    sm = parseInt(aform.from_month.selectedIndex+1);
    sy = parseInt(aform.from_year.options[aform.from_year.selectedIndex].value);

	if ((sd > endOfMonth(sm,sy)) )
	{
        aform.from_date.focus();
		alert("Invalid From Date.");
		return false;
    } 

    sd = parseInt(aform.to_date.selectedIndex+1);
    sm = parseInt(aform.to_month.selectedIndex+1);
    sy = parseInt(aform.to_year.options[aform.to_year.selectedIndex].value);

	if ((sd > endOfMonth(sm,sy)) )
	{
    aform.to_date.focus();
    alert("Invalid To Date.");
		return false;
        } 

    return true;
}


function deleteClosedFlight(name,f_date,f_time)   //  for test only
{
		if ( !confirm('Do you want to delete the closed flight #' + name  + '\nDate:' + f_date 
		+ '\nTime:' + f_time) ) { return; }

		var $a = f_date.split('/');

		document.location = "flight_closed_del.php?id=" + id;
}