/* Minification failed. Returning unminified contents.
(3,10): run-time error CSS1031: Expected selector, found 'setupSchoolData('
(3,10): run-time error CSS1025: Expected comma or open brace, found 'setupSchoolData('
(11,10): run-time error CSS1031: Expected selector, found 'updateCities('
(11,10): run-time error CSS1025: Expected comma or open brace, found 'updateCities('
(36,10): run-time error CSS1031: Expected selector, found 'clearSchoolNameEntered('
(36,10): run-time error CSS1025: Expected comma or open brace, found 'clearSchoolNameEntered('
(44,10): run-time error CSS1031: Expected selector, found 'updateSchools('
(44,10): run-time error CSS1025: Expected comma or open brace, found 'updateSchools('
(79,10): run-time error CSS1031: Expected selector, found 'lookSchoolChanged('
(79,10): run-time error CSS1025: Expected comma or open brace, found 'lookSchoolChanged('
(86,10): run-time error CSS1031: Expected selector, found 'lookYearChanged('
(86,10): run-time error CSS1025: Expected comma or open brace, found 'lookYearChanged('
(104,10): run-time error CSS1031: Expected selector, found 'ValidateNoSchoolForm('
(104,10): run-time error CSS1025: Expected comma or open brace, found 'ValidateNoSchoolForm('
 */

// v1
function setupSchoolData() {
    $('#State').val(State.GetValue());
    $('#City').val(City.GetValue());
    $('#SchoolName').val(School.GetText());

    return true;
}

function updateCities(state) {
    $('#waitCity').show();
    $('#btnSubmit').prop('disabled', true);
    School.ClearItems();
    clearSchoolNameEntered();

    $.post("/Account/CitiesInState",
        {
            "state": state,
            '__RequestVerificationToken': $('input[name="__RequestVerificationToken"]').val()
        },
        function (data) {
        $("#divCmbCities").html(data);

        if ($('#hidSeqCascade').length && $('#hidSeqCascade').val()== "1") {
            $('#divLookupMasterCity').show();
        }

        City.ShowDropDown();
        City.Focus();
        $('#waitCity').hide();
    });

}

function clearSchoolNameEntered() {
    if ($('#chkCantFind').length) {
        $("#chkCantFind").prop('checked', false);
        $('#SchoolNameEntered').val("");
        $('#divSchoolNameEntered').hide();
    }
}

function updateSchools(city, state, schoolYear) {
    var allowMulti = 0;

    $('#waitSchool').show();
    $('#btnSubmit').prop('disabled', true);

    if ($('#hidAllowMulti').length) {
        allowMulti = $('#hidAllowMulti').val();
    }

    $.post("/Account/SchoolsInCity",
        {
            "city": city,
            "state": state, 
            "schoolYear": schoolYear,
            "allowMulti": allowMulti,
            '__RequestVerificationToken': $('input[name="__RequestVerificationToken"]').val()
        },
        function (data) {

            $("#divCmbSchools").html(data);

            clearSchoolNameEntered();

            if ($('#hidSeqCascade').length) {
                $('#divLookupMasterSchool').show();
            }

        School.ShowDropDown();
        School.Focus();
        $('#waitSchool').hide();
    });
}


function lookSchoolChanged() {
    clearSchoolNameEntered();
    $('#masterNo').val(School.GetValue());

    $('#btnSubmit').prop('disabled', false);
}

function lookYearChanged() {
  
    var yearval = $('#dlYear').val();

    $('#btnSubmit').prop('disabled', true);
    School.ClearItems();
    City.ClearItems();
    State.SetSelectedIndex(-1);
    if (yearval.length > 1) {
        State.SetEnabled(true);
        if ($('#hidSeqCascade').length) {
            $('#divLookupMasterState').show();
        }
    }
    else
        State.SetEnabled(false);
}

function ValidateNoSchoolForm() {
    var failed = false;
    var chkCantChecked = $("#chkCantFind").is(':checked');

    if ($('#formCallMe').valid() == false) {
        failed = true;
    }
    $('#CityError').hide();
    $('#StateError').hide();
    $('#SchoolError').hide();

    var theState = State.GetValue();
    if (theState == null) {
        $('#StateError').show();
        failed = true;
    }

    var theCity = City.GetValue();
    if (theCity == null) {
        $('#CityError').show();
        failed = true;
    }

    if (!chkCantChecked) {
        var theSchool = School.GetValue();
        if (theSchool == null) {
            $('#SchoolError').show();
            failed = true;
        }
    }

    if (failed)
        return false;

    if (chkCantChecked) {
        $('#SchoolName').val($('#SchoolNameEntered').val());
    }
    else {
        var school = School.GetText();
        if (school.length == 0) {
            $('#SchoolError').show();
            return false;
        }
        $('#SchoolName').val(School.GetText());
    }

    $('#State').val(State.GetValue());
    $('#City').val(City.GetValue());

    return true;
}


