/*
 * js para aplicaciones general - zona publica 
 * LOTOLUCK 
 * Date: 2011-06
 * Revision: --
 */
var ajax_request;


/**
* inicializamos la aplicacion
*/

$(document).ready(function(){
	//$(".loguearse").live('click',activa_login);
	//$("#resultados_email_form").live('submit',eval_resultados_via_email);
	if($("#resultados_email_form").length){
		$("#resultados_email_form").validate({
			submitHandler: eval_resultados_via_email
		});
	}
	
	$(".ic_juegos_horz").easyTooltip();
});

$(window).resize(function() {
	if($("#black_curt").length>0)	$("#black_curt").hide();
	
	if($("#black_curt").length>0){
		check_curt_size();
	}
});



function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}
/*
 *
 */
function addBookmark(){
	// add a "rel" attrib if Opera 7+

		var url = this.href;
		var title = this.title;

		if (window.sidebar) { // Mozilla Firefox Bookmark
		//alert("window.sidebar");
			window.sidebar.addPanel(title, url,"");
		} else if( window.external && $.browser.msie) { // IE Favorite
		//alert("IE");
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
		//alert("Opera");
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Por favor presione CTRL+D para añadir a sus favoritos.');
		}

   return false; 
}

/*
 *
 */
function addBookmark_org(){
	var bookmarkUrl = this.href;
   var bookmarkTitle = this.title;
 
   if ($.browser.mozilla) // For Mozilla Firefox Bookmark
   { 
	window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
   } 
   else if($.browser.msie || $.browser.webkit) // For IE Favorite
   { 
	window.external.AddFavorite( bookmarkUrl, bookmarkTitle); 
   }
   else if($.browser.opera ) // For Opera Browsers
   { 
	$(this).attr("href",bookmarkUrl);
	$(this).attr("title",bookmarkTitle);
	$(this).attr("rel","sidebar");
	$(this).click();
   } 
   else // for other browsers which does not support
   { 
        alert('Por favor presione CTRL+D para añadir a sus favoritos.');
   }
   return false; 
}
/*
 *
 */
 
 function eval_resultados_via_email(form)
{
	$("#notas_correo_via_email").css('display','none');
	var allVals = [];
	var frecuencia;
	var dia_semana = '';
	
	if($('#resultados_email_form :checked').length <= 1){
		$("#notas_correo_via_email span").html('Debes seleccionar al menos un juego para recibir los resultados<br/>');
		$("#notas_correo_via_email").css('display','block');
		$("#notas_correo_via_email").addClass('ko');
		
		return;
	}
//	alert($('#resultados_email_form :checked').length);
	//verificamos el dia de la semana
	
	//if(sid.length==32){
		$('#resultados_email_form :checked').each(function() {
			 var nm	=	$(this).attr('name');
			if(nm == 'juego') allVals.push($(this).val());
			if(nm == 'frecuencia') frecuencia = $(this).val();
		});
	
	//comprobamos la frecuencia 
	if(frecuencia == 's'){
		//vemos el dia de la semana
		if($("#dia_semana").val() == 0){
			$("#notas_correo_via_email").html('Debes seleccionar un dia de la semana para recibir lso resultados. O seleccionar Todos los días');
			$("#notas_correo_via_email").css('display','block');
			return;
		}
		
	}
		
		if(!allVals.length){
			$("#notas_correo_via_email").html('Debes seleccionar al menos un juego para recibir los resultados');
			$("#notas_correo_via_email").css('display','block');
		}else{
			$("#suscribirse_btn").hide();
			//SUBMIT
			//$("#resultados_email_form").attr('action',"");
			$("#resultados_email_form").find('#action').val('send_results_via_email');
			$("#resultados_email_form").find('#all_juegos').val(allVals);
			
			form.action ="";
			
			form.submit();
			//$("#resultados_email_form").submit();
		}
		//alert('ll_sp'+ll_sp); return;
	//}else{
	//	activa_login();
	//}
}
/*

*/

function loadSwfMovie(url, o,w,h,id)
{
	var vars = {};// 
	var params = { scale:'noScale', menu:'false' ,allowfullscreen:'true' };//salign:'lt', ,backgroundColor:'#000'
	var attributes = { id:id, name:id}; // give an id to the flash object
	
	//swfobject.embedSWF(url, o, w, h, "10.0.0", "js/expressInstall.swf", vars, params, attributes );
}
/*

*/
function activateCurt(autoClose, loading)
{
	var sty		=	loading	? 'black_curt loadingimg' : 'black_curt';
	var code	=	'<div class="'+sty+'" id="black_curt"></div>';
	$('body').append(code);
	var doc_he	=	$(document).height();
	$(".black_curt").css('height', doc_he+'px');
	
	if(autoClose)	$('.black_curt').click(removeCurt);
	
	
	$(document).bind('resize', function() {
		var doc_he	=	$(document).height();
		$(".black_curt").css('height', doc_he+'px');
	});
	
}
function removeCurt()
{
	$('#black_curt').remove();
	$(document).unbind('resize');
}

function check_curt_size()
{
	var doc_he	=	$(document).height();
	var doc_wi	=	$(document).width();
	
	$("#black_curt").css('width', doc_wi+'px');
	$("#black_curt").css('height', doc_he+'px');
	$("#black_curt").show();
}
/*

*/
function activa_login(errormess)
{
}
function activa_login_org(errormess)
{
	if(ajax_request)	ajax_request.abort();
	
	activateCurt(true, false);
	//$("#contenido_over_wrapper").show();
	$("#contenido_over_wrapper").fadeIn();
	
	//$('#contenido_over_wrapper').click(removeRegistro);
	
	var temp_code	=	'<div class="pop_closebtn" id="pop_closebtn"></div><div id="block_w" class="block_w loadingimg_w"></div>';
	$('#contenido_pop').html(temp_code);
	$('#pop_closebtn').click(removeRegistro);
	var url_r	=	ll_sp+'includes_modulos/login.php';
	
	ajax_request	=	$.ajax({ 
		  url: url_r,
		  success: function(data) 
		  {
			$('#contenido_pop').html('<div class="pop_closebtn" id="pop_closebtn"></div>' + data);
			$('#pop_closebtn').click(removeRegistro);
			
			if(errormess.length > 2){
				var code = '<ul>'+errormess+'</ul>';
				$('#mensaje_error').html(code);
				$('#mensaje_error').show();
			}
			
			check_curt_size();
		  }
	   
	 });
	/*l
	*/
}

function removeRegistro()
{
	if(ajax_request)	ajax_request.abort();
	
	$("#contenido_over_wrapper").hide();
	$("#contenido_over_wrapper").hide();
	removeCurt();
}



function inArray_pos(v, a)
{
	for(var i=0;i<a.length;i++) {
    	if ( a[i] == v  ){ return i; }
  	}
	return -1;
}

function in_array( aguja , pajar )
{
	for (var i = 0; i < pajar.length; i++)
	{
		if ( pajar[i] == aguja )
		{
			return true;
		}
	}
	
	return false;
}



/**
* Go to a page
* @param p page
* @param a action
* @param ids id to delete
* @param myvars
*/
function gotToPage( p,su, a,ids,myvars ){
	
	var url = p;

	for (x=0 ; x<ids.length ; x++){		
		url = url + '&'+myvars[x]+'='+ids[x];
	}
	
	location.href = url;
	return;
}

