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=="eng"){
		vTestorichiesta="Select a product!";
		//vTesti[0]="Il campo Azienda é obbligatorio";
		vTesti[1]="The name is required";
		vTesti[2]="Last name is required";
		vTesti[3]="The Phone field is required";
		vTestomail="You must specify a valid email address!";
		vTesti[4]="Enter Request";
		vTestoprivacy="You must agree to the processing of personal data to make an entry!";
	}
	else{
		vTestorichiesta="Devi selezionare un Prodotto";
		//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;  
	   }
	   
	   //prodotto !=0
	   if (GID('prodotto').value=="0")
		      { 
			alert(vTestorichiesta);
			GID('prodotto').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=1;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;
	
}


//solo numeri
function numbersonly(myfield, e, dec) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  } else
    return false;
}



function CreaVettoreSped(lang)
{
	if(lang=="eng"){

		
		vTesti[0]="The field name is compulsory!";
		vTesti[1]="Check the written surname!";
		vTesti[2]="Check the written address!";
		vTesti[3]="The field CAP is compulsory!";
		vTesti[4]="The field city is compulsory!";
		vTesti[5]="Provincia!";
		vTesti[6]="The field nation is compulsory!";
		vTesti[7]="Telephone!";
		vTesti[8]="Tax!";
		
		


	}
	else{
		vTesti[0]="Il campo Nome è obbligatorio!";
		vTesti[1]="Controlla il Cognome inserito!";
		vTesti[2]="Controlla l'Indirizzo inserito!";
		vTesti[3]="Il campo CAP è obbligatorio!";
		vTesti[4]="Il campo Città è obbligatorio!";
		vTesti[5]="Il campo Provincia è obbligatorio!";
		vTesti[6]="Devi specificare una Nazione!";
		vTesti[7]="Immetti il numero di telefono";
		vTesti[8]="Immetti Codice Fiscale!";

	
	}
}





function ControllaDatiSped(lang){
	CreaVettoreSped(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]='nome';
	id[1]='cognome';
	id[2]='indirizzo';
	id[3]='cap';
	id[4]='citta';
	id[5]='provincia';
	id[6]='nazione';
	id[7]='telefono';
	id[8]='cod_fiscale';
	

	
	
	if ( (GID('tipo').value=='new') )
	{
		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; 
			}
		}
		//Nazione !=0
		if (GID('nazione').value=="0")
		{ 
			alert(vTesti[6]);
			GID('nazione').focus();
			return false; 
		}



		//Controlla Correttezza cognome
		Filtro = /^([a-zA-Z\/s' ])+$/;
		Cognome = document.SuperForm.cognome.value;
		if( !Filtro.test(Cognome) )
		{
			alert(vTesti[1]);
			document.SuperForm.cognome.focus();
			return false;
		}
	}
	return true;

}

