function ReturnPressed(evento){
//	alert(typeof(window.event));
	if(typeof(window.event) == "object"){
		key = window.event.keyCode;
	} else {
		if(evento.which != 0){
			key=evento.which;
		} else {
			key = evento.keyCode;
		}
	}

	if (key==13){
		//ho premuto invio
		return true;
	} else {
		return false;
	}
}



/********************************************************
				GESTIONE 	Eventi						*/
var Dati=new Array();//matrice contente le organizzazioni selezioante
var IDRequest_Search_Events='';	//IDUnivoco della richiesta effettuata tramite la funzione "setTimeout()"

function SelectDeselctAllCheck(NameCheck){
		//alert(NameCheck);
	//Funzione che seleziona o deselziona il gruppo di checkbox
	var Check=prendiElementoDaId(NameCheck);	//Estrazione dell'oggetto check globale del gruppo
	var TotalCheck=parseInt(prendiElementoDaId(NameCheck + '_Total_Child').value);	//Estrazione del numero totale dele check box associate al gruppo
	for (I=1;I<=TotalCheck;I++){ //scortto tutte le check relative al gruppo
		//se è stata avviata la ricehista di filtraggio degli eventi per le organizzazioni selezioante la interrompo perchè devo riaggiornare il filtro
		//if (IDRequest_Search_Events!='') clearTimeout(IDRequest_Search_Events);
		//Se lo stato della cehck corrente è diversa da quella dello stato globale simulo il click su di essa altrimenti avvio la richiesta di filtraggio
		if (prendiElementoDaId(NameCheck + '_' + I).checked!=Check.checked){
			prendiElementoDaId(NameCheck + '_' + I).click();
		} else {
			//IDRequest_Search_Events=setTimeout('FilterEvents(\'Filtered_list_Events\');',1000);
		}
		
	}
}

function SelectDeselctAllCheck_onLoad(NameCheck){
		//alert(NameCheck);
	//Funzione che seleziona o deselziona il gruppo di checkbox
	var Check=prendiElementoDaId(NameCheck);	//Estrazione dell'oggetto check globale del gruppo
	Check.click();
}


function SetArrayValue(Father_Key,Child_Key, ObjCheck){
	//Gestione dell'array per il filtraggio degli eventi
	
	//Se non esiste nel vettore la nazione corrente creo l'elemento
	if(typeof(Dati[Father_Key])=='undefined') Dati[Father_Key]=new Array();
		
	if (ObjCheck.checked){
		//Se l'elemento è selezionato inserisco il suo valore
		Dati[Father_Key][Child_Key]=ObjCheck.value;		
	} else {
		//Se l'elemento non è selezionato importo il contenuto a -1 ovvero non selezionato
		Dati[Father_Key][Child_Key]=-1;
	}
	//avvio la richiesta di filtraggio dati
	//IDRequest_Search_Events=setTimeout('FilterEvents(\'Filtered_list_Events\');',1000);
}

function FilterEvents_GetIDSelected(){
	var strTesto='';
	var strVirgola='';
	for (key in Dati)  {
		for (key1 in Dati[key])  {
			if (parseInt(Dati[key][key1])>0) {
				strTesto=strTesto + strVirgola + Dati[key][key1];
				strVirgola=',';
			}
		}
	}
	//alert(strTesto);
	return strTesto;
}

function FilterEvents(elemento, day, month, year, ActionView){
	var DatasToSend='IDSelected=' + FilterEvents_GetIDSelected() + '&ActionView=' + ActionView  + '&day=' + day + '&month=' + month + '&year=' + year;
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	    //alert("Modules/Ajax/events-Filtered-list.php?rand=" + escape(Math.random()));
		ajax.open("POST", "Modules/Ajax/events-Filtered-list.php?rand=" + escape(Math.random()), true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", DatasToSend.length);

	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      	    
        if(ajax.readyState === readyState.COMPLETATO) {
				
          if (statusText[ajax.status] === "OK") {
			   prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			   ahahEvalJS(elemento);
		  } else {
			  //alert(elemento);
			  prendiElementoDaId(elemento).innerHTML ='Load Error! ' + statusText[ajax.status];
          }
        }
      }
	  
	  ajax.send(DatasToSend);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser di navigazione non ideneo per questo sito!");
	}
}

function GetCalendar(form, Url){
	//get calendar for export to .ICS, .VCS
	prendiElementoDaId(form).action=Url;
	prendiElementoDaId(form).submit();
}

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

function OnLoad(pagina){
	//if (pagina.indexOf("members.php")>=0){
		load();
	//}
}

function open_close(id, oo, cc) {
	ff = document.getElementById(id);
	
	if( ff.style.display != "none" ) {
		ff.style.display = "none";
		return oo;
	}
	else {
		ff.style.display = "";
		return cc;
	}
}

function send_form(form,pagina){
	message=valida_campi(form);
	if (message=="ok"){
        var xmlHttpReq = false;
        var self = this;
        if (window.XMLHttpRequest) {
          self.xmlHttpReq = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	    self.xmlHttpReq.open('POST',  pagina + "?mode=update", true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  //alert("ok");
		  prendiElementoDaId("Colonna_Centrale").innerHTML =self.xmlHttpReq.responseText;
		  //alert(form.usrid.value + " " + form.pwd.value);		  
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
	  //alert(collect_datas(form));
      self.xmlHttpReq.send(collect_datas(form));

	} else {
		alert("WARNING!\nThe form present the following problems:\n\n" + message +"\n\nPlease correct the form before send it.");
	}
}

function send_country(form,pagina){
	message=valida_campi(form);
	if (message=="ok"){
        var xmlHttpReq = false;
        var self = this;
        if (window.XMLHttpRequest) {
          self.xmlHttpReq = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	    self.xmlHttpReq.open('POST',  pagina , true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  //alert("ok");
		  prendiElementoDaId("Colonna_Centrale").innerHTML =self.xmlHttpReq.responseText;
		  //alert(form.usrid.value + " " + form.pwd.value);		  
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
	  //alert(collect_datas(form));
      self.xmlHttpReq.send(collect_datas(form));

	} else {
		alert("WARNING!\nThe form present the following problems:\n\n" + message +"\n\nPlease correct the form before send it.");
	}
}
function scrivi_padre(elemento,contenuto){
	prendiElementoDaId(elemento).innerHTML = contenuto;
}

function Fill_e_Download(){
	var error="";
	var name_organization = prendiElementoDaId("name_organization").value;	
	var address = prendiElementoDaId("address").value;
	var telephone = prendiElementoDaId("telephone").value;	
	var fax = prendiElementoDaId("fax").value;
	var mail_address = prendiElementoDaId("mail_address").value;	
	var web_address = prendiElementoDaId("web_address").value;
	var organization_mission = prendiElementoDaId("organization_mission").value;	
	var ejn_think = prendiElementoDaId("ejn_think").value;
	var ejn_benefit = prendiElementoDaId("ejn_benefit").value;	
    //alert(usrid + " " + pwd);
    if (name_organization.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Name Organization Missing!";
	}
    if (address.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Address Organization Missing!";
	}
    if (telephone.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Telephone Organization Missing!";
	}
    if (mail_address.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Mail Organization (or Contact Person) Missing!";
	}
    if (organization_mission.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Organization Mission Missing!";
	}
    if (ejn_think.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Please fill what you think you can give to the EJN as a member!";
	}
    if (ejn_benefit.length<2){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- Please say why you think your organisation will benefit from membership of EJN!";
	}
	if (organization_mission.length>2500 || ejn_think.length>2500 || ejn_benefit.length>2500){
		if (error!=""){
			  error=error + "\n";
		}
		error=error + "- One (or More) description fields Too Long!";
	}
	if (error==""){
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
      self.xmlHttpReq.open('POST', 'Modules/Ajax/about-ejn.php?action=fill_send&lang=eng&sid=2&rand=' + escape(Math.random()), true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  var sVet=self.xmlHttpReq.responseText.split("$$");
		  prendiElementoDaId("Colonna_Centrale_About-EJN").innerHTML =sVet[1];
		  window.location.href=(sVet[0]);
		  //alert()
        } else {
		  prendiElementoDaId("Colonna_Centrale_About-EJN").innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		}
      }	
      self.xmlHttpReq.send("name_organization=" + name_organization +"&address=" + address + "&telephone=" + telephone + "&fax=" + fax + "&mail_address=" + mail_address + "&web_address=" + web_address +"&organization_mission=" + organization_mission + "&ejn_think=" + ejn_think +"&ejn_benefit=" + ejn_benefit);
	} else {
	  alert("WARNING!\nThe form present the following problems:\n\n" + error +"\n\nPlease correct the form before send it.");
    }

}

function send_form_WA(form,pagina,mode){
	message=valida_campi(form);
	if (message=="ok"){
        var xmlHttpReq = false;
        var self = this;
        if (window.XMLHttpRequest) {
          self.xmlHttpReq = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
		//alert(pagina);
	    self.xmlHttpReq.open('POST',  pagina + "?mode=" + mode, true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  //alert("ok");
		  prendiElementoDaId("Colonna_Centrale").innerHTML =self.xmlHttpReq.responseText;
		  //alert(form.usrid.value + " " + form.pwd.value);		  
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send(collect_datas(form));

	} else {
		alert("WARNING!\nThe form present the following problems:\n\n" + message +"\n\nPlease correct the form before send it.");
	}
}

function send_search(sezione){
	//alert("ciao");
	if (prendiElementoDaId("q").value.length<2){
		alert("WARNING!\nYou Must insert at least two carachters.");
	} else {
	  load_admins('Colonna_Centrale',sezione,'search&q=' + prendiElementoDaId("q").value,'no')
	}
}

function valida_campi(form){
	errors="";
	switch (form){
		case "My_Organitazion":
		  if (document.forms[form].Name.value.length>1){
			  errors="ok";
		  } else {
			  errors="- You must fill the Name of the Organization al least.";
		  }
		  break;
		case "Change_My_Password":
		  if (document.forms[form].Username.value.length<1){
			  errors="- Username Missing!";			  
		  }
		  if (document.forms[form].Old_Password.value.length<1){
			  if (errors.length>0){
			    errors=errors + "\n";
			  }
			  errors=errors + "- Old Password missing.";			  
		  }
		  if (document.forms[form].New_Password.value.length<8){
			  if (errors.length>0){
			    errors=errors + "\n";
			  }
			  errors=errors + "- New Password must be at least 8 carachters.";			  
		  }
		  if (document.forms[form].Repeat_New_Password.value.length<8){
			  if (errors.length>0){
			    errors=errors + "\n";
			  }
			  errors=errors + "- Repeat New Password must be at least 8 carachters.";			  
		  }
		  if (document.forms[form].New_Password.value.length>1 && document.forms[form].Repeat_New_Password.value.length>1){
			  if (document.forms[form].New_Password.value!=document.forms[form].Repeat_New_Password.value){
			    if (errors.length>0){
			      errors=errors + "\n";
			    }
		        errors=errors + "- New Password and Repeat New Password fields must be equal.";
			  }
		  }
		  break;
		case "My_Organitazion_Admin":
		  if (document.forms[form].Name.value.length<1 &&document.forms[form].First_name.value.length<1){
			  errors="- You must fill at least one field between Name or Firs Name.";
		  } else {
			  errors="ok";
		  }
		  break;
		case "My_Map":
		  if (document.forms[form].Grades_Latitude.value.length<1){
			  document.forms[form].Grades_Latitude.value=0;	  
		  } else {
		    miaStringa = document.forms[form].Grades_Latitude.value;
            if (miaStringa.indexOf(",")>(-1)) {
			  errors="- Numeric separator invalid!\nYou must use \".\" to express, for example, Langitude Grades 19.5";
			}
		  }
		  if (document.forms[form].Minutes_Latitude.value.length<1){
			  document.forms[form].Minutes_Latitude.value=0;	  
		  } else {
		    miaStringa = document.forms[form].Minutes_Latitude.value;
            if (miaStringa.indexOf(",")>(-1)) {
			  errors="- Numeric separator invalid!\nYou must use \".\" to express, for example, Langitude Grades 19.5";
			}
		  }
		  if (document.forms[form].Seconds_Latitude.value.length<1){
			  document.forms[form].Seconds_Latitude.value=0;	  
		  } else {
		    miaStringa = document.forms[form].Seconds_Latitude.value;
            if (miaStringa.indexOf(",")>(-1)) {
			  errors="- Numeric separator invalid!\nYou must use \".\" to express, for example, Langitude Grades 19.5";
			}
		  }
		  if (document.forms[form].Grades_Longitude.value.length<1){
			  document.forms[form].Grades_Longitude.value=0;	  
		  } else {
		    miaStringa = document.forms[form].Grades_Longitude.value;
            if (miaStringa.indexOf(",")>(-1)) {
			  errors="- Numeric separator invalid!\nYou must use \".\" to express, for example, Langitude Grades 19.5";
			}
		  }
		  if (document.forms[form].Minutes_Longitude.value.length<1){
			  document.forms[form].Minutes_Longitude.value=0;	  
		  } else {
		    miaStringa = document.forms[form].Minutes_Longitude.value;
            if (miaStringa.indexOf(",")>(-1)) {
			  errors="- Numeric separator invalid!\nYou must use \".\" to express, for example, Langitude Grades 19.5";
			}
		  }
		  if (document.forms[form].Seconds_Longitude.value.length<1){
			  document.forms[form].Seconds_Longitude.value=0;	  
		  } else {
		    miaStringa = document.forms[form].Seconds_Longitude.value;
            if (miaStringa.indexOf(",")>(-1)) {
			  errors="- Numeric separator invalid!\nYou must use \".\" to express, for example, Langitude Grades 19.5";
			}
		  }
		  break;
		case "add_country":
		  if (document.forms[form].Country.value.length<1){
			  errors=errors + "- New Country Name missing.";			  
		  }
		  break;
		case "My_Events_News_Detail":
		if (document.forms[form].id_activity.value<1){
			  errors="- Select activity.";
			  errors= errors + "\n   (To select an activity you must have any pop up blocker disabled)."; 
		  }
		  if (document.forms[form].id_band.value<1){
			  errors= errors + "\n- Select Band.";
			  errors= errors + "\n   (To select a band you must have any pop up blocker disabled)."; 
		  }
		  if (document.forms[form].date.value.length<8){
			  errors = errors + "\n- Select a valid date.";
		  }
		  if (document.forms[form].ticket_price.value.length<1){
			  document.forms[form].ticket_price.value=0;
		  }
		  break;
		case "My_Events_News_Detail2":
		  if (document.forms[form].title.value.length<1){
			  errors="- Insert a title.";
		  }
		  if (document.forms[form].date.value.length<8){
			  errors = errors + "\n- Select a valid date.";
		  }
		  break;
		default:
		  return "ok";
		  break;
	}
	if (errors==""){
		errors="ok";
	}
	return errors;
}
function collect_datas(form){
	qstr = "";
	//alert("comincio");
	for (iElement = 0; iElement < document.forms[form].elements.length; iElement++){
		if (iElement>0){
		  qstr = qstr + "&";
		}
		//alert(document.forms[form].elements[iElement].type + "\n" + document.forms[form].elements[iElement].name + "\n" + document.forms[form].elements[iElement].value);
		switch (document.forms[form].elements[iElement].type){
	      case 'text':
		  case 'textarea':
		    qstr = qstr + document.forms[form].elements[iElement].name + '=' + document.forms[form].elements[iElement].value;  // NOTARE bene che non viene messo '?' prima della querystrin
			break;
		   case 'checkbox':
		     if(document.forms[form].elements[iElement].checked==true){
			   //alert("Aggiungo: " + document.forms[form].elements[iElement].name + " col valore:" + document.forms[form].elements[iElement].value);
			   qstr = qstr + document.forms[form].elements[iElement].name + '=' + document.forms[form].elements[iElement].value;
			 }
		     break;
		  default:
            qstr = qstr + document.forms[form].elements[iElement].name + '=' + document.forms[form].elements[iElement].value;  // NOTARE bene che non viene messo '?' prima della querystrin
		    break;
		}
	}
	return qstr;
}
function carica_citta(elemento){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  ajax.open("get", "Modules/Ajax/Town.php?id=" + elemento.value + "&rand=" + escape(Math.random()), true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			   prendiElementoDaId('Town').innerHTML =ajax.responseText;
			   
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId('Town').innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId('Town').innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}
}
function accendi_pulsanti_country(stato){
	switch (stato) {
		case "acceso":
		prendiElementoDaId('pulsanti_country').innerHTML ='<a href="#" onClick="Modify_Country(\'add_country\');">new</a> | <a href="#" onClick="Modify_Country(\'edit_country\');">edit</a> | <a href="#" onClick="Modify_Country(\'delete_country\');">delete</a> <!-- | <a href="#" onClick="Modify_Country(\'merge_country\');">merge</a> -->';
		break;
	case "spento":
		prendiElementoDaId('pulsanti_country').innerHTML ='<a href="#" onClick="Modify_Country(\'add_country\');">new</a> | <font color="#666666">edit</font> | <font color="#666666">delete</font> <!--  | <font color="#666666">merge</font> -->';
		break;
	}
}

function accendi_pulsanti_town(stato){
	switch (stato) {
	  case "acceso":
		prendiElementoDaId('pulsanti_town').innerHTML ='<a href="#" onClick="Modify_Country(\'add_town\');">new</a> | <a href="#" onClick="Modify_Country(\'edit_town\');">edit</a> | <a href="#" onClick="Modify_Country(\'delete_town\');">delete</a> <!-- | <a href="#" onClick="Modify_Country(\'merge_town\');">merge</a> -->';
		break;
	  case "spento":
		prendiElementoDaId('pulsanti_town').innerHTML ='<a href="#" onClick="Modify_Country(\'add_town\');">new</a> | <font color="#666666">edit</font> | <font color="#666666">delete</font> <!-- | <font color="#666666">merge</font> -->';
		break;
	  case "completamente_spento":
		prendiElementoDaId('pulsanti_town').innerHTML ='&nbsp;';
		break;
	}
}

function mostra_comandi_citta(elemento){
	//alert(prendiElementoDaId('Town_list').value);
	//alert("Ciaoo");
	if (elemento.value>0){
		accendi_pulsanti_town("acceso")
	} else {
		accendi_pulsanti_town("spento")
	}
}

function carica_citta_edit(elemento){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  if (elemento.value>0){
	    ajax.open("get", "Pages/Admin/Town_Modify.php?id=" + elemento.value + "&rand=" + escape(Math.random()), true);
	    ajax.setRequestHeader("connection", "close");
	    ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			   prendiElementoDaId('Town').innerHTML =ajax.responseText;
			   accendi_pulsanti_country('acceso');
			   accendi_pulsanti_town('spento');
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId('Town').innerHTML = "";
			  
          }
        }
      }
	  ajax.send(null);
	  accendi_pulsanti_town('completamente_spento');
	  prendiElementoDaId('Town').innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
	  prendiElementoDaId('Town').innerHTML ="";
	  accendi_pulsanti_country('spento');
	  accendi_pulsanti_town('completamente_spento');
	}
  } else {
    alert("Browser invalid!");
  }
}

function Modify_Country(azione){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  switch (azione){
		  case "add_country":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Countries').value;
		    break;
		  case "edit_country":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Countries').value;
			break;
		  case "delete_country":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Countries').value;
			break;
		  case "merge_country":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Countries').value;
			break;
		  case "add_town":
		    //alert(prendiElementoDaId('Countries').value);
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Countries').value;
			break;
		  case "edit_town":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Town_list').value;
			break;
		  case "delete_town":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Town_list').value;
			break;
		  case "merge_town":
		    pagina = "Pages/Admin/modify_country_panel.php?action=" + azione + "&id=" + prendiElementoDaId('Town_list').value;
			break;
	  }
	  
	  ajax.open("get", pagina, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			   prendiElementoDaId('Modify_Panel').innerHTML =ajax.responseText;
			   
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId('Modify_Panel').innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId('Modify_Panel').innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}
}
function carica_detail_classic(elemento, pagina, chiamante, ricerca, mode_view, pars){
	//alert(pars);
	//document.page.action="modules.php?musician=" + elemento + "&module=" + chiamante + "&submodule=" + pagina + "&topicid=" + ricerca;
	if (mode_view!=undefined){
	  //alert(mode_view);
	  document.page.action=chiamante + "-" + pagina + "-" + elemento + "-" + mode_view + ".html";
	} else {
	  document.page.action=chiamante + "-" + pagina + "-" + elemento + ".html";
	}
	
	if (pars!=undefined) {
		document.page.pars.value=pars;
	}
	//alert(document.page.query.value);
	
	document.page.submit();
	return false;
}

function carica_detail(elemento, pagina, chiamante, ricerca){
      var xmlHttpReq = false;
      var self = this;
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
      self.xmlHttpReq.open("POST", "Pages/" + pagina +"?musician=" + elemento + "&rand=" + escape(Math.random()), true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			   prendiElementoDaId('Corpo').innerHTML =self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Corpo").innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		}
      }
	  //alert(prendiElementoDaId("num").value);
	  switch (pagina){
		  case "detail_musician.php":
		  case "musicians.php":
		    carica_menu('musicians');
		    break;
		  case "agencies.php":
		  case "detail_agencies.php":
		    carica_menu('agencies');
			break;
		  case "detail_band.php":
		    ripristina_menu();
			break;			
	  };	  
	  self.xmlHttpReq.send("query=" + prendiElementoDaId("query").value + "&num=" + prendiElementoDaId("num").value + "&chiamante=" + chiamante + "&ricerca=" + ricerca);
	  prendiElementoDaId('Corpo').innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
}

function LogIn() {
    var usrid = prendiElementoDaId("usrid").value;	
	var pwd = prendiElementoDaId("pwd").value;
    //alert(usrid + " " + pwd);
    if (prendiElementoDaId("usrid").value.length>2 && prendiElementoDaId("pwd").value.length>2){
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	
      self.xmlHttpReq.open('POST', 'Modules/Do-LogIn.php', true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  //alert("ok");
		  var sVet=self.xmlHttpReq.responseText.split("$$");

		  //alert(sVet[0]);
		  prendiElementoDaId("user_panel").innerHTML =sVet[1];
		  
		  //alert(form.usrid.value + " " + form.pwd.value);
		  if (sVet[0]!="0"){
		    load_personal_commands('personal_commands','show');
		  }
        } else {
		  prendiElementoDaId("user_panel").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send(getquerystring() + "&action=login");
	} else {
	alert("You must fill User ID and Password field before!");
    }
}

function Invite() {
    var usrid = prendiElementoDaId("usrid").value;	
	var pwd = prendiElementoDaId("pwd").value;
	var id_ejn_user = prendiElementoDaId("id_ejn_user").value;
	var azione = prendiElementoDaId("azione").value;
    //alert(usrid + " " + pwd);
    if (prendiElementoDaId("usrid").value.length>2 && prendiElementoDaId("pwd").value.length>2){
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	
      self.xmlHttpReq.open('POST', 'Modules/Invite.php', true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId("Colonna_Centrale").innerHTML =self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send(getquerystring() + "&id_ejn_user="+ id_ejn_user + "&azione="+ azione + "&action=invite");
	} else {
	  alert("You must fill User ID and Password field before!");
    }
}

function cambia_lista(lista){
	load_admins('Colonna_Centrale','News_EJN_Member.php','show&topicid=' + lista.value)
}

function cambia_pagina_admin(num, pagina) {
	      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	
      self.xmlHttpReq.open('POST', 'Pages/Admin/' + pagina +'?search=ok&nums=' + num, true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId("Colonna_Centrale").innerHTML = self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		}
      }	
	  //alert(prendiElementoDaId("topicid").value);
      self.xmlHttpReq.send("where=" + prendiElementoDaId("where").value + "&topicid=" + prendiElementoDaId("topicid").value + "&data=" + prendiElementoDaId("data").value + "&orderby=" + prendiElementoDaId("orderby").value + "&query=" + prendiElementoDaId("query").value);

}

function cambia_pagina_classic(num, pagina, topicid) {
	//document.page.action="modules.php?num=" + num + "&module=" + pagina;
	document.page.action=pagina + ".html";
	//alert(num);
	if (topicid!=undefined){
	  document.page.topicid.value=topicid;
	}
	document.page.num.value=num;
	//alert(document.page.num.value);
	document.page.submit();
	//alert(document.page.query.value);
}

function cambia_pagina(num, pagina) {
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	
      self.xmlHttpReq.open('POST', 'Pages/' + pagina +'?search=ok&num=' + num, true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId("Corpo").innerHTML = self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Corpo").innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		}
      }	
	  //alert(prendiElementoDaId("query").value);
      self.xmlHttpReq.send("search=ok&where=" + prendiElementoDaId("where").value + "&data=" + prendiElementoDaId("data").value + "&orderby=" + prendiElementoDaId("orderby").value + "&query=" + prendiElementoDaId("query").value);
}
function manda_ricerca(num,pagina) {
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	
      self.xmlHttpReq.open('POST', 'Pages/' + pagina +'?search=ok&num=' + num, true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId("Corpo").innerHTML = self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Corpo").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send("where=" + prendiElementoDaId("where_CP").value + "&data=" + prendiElementoDaId("data_CP").value + "&orderby=" + prendiElementoDaId("orderby_CP").value + "&query=" + prendiElementoDaId("query_CP").value);
}
function setPointer(theRow, thePointerColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }

    return true;
} // end of the 'setPointer()' function

function send_forget_password() {
   
    if (prendiElementoDaId("Userid").value.length>2 || prendiElementoDaId("Confirmation_Code").value.length>2){
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
      self.xmlHttpReq.open('POST', 'Pages/forget_password.php?mode=send_confirmation_code', true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId("Corpo").innerHTML =self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Corpo").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send("Userid=" + escape(prendiElementoDaId("Userid").value) + "&Confirmation_Code=" + escape(prendiElementoDaId("Confirmation_Code").value));
	} else {
	  alert("You must fill User ID or Confirmation Code fields before!");
    }
}


function LogOut(mode) {
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	
      self.xmlHttpReq.open('POST', 'Modules/Do-LogOut.php', true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  //alert("ok");
		  prendiElementoDaId("user_panel").innerHTML =self.xmlHttpReq.responseText;
		  prendiElementoDaId("usrid").value = "";
		  prendiElementoDaId("pwd").value = "";
		  if (mode!="strict"){
		    load_personal_commands('personal_commands', 'hide');
		    carica_index('Corpo', 'home');
		  }
        } else {
		  prendiElementoDaId("user_panel").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send("action=logout");
}
function load_personal_commands(elemento,mode){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  ajax.open("get", "Modules/Ajax/Personal_menu.php?mode=" + mode + "&rand=" + escape(Math.random()), true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			   risultato=ajax.responseText;
			   var sVet=risultato.split("$$");
			   //alert(risultato);
			   //alert(sVet[0]);
			   //alert(sVet[1]);
			   prendiElementoDaId(elemento).innerHTML = sVet[1];
			   if (mode=='show'){				   
			     carica_admin('Corpo', sVet[0])
			   }
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="0" height="0">';
	} else {
		alert("Browser invalid!");
	}
}

function getquerystring() {
    qstr = 'usrid=' + escape(prendiElementoDaId("usrid").value) + '&pwd=' + escape(prendiElementoDaId("pwd").value);  // NOTARE bene che non viene messo '?' prima della querystring
    return qstr;
}
function back_invite(colonna,sezione,azione,id_ejn_user) {
	load_admins(colonna,sezione,azione+"&id_ejn_user="+id_ejn_user,"no");
}
function back_invite_and_invite(colonna,sezione,azione,id_ejn_user) {
    var From = prendiElementoDaId("From").value;	
	var To = prendiElementoDaId("To").value;
	var Subject = prendiElementoDaId("Subject").value;
	var Testo = prendiElementoDaId("Testo").value;
      var xmlHttpReq = false;
      var self = this;
      // Xhr per Mozilla/Safari/Ie7
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // per tutte le altre versioni di IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
	  //alert(From + "\n" + To + "\n" + Subject + "\n" + Testo)
      self.xmlHttpReq.open('POST', 'Pages/Admin/Users_viewer.php?mode=modify&page=1&subazione=send_invite&id_ejn_user=' + id_ejn_user, true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId("Colonna_Centrale").innerHTML =self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<div align="right"><img src="images/indicator_snake.gif" width="16" height="16"></div>';
		}
      }	
      self.xmlHttpReq.send("From=" + From +"&To=" + To + "&Subject=" + Subject + "&Testo=" + Testo +"&id_ejn_user="+ id_ejn_user + "&azione="+ azione);

}
function carica_mail_categoria(typology){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  ajax.open("get", "Pages/Admin/carica_mail_categoria.php?typology=" + typology + "&rand=" + escape(Math.random()), true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			   risultato=ajax.responseText;
			   var sVet=risultato.split("$$");
			   //alert(risultato);
			   //alert(sVet[0]);
			   //alert(sVet[1]);
			   //Inserisco Valori sVet[1]
			   prendiElementoDaId("To").value = sVet[0]
			   alert("Done!\nAll mail previously written has been\ndeleted and replaced with " + sVet[1] + " mail found for the choosen category.");
			   prendiElementoDaId("Colonna_Centrale_Mail").innerHTML = "<div align=\"right\">To:<img src=\"images/dot.gif\" width=\"5\" height=\"1\"></div>";
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId("Colonna_Centrale_Mail").innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId("Colonna_Centrale_Mail").innerHTML ='<div align="right"><img src="images/indicator_snake.gif"><img src="images/dot.gif" width="5" height="1"></div>';
	} else {
		alert("Browser invalid!");
	}
}

function Associa_strumento(page,id_ejn_user){
	Instrument=prendiElementoDaId("NewInstrument");
	azioni='modify&page=' + page + '&id_ejn_user=' + id_ejn_user + '&step=instr&actionstep=add&idadd=' + Instrument.value
	//alert(azioni);
	load_admins('Colonna_Centrale','Users_viewer.php',azioni,'no')	
}

function Associa_Musicista(page,id_ejn_user){
	Musician=prendiElementoDaId("NewMusician");
	azioni='modify&page=' + page + '&id_ejn_user=' + id_ejn_user + '&step=mus_band&actionstep=add&idadd=' + Musician.value
	//alert(azioni);
	load_admins('Colonna_Centrale','Users_viewer.php',azioni,'no')	
}
function Associa_Musicista_Agent(page,id_ejn_user){
	Musician=prendiElementoDaId("NewMusician");
	azioni='modify&page=' + page + '&id_ejn_user=' + id_ejn_user + '&step=mus_agent&actionstep=add&idadd=' + Musician.value
	//alert(azioni);
	load_admins('Colonna_Centrale','Users_viewer.php',azioni,'no')	
}
function modifica_utente(colonna,sezione,azione) {
	radio=prendiElementoDaId("user_id");
	if (radio!=null){							 
	  selezionato=0;	 
	  if(document.forms["Users_viewer"].elements["rec"].value>1){
        for ( i = 0 ; i < document.forms["Users_viewer"].elements["rec"].value; i++ ) {	      
		  if (document.forms["Users_viewer"].elements["user_id"][i].checked==true){
		    selezionato=document.forms["Users_viewer"].elements["user_id"][i].value;
			break;
		  }
	    }
	  } else {
	    if (document.forms["Users_viewer"].elements["user_id"].checked==true){
		  selezionato=document.forms["Users_viewer"].elements["user_id"].value;
		}		  
	  }
	  if (selezionato!=0){
	    load_admins(colonna,sezione,azione+"&id_ejn_user="+selezionato,"no");
	    //alert(selezionato);
	  } else {
		  alert("WARNING!\nYou must select an user before!");
	  }
	} else {
	  alert("WARNING!\nYou must select an user before!");
	}	
}
function modifica_events_news(colonna,sezione,azione) {
	radio=prendiElementoDaId("events_id");
	if (radio!=null){							 
	  selezionato=0;	 
	  if(document.forms["My_Events_News"].elements["rec"].value>1){
        for ( i = 0 ; i < document.forms["My_Events_News"].elements["rec"].value; i++ ) {	      
		  if (document.forms["My_Events_News"].elements["events_id"][i].checked==true){
		    selezionato=document.forms["My_Events_News"].elements["events_id"][i].value;
			break;
		  }
	    }
	  } else {
	    if (document.forms["My_Events_News"].elements["events_id"].checked==true){
		  selezionato=document.forms["My_Events_News"].elements["events_id"].value;
		}		  
	  }
	  if (selezionato!=0){
	    load_admins(colonna,sezione,azione+"&id_events="+selezionato,"no");
	    //alert(selezionato);
	  } else {
		  alert("WARNING!\nYou must select an event/news before!");
	  }
	} else {
	  alert("WARNING!\nYou must select an event/news before!");
	}	
}

function modifica_events_news_from_detail(elemento,sezione,azione,id,pars) {
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  //alert(sezione);
	  ajax.open("get", "Pages/Admin/Web_Site_Admin.php?rand=" + escape(Math.random()), true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			   prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			   carica_contenuti(sezione);			
			   //alert(sezione);
			  selezionato=id;	 
			  if (selezionato!=0){
				load_admins_from_detail("Colonna_Centrale",sezione,azione+"&id_events="+selezionato+"&from=detail_news","no",pars);
				//alert(selezionato);
			  } else {
				  alert("WARNING!\nYou must select an event/news before!");
			  }
		  } else {
			  //alert("Impossibile caricare Member List!");
			  prendiElementoDaId(elemento).innerHTML ='Load Error! ' + statusText[ajax.status];
          }
        }
      }
	  ajax.send(null);
	 // prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	  ripristina_menu();
	  carica_control_panel(sezione, 'Pannelo_Controllo');
	} else {
		alert("Browser di navgazione non ideneo per questo sito!");
	}
}


function load_admins_from_detail(elemento,pagina,mode,carica_panel,pars){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;	  
	  query="Pages/Admin/" + pagina + "?mode=" + mode;
	  //alert(query)
	  //alert(query);
	  ajax.open("POST", query, true);
	  //ajax.setRequestHeader("connection", "close");
 	  ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.onreadystatechange = function() {    
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			  ahahEvalJS(elemento);
			  if (carica_panel!="no"){
			    carica_control_panel(pagina, 'Pannelo_Controllo');
			  }
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(pars);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	
}


function ApriPopUp(pagina,target,history,resizable,status,scrollbars,menubar,larghezza,altezza){
	var w = larghezza; 
	var h = altezza; 
	var pw = Math.floor((screen.width-w)/2); 
	var ph = Math.floor((screen.height-h)/2); 
	//alert(pagina);
	pop=window.open("Pages/Admin/scarica.php?file=" + pagina, target, "history=" + history +",resizable=" + resizable + ",status=" + status + ",scrollbars=" + scrollbars + ",menubar=" + menubar + ",width=" + larghezza + ",height=" + altezza + ",top=" + ph + ",left=" + pw);
    pop.focus();
    void(0);
}

function scrivi_dati_e_chiudi(campo_valore,valore_campo,campo_etichetta,etichetta_campo, campo_valore2, valore_campo2, campo_valore3, valore_campo3) {
	opener.prendiElementoDaId(campo_valore).value=valore_campo;
	opener.prendiElementoDaId(campo_etichetta).innerHTML=etichetta_campo;		
	if ((campo_valore2 === undefined ) || (valore_campo2 === undefined)) {
	
	} else {
//		alert(typeof( opener.prendiElementoDaId(campo_valore2)));
		if (typeof(opener.prendiElementoDaId(campo_valore2)) == 'object'){
			//alert(opener.prendiElementoDaId(campo_valore));
			opener.prendiElementoDaId(campo_valore2).innerHTML=valore_campo2;
		}
	}
	if ((campo_valore3 === undefined ) || (valore_campo3 === undefined)) {
	
	} else {
//		alert(typeof( opener.prendiElementoDaId(campo_valore2)));
		if (typeof(opener.prendiElementoDaId(campo_valore3)) == 'object'){
			//alert(opener.prendiElementoDaId(campo_valore));
			opener.prendiElementoDaId(campo_valore3).innerHTML=valore_campo3;
		}
	}

window.close();
}

function associa_member_e_chiudi(campo_da_scrivere,valore_scrivente) {
	//alert(opener.prendiElementoDaId(campo_da_scrivere).value)
	preso="";
	for ( i = 0 ; i < prendiElementoDaId("rec").value; i++ ) {
		if (document.forms["show_member"].elements["mails"][i].checked==true){
			if (preso==""){
				preso+=document.forms["show_member"].elements["mails"][i].value
			} else {
			    preso+="," + document.forms["show_member"].elements["mails"][i].value;
		  }
		}
	}
	//alert(preso);
	
	opener.prendiElementoDaId(campo_da_scrivere).value=preso;
    window.close();
}

function scrivi_dati_e_chiudi2(campo_valore,valore_campo,campo_etichetta,etichetta_campo) {
    prendiElementoDaId(campo_valore).value=valore_campo;
	prendiElementoDaId(campo_etichetta).innerHTML=etichetta_campo;    
}

function cancella_events_news(colonna,sezione,azione) {	
	radio=prendiElementoDaId("events_id");
	if (radio!=null){
	  selezionato=0;	 
	  if(document.forms["My_Events_News"].elements["rec"].value>1){
        for ( i = 0 ; i < document.forms["My_Events_News"].elements["rec"].value; i++ ) {	      
		  if (document.forms["My_Events_News"].elements["events_id"][i].checked==true){
		    selezionato=document.forms["My_Events_News"].elements["events_id"][i].value;
			break;
		  }
	    }
	  } else {
	    if (document.forms["My_Events_News"].elements["events_id"].checked==true){
		  selezionato=document.forms["My_Events_News"].elements["events_id"].value;
		}		  
	  }
	  if (selezionato!=0){
		if(confirm("WARNING!\nYou are attempting to delete permanently a record from EJN.\n\nProceed?")){
	      load_admins(colonna,sezione,azione+"&id_events="+selezionato,"no");
	      //alert(selezionato);
		}
	  } else {
		  alert("WARNING!\nYou must select a record before!");
	  }
	} else {
	  alert("WARNING!\nYou must select a record before!");
	}
	
}

function cancella_utente(colonna,sezione,azione) {
	
	radio=prendiElementoDaId("user_id");
	if (radio!=null){							 
	  
	    selezionato=0;	 
	  if(document.forms["Users_viewer"].elements["rec"].value>1){
        for ( i = 0 ; i < document.forms["Users_viewer"].elements["rec"].value; i++ ) {	      
		  if (document.forms["Users_viewer"].elements["user_id"][i].checked==true){
		    selezionato=document.forms["Users_viewer"].elements["user_id"][i].value;
			break;
		  }
	    }
	  } else {
	    if (document.forms["Users_viewer"].elements["user_id"].checked==true){
		  selezionato=document.forms["Users_viewer"].elements["user_id"].value;
		}		  
	  }
	  if (selezionato!=0){
		if(confirm("WARNING!\nYou are attempting to delete permanently an user from EJN.\n\nProceed?")){
	      load_admins(colonna,sezione,azione+"&id_ejn_user="+selezionato,"no");
	      //alert(selezionato);
		}
	  } else {
		  alert("WARNING!\nYou must select an user before!");
	  }
	} else {
	  alert("WARNING!\nYou must select an user before!");
	}
	
}

function scarica_file(doc){
	//alert(doc);
	top.frames.location.href=(doc);
	//window.location.href=("Documents/EJN_MEMBERSHIP_APPLICATION.doc");
}

function load_admins_explorer(elemento,pagina,mode,carica_panel){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  query="Pages/Admin/" + pagina;
	  //alert(query);
	  ajax.open("get", query, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {			
          if (statusText[ajax.status] === "OK") {
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			  if (carica_panel!="no"){
			    carica_control_panel(pagina, 'Pannelo_Controllo');
			  }
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	
}

function load_admins_explorer3(elemento,pagina,carica_panel){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  query=pagina;
	  //alert(query);
	  ajax.open("get", query, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
			if (ajax.readyState==4){
			  //alert(ajax.responseText);
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			}
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	
}

function load_admins_explorer2(elemento,pagina,mode,carica_panel){
        var xmlHttpReq = false;
        var self = this;
		query=pagina;
		//alert(query);
        if (window.XMLHttpRequest) {
          self.xmlHttpReq = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	    self.xmlHttpReq.open("get", query, true);
        //self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  prendiElementoDaId(elemento).innerHTML =self.xmlHttpReq.responseText;
        } else {
		  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		}
      }	
      self.xmlHttpReq.send(null);
}

function write_about(elemento, pagina){
	    //alert(prendiElementoDaId("namefile").value);
		//alert(prendiElementoDaId("contents").value);
        var xmlHttpReq = false;
        var self = this;
		pagina="Pages/Admin/" + pagina;
        if (window.XMLHttpRequest) {
          self.xmlHttpReq = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
          self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	    self.xmlHttpReq.open('POST',pagina, true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		  //alert("ok");
		  prendiElementoDaId("Colonna_Centrale").innerHTML =self.xmlHttpReq.responseText;
		  //alert(form.usrid.value + " " + form.pwd.value);		  
        } else {
		  prendiElementoDaId("Colonna_Centrale").innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		}
      }	
	  contents=prendiElementoDaId("contents").value.replace(/&/g, "_-_");
	  alert(contents);
	  //document.forms["contents___Frame"].elements.element
	  //alert(prendiElementoDaId("contents___Config").value);
	  /*for (iElement = 0; iElement < document.elements.length; iElement++){
		  alert(document.elements[iElement].name + " " + document.elements[iElement].type);
	  }*/
      //self.xmlHttpReq.send("&namefile=" + prendiElementoDaId("namefile").value + "&contents=" + contents);
}
function load_admins_lineup(elemento,pagina,mode,carica_panel){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;	  
	  query="Pages/Admin/" + pagina + "?mode=" + mode + "&idband=" + prendiElementoDaId("id_band").value;
	  //alert(query);
	  ajax.open("get", query, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
// <![CDATA[
  //new Ajax.Autocompleter('ac2','ac2update','_autocomplete_result.html',{parameters:'a=b&b=c'});
// ]]>

			  if (carica_panel!="no"){
			    carica_control_panel(pagina, 'Pannelo_Controllo');
			  }
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	

}
function load_admins_lineup_insert(elemento,pagina,mode,carica_panel){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;	  
	  query="Pages/Admin/" + pagina + "?mode=" + mode + "&idband=" + prendiElementoDaId("id_band").value + "&insert=" + prendiElementoDaId("id_musician").value;
	  //alert(query);
	  ajax.open("get", query, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
// <![CDATA[
  //new Ajax.Autocompleter('ac2','ac2update','_autocomplete_result.html',{parameters:'a=b&b=c'});
// ]]>

			  if (carica_panel!="no"){
			    carica_control_panel(pagina, 'Pannelo_Controllo');
			  }
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	

}

function load_admins(elemento,pagina,mode,carica_panel){
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;	  
	  query="Pages/Admin/" + pagina + "?mode=" + mode;
	  //alert(query);
	  ajax.open("get", query, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			  ahahEvalJS(elemento);
			  if (carica_panel!="no"){
			    carica_control_panel(pagina, 'Pannelo_Controllo');
			  }
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	
}

function delete_file_folder(elemento,pagina){
	selezionato="no";
	for (i = 0 ; i < document.forms["File_viewer"].elements.length; i++ ) {
		if (document.forms["File_viewer"].elements[i].name=="file_folder"){
			if(document.forms["File_viewer"].elements[i].checked){
				selezionato="si";
				deldir=document.forms["File_viewer"].elements[i].value;
			}
		}
	}
	if (selezionato=="si"){
	  if(confirm("WARNING!\nYou are attempting to delete permanently a file or folder.\n\nProceed?")){
		var ajax = assegnaXXMLHttpRequest();
		if (ajax){
		  usaLink = false;
		  
		  query="Pages/Admin/" + pagina + "&deldir=" + deldir;
		  //alert(query);
		  ajax.open("get", query, true);
		  ajax.setRequestHeader("connection", "close");
		  ajax.onreadystatechange = function() {      
			//alert(ajax.readyState)
			if(ajax.readyState === readyState.COMPLETATO) {
			  if (statusText[ajax.status] === "OK") {
				  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
			  } else {
				  //alert(elemento);
				  alert('Load Error! ' + statusText[ajax.status]);
				  prendiElementoDaId(elemento).innerHTML = "";
			  }
			}
		  }
		  ajax.send(null);
		  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
		} else {
			alert("Browser invalid!");
		}	
	  }
	} else {
		alert("No file or folder selected!");
	}
}

function crea_file(elemento,pagina,dir){
  if (prendiElementoDaId("newfile").value.length>2){
    document.forms["upload_form"].submit();
    //document.getElementById('upload_status').value = "uploading file...";
    document.forms["upload_form"].disabled = true;
	prendiElementoDaId("loader").innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
    return true;
	
  } else {
    alert("You must insert a file before!");
  }
}

function crea_dir(elemento,pagina){
	//alert(elemento + " " + pagina);
	var ajax = assegnaXXMLHttpRequest();
	if (ajax){
      usaLink = false;
	  
	  query="Pages/Admin/" + pagina + "&newdir=" + prendiElementoDaId("newdir").value;
	  //alert(query);
	  ajax.open("get", query, true);
	  ajax.setRequestHeader("connection", "close");
	  ajax.onreadystatechange = function() {      
	    //alert(ajax.readyState)
        if(ajax.readyState === readyState.COMPLETATO) {
          if (statusText[ajax.status] === "OK") {
			  prendiElementoDaId(elemento).innerHTML =ajax.responseText;
		  } else {
			  //alert(elemento);
			  alert('Load Error! ' + statusText[ajax.status]);
			  prendiElementoDaId(elemento).innerHTML = "";
          }
        }
      }
	  ajax.send(null);
	  prendiElementoDaId(elemento).innerHTML ='<img src="images/indicator_snake.gif" width="16" height="16">';
	} else {
		alert("Browser invalid!");
	}	
}

function Invia_News(){
	document.forms['My_Events_News_Detail2'].submit();
}


function jsUpload(upload_field)
{
    upload_field.form.submit();
    //document.getElementById('upload_status').value = "uploading file...";
    upload_field.disabled = true;
    return true;
}


ahahEvalJS = function(elementId) {
	var scripts = prendiElementoDaId(elementId).getElementsByTagName('script');
	var code;
	for (var i = 0; i < scripts.length; i++) {
		code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
			scripts[i].text ? scripts[i].text : 
			scripts[i].textContent;
		try {
			eval(code);
		} catch(e) {
			alert(e);
		}
	}
}

