$(document).ready(function(){  
  //$('img[@src$=.png]').ifixpng();
  $('input:text').hint();
  $('textarea').hint();
});

function busca() { document.formulario.submit(); }

function avanza_pag() {
	document.formulario.accion.value="avanza_pag";
	document.formulario.submit();
}

function retrocede_pag() {
	document.formulario.accion.value="retrocede_pag";
	document.formulario.submit();
}

function ir_a_pag(pag) {
	document.formulario.accion.value="ir_a_pag";
	document.formulario.elemento.value=pag;
	document.formulario.submit();
}

function filtra() {
	document.formulario.accion.value="filtrar";
	document.formulario.offset.value="0";
	document.formulario.submit();
}

function actualiza_provs() {
	var comu = document.formulario.comunidad.value;
	
	$('#prov').attr("disabled", true); 
	$('#ganaderia').attr("disabled", true); 
	
	$('#prov').html("<option selected>actualizando...</option>");
	$('#ganaderia').html("<option selected>actualizando...</option>");
	
	$.ajax({
   		url: 'dame_provs.php?id='+comu,
	    type: 'GET',
	    dataType: 'html',
	    timeout: 30000,
	    error: function(response_text){
	        alert('Error en llamada ajax:\n'+response_text);
	    },
    	success: function(response_text){
	        cargaProvs(response_text);
    	}
    });
	$.ajax({
   		url: 'dame_ganad.php?criterio=comunidad_autonoma&id='+comu,
	    type: 'GET',
	    dataType: 'html',
	    timeout: 30000,
	    error: function(response_text){
	        alert('Error en llamada ajax:\n'+response_text);
	    },
    	success: function(response_text){
	        cargaGanads(response_text);
    	}
	});
}

function cargaProvs(response_text) {
	$('#prov').attr("disabled", false);
	$('#prov').html(response_text);
	document.getElementById('prov').selectedIndex=0;
}

function cargaGanads(response_text) {
	$('#ganaderia').attr("disabled", false);
	$('#ganaderia').html(response_text);
	document.getElementById('ganaderia').selectedIndex=0;
}

function actualiza_ganaderias() {
	var prov = document.formulario.prov.value;
	$('#ganaderia').attr("disabled", true); 
	$('#ganaderia').html("<option selected>actualizando...</option>");
	$.ajax({
   		url: 'dame_ganad.php?criterio=provincia&id='+prov,
	    type: 'GET',
	    dataType: 'html',
	    timeout: 30000,
	    error: function(response_text){
	        alert('Error en llamada ajax:\n'+response_text);
	    },
    	success: function(response_text){
	        cargaGanads(response_text);
    	}
	});
}

function validaEmail(dir) {
	r = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
	return(r.test(dir));
}

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}