/************************************************************/
/************************************************************/
function controllaNuovaAtleta()
{
	reTrim=/\s+$|^\s+/g;
	var squadra = document.nat.squadra.options[document.nat.squadra.selectedIndex].value;
	var nome = document.nat.nome.value.replace(reTrim,"");
	var cognome = document.nat.cognome.value.replace(reTrim,"");
	//var giorno = document.nat.giorno.options[document.nat.giorno.selectedIndex].value;
	//var mese = document.nat.mese.options[document.nat.mese.selectedIndex].value;
	//var anno = document.nat.annoN.options[document.nat.annoN.selectedIndex].value;
	var ruolo = document.nat.ruolo.options[document.nat.ruolo.selectedIndex].value;
	//var altezza = document.nat.altezza.value.replace(reTrim,"");
	//var file = document.nat.upfile.value;


	if ((squadra == "") || (squadra == "undefined")) {
           alert("La squadra e' obbligatoria.");
           document.nat.squadra.focus();
           return false;
        }
	if ((nome == "") || (nome == "undefined")) {
           alert("Il nome e' obbligatorio.");
           document.nat.nome.focus();
           return false;
        }
	if ((cognome == "") || (cognome == "undefined")) {
           alert("Il cognome e' obbligatorio.");
           document.nat.cognome.focus();
           return false;
        }
	/*if ((giorno == "") || (giorno == "undefined")) {
           alert("Il giorno di nascita e' obbligatorio.");
           document.nat.giorno.focus();
           return false;
        }
	if ((mese == "") || (mese == "undefined")) {
           alert("Il mese di nascita e' obbligatorio.");
           document.nat.mese.focus();
           return false;
        }
	if ((anno == "") || (anno == "undefined")) {
           alert("L'anno di nascita e' obbligatorio.");
           document.nat.annoN.focus();
           return false;
        }
	var data=giorno+'/'+mese+'/'+anno;
	//alert(data);
	if(!verif_date(data))
	{
	   alert("Attenzione la data inserita non è valida \n Controlla la data di nascita.");
           document.nat.giorno.focus();
           return false;
	}*/
	if ((ruolo == "") || (ruolo == "undefined")) {
           alert("Il ruolo e' obbligatorio.");
           document.nat.ruolo.focus();
           return false;
        }
	/*if((altezza == "") || (altezza == "undefined")) {
           alert("L'altezza e' obbligatoria.");
           document.nat.altezza.focus();
           return false;
        }
	if (isNaN(altezza) || (altezza.length<3) || (altezza.length>3))
	{
	   alert("L'altezza deve essere un numero a 3 cifre.");
           document.nat.altezza.focus();
           return false;
	} 
	if(!check_extension_img(file) && !((file == "") || (file == "undefined")) )
	{
	   alert("Il file devessere una immagine\n(gif , jpg , jpeg , bmp , png)");
           document.nat.uploadfile.focus();
           return false;
	}*/

	
	//document.nat.action = "elabora_dati.asp";
        document.nat.submit();
	
}

/************************************************************/
/************************************************************/

function conferma(messaggio)
{
  return confirm(messaggio);
} 

/************************************************************/
/************************************************************/

function isset(variable)
{
    return (typeof(variable) != 'undefined');
}

/************************************************************/
/************************************************************/
function controllaNuovaNews()
{
	reTrim=/\s+$|^\s+/g;
	var titolo = document.nat.titolo.value.replace(reTrim,"");
	if(isset(document.nat.upfile))
	{
		var file = document.nat.upfile.value;
	}
	else
	{
		var file = document.nat.immagine.src;
	}
	if(isset(document.nat.upallegato))
	{
		var allegato = document.nat.upallegato.value;
	}
	var testo = document.nat.testo.value.replace(reTrim,"");

	
	if ((titolo == "") || (titolo == "undefined")) {
           alert("Il titolo della notizia e' obbligatoria.");
           document.nat.titolo.focus();
           return false;
        }

	if(isset(document.nat.upfile))
	{
		if(!check_extension_img(file) && !((file == "") || (file == "undefined")) )
		{
			alert("Il file immagine deve avere le seguenti estensioni\n(gif , jpg , jpeg , bmp , png)");
			document.nat.upfile.focus();
			return false;
		}
	}
	if(isset(document.nat.upallegato))
	{
		if(!check_extension_allegato(allegato) && !((allegato == "") || (allegato == "undefined")) )
		{
			alert("Il file allegato deve avere le seguenti estensioni\n(doc , pdf)");
			document.nat.upallegato.focus();
			return false;
		}
	}
	if ((testo == "") || (testo == "undefined")) {
           alert("Il testo della notizia e' obbligatorio.");
           document.nat.testo.focus();
           return false;
    }
	document.nat.submit();
}

/************************************************************/
/************************************************************/
function controllaNuovoEvento()
{
	reTrim=/\s+$|^\s+/g;
	var titolo = document.nat.titolo.value.replace(reTrim,"");
	if(isset(document.nat.upfile))
	{
		var file = document.nat.upfile.value;
	}
	else
	{
		var file = document.nat.immagine.src;
	}
	if(isset(document.nat.upallegato))
	{
		var allegato = document.nat.upallegato.value;
	}
	else
	{
		//var allegato = document.nat.immagine.src;
	}
	var testo = document.nat.testo.value.replace(reTrim,"");

	
	if ((titolo == "") || (titolo == "undefined")) {
           alert("Il titolo della notizia e' obbligatoria.");
           document.nat.titolo.focus();
           return false;
        }

	if(isset(document.nat.upfile))
	{
		if(!check_extension_img(file) && !((file == "") || (file == "undefined")) )
		{
			alert("Il file immagine deve avere le seguenti estensioni\n(gif , jpg , jpeg , bmp , png)");
			document.nat.upfile.focus();
			return false;
		}
	}
	if(isset(document.nat.upallegato))
	{
		if(!check_extension_allegato(allegato) && !((allegato == "") || (allegato == "undefined")) )
		{
			alert("Il file allegato deve avere le seguenti estensioni\n(doc , pdf)");
			document.nat.upallegato.focus();
			return false;
		}
	}
	if ((testo == "") || (testo == "undefined")) {
           alert("Il testo della notizia e' obbligatorio.");
           document.nat.testo.focus();
           return false;
    }
	document.nat.submit();
}


/************************************************************/
/************************************************************/
function intestazione()
{
var percorso="http://www.mugellovolley.it/FLASH/";
var mygallery=new fadeSlideShow({
	wrapperid: "fadeshow1", //ID o DIV
	dimensions: [540, 265], 	
	imagearray: [
		[percorso+"corso-ronta.jpg"],
		[percorso+"corso-vicchio.jpg"],
		[percorso+"IMG_8387.jpg"],
		[percorso+"IMG_8846.jpg"],
		[percorso+"IMG_9135.jpg"]
	],
	displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
	persist: false, 
	fadeduration: 3000,
	descreveal: "",
	togglerid: ""
})

var mygallery=new fadeSlideShow({
	wrapperid: "fadeshow1", //ID o DIV
	dimensions: [540, 265], 	
	imagearray: [
		[percorso+"corso-ronta.jpg"],
		[percorso+"corso-vicchio.jpg"],
		[percorso+"IMG_8387.jpg"],
		[percorso+"IMG_8846.jpg"],
		[percorso+"IMG_9135.jpg"]
	],
	displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
	persist: false,
	fadeduration: 500,
	descreveal: "always",
	togglerid: ""
})
}


/************************************************************/
/************************************************************/

function check_extension_img(filename,submitId) {
	var hash = {
  		'.jpg'  : 1,
  		'.jpeg' : 1,
		'.gif' : 1,
		'.bmp' : 1,
		'.png' : 1,
		'.JPG'  : 1,
  		'.JPEG' : 1,
		'.GIF' : 1,
		'.BMP' : 1,
		'.PNG' : 1
	};

      var re = /\..+$/;
      var ext = filename.match(re);
      var submitEl = document.getElementById(submitId);
      if (hash[ext]) {
        return true;
      } else {

        return false;
      }
}

/************************************************************/
/************************************************************/


function check_extension_allegato(filename,submitId) {
	var hash = {
  		'.doc'  : 1,
  		'.docx' : 1,
		'.pdf' : 1,
		'.DOC' : 1,
		'.DOCX' : 1,
		'.PDF'  : 1
	};

      var re = /\..+$/;
      var ext = filename.match(re);
      var submitEl = document.getElementById(submitId);
      if (hash[ext]) {
        return true;
      } else {
        return false;
      }
}

/************************************************************/
/************************************************************/

function verif_date(input)
{
	var regex = new RegExp("[/-]");
	var date = input.split(regex);
	var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
	var result = true;

	if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
		nbJours['2'] = 29;

	if( isNaN(date['2']) )
		result=false;

	if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
		result=false;

	if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
	result=false;

	return result;
}


/************************************************************/
/************************************************************/

function seleziona_select(nomesel,testo)
{
	var idx = document.getElementById(nomesel);

	for(var k=0;k<idx.options.length;k++)
	{
    		if(idx.options[k].value==testo)
     		{
      			idx.selectedIndex=k;
      			break;
    		}
  	}
}

/************************************************************/
/*************** INIZIO DIV A SCOMPARSA**********************/
/************************************************************/
/************************************************************/

//Animated Collapsible DIV- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated June 27th, 07'. Added ability for a DIV to be initially expanded.

var uniquepageid=window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, "") //get current page path and name, used to uniquely identify this page for persistence feature

function animatedcollapse(divId, animatetime, persistexpand, initstate){
	this.divId=divId
	this.divObj=document.getElementById(divId)
	this.divObj.style.overflow="hidden"
	this.timelength=animatetime
	this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
	this.isExpanded=animatedcollapse.getCookie(uniquepageid+"-"+divId) //"yes" or "no", based on cookie value
	this.contentheight=parseInt(this.divObj.style.height)
	var thisobj=this
	if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
		animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
		if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
			this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
	}
	else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
	if (persistexpand)
		animatedcollapse.dotask(window, function(){animatedcollapse.setCookie(uniquepageid+"-"+thisobj.divId, thisobj.isExpanded)}, "unload")
}

animatedcollapse.prototype._getheight=function(persistexpand){
	this.contentheight=this.divObj.offsetHeight
	if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //collapse content
		this.divObj.style.visibility="visible"
	}
	else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
		this.divObj.style.height=this.contentheight+"px"
}


animatedcollapse.prototype._slideengine=function(direction){
	var elapsed=new Date().getTime()-this.startTime //get time animation has run
	var thisobj=this
	if (elapsed<this.timelength){ //if time run is less than specified length
		var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
	this.divObj.style.height=distancepercent * this.contentheight +"px"
	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
	}
	else{ //if animation finished
		this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
		this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
		this.runtimer=null
	}
}


animatedcollapse.prototype.slidedown=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine("down")
		}
	}
}

animatedcollapse.prototype.slideup=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
			this.startTime=new Date().getTime()
			this._slideengine("up")
		}
	}
}

animatedcollapse.prototype.slideit=function(){
	if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
		alert("Please wait until document has fully loaded then click again")
	else if (parseInt(this.divObj.style.height)==0)
		this.slidedown()
	else if (parseInt(this.divObj.style.height)==this.contentheight)
		this.slideup()
}

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------

animatedcollapse.curveincrement=function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}


animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

animatedcollapse.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

animatedcollapse.setCookie=function(name, value, days){
	if (typeof days!="undefined"){ //if set persistent cookie
		var expireDate = new Date()
		var expstring=expireDate.setDate(expireDate.getDate()+days)
		document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()
	}
	else //else if this is a session only cookie
		document.cookie = name+"="+value
}



/************************************************************/
/*************** FINE DIV A SCOMPARSA************************/
/************************************************************/
/************************************************************/

function createRequestObject() { 
    var ro; 
    var browser = navigator.appName; 
    if(browser == "Microsoft Internet Explorer"){ 
        ro = new ActiveXObject("Microsoft.XMLHTTP"); 
    }else{ 
        ro = new XMLHttpRequest(); 
    } 
    return ro; 
} 
  
var http = createRequestObject(); 

/************************************************************/
/************<++++++++++++++*** AJAX ************************/
/************************************************************/
/************************************************************/
  
function delFile(action,tipo) { 
//cancella_img.php?name=immagine&id=<?php echo $notizia['id'] ?>&dir=immagini/rassegna/&table=<?php echo $_CONFIG['table_rassegna'] ?>&pagina=form-rassegna.php"
	var conf= confirm('Sei sicuro di voler cancellare questo file?');
	if(conf)
	{
		if(tipo=='immagine')
		{
			http.open('get', 'http://www.mugellovolley.it/cancella_file.php?'+action); 
			//http.open('get', 'http://127.0.0.1/cancella_file.php?'+action); 
			http.onreadystatechange = sendDelFileImg; 
		}
		else if(tipo=='allegato')
		{
		http.open('get', 'http://www.mugellovolley.it/cancella_file.php?'+action); 
			//http.open('get', 'http://127.0.0.1/cancella_file.php?'+action); 
			http.onreadystatechange = sendDelFileAll; 
		}

		http.send(null); 
	}
} 
  
function sendDelFileImg() { 
    if(http.readyState == 4){ 
        var response = http.responseText; 
        var update = new Array(); 
  
        if(response.indexOf('|' != -1)) { 
            //update = response.split('|');
				
			document.getElementById('formimg').innerHTML = '<input type="file" name="upfile" id="upfile">'; 
            document.getElementById('messimg').innerHTML = response; 
        } 
    } 
}

function sendDelFileAll() { 
    if(http.readyState == 4){ 
        var response = http.responseText; 
        var update = new Array(); 
		//alert('response allegato '+response);
  
        if(response.indexOf('|' != -1)) { 
            //update = response.split('|');
				
			document.getElementById('formall').innerHTML = ' <input type="file" name="upallegato" id="upallegato">'; 
            document.getElementById('messall').innerHTML = response; 
        } 
    } 
}
/******** AJAX**********/
 
//var http = createRequestObject();
var sito='http://www.mugellovolley.it/'
 
function primapagina(action) {
	
  http.open('get', 'http://www.mugellovolley.it/prima.php?'+action);  
  http.onreadystatechange = prova; 
  http.send(null);
}
 
function prova() {
  if(http.readyState == 4){
    var response = http.responseText;
    var update = new Array();
	alert("Operazione eseguita con successo");
  }
}

