vTesti = new Object;

/*
Abbreviazione per document.getElementById(nomediv)
*/
function GID(id){
	return document.getElementById(id);
}


function PopUpPagina(paginarichiesta)
{

	var winLocation, winName, winParam, winObj;
	var winPos, winPosTop, winPosLeft, winWidth, winHeight;
	
	winWidth = 1000;
	winHeight = 580;
	
	winPosTop = (screen.height / 2) - winHeight / 2;
	winPosLeft = (screen.width / 2) - winWidth / 2;
	winPos = ',top=' + winPosTop + ',left=' + winPosLeft;
	
	winLocation = paginarichiesta;
	winName = 'popUp';

	winParam = 'status=0,toolbars=0,menubar=0,history=0,resizable=1,width=' + winWidth + ',height=' + winHeight + winPos;
	winObj = window.open(winLocation, winName, winParam);
	winObj.focus();
}

function PopUpZoom(paginarichiesta)
{

	var winLocation, winName, winParam, winObj;
	var winPos, winPosTop, winPosLeft, winWidth, winHeight;
	
	winWidth = 750;
	winHeight = 650;
	
	winPosTop = (screen.height / 2) - winHeight / 2;
	winPosTop=20;
	winPosLeft = (screen.width / 2) - winWidth / 2;
	winPos = ',top=' + winPosTop + ',left=' + winPosLeft;
	
	winLocation = paginarichiesta;
	winName = 'popUpZoom';

	winParam = 'status=0,toolbars=0,menubar=0,history=0,resizable=1,width=' + winWidth + ',height=' + winHeight + winPos;
	winObj = window.open(winLocation, winName, winParam);
	winObj.focus();
}

function CreaVettore(lang)
{
	if(lang=="en"){
		vTestorichiesta="Devi selezionare un Tipo Richiesta";
		vTesti[0]="Il campo Azienda é obbligatorio";
		vTesti[1]="Il campo Nome é obbligatorio";
		vTesti[2]="Il campo Cognome é obbligatorio";
		vTesti[3]="Il campo Telefono è obbligatorio";
		vTestomail="Devi specificare un Indirizzo E-mail valido!";
		vTesti[4]="Inserisci la Richiesta";
		vTestoprivacy="Devi accettare il trattamento dei Dati Personali per effettuare un'iscrizione!";
	}
	else{
		vTestorichiesta="Devi selezionare un Tipo Richiesta";
		vTesti[0]="Il campo Azienda é obbligatorio";
		vTesti[1]="Il campo Nome é obbligatorio";
		vTesti[2]="Il campo Cognome é obbligatorio";
		vTesti[3]="Il campo Telefono è obbligatorio";
		vTestomail="Devi specificare un Indirizzo E-mail valido!";
		vTesti[4]="Inserisci la Richiesta";
		vTestoprivacy="Devi accettare il trattamento dei Dati Personali per effettuare un'iscrizione!";
	
	
	}
}


function ControllaDati(lang){
	CreaVettore(lang);

	var lung=null;
	var stringa=null;
	
	
	/*if(document.SuperForm.tipo.value=='remove'){
		EmailAddr = document.SuperForm.removemail.value;
		if (Filtro.test(EmailAddr))
			return true;
		else{
			alert(vTesti[11]);
			document.SuperForm.removemail.focus();
			return false;
		}
	}*/
	
	var id=new Array();

	id[0]='azienda';
	id[1]='nome';
	id[2]='cognome';
	id[3]='telefono';
	id[4]='richiesta';
	
	
	
	if (document.SuperForm.tipo.value=='new')
	{
	
	   if (document.SuperForm.acce[0].checked==false)
	   {
	      alert(vTestoprivacy);
	      document.SuperForm.acce[0].focus();
	      return false;  
	   }
	   
	   //tipo_richiesta !=0
	   if (GID('tipo_richiesta').value=="0")
		      { 
			alert(vTestorichiesta);
			GID('tipo_richiesta').focus();
			return false; 
	              }
	   
	   
	   
	   	              //Controlla Correttezza mail
	   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	   EmailAddr = document.SuperForm.mail.value;
	   if (Filtro.test(EmailAddr))
	      {  }
	   else
	      {
	      alert(vTestomail);
	      document.SuperForm.mail.focus();
	      return false;
	      }
	
	
	
	
	for (i=0;i<id.length;i++){
	
	   stringa=GID(id[i]).value;
	   lung=stringa.length;
	   if (lung<=0)
		      { 
		     
			alert(vTesti[i]);
			GID(id[i]).focus();
			return false; 
			
	              }
	}
	   
	              

		
	}
	return true;
	              


}

/*
Funzione per l'apertura di una PopUp dimensionata
*/

function PrevFoto(img){
    foto1= new Image();
    foto1.src=(img);
    Controlla(img);
    }

function Controlla(img){
    if((foto1.width!=0)&&(foto1.height!=0)){
        viewFoto(img);
        }
    else{
        funzione="Controlla('"+img+"')";
        intervallo=setTimeout(funzione,100);
    }
}

function viewFoto(img){

 var winLocation, winName, winParam, winObj;
 var winPos, winPosTop, winPosLeft, winWidth, winHeight;

 winWidth=foto1.width+20;
 winHeight=foto1.height+25;

 winPosTop = (screen.height / 2) - winHeight / 2;
 winPosLeft = (screen.width / 2) - winWidth / 2;

 winPos = ',top=' + winPosTop + ',left=' + winPosLeft;
 winLocation = "zoom.asp?img="+img;
 winName = 'popUp';
 winParam = 'status=0,toolbars=0,menubar=0,history=0,width=' + winWidth + ',height=' + winHeight + winPos;

 winObj = window.open(winLocation, winName, winParam);

}
function createMailto(name,domain,text,style){
	var STYLE="";
	EMAIL=name+"@"+domain;
	if( text )
		TESTO=text;
	else
		TESTO=EMAIL;
	if( style )
		STYLE="style=\""+style+"\"";
	document.write("<a class=\"mail\" href=\"mailto:"+EMAIL+"\""+STYLE+">"+TESTO+"</a>");
}


function CalcolaPercorso(){
	CITTAD="35020 Due Carrare";
	INDIRIZZOD="Via%20Mezzavia,%20132";
	ND="132";
			
	
	if (GID("cap").value != ""){
		var CITTA=GID("cap").value + ", " +GID("citta").value;
	}else{
		var CITTA=GID("citta").value;
	}
	var INDIRIZZO=GID("indirizzo").value;
	var N=GID("n").value;
	if( CITTA=="" ){
		alert("Inserire la città di partenza!");
		GID("citta").focus();
	}
	else
		window.open("http://www.viamichelin.it/viamichelin/ita/dyn/controller/Itineraires?strStartCityCountry=612&strStartAddress="+INDIRIZZO+"%2C+"+N+"&strStartMerged="+CITTA+"&strDestCityCountry=612&strDestAddress="+INDIRIZZOD+"&strDestMerged="+CITTAD+"&choiceType=1&ie=UTF-8&x=0&y=0");
}


function startmenu()
{
	document.getElementById('menu1').style.display = "none";
	document.getElementById('menu2').style.display = "none";
	document.getElementById('menu3').style.display = "none";
	document.getElementById('menu4').style.display = "none";
	
	document.getElementById('goccia1').style.visibility = "hidden";
	document.getElementById('goccia2').style.visibility = "hidden";
	document.getElementById('goccia3').style.visibility = "hidden";
	document.getElementById('goccia4').style.visibility = "hidden";
	document.getElementById('goccia5').style.visibility = "hidden";
	document.getElementById('goccia6').style.visibility = "hidden";
	
	document.getElementById('titolo1').style.color = "black";
	document.getElementById('titolo2').style.color = "black";
	document.getElementById('titolo3').style.color = "black";
	document.getElementById('titolo4').style.color = "black";
	document.getElementById('titolo5').style.color = "black";
	document.getElementById('titolo6').style.color = "black";
}

function menufunc(menuId,titoloId,gocciaId)
{
	if(document.getElementById(menuId).style.display == "none")
	{
		startmenu();
		document.getElementById(menuId).style.display = "block";
		document.getElementById(gocciaId).style.visibility = "visible";
		document.getElementById(titoloId).style.color = "#4BBCD7";
		
	}
	else
	{
		startmenu();
	}
}

function ucfirst(str) {
    var firstLetter = str.substr(0, 1);
    return firstLetter.toUpperCase() + str.substr(1);
}

function checkData(){

	var campi=new Array('nome','cognome');
	for(i=0;i<campi.length;i++){
		if( document.getElementsByName(campi[i])[0].value=="" ){
			alert("Attenzione: manca il campo obbligatorio \""+ucfirst(campi[i])+"\"!");
			document.getElementsByName(campi[i])[0].focus();
			return false;
		}
	}
	
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   	Email = document.getElementsByName("email")[0].value;
	if (!Filtro.test(Email)){
		alert("Controlla l'indirizzo e-mail inserito!");
		document.getElementsByName("email")[0].focus();
		return false;
	}
	
	if( !document.getElementById("accetta").checked ){
		alert("Devi accettare il trattamento dei dati personali per continuare!");
		return false;
	}
	
	return true;
	
}
