// IsCompanySameRadioList_SelectedIndexChanged
function IsCompanySameRadioList_SelectedIndexChanged()
{
    if (IsCompanySameRadioList.checked)
    {
        CompanyContactFirstTextBox.value = FirstNameTextBox.value;
        CompanyContactLastTextBox.value = LastNameTextBox.value;
        CompanyTitleTextBox.value = YourTitleTextBox.value;
        CompanyEmailTextBox.value = YourEmailAddressTextBox.value;
        CompanyNameTextBox.value = YourCompanyNameTextBox.value;
        CompanyAddress1TextBox.value = YourAddress1TextBox.value;
        CompanyAddress2TextBox.value = YourAddress2TextBox.value;
        CompanyCityTextBox.value = YourCityTextBox.value;
        CompanyStateTextBox.value = YourStateTextBox.value;
        CompanyZipTextBox.value = YourZipPostalCodeTextBox.value;
        CompanyCountryDropDownList.value = YourCountryDropDownList.value;
    }
    else
    {
        CompanyContactFirstTextBox.value = "";
        CompanyContactLastTextBox.value = "";
        CompanyTitleTextBox.value = "";
        CompanyEmailTextBox.value = "";
        CompanyNameTextBox.value = "";
        CompanyAddress1TextBox.value = "";
        CompanyAddress2TextBox.value = "";
        CompanyCityTextBox.value = "";
        CompanyStateTextBox.value = "";
        CompanyZipTextBox.value = "";
        CompanyCountryDropDownList.value = "";
    }
}

// IsControlledDrawingRadioList_SelectedIndexChanged
function IsControlledDrawingRadioList_SelectedIndexChanged(i)
{
    eval("var IsControlledDrawingRadioList = IsControlledDrawingRadioList" + i.toString());
    eval("var DrawingNoTextBox = DrawingNo" + i.toString() + "TextBox");

    if (IsControlledDrawingRadioList.checked)
    {
        DrawingNoTextBox.disabled = false;
    }
    else
    {
        DrawingNoTextBox.disabled = true;
        DrawingNoTextBox.value = "";
    }
}

// CopyCompany_ClientValidate
function CopyCompany_ClientValidate(source, arguments)
{
    var value = document.getElementById(source.id.substr(0, source.id.length - 1)).value;
    if (CustomerLOACopyRadioList.checked)
    {
        arguments.IsValid = (value != "");
    }
    else
    {
        arguments.IsValid = true;
    }
}

// AdditionalLOACopyRadioList_SelectedIndexChanged
function AdditionalLOACopyRadioList_SelectedIndexChanged()
{
    var isDisabled = !AdditionalLOACopyRadioList.checked;
    
    CopyFirstNameTextBox.disabled = isDisabled;
    CopyLastNameTextBox.disabled = isDisabled;
    CopyCompanyTextBox.disabled = isDisabled;
    CopyAddress1TextBox.disabled = isDisabled;
    CopyAddress2TextBox.disabled = isDisabled;
    CopyCityTextBox.disabled = isDisabled;
    CopyStateTextBox.disabled = isDisabled;
    CopyPostalCodeTextBox.disabled = isDisabled;
    CopyCountryDropDownList.disabled = isDisabled;
    CopyEmailTextBox.disabled = isDisabled;
}

// trim
function trim(string)
{
    return string.replace(/^\s+|\s+$/g, "");
}

// Item_ClientValidate
function Item_ClientValidate(source, arguments)
{
    arguments.IsValid = trim(WestItemNo1TextBox.value) != "" || (Formulation1DropDownList.value == 'Other' ? trim(Formulation1TextBox.value) != '' : Formulation1DropDownList.selectedIndex > 0);
}

// WestItemNo_ClientValidate
function WestItemNo_ClientValidate(source, arguments)
{
    var i = source.id.substr(source.id.length - 1, 1);
    eval("var WestarWashingList = WestarWashingList" + i);
    eval("var WestItemNoTextBox = WestItemNo" + i + "TextBox");
    
    if (WestarWashingList.checked)
    {
        // trim
        arguments.IsValid = trim(WestItemNoTextBox.value) != "";
    }
    else
    {
        arguments.IsValid = true;
    }
}

// HandleOtherListItem
function HandleOtherListItem(controlPrefix)
{
    eval("var OtherDropDownList = " + controlPrefix + "DropDownList");
    eval("var OtherPanel = " + controlPrefix + "OtherPanel");
    eval("var TextBox = " + controlPrefix + "TextBox");
    
    if (OtherDropDownList.value == 'Other')
    {
        OtherPanel.style.display = 'block';
        TextBox.focus();
    }
    else
    {
        OtherPanel.style.display = 'none';
        TextBox.value = '';
    }
}

// RegAgencyDropDownList_SelectedIndexChanged
function RegAgencyDropDownList_SelectedIndexChanged(i)
{
    eval("var RegAgencyDropDownList = RegAgencyDropDownList" + i.toString());
    eval("var AppTypeDropDownList = AppTypeDropDownList" + i.toString());
    eval("var AppNoTextBox = AppNoTextBox" + i.toString());
    eval("var AppOtherPanel = AppOtherPanel" + i.toString());
    eval("var AppOtherTextBox = AppOtherTextBox" + i.toString());
    
    if (RegAgencyDropDownList.value == '')
    {
        AppTypeDropDownList.disabled = true;
        AppTypeDropDownList.value = '';
        AppNoTextBox.disabled = true;
        AppNoTextBox.value = '';
        AppOtherPanel.style.display = 'none';
        AppOtherTextBox.value = '';
    }
    else
    {
        AppTypeDropDownList.disabled = false;
        AppNoTextBox.disabled = false;
    }
}

// AppTypeDropDownList_SelectedIndexChanged
function AppTypeDropDownList_SelectedIndexChanged(i)
{
    eval("var AppTypeDropDownList = AppTypeDropDownList" + i.toString());
    eval("var AppNoTextBox = AppNoTextBox" + i.toString());
    eval("var AppOtherPanel = AppOtherPanel" + i.toString());
    eval("var AppOtherTextBox = AppOtherTextBox" + i.toString());

    if (AppTypeDropDownList.value == '')
    {
        AppNoTextBox.disabled = true;
        AppNoTextBox.value = '';
        AppOtherPanel.style.display = 'none';
        AppOtherTextBox.value = '';
    }
    else
    {
        AppNoTextBox.disabled = false;
    }
    
    if (AppTypeDropDownList.value == 'Other')
    {
        AppOtherPanel.style.display = "block";
    }
    else
    {
        AppOtherPanel.style.display = "none";
        AppOtherTextBox.value = '';
    }
}

