var AJ_dia, AJ_mes, AJ_anio=0; AJ_fecha='';
var meses = new Array("", "ENERO", "FEBRERO","MARZO","ABRIL", "MAYO","JUNIO", "JULIO", "AGOSTO", "SEPTIEMBRE", "OCTUBRE", "NOVIEMBRE", "DICIEMBRE");

function sincero(string){
	var str="";
	var i=-1;
	while(string.charAt(++i)==0);
	// en "i" esta el indice del primer caracter no igual a cero
		str=string.substring(i,string.length);
	return str;
}

//function buscarfirma(dia, mes, anio){
function buscarfirma(fecha)
{
	if (fecha != AJ_fecha)
	{
		AJ_fecha=fecha;

		$.post("librodefirmas_ajaxlibrodefirmas_ajax.php",
		{ fecha: fecha },
		function(data)
		{
			// Si se obtuvieron datos los muestro
			if(data.substr(0,3)=="OK_"){
				firmas = data.substring(3);
				document.getElementById("FIRMAS").innerHTML = firmas;
			}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
				document.getElementById("FIRMAS").innerHTML = "";
			}
		}); //Fin data
	}
}


function buscarcalendario( mes, anio)
{
	if (mes+"_"+anio != AJ_mes+"_"+AJ_anio)
	{
		AJ_mes = mes;
		AJ_anio = anio;

		$.post("eventos_ajax.php",
		{ year: anio, mes: mes },
		function(data)
		{
			// Si se obtuvieron datos los muestro
			if(data.substr(0,3)=="OK_"){
				firmas = data.split('_*_');
				document.getElementById("mes").innerHTML = firmas[1];
				document.getElementById("EVENTOS").innerHTML = firmas[2];
				  Nifty("td.esquinas4","transparent big all");
				  Nifty("td.Pcolor2","transparent medium top");
			}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
				document.getElementById("EVENTOS").innerHTML = "";
			}
		}); //Fin data
	}
}

function cerrarmuestra(){
	document.body.removeChild(document.getElementById('muestra2'))
}


function mostrarMes(mes) {
	eventoscambio( mes, year);
}


function festivoscambio(year,anio)
{
	if (year != '')
	{
		$.post("eventos_festivos_ajax.php",
		{ year: year },
		function(data)
		{
			// Si se obtuvieron datos los muestro
			if( data.substr( 0, 3 ) == "OK_" ){
				firmas=data.substring( 3 );
				document.getElementById( "CONT_eventos" ).innerHTML = firmas;
				Nifty( "td.esquinas4" , "transparent big all" );
				Nifty( "td.Pcolor2" , "transparent medium top" );
				Nifty( "td.RED" , "transparent medium top" );
				if (year>(anio-1)){
					document.getElementById("yearant").innerHTML ='<a href="#" onclick="festivoscambio(\''+(parseInt(year)-1)+'\',\''+(parseInt(anio))+'\');" class="basmenu"><img src="img/cabecera_atras.gif" width="26" height="20" border="0" /></a>';
					document.getElementById("yearant").style.display = "block";
				}else{
					document.getElementById("yearant").innerHTML ='';
				}
				if (year<anio){
					document.getElementById("yearpost").innerHTML ='<a href="#" onclick="festivoscambio(\''+(parseInt(year)+1)+'\',\''+(parseInt(anio))+'\');" class="basmenu"><img src="img/cabecera_siguiente.gif" width="26" height="20" border="0" align="absbottom" /></a>';
					document.getElementById("yearpost").style.display = "block";
				}else{
					document.getElementById("yearpost").innerHTML ='';
				}
				document.getElementById("year").innerHTML = year;
			}else if(ajax.responseText=="VACIO"){
				document.getElementById( "CONT_eventos" ).innerHTML = '';
				if (year>(anio-1)){
					document.getElementById("yearant").innerHTML ='<a href="#" onclick="festivoscambio(\''+(parseInt(year)-1)+'\',\''+(parseInt(anio))+'\');" class="basmenu"><img src="img/cabecera_atras.gif" width="26" height="20" border="0" /></a>';
					document.getElementById("yearant").style.display = "block";
				}else{
					document.getElementById("yearant").innerHTML ='';
				}
				if (year<anio){
					document.getElementById("yearpost").innerHTML ='<a href="#" onclick="festivoscambio(\''+(parseInt(year)+1)+'\',\''+(parseInt(anio))+'\');" class="basmenu"><img src="img/cabecera_siguiente.gif" width="26" height="20" border="0" align="absbottom" /></a>';
					document.getElementById("yearpost").style.display = "block";
				}else{
					document.getElementById("yearpost").innerHTML ='';
				}
				document.getElementById("year").innerHTML = year;
			}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
				//document.getElementById("FIRMAS").innerHTML = "";
			}
		}); //Fin data

	} // Fin year !=''
}

function eventoscambio(jmes,year){
	if (year != '')
	{
		janio = year;
//		$(".Lmes").css("color","#ffffff");
//		$("#Lmes"+jmes).css("color", "#ff0000");
		var loading = '<p></p<p></p><img src="img/apartados/eventos/loading.gif" align="center" />';
		$("#CONT_eventos").html('');
		
		$.post("eventos_soltienda_ajax.php",
		{ year: janio, mes: jmes },
		function(data)
		{
			// Si se obtuvieron datos los muestro
			if( data.substr( 0, 3 ) == "OK*" ){
				DATAeventos=data.substring( 3 );
			}else if(data=="VACIO"){
				DATAeventos='';
			}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
			}
			$("#CONT_eventos" ).html(DATAeventos);
			/*
			if (year>(anio-1)){
				$("#yearant").html('<a href="#" name="ancatras" onclick="eventoscambio(\''+(parseInt(year)-1)+'\',\''+(parseInt(year))+'\');" class="basmenu"><img src="img/cabecera_atras.gif" width="26" height="20" border="0" /></a>');
				document.getElementById("yearant").style.display = "block";
			}else{
				$("#yearant").html('');
			}
			if (year<anio){
				$("#yearpost").html('<a href="#" name="ancadelante" onclick="eventoscambio(\''+(parseInt(year)+1)+'\',\''+(parseInt(year))+'\');" class="basmenu"><img src="img/cabecera_siguiente.gif" width="26" height="20" border="0" align="absbottom" /></a>');
				document.getElementById("yearpost").style.display = "block";
			}else{
				$("#yearpost").html('');
			}
			$("#year").html(year);
			*/
		}); //Fin data
	}
}

function acomodarflechas()
{
	if (janio == aniomin){
		$("#flecha_anio_anterior").hide();
	}else{
		$("#flecha_anio_anterior").show();
	}
	if (janio == aniomax){
		$("#flecha_anio_siguiente").hide();
	}else{
		$("#flecha_anio_siguiente").show();
	}

	if (jmes==1 && janio == aniomin){ //jmes==1
		$("#flecha_mes_anterior").hide();
	}else{
		$("#flecha_mes_anterior").show();
	}
	//alert(jmes+"_"+mesmax+"_"+jani+"_"+aniomax);
	var strcomp = janio+""+jmes;
	if ( strcomp==mesmax ){ //jmes==12 		&& janio == aniomax
		$("#flecha_mes_siguiente").hide();
	}else{
		$("#flecha_mes_siguiente").show();
	}
}

function eventoscambioN(accion)
{	
	if (accion == 'anterior')
	{
		if (janio > aniomin){
			janio--;
		}
	}
	else if (accion == 'siguiente')
	{
		if (janio < aniomax){
			janio++;
		}
	}
	$("#CONT_eventos").html('');
	//alert(janio+jmes);
	$.post("eventos_soltienda_ajax.php",
	{ year: janio, mes: jmes },
	function(data)
	{
		// Si se obtuvieron datos los muestro
		var DATAeventos = "";
		if( data.substr( 0, 3 ) == "OK*" ){
			DATAeventos=data.substr(3);
			/*if( data.substr( 3, 6 ) == "NO*" ){
				$("#flecha_mes_siguiente").hide();
			}
			DATAeventos=data.substr(6);*/
		}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
		}
		$("#CONT_eventos" ).html(DATAeventos);
		$("#year").html(janio);
		acomodarflechas();
		$.extend($.fn.Tooltip.defaults, {
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - "
		});
		$('a').Tooltip(); //a, input, img
	}); //Fin data

}

function eventoscambiomesN(accion)
{
	if (accion == 'anterior')
	{
		if (jmes>1){
			jmes--;
		}else{
			jmes=12;
			eventoscambioN('anterior');
		}
	}
	else if (accion == 'siguiente')
	{
		if (jmes<12){
			jmes++;
		}else{
			jmes=1;
			eventoscambioN('siguiente');
		}
	}
	//var tienedatos = "SI";

	$(".Lmes").css("color","#ffffff");
	$("#Lmes"+jmes).css("color", "#ff0000");
	$( "#CONT_eventos" ).html('');
	//alert(janio+jmes);
	$.post("eventos_soltienda_ajax.php",
	{ year: janio, mes: jmes },
	function(data)
	{
		var DATAeventos = "";
		if( data.substr( 0, 3 ) == "OK*" ){
			DATAeventos=data.substr(3);
			//alert(DATAeventos);
			/*if( data.substr( 3, 3 ) == "NO*" ){
				tienedatos = "NO";
			}
			DATAeventos=data.substr(6);*/

		}else if(data.substr( 0, 5 )!="ERROR"){ //ajax.responseText VACIO
		}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
		}
		$("#mes").html(Ames[jmes]);
		$( "#CONT_eventos" ).html(DATAeventos);
		acomodarflechas();
		$.extend($.fn.Tooltip.defaults, {
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - "
		});
		$('a').Tooltip(); //a, input, img
	});

}

function firmascambioN(accion){
	if (accion == 'anterior')
	{
		if (janio > aniomin){
			janio--;
		}
	}
	else if (accion == 'siguiente')
	{
		if (janio < aniomax){
			janio++;
		}
	}
	//$("#xmes").html('<img src="images/ajax-loader.gif">');
	$("#CorreTiempo").show();
	$("#xanio").html("");
	$("#FIRMAS").html('');
	//alert(janio+jmes);
	$.post("huespedes_firmas_ajax.php",
		{ year: janio	, mes: jmes },
		function(data)
		{
			// Si se obtuvieron datos los muestro
			var DATAeventos = "";
			if( data.substr( 0, 3 ) == "OK_" ){
				DATAeventos=data.substr(3);
			}else{ // En caso contrario seteo la busqueda actual como una busqueda sin resultados
			}
			$("#mes").html(Ames[jmes]);
			$("#FIRMAS" ).html(DATAeventos);
			$("#year").html(janio);
			acomodarflechas();
			$("#LABEL_year_actual").html(janio);
			$("#xmes").html(Ames[jmes]);
			$("#xanio").html(janio);
			$("#CorreTiempo").hide();
		}
	); //Fin data

}



function firmascambiomesN(jmes)
{
	
	//var tienedatos = "SI";
	janio=year;
	//$("#xmes").html('<img src="images/ajax-loader.gif">');
	$("#xanio").html("");
	$("#CorreTiempo").show();
	$("#FIRMAS").html('');
	//alert(janio+jmes);
	$.post("huespedes_firmas_ajax.php",
	{ year: janio, mes: jmes },
		function(data)
		{
			// Si se obtuvieron datos los muestro
			var DATAeventos = "";
			if( data.substr( 0, 3 ) == "OK_" ){
				DATAeventos=data.substr(3);
				/*if( data.substr( 3, 3 ) == "NO_" ){
					tienedatos = "NO";
				}
				DATAeventos=data.substr(6);*/
			}else if (data=="VACIO"){ // En caso contrario seteo la busqueda actual como una busqueda sin resultados

			}
			$("#mes").html(Ames[jmes]);
			$("#FIRMAS" ).html(DATAeventos);
			$("#year").html(janio);
			acomodarflechas();
			$("#LABEL_year_actual").html(janio);
			$("#xmes").html(Ames[jmes]);
			$("#xanio").html(janio);
			$("#CorreTiempo").hide();
		}
	);
}

