/****************************************************************************************************************/
/*                                               IAFAS -  2010                                                  */
/****************************************************************************************************************/

//Funciones iniciales para mostrar datos y tomar los parametros de la pantalla
var documentHeight; 
var scrollPosition;
$(window).load(function(){
	documentHeight = $(document).height(); 
	scrollPosition = $(window).scrollTop();
	$("#capa_100").height(documentHeight);
	$("#columna").height($("#cuerpo").height()-940);
	$(document).click(function(){ 
		documentHeight = $(document).height(); 
		scrollPosition = $(window).scrollTop();
	});
	$("#fecha").change(function(){
		calcular_fecha();
		buscar_loteria();
	});
	$("#tipo").change(function(){
		buscar_loteria();
	});
});

//Funciones iniciales para mostrar la fecha completa en el menu principal
var nmes = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
var ndia = new Array('Domingo', 'Lunes', 'Martes','Miércoles', 'Jueves', 'Viernes','Sábado');
function reloj(){
	ahora = new Date()
    minuto = ahora.getMinutes()
    segundo = ahora.getSeconds()
	dia = ahora.getDate()
	day = ahora.getDay()
	anio = ahora.getFullYear();
	mes = ahora.getMonth()
	if(minuto < 10)	minuto = '0'+minuto;
	ha = ndia[day]+" "+dia+" de "+nmes[mes]+" de "+anio+" | "+ ahora.getHours()+ ":" + minuto+" hs.";
	document.getElementById('clock').innerHTML = ha;
    setTimeout("reloj()",1000);
}


//Cruza los numeros de la loteria
function cruzar_loteria(){
	$('#reslot').fadeOut('normal', function(){
		$('#reslot'+xnot_old).hide();
		$('#reslot'+xnot_new).show();
		$(".num_conten_list li").removeClass("selected"); 
	    $("#n"+xnot_new).addClass("selected");
		xnot_old = xnot_new; 
		xnot_new = xnot_new + 1;
		if(xnot_new > xnot_max)	xnot_new = 1;
	}).fadeIn('normal');
}

//Mostramos los datos de la loteria en el principal y ajustamos los botones
function resp_loteria(data){
	$('#reslot').html(data);
	k = 0;
	//$("ul.num_conten_list > li").hide();
	$(".num_conten_list li").removeClass("noselected");
	$(".num_conten_list li").unbind('click')
	$(".num_conten_list li").each(function(){ 
		$(this).click(function(){ 
			$(".num_conten_list li").removeClass("selected"); 
			$(this).addClass("selected"); 
			if((xnot_new-1) == 0) xnot_old = xnot_max; else	xnot_old = xnot_new - 1;
			xnot_new = $(this).attr("value")*1.0;
		    cruzar_loteria()
		});
	});

	for(i=1;i<=4;i++){
		if(!document.getElementById('reslot'+i)){
			$('#n'+i).unbind('click'); 
			$("#n"+i).addClass("noselected"); 
		}
	}
	
	xnot_old = 1;
	xnot_new = 2;
	$(".num_conten_list li").removeClass("selected"); 
	$("#n1").addClass("selected"); 
	$("#reslotb").hide();
	$("#reslotbt").hide();
}

//Calcula el dia y ordena las opciones de acuerdo a el dia que nos encontramos
function calcular_fecha(){
	/*var myOptions = {"1":"El Primero","2":"Matutina","3":"Vespertina","4":"Nocturna"}
	var dob = $("#fecha").val();
	dob = dob.split('-');
	var thenx = new Date(dob[0],dob[1],dob[2]); 
	if(thenx.getDay() == 2)
		$("#tipo").removeOption("3");
	else{
		$("#tipo").removeOption(/./);
		$("#tipo").addOption(myOptions,false);
	}
	var str = $("#tipo_flag").val();
	$("#tipo").selectOptions('\''+str.toString()+'\'',false);*/
}



function calendario(f){
	var dataString = 'f='+f+'&d='+dias+'&fmax='+max_fecha+'&fmin='+min_fecha;
	$("#calend_back").show();
	$.ajax({
		type:"POST", 
		url:"../php/calendario.php",
		dataType:"html",
		error: function (XMLHttpRequest, textStatus, errorThrown){},
		data:dataString,
		timeout:5000,
		success: resp_calendario
	});  
}

function resp_calendario(data){$('#calendario').html(data);$("#calend_back").hide();}



function juegos_buscar(f){
	var dataString = 'f='+f;
	$("#juego_buscando").show();
	$("#juegos_resultados").hide();
	$.ajax({
		type:"POST", 
		url:pagina_ref,
		dataType:"html",
		error: function (XMLHttpRequest, textStatus, errorThrown){},
		data:dataString,
		timeout:5000,
		success: juegos_resultados
	}); 
}

function juegos_resultados(data){$('#juegos_resultados').html(data);$("#juego_buscando").hide();$("#juegos_resultados").show();$("#columna").height($("#cuerpo").height()-900);}



















function layerpos(layer,width,height){
/*	$(layer).width(width);
	$(layer).height(height);
	$(layer).css("margin-left",(-1*width/2));
	$(layer).css("margin-top",(-1*height/2)+scrollPosition);
	return false;*/
}


function abrir_ventana(data,height,width,layer){
/*	layerpos(layer,width,height)
	$(layer).show();
	if(data != '') $(layer).html(data);
	$('input').keypress(function(e){if(e.which == 13){return false;}}); 
	$("#capa_ca").hide();
	return false;*/
}
function cerrar_ventana(){
	/*$("#preg").hide(); 
	$("#capa_100").hide(); 
	return false;*/
}
	