//Creado con Ardora - www.webardora.net
//bajo licencia Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
//para otros usos contacte con el autor
$(function(){
   $(".fg-button:not(.ui-state-disabled)")
   .hover(
      function(){
         $(this).addClass("ui-state-hover");
      },
      function(){
         $(this).removeClass("ui-state-hover");
      }
   )
   .mousedown(function(){
      $(this).parents(".fg-buttonset-single:first").find(".fg-button.ui-state-active").removeClass("ui-state-active");
      if( $(this).is(".ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active") ){ $(this).removeClass("ui-state-active"); }
      else { $(this).addClass("ui-state-active"); }})
   .mouseup(function(){
      if(! $(this).is(".fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button") ){
        $(this).removeClass("ui-state-active");}});
});
   var addressFormatting = function(text){
      var newText = text;
      var findreps = [
      {find:/^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>'},
      {find:/([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
      {find:/([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2'},
      {find:/([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
      {find:/(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>'}
  ];
  for(var i in findreps){
      newText = newText.replace(findreps[i].find, findreps[i].rep);
  }
  return newText;
}

function showDialog(){
    $("#gravar").dialog("open");
    return false;
}
$(document).ready(function() {
$("#gravar").dialog({
       autoOpen: false,
       modal: true,
       height: 200,
       width: 300,
       modal:true,
       buttons:{
           "OK" : function(){
              if (jQuery.trim(document.entraDatos.titulo.value).length==0){
                     alert("Debes de escribir un nome do personaxe ou un feito. Exm.: Tratado de Uttrech.");
                     $(this).dialog("close");
                     document.entraDatos.titulo.focus();
              }
              else{
                  if (jQuery.trim(document.entraDatos.anoI.value).length==0){
                     alert("Debes de introducir unha data");
                     $(this).dialog("close");
                     document.entraDatos.anoI.focus();
                  }
  	           else{
  	              if (isNaN(parseInt(jQuery.trim(document.entraDatos.anoI.value)))) {
                        alert("Number!");
  	  	         $(this).dialog("close");
                        document.entraDatos.anoI.focus();
                     }
  	              else{
    	                 document.entraDatos.submit();
                     }
                  }
              }
       },
           "Cancelar": function(){$(this).dialog("close")}
       }
    });
 });

function showDialogBorrar(){
  if (document.entraDatos.speedA.value!="0"){
      $("#borrar").dialog("open");
  }
  return false;
}

$(document).ready(function() {
$("#borrar").dialog({
      autoOpen: false,
      modal: true,
      height: 200,
      width: 300,
      buttons:{
          "OK" : function(){
               var retorno =1;
		if (jQuery.trim(document.entraDatos.titulo.value).length==0){ retorno = 0;}
               if (retorno == 0){
                 alert("Como mínimo, debes de introducir un título.");
                  $(this).dialog("close");
                  document.entraDatos.titulo.focus();
               }
               else{ parent.location.href="borrar.php?indi="+document.entraDatos.speedA.value;}
          },
          "Cancelar": function(){ $(this).dialog("close")}
      }
   });
if ( $("#speedA").length ) {if (document.entraDatos.speedA.value!="0"){$("#b_borra").css("visibility", "visible");}else{$("#b_borra").css("visibility", "hidden");}}else{$("#b_borra").css("visibility", "hidden");}
});

function showDialogProfe(){
  $("#profe").dialog("open");
  return false;
}

$(document).ready(function() {
  $("#profe").dialog({
  autoOpen: false,
  modal: true,
  height: 575,
  width: 925,
  buttons:{
      "Pechar": function(){ $(this).dialog("close")}
  }
 });
});
