$(document).ready(function() {

    if ( $("#frmunit").length > 0 ) {
        $("#frmunit").example('Unit name');
    }

     $("select#country").change(function(){
      if(this.value == "0"){
          alert('Please select a country');
      }else{
	  $.getJSON("/units/getjson/states/"+$(this).val(), function(j){
      var options = '';
      for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].id + '">' + j[i].estado + '</option>';
      }
      $("select#state").html(options);
      })
      }
  });

   $("#formpesq").submit(function(){
       
   if(("#country").val() == 0 && ("#state").val() == 0 && ("#frmunit").val() == 0)
       {
           alert('Please provide at least 1 search criteria');
           return false;
       }else{
           return false;
       }
  return false;
   });
});


var winmapa =
{
	janela:
	{
		status:0,toolbar:0,resizable:0,scrollbars:0,height:470,width:605,center:1,createnew:0
	}

};


function msgconf(msg,ajaxurl) {
  if (confirm(msg,ajaxurl)) {
    $.ajax({
      url: ajaxurl + '/',
      cache: false,
      success: function(html){
       alert(html);
      },
      error: function(){
        alert("Ocorreu um erro");
    }
    });

  }
}


function addActividades(max)
{
    var tam1 = $("#selactividades option").length;
    var tam2 = $("#actdisponiveis option:selected").length;
    var total = tam1 + tam2;

    if(total <= max){
         $("#actdisponiveis option:selected").remove().appendTo('#selactividades');
         $("#selact").val(1);
    }else if(total > 1 && total < 3){
        alert('Your account only allows one listing. Create a Gold Account if you wish to add up to three listings.');
    }else if(total > 3){
        alert('This account has a limit of three listings. If you wish to add more, please contact info@ridingtourism.com.');
    }
}


function remActividades(){
     $('#selactividades option:selected').remove().appendTo('#actdisponiveis');
     var tam1 = $("#selactividades option").length;
     if(tam1 <= 0){
         $("#selact").val('');
     }
}

