var xmlHttp = CreaOggettoXmlHttp();

function CreaOggettoXmlHttp(){
	var xmlHttp;
	
	try{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
																		"MSXML2.XMLHTTP.5.0",
																		"MSXML2.XMLHTTP.4.0",
																		"MSXML2.XMLHTTP.3.0",
																		"MSXML2.XMLHTTP",
																		"Microsoft.XMLHTTP");
		for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
			try{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	
	if(!xmlHttp)
		alert("Errore nella creazione dell'oggetto");
	else
		return xmlHttp;
}

//convalida pagina nuova news
function Convalida_news(){
	var titolo = document.News.elements['titolo[1]'].value;
//	var descrizione = tinyMCE.get('descrizione').getContent(); 
	var autore = document.News.autore.value;

	if( (titolo == "") || (titolo == "undefined") ){
		alert("Il campo titolo news è obbligatorio!");
		document.News.elements['titolo[1]'].focus();
		return false;
	}
	else if( (autore == "") || (autore == "undefined") ){
		alert("Il campo autore è obbligatorio!");
		document.News.autore.focus();
		return false;
  }		
  else {
  	document.News.action = "../admin/includes/action.php";
    document.News.submit();
  }
}

//convalida pagina nuovo volantino
function Convalida_volantino(){
	var nome_volantino = document.Volantino.nome_volantino.value;
	var file = document.Volantino.file.value;

	if( (nome_volantino == "") || (nome_volantino == "undefined") ){
		alert("Il campo nome volantino è obbligatorio!");
		document.Volantino.nome_volantino.focus();
		return false;
	}
	else if( (file == "") || (file == "undefined") ){
		alert("Il campo file è obbligatorio!");
		document.Volantino.file.focus();
		return false;
  }		
  else {
  	document.Volantino.action = "../admin/includes/action.php";
    document.Volantino.submit();
  }
}


//convalida pagina account
function Convalida_account(){
	var email = document.Account.email.value;
	var mail_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	var username = document.Account.username.value;

	if (!mail_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert("Il campo email è obbligatorio!");
		document.Account.email.focus();
    return false;
  }	
	else if( (username == "") || (username == "undefined") ){
		alert("Il campo username è obbligatorio!");
		document.Account.username.focus();
		return false;
	}
  else {
  	document.Account.action = "../admin/includes/action.php";
    document.Account.submit();
  }
}

function Apri_div(div){
	document.getElementById(div).style.display = "block";
}
function Chiudi_div(div){
	document.getElementById(div).style.display = "none";
}