function ValStartDate(source, args, theStartDay, theStartMonth, theStartYear) {
    args.IsValid = true;
    
    var startDay = GetObj(theStartDay);
    var startMonth = GetObj(theStartMonth);
    var startYear = GetObj(theStartYear);

    // check if the user is supplying a start date
    if(startDay.selectedIndex != 0 || startMonth.selectedIndex != 0 || startYear.selectedIndex != 0) {
        if (startDay.selectedIndex == 0 || startMonth.selectedIndex == 0 || startYear.selectedIndex == 0) {
            args.IsValid = false;
        }
        else {
           // ensure date is in the correct format
           if(!isDate(startDay.value + "/" + startMonth.value + "/" + startYear.value)) {
                args.IsValid = false;
           }
        }
    }
    
    return args;
}

function ValEndDate(source, args, theEndDay, theEndMonth, theEndYear) {
    args.IsValid = true;
    
    var endDay = GetObj(theEndDay);
    var endMonth = GetObj(theEndMonth);
    var endYear = GetObj(theEndYear);
    
    // check if the user is supplying a end date
    if(endDay.selectedIndex != 0 || endMonth.selectedIndex != 0 || endYear.selectedIndex != 0) {
        if (endDay.selectedIndex == 0 || endMonth.selectedIndex == 0 || endYear.selectedIndex == 0) {
            args.IsValid = false;
        }
        else {
           // ensure date is in the correct format
           if(!isDate(endDay.value + "/" + endMonth.value + "/" + endYear.value)) {
                args.IsValid = false;
           }
        }
    }
    
    return args;
}

function ValEndDateSelection(source, args, theStartDay, theStartMonth, theStartYear, theEndDay, theEndMonth, theEndYear) {
    args.IsValid = true;
    
    var startDay = GetObj(theStartDay);
    var startMonth = GetObj(theStartMonth);
    var startYear = GetObj(theStartYear);
    var endDay = GetObj(theEndDay);
    var endMonth = GetObj(theEndMonth);
    var endYear = GetObj(theEndYear);
    
    if ((startDay.selectedIndex != 0 && startMonth.selectedIndex != 0 && startYear.selectedIndex != 0)
    && (endDay.selectedIndex != 0 && endMonth.selectedIndex != 0 && endYear.selectedIndex != 0)) {
        // both start and end dates have been supplied so check if end date is before the start date

        var startDate = startMonth.value + "/" + startDay.value + "/" + startYear.value;
        var endDate   = endMonth.value + "/" + endDay.value + "/" + endYear.value;
        
        
        if (Date.parse(startDate) > Date.parse(endDate)) {
            args.IsValid = false;
        }
    }
    
    return args;
}

// Ensures that no ca numbers are selected if the user selects a tender group
function ClearAccountItems(caNumbersListboxId) {

    var theListbox = GetObj(caNumbersListboxId);
    var i;
    
    for (i = 0; i < theListbox.options.length; i++) {
        theListbox.options[i].selected = false;
    }
}

// Ensures that no group is selected if the user selects a ca number
function ClearCaGroup(ddlCaGroupsId) {

    var groups = GetObj(ddlCaGroupsId);
    
    groups.selectedIndex = 0;
}
