//  jQuery(function($){
//    $.datepicker.regional['es'] = {
//        closeText: 'Cerrar',
//        prevText: '&#x3c;Ant',
//        nextText: 'Sig&#x3e;',
//        currentText: 'Hoy',
//        monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
//        'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
//        monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
//        'Jul','Ago','Sep','Oct','Nov','Dic'],
//        dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
//        dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
//        dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
//        weekHeader: 'Sm',
//        dateFormat: 'dd/mm/yy',
//        firstDay: 1,
//        isRTL: false,
//        showMonthAfterYear: false,
//        yearSuffix: ''
//    };
//    $.datepicker.setDefaults($.datepicker.regional['es']);
//});

  $(document).ready(function() {
function ImgCargaShow(id) {
    $("#"+id).show().append('<img src="imagenes/loading.gif" alt="Cargando.." id="loading" />');
}

function ImagenCargaBorra() {
 //   $('#loading').remove();
 $('#loading').fadeOut(1000, function() {
                $(this).remove();
                });
}
 function updateTips(t) {
        tips
        .text(t)
        .addClass('ui-state-highlight');
        setTimeout(function() {
            tips.removeClass('ui-state-highlight', 1500);
        }, 3500);
    }

    function checkLength(o,n,min,max) {

        if ( o.val().length > max || o.val().length < min ) {
            o.addClass('ui-state-error');
            updateTips("Longitud de  " + n + " debe estar entre  "+min+" y "+max+".");
            return false;
        } else {
            return true;
        }

    }

    function checkRegexp(o,regexp,n) {

        if ( !( regexp.test( o.val() ) ) ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
        } else {
            return true;
        }

    }


    function enviamail(cfname,mail,mensaje,area) {
	var dataString = 'nombre='+ cfname + '&correo=' + mail + '&mensaje=' + mensaje ;

	$.ajax({
      type: "POST",
      url: "./include/enviamail.php",
      data: dataString,
      success: function(datos) {
                                var $dialog = $('<div></div>')
                               .html(datos)
                               .dialog({
                                  autoOpen: false,
                                  title: 'Mensaje',
                                  height:200,
                                  closeText:'ok',
                                  modal: true,
                                  buttons: {
                                   'Cerrar': function() {
                                            $(this).dialog('close');
                                            $(".post").show();
                                               }
                                   }
                               });
                              $dialog.dialog('open');
      }
     });

    }
//
//
//
//
      var cfname = $("#cfname"),  // apellido del formulario de contacto
    mail = $("#mail"), // mail del formulario de contacto
    mensaje=$("#mensaje"),  // mensaje del formulario de contacto
     tips = $(".validateTips"),
    allFieldscf = $([]).add(cfname).add(mail).add(mensaje);

$("#contact-form").dialog({
        autoOpen: false,
        height: 550,
        width: 450,
        modal: true,
        buttons: {
            'Enviar': function() {
                var bValid = true;
                allFieldscf.removeClass('ui-state-error');
                bValid = bValid && checkLength(cfname,"apellido",3,50);
bValid = bValid && checkRegexp(mail,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"ingrese su mail, p.ej. aa@algo.com");
bValid = bValid && checkLength(mensaje,"mensaje",10,200);

                if (bValid) {

                   enviamail(cfname.val(),mail.val(),mensaje.val());

                    $(this).dialog('close');
                }
            },
            'Cancelar': function() {

                $(this).dialog('close');
                 $(".post").show();
            }
        },
        close: function() {
            allFieldscf.val('').removeClass('ui-state-error');
        }
    });
  $('#contactoinferior')
    .click(function() {
     $('#contact-form').dialog('open');
            });
     $('#contacto')
    .button({icons: {primary:'ui-icon-mail-closed'}})
    .click(function() {

     $('#contact-form').dialog('open');
            });

//     $("#sidebar").accordion({ header: "h3",
//                                       active:false,
//                                       collapsible:true});  


$(".boton").button();


$('#ims').show().cycle({  // imagens sponsor
 fx:  'scrollRight'   //
});

// tabs de la info del torneo, en centro0911.php
$("#tabs1").tabs();


//
//// galeria imagenes de los torneos anteriores
//$("a[rel=foto_gal1]").fancybox({'titlePosition': 'outside',
//                                 'transitionIn'		: 'easeInElastic',
//				'transitionOut'		: 'jswing',
//				'overlayColor'		: '#000',
//				'overlayOpacity'	: 0.9
//                            
//                        });
                        
                        
// acordion sidebar
// $("#sidebar").accordion({header: "h3",                                
//                          autoHeight: false,
//                          active:false,
//                          collapsible:true
//                          
//    });  
//                                   
                                   
 // consulta jugadores inscriptos
 $("li.cat,li.prog,li.res,li.todos").button ({  // por categoria y sexo
        icons: {
//            primary:'ui-icon-search'
        }
   });
$("li.cat span.ui-button-text").click(function(){
     $(".post").hide();
        $('#contenido').empty();
        ImgCargaShow("contenido");
        
         var scat=$(this).html();

        $.ajax({
              data: "scat="+scat,
              type: "POST",
            url: 'listaporcatvete.php',
            success: function(datos){
                if (datos.length<20){
                    
                    var $dialog = $('<div></div>')
                    .html(datos)
                    .dialog({
                        autoOpen: false,
                        title: 'Mensaje',
                        height:140,
                        closeText:'ok',
                        modal: true,
                        buttons: {
                            'Cerrar': function() {
                                $(this).dialog('close');
                            }
                        }
                    });
                    ImagenCargaBorra();
                    $dialog.dialog('open');
                  $("#contenido, .post").toggle();
//                    $(".post").show();
                    return false ;
                }
                ImagenCargaBorra();

                $("#contenido").show().html(datos);

            }
        });
        return false;
    });

 $("li.todos span.ui-button-text").click(function(){
     $(".post").hide();
        $('#contenido').empty();
        ImgCargaShow("contenido");
        
         var scat=$(this).html();

        $.ajax({
              data: "scat="+scat,
              type: "POST",
            url: 'todosvet.php',
            success: function(datos){
                if (datos.length<20){
                    
                    var $dialog = $('<div></div>')
                    .html(datos)
                    .dialog({
                        autoOpen: false,
                        title: 'Mensaje',
                        height:140,
                        closeText:'ok',
                        modal: true,
                        buttons: {
                            'Cerrar': function() {
                                $(this).dialog('close');
                            }
                        }
                    });
                    ImagenCargaBorra();
                    $dialog.dialog('open');
                  $("#contenido, .post").toggle();
//                    $(".post").show();
                    return false ;
                }
                ImagenCargaBorra();

                $("#contenido").show().html(datos);

            }
        });
        return false;
    });
                       

});


