$(document).ready(function(){
	$(function()
	{
		$('.scroll-pane').jScrollPane();
		$('#columnafooter .jScrollPaneTrack').css({'background':'#D00505'})
	});



	$("select").change(function () {
        //console.log($(this).val());
        $("#info > div").hide();
        $("#" + $(this).val()).slideDown("slow");     
   
    }).change();


	$('#buscadoravanzado a').click(function(){
		$('#bavanzado').slideToggle('slow');
		if ($('#campo_avanzado').val() == 'false')
			$('#campo_avanzado').val('true');
		else
			$('#campo_avanzado').val('false');
	});
	$('#camposavanzados a').mouseenter(function(){
		$(this).addClass('hover');
	}).mouseleave(function(){
		$(this).attr('class', '');
	})
	$('#camposavanzados a').click(function(){
		var busqueda = $('#formbusqueda').val();
		var desde = $('select[name=desde]').val();
		var hasta = $('select[name=hasta]').val();
		var avanzado = $('input[name=avanzado]').val();
		var campo = $(this).attr('rel');
		//console.log(busqueda, desde, hasta);
		if ($('#bavanzado').is(':visible'))
		{
			if (busqueda && desde && hasta){
				location.href = "/?s=" + busqueda + "&desde="+ desde + "&hasta=" + hasta + "&campo=" + campo + "&avanzado=" + avanzado;
			}
			else{ 
				alert('Debe ingresar todos los campos de la busqueda avanzada');
				return false;
			}
		}
	})
	
	$('#formbusqueda').bind('keypress', function(e) {
		var busqueda = $('#formbusqueda').val();
		if ($('#bavanzado').is(':hidden')){
			var code = (e.keyCode ? e.keyCode : e.which);
		 	if(code == 13) { //Enter keycode
				if (!busqueda){
					alert('debe ingresar un termino para buscar');
					return false;
				}
			}
		}
	});
	
	$('#suscripcion').submit(function(){
        formulario = $(this).serialize();
        
        $.ajax({
            url     : '/enviar-suscripcion/',
            data    : formulario,
            success : function(msg){
                alert('Mensaje Enviado');
                $(this).clearForm();
            }
        });
	    return false;
	})
	
	$.fn.clearForm = function() {
      // iterate each matching form
      return this.each(function() {
        // iterate the elements within the form
        $(':input', this).each(function() {
          var type = this.type, tag = this.tagName.toLowerCase();
          if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
          else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
          else if (tag == 'select')
            this.selectedIndex = -1;
        });
      });
    };
	
	
	
	
})

