function ajaxUpdater(id,url,form1) {  
	if(form1==""){
		new Ajax.Updater( id, url, { method: 'post',
		asynchronous: false,
		evalScripts: true} );
	}else{
		new Ajax.Updater( id, url, { method: 'post',
		evalScripts: true,
		asynchronous: false,
		parameters: $(form1).serialize() } );	
	}	
}  
	
function menuExec(id,url,form){
	ajaxUpdater(id,url,form);
	$('error').innerHTML='';
	$('mainRightTop').innerHTML='';
	$('mainRightBottom').innerHTML='';
}	

function showAllMenu(){
	$('slideDiv6').style.height="370px";
	$('associazione').style.display="";
	$('comitati').style.display="";
	$('atleti').style.display="";
	$('news').style.display="";
	$('news_comitati').style.display="";
	$('download_comitati').style.display="";
	$('utenti').style.display="";
	$('classifiche').style.display="";
	$('logins').style.display="";
	$('download').style.display="";
	$('scrollbar').style.display="";
	$('mailinglist').style.display="";
	$('stampa_tessere').style.display="";
	$('file_hosting').style.display="";
	$('forum').style.display="";
	$('photo').style.display="";
}

function showComitato(){
	$('slideDiv6').style.height="180px";
	$('associazione').style.display="";	
	$('atleti').style.display="";	
	$('news_comitati').style.display="";
	$('download_comitati').style.display="";	
	$('classifiche').style.display="";		
	$('photo').style.display="";
}

function showAssociazione(){
	$('slideDiv6').style.height="100px";
	$('associazione').style.display="";	
	$('atleti').style.display="";	
}
function showAtleta(){
	$('slideDiv6').style.height="100px";	
	//$('forum').style.display="";
}

function hideAllMenu(){

	$('slideDiv6').style.height="1px";
	$('associazione').style.display="none";
	$('comitati').style.display="none";
	$('atleti').style.display="none";
	$('news').style.display="none";
	$('news_comitati').style.display="none";
	$('download_comitati').style.display="none";
	$('utenti').style.display="none";
	$('classifiche').style.display="none";
	$('logins').style.display="none";
	$('download').style.display="none";
	$('scrollbar').style.display="none";
	$('mailinglist').style.display="none";
	$('stampa_tessere').style.display="none";
	$('file_hosting').style.display="none";
	$('forum').style.display="none";
	$('photo').style.display="none";
}

function poptastic(url){
	$('status').value="";
	var newwindow=window.open(url,'Carica_File','height=200,width=500');
	if (window.focus) {newwindow.focus()}
}

function poptastic(url){
	if($('status'))
		$('status').value="";
	var newwindow=window.open(url,'Carica_File','height=200,width=500');
	if (window.focus) {newwindow.focus()}
}

window.onfocus=(function(){
	if($('pathFile') && $('id_downloads')){
		
		if($('id_downloads').value=="" && $('status').value==""){
			$('status').value="upload";	
			ajaxUpdater("error","downloads.php?PRG_modo=upload","");			
			
		}
	}
});

function disableForm(form){
	for(i=0;i<$(form).elements.length;i++){
		if($(form).elements[i]){		
			$(form).elements[i].disabled="disabled";		
			$(form).elements[i].style.background="#efefef";	
		}
	}
}


function viewSelectAssociazione(sel){
	if($(sel).options[3].selected){
		$('ass_desc').style.display="";
		$('ass_value').style.display="";
	}else{
		$('ass_desc').style.display="none";
		$('ass_value').style.display="none";
	}

}
function changeSelectUtenti(type){	
	if(type=="amministratore"){
		$('select_associazione').style.display="none";
		$('select_comitato').style.display="none";
		$('select_atleta').style.display="none";
		$('nome_tr').style.display="";
	}else if(type=="comitato"){
		$('select_associazione').style.display="none";
		$('select_comitato').style.display="";
		$('select_atleta').style.display="none";
		$('nome_tr').style.display="none";
	}else if(type=="associazione"){
		$('select_associazione').style.display="";
		$('select_comitato').style.display="none";
		$('select_atleta').style.display="none";
		$('nome_tr').style.display="none";
	}else if(type=="atleta"){
		$('select_associazione').style.display="";
		$('select_comitato').style.display="none";
		$('select_atleta').style.display="";
		$('nome_tr').style.display="none";
	}
}

function removeAllOption(select){
	
	 for(i=0;i<=$(select).options.length;i++){
		$(select).remove(0);
	 }
}

function addOption(id,testo,valore,selected){

	var select = $(id);
	select.options[select.options.length] = new Option(testo, valore, selected);
	if (selected) select.options[select.options.length-1].selected = true;

}

function calcEta(nascita){
	
	var app=$(nascita).value.split('/');
	var anno=app[2];
	var mese=app[1];
	var giorno=app[0];
	
	var data = new Date();
	var oggi_giorno=data.getDate();
	var oggi_mese=data.getMonth() + 1;
	var oggi_anno=data.getFullYear();
	
	var eta=oggi_anno-anno;
	if(oggi_mese<mese){
		eta--;
	}
	
	if (oggi_mese == mese) {
		if (oggi_giorno < giorno) {
			eta--;
		}
	}
	return eta;
}

function checkMinore(nascita,tutore){
	var eta=calcEta(nascita);
	if(eta<18){
		$(tutore).style.display="";
	}else{
		$(tutore).style.display="none";
	}

}

var speed=80;       // speed of scroller
var step=3;          // smoothness of movement

var x, scroll, divW, sText="";

function startScroller(){
  if($('tag')){
	  document.getElementById('tag').style.whiteSpace='nowrap';
	  var p=document.createElement('P');
	  p.id='testP';
	  p.style.fontSize='25%'; //fix for mozilla. multiply by 4 before using
	  x-=step;
	  if (document.getElementById('tag').className) p.className=document.getElementById('tag').className;
	  p.appendChild(document.createTextNode(sText));
	  document.body.appendChild(p);
	  pw=p.offsetWidth;
	  document.body.removeChild(p);
	  if (x<(pw*4)*-1-200){x=divW;}
	  document.getElementById('tag').style.left=x+'px';
	  scroll=setTimeout('startScroller()',speed);
  }
}

function initScroller(){
  if (document.getElementById && document.createElement && document.body.appendChild) {
    
	divW=document.getElementById('scroller').offsetWidth;
	x=divW;
	document.getElementById('tag').style.position='relative';
	document.getElementById('tag').style.left=divW+'px';
	var ss=document.getElementById('tag').childNodes;
	for (i=0;i<ss.length;i++) {sText+=ss[i].nodeValue+" ";}	
    scroll=setTimeout('startScroller()',speed);
  }
}

function validateForm(form){

	for(i=0;i<$(form).elements.length;i++){
		if($(form).elements[i].id && $(form).elements[i].id.indexOf("*")!=-1){
			if($(form).elements[i].value==""|| $(form).elements[i].value=="0"){
				$(form).elements[i].style.borderColor="#C1001F";
				
			}else{
				$(form).elements[i].style.borderColor="";
			}		
		}else{
			$(form).elements[i].style.borderColor="";
		}	
	}
}