$(document).ready(function(){
  $("#province").change(function(){
    $.ajax({
      type:"post",
      url:"/modules/martins_locator/default/ajax/change_city.php",
      data:"province=" + $(this).val(),
      success:function(returnText){
        $("#city").html(returnText);
      },
      error:function(){
        $.fn.colorbox({html:"There was an error while trying to find cities matched to the selected province, please try again."});
      }
    });
  });
  
  $("#martins_locator_button").click(function(){
    if($("#province").val() == "" || $("#city").val() == ""){
      $.fn.colorbox({html:"Please select a province AND a city before pressing the 'Submit' button."});
    }
    else{
      $.ajax({
        type:"post",
        url:"/modules/martins_locator/default/ajax/get_stores.php",
        data:"province=" + $("#province").val() + "&city=" + $("#city").val(),
        success:function(returnText){
          $.fn.colorbox({html:returnText});
        },
        error:function(){
          $.fn.colorbox({html:"There was an error while trying to find cities matched to the selected province, please try again."});
        }
      });
    }
    return false;
  });
});
