﻿function resetFormDefaults() {
    var parent = $find('CCDClinicCityDropDown');
    parent._selectedValue = null;
    parent.initialize();

    document.forms[0].reset;
    enableForm();
}

function enableForm() {
    $get("LastNameTextBox").disabled = false;
    $get("SpecialtiesDropDown").disabled = false;
    $get("DiseaseTextBox1").disabled = false;
//    $get("RadioButtonList1").disabled = false;
    $get("DiseaseTextBox2").disabled = false;
    $get("ClinicCityDropDown").disabled = false;
    $get("LocationDropDown").disabled = false;
    $get("ProgramDropDown").disabled = false;
}
            
function formChangedEvent(f)
{
    // NOTE: The control state code was implemented in C# by the 
    // Mediator pattern, but the ASP.NET TextBox control does not 
    // expose a client-side text changed event to capture which made
    // its use impossible. This is a "temprorary" solution in lieu
    // of an OOP JavaScript implementation that should be coded later.
    enableForm();                
    
    switch( f.name ) {
        case "LastNameTextBox":
            if( 0 < f.value.length ) {
                $get("LastNameTextBox").disabled = false;
                $get("SpecialtiesDropDown").disabled = true;
                $get("DiseaseTextBox1").disabled = true;
                // $get("RadioButtonList1").disabled = true;
                $get("DiseaseTextBox2").disabled = true;
                $get("ClinicCityDropDown").disabled = true;
                $get("LocationDropDown").disabled = true;
                $get("ProgramDropDown").disabled = true;
            }
            break;
        case "SpecialtiesDropDown":
            if( 0 != f.selectedIndex ) {
                $get("SpecialtiesDropDown").disabled = false;
                $get("LastNameTextBox").disabled = true;
                $get("DiseaseTextBox1").disabled = true;
                // $get("RadioButtonList1").disabled = true;
                $get("DiseaseTextBox2").disabled = true;
                $get("ClinicCityDropDown").disabled = true;
                $get("LocationDropDown").disabled = true;
                $get("ProgramDropDown").disabled = true;  
            }
            break;
        case "DiseaseTextBox1":
            if( 0 < f.value.length ) {
                $get("DiseaseTextBox1").disabled = false;
                // $get("RadioButtonList1").disabled = false;
                $get("DiseaseTextBox2").disabled = false;                        
                $get("LastNameTextBox").disabled = true;
                $get("SpecialtiesDropDown").disabled = true;
                $get("ClinicCityDropDown").disabled = true;
                $get("LocationDropDown").disabled = true;
                $get("ProgramDropDown").disabled = true;
            }
            break;
        case "DiseaseTextBox2":
            if( 0 < $get("DiseaseTextBox1").value.length ) {
                $get("LastNameTextBox").disabled = true;
                $get("SpecialtiesDropDown").disabled = true;
                $get("ClinicCityDropDown").disabled = true;
                $get("LocationDropDown").disabled = true;
                $get("ProgramDropDown").disabled = true;
            }
            break;
        case "ClinicCityDropDown":
            if( 0 != f.selectedIndex ) {
                $get("ClinicCityDropDown").disabled = false;
                $get("LocationDropDown").disabled = false;
                $get("LastNameTextBox").disabled = true;
                $get("SpecialtiesDropDown").disabled = true;
                $get("DiseaseTextBox1").disabled = true;
                // $get("RadioButtonList1").disabled = true;
                $get("DiseaseTextBox2").disabled = true;
                $get("ProgramDropDown").disabled = true;  
            }
            else {
                $get("LocationDropDown").selectedIndex = 0;
            }
            break;
        case "LocationDropDown":
            break;
        case "ProgramDropDown":
            if( 0 != f.selectedIndex ) {
                $get("ProgramDropDown").disabled = false;  
                $get("LastNameTextBox").disabled = true;
                $get("SpecialtiesDropDown").disabled = true;
                $get("DiseaseTextBox1").disabled = true;
                // $get("RadioButtonList1").disabled = true;
                $get("DiseaseTextBox2").disabled = true;
                $get("ClinicCityDropDown").disabled = true;
                $get("LocationDropDown").disabled = true;
            }
            break;
        default:
            break;
            
        f.focus();
    }
}
