function indirizzoEmailValido(indirizzo) 
{
  var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
  var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
  var regnv = new RegExp(nonvalido);
  var regv = new RegExp(valido);
  if (!regnv.test(indirizzo) && regv.test(indirizzo))
    return true;
  return false;
};

function openPopup(iTop, iLeft, width, height, redirect) 
{
  var OpenWindow = redirect;
  var params = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + width + ',height=' + height + ',top='+iTop+',left='+iLeft
  window.open(OpenWindow,"BETSITE", params);
  if(navigator.appName.substring(0,8) == "Netscape" ) 
  {
    popup.location = puURL; 
  }
}

function genPopup(url, wi , he) {
	iTop   = 100;
	iLeft   = 50;
 	window.open(url, 'POPUP','scrollbars=yes,resizable=1,toolbar=0,directories=0,menubar=0,location=0,width='+wi+',height='+he+',top='+iTop+',left='+iLeft)
}

function navigatorSubmit(theForm, navigatorName, valore)
{
  var elementi = theForm.elements;
  elementName = navigatorName + ".thisPage"
  for(i = 0; i < elementi.length; i++)
  {
    if(elementi[i].name.indexOf(elementName) == 0)
    {
      elementi[i].value = valore;
      break;
    }      
  }
  theForm.submit();
}

function selectOption(select, value)
{
  if((select != null) && (! isEmpty(value)))
  {    
    elements = select.options;
    if((elements != null) && (elements.length > 0))
    {
      for(i = 0; i < elements.length; i++)
      {
        if(value == elements[i].value)
        {  
          select.selectedIndex = i;
          break;  
        }  
      }
    }
  }
}

function setTextValue(text, value)
{
  if((text != null) && (! isEmpty(value)))
  {    
    if(text.value != null)
    {
      text.value = value;
    }
  }
}

function setCheckBoxChecked(checkBox, value)
{
  if((checkBox != null) && (! isEmpty(value)))
  {    
    if(checkBox.value != null)
    {
      if((Trim(value).toLowerCase() == 'true') || (Trim(value) == '1'))
      {
        checkBox.checked = true;
      }
    }
  }
}

function setRadioButtonChecked(radios, value)
{
  if((radios != null) && (radios.length > 0) && (! isEmpty(value)))
  {    
    for(i = 0; i < radios.length; i++)
    {
      if(value == radios[i].value)
      {  
        radios[i].checked = true;
        break;  
      }  
    }
  }
}

function LTrim(text)
{
  if(text == null || text.length == 0)
  {
    return "";      
  }      
  idx = 0;
  while(text.charAt(idx) == ' ')
  {
    ++idx;
    if(idx >= text.length)
      break; 
  }
  if(idx < text.length)
  {
    return text.substring(idx);
  }
  else  
    return "";
}

function RTrim(text)
{
  if(text == null || text.length == 0)
  {
    return "";      
  }
  idx = text.length - 1;
  while(text.charAt(idx) == ' ')
  {
    --idx;
    if(idx < 0)
      break;
  }
  if(idx >= 0)
  {
    return text.substring(0, (idx + 1));
  }    
  else  
    return "";
}

function Trim(text)
{
  testo = LTrim(text);
  testo = RTrim(testo);
  return testo;
}

function eNumero(text)
{
  text = '' + text;
  if(Trim(text).length == 0)
    return false
  else  
    return (isFinite(Trim(text.replace(',','.'))) && (!isNaN(Trim(text.replace(',','.')))));
}

function isEmpty(text)
{
  if(text == null)
  {
    return true;  
  }
  else
  {
    testo = Trim(text);
    if(testo.length == 0)
    {
      return true;
    }
    else
      return false;
  }
}

function checkErrore(errore)
{
  if(! isEmpty(errore))
  {
    alert('An error occurred');
  }
}

function getMaxValueOfArray(array)
{
	var len = array.length;
	var maxValue = 0;
	
	for (var i=0; i < len; i++)
	{
		if(array[i] > maxValue)
			maxValue = array[i]
	}
	
	return maxValue;
}



// CONTROLLO DELLE MANIFESTAZIOI SELEZIONATE START

var numeroCampionati = 0;
var numeroCampionatiSelezionati = 0;


function checkAll(formDati, codiceSport)
{
	which = 'check'+codiceSport
	if (document.getElementById(which).value==0) 
	{
		document.getElementById(which).value=1;
		checkAll_1(formDati, codiceSport)
	}
	else 
	{
		document.getElementById(which).value=0;
		unCheckAll(formDati, codiceSport)
	}
}


function checkAll_1(formDati, codiceSport)
{ 
	for(i=0 ; i < formDati.m.length; i++)
	{
		if (formDati.m[i].id == codiceSport)
		{
			formDati.m[i].checked = true; 
			numeroCampionatiSelezionati++;
			}
	}  
}
	
	
	
function unCheckAll(formDati, codiceSport)
{
	 for(i=0 ; i < formDati.m.length; i++)
		{
			if (formDati.m[i].id == codiceSport)
			{
				formDati.m[i].checked = false; 
				numeroCampionatiSelezionati++;
				}
		}  
}


function unCheckFull(formDati)
{
	 for(i=0 ; i < formDati.m.length; i++)
		{
			formDati.m[i].checked = false; 
			numeroCampionatiSelezionati++;
		}  
}

function checkFull(formDati)
{
	 for(i=0 ; i < formDati.m.length; i++)
		{
			formDati.m[i].checked = true; 
			numeroCampionatiSelezionati++;
		}  
}
	

function contaCampionatiSelezionati(oggetto) {
  if(oggetto.checked)
    numeroCampionatiSelezionati++;
  else
    numeroCampionatiSelezionati--;
}