$$$(document).ready(function(){
	$$$('#tipo_test').change(function(){
		$$$.ajax({
		    beforeSend : function(xhr) {
              if (xhr.overrideMimeType) {
				xhr.overrideMimeType('text/html; charset=iso-8859-1');
              }
			},
			type: "POST",
			url: "modulos/ajax/analiticas_descripcion.php",
			data: "&analisis=" + $$$('#tipo_test option:selected').val(),
			success: function(html){
				$$$('div.analiticasR').hide().html(html).fadeIn('slow');
			}
		});
		$$$.ajax({
			type: "POST",
			url: 'library/calendar/ott.calendar.php',
			data: "analisis=" + $$$('#tipo_test option:selected').val(),
			success: function(html){
				$$$('div.calendario').hide().html(html).fadeIn('slow');
			}
		});
		$$$('#select_hora').html('<option value="0">Seleccione día</option>');
	});
	$$$('table.calendar td a').live('click',function(){
		$$$.ajax({
			type: "POST",
			url: 'modulos/ajax/horas_disponibles.php',
			data: "date=" + $$$(this).parent().attr('title') + "&analisis=" + $$$('#tipo_test option:selected').val(),
			success: function(html){
				$$$('#select_hora').html(html);
			}
		});
		var body = $$$.ajax({
		    beforeSend : function(xhr) {
              if (xhr.overrideMimeType) {
				xhr.overrideMimeType('text/html; charset=iso-8859-1');
              }
			},
			type: "POST",
			url: 'library/calendar/ott.calendar.php' + $$$(this).attr('href'),
			data: "analisis=" + $$$('#tipo_test option:selected').val(),
			async: false
		}).responseText;
		$$$(this).parent().parent().parent().parent().replaceWith(body);
		return false;
	});
	
	// Rservar
	$$$('#linkReservar').click(function(){
		var tipo = $$$('#tipo_test').attr('value');
		var dia  = $$$('table.calendar td.selected').attr('title');
		var hora = $$$('#select_hora').attr('value');
		$$$.ajax({
		    beforeSend : function(xhr) {
              if (xhr.overrideMimeType) {
				xhr.overrideMimeType('text/html; charset=iso-8859-1');
              }
            },
			type: "POST",
			url: 'modulos/ajax/reserva_analitica.php',
			data: "tipo=" + tipo + '&dia=' + dia + '&hora=' + hora,
			success: function(msg){
				alert(msg);
			}
		});
		return false;
	});
});