function GetParameter( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if ( results == null )
    return "";
  else
    return results[1];
}

function AggiustaPagina() 
{ 
	
	if (document.getElementById('supercontainer').offsetHeight < window.innerHeight) 
	{
		//document.getElementById('footer').style.marginTop = (window.innerHeight-document.getElementById('supercontainer').offsetHeight+5)+"px";
		var paragrafi = document.getElementsByTagName("p");
		var i;
		for(i = 0; i < paragrafi.length; i++) 
		{
			if(paragrafi.item(i).className == "titolo_bottom" || paragrafi.item(i).className == "errore_bottom") 
			{
				paragrafi.item(i).style.marginTop = (window.innerHeight-document.getElementById('supercontainer').offsetHeight+5)+"px";
			}
		}
	}
	
	if ( GetParameter('operazione') == "albo_doro_scommesse" ) document.getElementById('content').style.height = "590px";
	
	if ( GetParameter('operazione') == "albo_doro_schedina" ) document.getElementById('content').style.height = "590px";
	
	
}

function roundNumber(num, dec) 
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function AggiornaEventualeVincita() 
{
	if(!isNaN(document.modulo_scommessa_corrente.puntata.value))
	{
		document.getElementById('eventuale_vincita').innerHTML = addCommas(roundNumber(Number(document.getElementById('quota').innerHTML.replace(",","").replace(",",""))*Number(document.modulo_scommessa_corrente.puntata.value.replace(",","").replace(",","")),2).toFixed(2));
	} 
}