$(document).ready(function () {
  $("#inner-contact-form").validate({
    messages: {
      NameTextBox: {
        required: '*'
      },
      AgeTextBox: {
        required: '*'
      },
      EmailTextBox: {
        required: '*',
        email: '*'
      },
      ContactTextBox: {
        required: '*'
      },
      CityTextBox: {
        required: '*'
      },
      CountryTextBox: {
        required: '*'
      },
      MedicalCondition: {
        required: '*'
      },
      ServiceRequired: {
        required: '*'
      }
    },
    submitHandler: function (form) {
      $(form).ajaxSubmit({
        dataType: 'json',

        beforeSubmit: function () {
          $('#loading-form').show();
        },
        success: function (data) {
          if (data.message == "Thank you for submitting the form. We will get back to you within 24-48 hours.") {
            window.location = "thank-you.html";
          }
          else {
            alert(data.message);
            $('#loading-form').hide();
          }

        }
      });
    }
  });

  $("li.mega").hoverIntent({
    interval: 100,
    sensitivity: 4,
    over: function () {
      $(this).addClass("hover");
    },
    timeout: 1500,
    out: function () {
      $(this).removeClass("hover");
    }
  });

  $("#contact-form2").validate({
    messages: {
      Name2TextBox: {
        required: '*'
      },
      Email2TextBox: {
        required: '*',
        email: '*'
      },
      PhoneTextBox: {
        required: '*'
      },
      City2TextBox: {
        required: '*'
      }
    },
    submitHandler: function (form) {
      $(form).ajaxSubmit({
        dataType: 'json',

        beforeSubmit: function () {
          $('#loading-form2').show();
        },
        success: function (data) {
          alert(data.message);
          $('#loading-form2').hide();
          $(form).clearForm();
        }
      });
    }
  });


  $.ajax({
    type: "GET",
    url: "assets/data/treatment.xml",
    dataType: "xml",
    success: function (xml) {
      var select = $('#treatment-list');
      select.change(function () { fillProcedures(); });
      $(xml).find('treatment').each(function () {
        var title = $(this).attr('name');
        select.append("<option>" + title + "</option>");
      });
      var select2 = $('#treatment-list2');
      select2.change(function () { fillProcedures2(); });
      $(xml).find('treatment').each(function () {
        var title = $(this).attr('name');
        select2.append("<option>" + title + "</option>");
      });
    }
  });

  $('#ProcedureSelectSubmit').click(function () {
    var treatment = $('#treatment-list').val();

    if (treatment == "Choose a Treatment") {
      alert("Please Choose a Treatment First");
      return;
    }

    var procedure = $('#procedures-list').val();

    if (procedure == "Choose a procedure") {
    
      alert("Please Choose a Procedure First");
      return;
    }

    if (procedure != '') {
      window.location = procedure;
    }
  });

  $('#ProcedureSelectSubmit2').click(function () {
    var treatment = $('#treatment-list2').val();

    if (treatment == "Choose a Treatment") {
      alert("Please Choose a Treatment First");
      return;
    }

    var procedure = $('#procedures-list2').val();

    if (procedure == "Choose a procedure") {

      alert("Please Choose a Procedure First");
      return;
    }

    if (procedure != '') {
      window.location = procedure;
    }
  });

 
});

function fillProcedures() {
  var parentSelect = $('#treatment-list');

  $.ajax({
    type: "GET",
    url: "/assets/data/treatment.xml",
    dataType: "xml",
    success: function (xml) {
      var select = $('#procedures-list');
      select.empty();
      select.append("<option selected='true'>Choose a procedure</option>");
      $(xml).find('treatment').each(function () {
        var title = $(this).attr('name');

        if (title == parentSelect.val()) {
          $(this).find('procedure').each(function () {
            var text = $(this).find('name').text();
            var value = $(this).find('value').text();
            select.append("<option value='" + value + "'>" + text + "</option>");
          });
        }
      });
    }
  });
}

function fillProcedures2() {
  var parentSelect = $('#treatment-list2');

  $.ajax({
    type: "GET",
    url: "/assets/data/treatment.xml",
    dataType: "xml",
    success: function (xml) {
      var select = $('#procedures-list2');
      select.empty();
      select.append("<option selected='true'>Choose a procedure</option>");
      $(xml).find('treatment').each(function () {
        var title = $(this).attr('name');

        if (title == parentSelect.val()) {
          $(this).find('procedure').each(function () {
            var text = $(this).find('name').text();
            var value = $(this).find('value').text();
            select.append("<option value='" + value + "'>" + text + "</option>");
          });
        }
      });
    }
  });
}



function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  }, 'google_translate_element');
}


