function GetCount(){

	dateNow = new Date();
	amount = dateFuture.getTime() - dateNow.getTime();
	delete dateNow;

	// time is already past
	if(amount < 0){
		$('countbox_'+count_box_tmp).innerHTML="--- ";
		document.location.href='/index.php/programa/actualizarpagina';
	}
	// date is still good
	else{
		days=0;hours=0;mins=0;secs=0;out="";

		amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

		days=Math.floor(amount/86400);//days
		amount=amount%86400;

		hours=Math.floor(amount/3600);//hours
		amount=amount%3600;

		mins=Math.floor(amount/60);//minutes
		amount=amount%60;

		secs=Math.floor(amount);//seconds

		if(days != 0){out += days +" dia"+((days!=1)?"s":"")+", ";}
		if(days != 0 || hours != 0){out += hours +" hora"+((hours!=1)?"s":"")+", ";}
		if(days != 0 || hours != 0 || mins != 0){out += mins +" minuto"+((mins!=1)?"s":"")+", ";}
		out += secs +" segundos";
		$('countbox_'+count_box_tmp).innerHTML=out;

		setTimeout("GetCount()", 1000);
	}
}
function marcarAzar()
{
	limpiarBoleto();
	for(var i=1;i<=cant_partidos;i++)
	{
		num = Math.random()*100;
		if(num<33) 
		{
			$("L_"+i).checked=true;
		}
		if((num>34)&&(num<63))
		{
			$("E_"+i).checked=true;
		}
		if((num>64)&&(num<100))
		{
			$("V_"+i).checked=true;
		}
			
	}
}
function validarcheck(check)
{
	diff = cant_partidos_max- cant_partidos;
	diff2 = diff/2;
	tres = hayTres();
	dos= hayDos();
	if(dos>diff)
	{
		$(check).checked=false;
		return;
		
	}
	if(dos==diff)
	{
		if(tres>=1)
		{
			$(check).checked=false;
		}
	}
			
	if(tres>diff2)
	{
		if(dos>=diff)
		{
			$(check).checked=false;
			return;	
		}	
		
	}
	
	if(CantidadMarcados()>cant_partidos_max)
	{
		$(check).checked=false;
	}

}
function CantidadMarcados()
{
	var can_marcados=0;
	for(var i=1;i<=cant_partidos;i++)
	{
		if($("L_"+i).checked==true)
			can_marcados++;
		if($("E_"+i).checked==true)
			can_marcados++;
		if($("V_"+i).checked==true)
			can_marcados++;
	}
	return can_marcados;
}
function CantidadFilasMarcadas()
{
	var can_marcados=0;
	for(var i=1;i<=cant_partidos;i++)
	{
		if(($("L_"+i).checked==true)||($("E_"+i).checked==true)||($("V_"+i).checked==true))
		{
			can_marcados++;
			
		}
	}
	return can_marcados;
}
function hayTres()
{
	var can_marcados=0;
	for(var i=1;i<=cant_partidos;i++)
	{
		if(($("L_"+i).checked==true)&&($("E_"+i).checked==true)&&($("V_"+i).checked==true))
		{
			can_marcados++;
			
		}
	}
	return can_marcados;
}
function hayDos()
{
	var can_marcados=0;
	
	for(var i=1;i<=cant_partidos;i++)
	{
		if(($("L_"+i).checked==true)&&($("E_"+i).checked==true))
		{
			can_marcados++;
		}
		else
		{
			if(($("L_"+i).checked==true)&&($("V_"+i).checked==true))
			{
				can_marcados++;
			}
			else
			{
				if(($("E_"+i).checked==true)&&($("V_"+i).checked==true))
				{
					can_marcados++;
				}
			}
		}

	}
	return can_marcados;
}

function validarJuego()
{
	diff = cant_partidos_max- cant_partidos;
	diff2 = diff/2;
	tres = hayTres();
	dos= hayDos();
	if(dos>diff)
	{
		alert('Solo puede tener 2 filas de dos');
		return false;
		
	}
	if(dos==diff)
	{
		if(tres>=diff2)
		{
			alert('No puede marcar una fila de tres ya marco 2 filas de dos');
			return false;
		}
	}
			
	if(tres>diff2)
	{
		if(dos>=diff)
		{
			alert('no puede marcar una fila de 2, ya marco una de 3');
			return false;	
		}	
		
	}
	if(CantidadFilasMarcadas()< cant_partidos)
	{
		alert('Tiene que escojer todas las filas');
		return false;
	}
	if(CantidadMarcados()>cant_partidos_max)
	{
		alert('Solo puede escojer '+ cant_partidos_max.toString());
		return false;
	}	
	
	return true;
}
function marcarLocales()
{
	for(var i=1;i<=cant_partidos;i++)
	{
		$("L_"+i).checked=true;
		$("E_"+i).checked=false;
		$("V_"+i).checked=false;
		
	}
}
function marcarEmpates()
{
	for(var i=1;i<=cant_partidos;i++)
	{
		$("E_"+i).checked=true;
		$("L_"+i).checked=false;
		$("V_"+i).checked=false;

	}
}
function marcarVisitantes()
{
	for(var i=1;i<=cant_partidos;i++)
	{
		$("V_"+i).checked=true;
		$("L_"+i).checked=false;
		$("E_"+i).checked=false;
	}
}

function limpiarBoleto()
{
	for(var i=1;i<=cant_partidos;i++)
	{
		$("L_"+i).checked=false;
		$("E_"+i).checked=false;
		$("V_"+i).checked=false;
	}
}



function LTrim(str)
{
 var whitespace = new String(" \t\n\r");

 var s = new String(str);

 if (whitespace.indexOf(s.charAt(0)) != -1)
 {
 var j=0, i = s.length;

 while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
 j++;

 s = s.substring(j, i);
 }

 return s;
}
function RTrim(str)
{
 var whitespace = new String(" \t\n\r");

 var s = new String(str);

 if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
 {
 var i = s.length - 1; // Get length of string

 while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
 i--;

 s = s.substring(0, i+1);
 }

 return s;
}

function MTrim(str)
{

 var CadenaaReemplazar = " ";
 var CadenaReemplazo = "";
 return Trim(str.split(CadenaaReemplazar).join(CadenaReemplazo));

}
function Trim(str)
{
 return RTrim(LTrim(str));
}

function validarBuscar(form)
{
	var datasel=Form.getInputs(form)
	
	buscar =datasel[0];
	buscar.value = Trim(buscar.value);
	if(buscar.value=='')
	{	
		alert('Debe ingresar un nickname para buscar');
		return false;
	} 
	if(buscar.value=="Buscar Perfil...")
	{
		return false;
	}
	
	
	if(buscar.value.length <  3)
	{
		alert('Debe ingresar minimo 3 caracteres');
		return false;
	}
	
	
	return true;
}
