$(document).ready(function(){function r(){f();u();i();n();t();$("#btnGenerateBallot").prop("disabled",!0)}function f(){$("#Elections").find("option:selected").prop("selected",!1);$("#Elections").removeClass("input-validation-error").addClass("valid")}function u(){$("select[id$=Counties] > option").remove();$("#Counties").removeClass("input-validation-error").addClass("valid")}function i(){$("select[id$=Jurisdictions] > option").remove();$("#Jurisdictions").removeClass("input-validation-error").addClass("valid")}function n(){$("select[id$=WardPrecincts] > option").remove();$("#WardPrecincts").removeClass("input-validation-error").addClass("valid")}function t(){$("#publicBallot-Form").find($(".field-validation-error")).html("");$("#publicBallot-Form").find($(".field-validation-error")).removeClass("field-validation-error").addClass("field-validation-valid")}r();$("#btnClear").on("click",function(n){n.preventDefault();r()});$("#Elections").change(function(r){r.preventDefault();u();i();n();t();$("#btnGenerateBallot").prop("disabled",!0);var f=$("#Elections").val();f!=0&&$.ajax({type:"POST",cache:!1,dataType:"json",url:"/PublicBallot/ElectionSelected",data:{electionID:f},success:function(n){n.length>0?($("#Counties").append($("<option><\/option>").val(0).html("Select")),$.each(n,function(n,t){$("#Counties").append($("<option><\/option>").val(t.Value).html(t.Text))})):QVFtoastr.Error("Ballot information is not available at this time.")},error:function(){QVFtoastr.Error("Ballot information is not available at this time.")}})});$("#Counties").change(function(r){r.preventDefault();i();n();t();$("#btnGenerateBallot").prop("disabled",!0);var f=$("#Elections").val(),u=$("#Counties").val();u!=0&&$.ajax({type:"POST",cache:!1,dataType:"json",url:"/PublicBallot/CountySelected",data:{electionID:f,countyID:u},success:function(n){n.length>0?($("#Jurisdictions").append($("<option><\/option>").val(0).html("Select")),$.each(n,function(n,t){$("#Jurisdictions").append($('<option class="one-rem"><\/option>').val(t.Value).html(t.Text))})):QVFtoastr.Error("Ballot information is not available at this time.")},error:function(){QVFtoastr.Error("Ballot information is not available at this time.")}})});$("#Jurisdictions").change(function(i){i.preventDefault();n();t();$("#btnGenerateBallot").prop("disabled",!0);var u=$("#Elections").val(),f=$("#Counties").val(),r=$("#Jurisdictions").val();r!=0&&$.ajax({type:"POST",cache:!1,dataType:"json",url:"/PublicBallot/JurisdictionSelected",data:{electionID:u,countyID:f,jurisdictionID:r},success:function(n){n.length>0?($("#WardPrecincts").append($("<option><\/option>").val(0).html("Select")),$.each(n,function(n,t){$("#WardPrecincts").append($("<option><\/option>").val(t.Value).html(t.Text))})):QVFtoastr.Error("Ballot information is not available at this time.")},error:function(){QVFtoastr.Error("Ballot information is not available at this time.")}})});$("#WardPrecincts").change(function(n){n.preventDefault();var t=$("#WardPrecincts").val();if(t==0){$("#btnGenerateBallot").prop("disabled",!0);return}$("#btnGenerateBallot").prop("disabled",!1);$("#btnGenerateBallot").focus()});$("#btnGenerateBallot").on("click",function(n){var f;n.preventDefault();var t=$("#Elections").val(),i=$("#Counties").val(),r=$("#Jurisdictions").val(),u=$("#WardPrecincts").val();if(t==0||i==0||r==0||u==0){$("#btnGenerateBallot").prop("disabled",!0);return}if(!$("#publicBallot-Form").valid())return!1;f={ElectionID:t,CountyID:i,JurisdictionID:r,WardPrecinct:u,Elections:null,Counties:null,Jurisdictions:null,WardPrecincts:null};$.ajax({type:"POST",cache:!1,dataType:"json",url:"/PublicBallot/GetMvicBallot",data:f,success:function(n){n.DataIssue?($("#modal-message").text(n.Message),document.getElementById("error-modal").open()):$("#body").html(n.Ballot)},error:function(){QVFtoastr.Error("Ballot information is not available at this time.")}})})})