// JavaScript Document
var form_invio=false;
var form_lavora=false;
var form_ricerca=false;
var video=false;
var cartina_info=false;
var schermo=false;
var testo_info=false;
var stradario=false;
var div_visualizzato="blank";
var player = false;
var cartina = false;
var street_view=false;
var pannello_cartina=false;
var from ="";
var to="";
YAHOO.namespace("example.container");



	YAHOO.util.Event.onDOMReady(function () {
        YAHOO.example.container.form_invio = new YAHOO.widget.Overlay("form_invio", {
			visible:false,
			draggable:false
		});
           YAHOO.example.container.form_ricerca = new YAHOO.widget.Overlay("form_ricerca", {
			visible:false,
			draggable:false
		});
             YAHOO.example.container.form_lavora = new YAHOO.widget.Overlay("form_lavora", {
			visible:false,
			draggable:false
		});
             YAHOO.example.container.video = new YAHOO.widget.Overlay("video", {
			visible:false,
			draggable:false
		});
        
		YAHOO.example.container.cartina_info = new YAHOO.widget.Overlay("cartina_info", { 
			width:"400px", 
			height:"335px",
			visible:false,
			draggable:false 
		});
  
        YAHOO.example.container.schermo = new YAHOO.widget.Overlay("schermo", {
			visible:false,
			draggable:false
		});
	
		YAHOO.example.container.stradario = new YAHOO.widget.Overlay("stradario", {
			visible:false,
			draggable:false
		});
        YAHOO.example.container.testo_info = new YAHOO.widget.Overlay("testo_info", {
			visible:false,
			draggable:false
		});
	
		 YAHOO.example.container.scivolo = new YAHOO.widget.Overlay("scivolo", {
			visible:true,
			draggable:false
		});

		YAHOO.example.container.cartina_info.render();
        YAHOO.example.container.form_invio.render();
        YAHOO.example.container.form_ricerca.render();
        YAHOO.example.container.form_lavora.render();
        YAHOO.example.container.video.render();
        YAHOO.example.container.schermo.render();
        YAHOO.example.container.testo_info.render();
		YAHOO.example.container.stradario.render();
		YAHOO.example.container.scivolo.render();

	});


        // sezione creazione video
   var secs
var timerID = null
var timerRunning = false
var delay = 500

function CaricaPosizioni(id)
{
    var tipo =document.work_us.tipologia.options[id].text;
    GetDiv('black.php','static');
	GetDiv('cerca_posizioni.php?id='+ tipo + '','div_posizioni');

}
function CaricaFinale(id)
{
    var tipo =document.work_us.posizioni.options[id].text;
   
    if(tipo!='Seleziona')
        {
	GetDiv('static.php?id='+ tipo + '','static');
   setTimeout('SettaUpload();', 1000);
        }
	


}
function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 2
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}
function StartPlayer()
{
	
    if(player!=false)
    {
      
        player.play();
        //player.sendEvent("START","true");
    }
}
function StopPlayer()
{
    if(player!=false)
    {


    //player.sendEvent("STOP","true");
        player.stop();
    }
}
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();
        if(player==false)
            {}
            else
                {
        //StartPlayer();
                }
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
 

// fine  sezione video
    function OscuraFinestre()
    {
        if(video==true)
        {


        }
        else
        {
            YAHOO.example.container.video.hide();
        }

        if(form_invio==true)
        {

        }
        else
        {
            YAHOO.example.container.form_invio.hide();
        }

         if(form_ricerca==true)
        {

        }
        else
        {
            YAHOO.example.container.form_ricerca.hide();
        }
        if(form_lavora==true)
        {

        }
        else
        {
            YAHOO.example.container.form_lavora.hide();
        }

         if(cartina_info==true)
        {


        }
        else
        {
            YAHOO.example.container.cartina_info.hide();
        }
         if(schermo==true)
        {

        }
        else
        {
            YAHOO.example.container.schermo.hide();
            if(street_view==true)
                {
            if(pano.isHidden())
            {


            }
            else
            {
                pano.hide();
            }
                }
        }
         if(testo_info==true)
        {

        }
        else
        {
            YAHOO.example.container.testo_info.hide();
        }
         if(stradario==true)
        {

        }
        else
        {
            YAHOO.example.container.stradario.hide();
        }
    }
    function VisualizzaFinestre()
    {
        if(video==true)
        {
           
            YAHOO.example.container.video.show();
            video=false;
        }
        else
        {
           
        }
        
        if(form_invio==true)
        {
            YAHOO.example.container.form_invio.show();
            form_invio=false;
        }
        else
        {
           
        }

         if(form_ricerca==true)
        {
            YAHOO.example.container.form_ricerca.show();
            form_ricerca=false;
        }
        else
        {
         
        }
   
        if(form_lavora==true)
        {
            YAHOO.example.container.form_lavora.show();
            
            form_lavora=false;
          

        }
        else
        {
            
        }
      
      
         if(cartina_info==true)
        {
            YAHOO.example.container.cartina_info.show();
            cartina_info=false;
           
        }
        else
        {
            
        }
         if(schermo==true)
        {
            YAHOO.example.container.schermo.show();
            schermo=false;
            if(street_view==true)
                {
                    if(pano.isHidden())
                    {
                        pano.show();

                    }
                    else
                    {

                    }
                }
        }
        else
        {
           
        }
         if(testo_info==true)
        {
            YAHOO.example.container.testo_info.show();
            testo_info=false;
        }
        else
        {
           
        }
         if(stradario==true)
        {
            YAHOO.example.container.stradario.show();
            stradario=false;
        }
        else
        {
          
        }

    }
	/*
	function createPlayer(div)
 {
       var flashvars = {
                    file:"video.flv",
                    autostart:"false",
					image:"preview.jpg",
					skin:"skins/grungetape/grungetape.swf"
            }
            var params = {
                    allowfullscreen:"true",
                    allowscriptaccess:"always",
					wmode: "transparent"
            }
            var attributes = {
                    id:"player1",
                    name:"player1"
            }
            swfobject.embedSWF("filmati/player.swf", div, "370", "256", "9.0.115", false, flashvars, params, attributes);

 }
	*/
	
/*  	
 function createPlayer(div)
 {
     
		player = flowplayer(div, "filmati/flowplayer.swf", {
						
	clip: { 
        	url: 'xmoov.php', 
        	provider: 'lighttpd', 
			autoPlay: true
    	},  
    	
		plugins: { 
			lighttpd: { 
            	url: 'filmati/flowplayer.pseudostreaming-3.1.3.swf', 
				// queryString -> dati passati allo script xmoov.php
				queryString: escape('?start=${start}&file=video.flv')			
    		}
		},
    logo: {
        url: '../images/logo_flow.png',
        fullscreenOnly: false,
        displayTime: 10
    },
   
    });
 
 }	
  */
 function createPlayer(div)
 {
      
		player = flowplayer(div, "filmati/flowplayer.swf", {
    clip:  { 
        autoPlay: true, 
        autoBuffering: true,
        
		url: vimeo_url
    },
    logo: {
        url: '../images/logo_flow.png',
        fullscreenOnly: false,
        displayTime: 10
    },
    key: '#$fc52ece9a3dd2690df6'
    });
   
  

        

 }
/*
  
function createPlayer(div)
 {
       var flashvars = {
                    file:"video.flv",
                    autostart:"false",
					image:"preview.jpg",
					skin:"skins/grungetape/grungetape.swf"
            }
            var params = {
                    allowfullscreen:"true",
                    allowscriptaccess:"always",
					wmode: "transparent"
            }
            var attributes = {
                    id:"player1",
                    name:"player1"
            }
            swfobject.embedSWF("filmati/player.swf", div, "370", "256", "9.0.115", false, flashvars, params, attributes);

 }
*/


    function ChiSiamo()
    {
        ResettaSottoMenu();
   		stopvolume();
        YAHOO.util.Dom.addClass("m2_1", 'current');
        OscuraFinestre();
        video = true;
        testo_info=true;
        div_visualizzato='video';
        VisualizzaFinestre();
        if(player==false)
        {
              createPlayer('televisione');
            //player = document.getElementById('player1');

           // InitializeTimer();
                   
        }
        else
        {
           StartPlayer();
        }
        if(cartina==false)
        {

           CaricaPagina('pagina.php?nome_articolo=Chi%20Siamo','testo_info');
        }
        else
        {
            Dimensiona('schermo_info',188);
        }
		TracciaSpostamentoSito('ChiSiamo');
       
    }
	function isValidEmail(email){ 
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/ 
    if(RegExp.test(email)){ 
        return true; 
    }else{ 
        return false; 
    } 
} 
	



    function PrimoInvio()
	{
		var fullname = document.getElementById('fullname').value;
		var email = document.getElementById('email').value;
		var citta = document.getElementById('citta').value;
		var indirizzo = document.getElementById('indirizzo').value;
		var message = document.getElementById('message').value;
		var privacy = document.getElementById('privacy');
		var messaggio=false;
		TracciaSpostamentoSito('InvioContatti');
		
		
		if(messaggio==false)
		{
			if ((citta.length < 3) || (citta.length > 30))
			{
				messaggio="Errore nella citta";
			}
			else
			{
				messaggio=false;
			}
		}
		
		if(messaggio==false)
		{
			if ((indirizzo.length < 3) || (indirizzo.length > 30))
			{
				messaggio="Errore nell' indirizzo";
			}
			else
			{
				messaggio=false;
			}
		}
		
		if(messaggio==false)
		{
			if ((fullname.length < 3) || (fullname.length > 30))
			{
				messaggio="Errore nel nome";
			}
			else
			{
				messaggio=false;
			}
		}
		
		if(messaggio==false)
		{
			if(privacy.checked==true)
			{
				messaggio=false;
			}
			else
			{
				messaggio="Accettare la privacy";
			}
		}
		
		if(messaggio==false)
		{
			if(isValidEmail(email))
			{
				messaggio=false;
			}
			else
			{
				messaggio="Errore nell' email";
			}
		}
        if(messaggio==false)
		{
			if ((message.length < 3) || (message.length > 1500))
			{
				messaggio="Errore nella lunghezza messaggio: " + message.length ;
			}
			else
			{
				messaggio=false;
			}
		}

		if(messaggio==false)
		{
            var container="form_invio";
            var url="invio_email2.php?ajax=1&privacy=1&email="+encodeURIComponent(email)+"&message="+encodeURIComponent(message)+
                "&fullname="+encodeURIComponent(fullname)+"&citta="+encodeURIComponent(citta)+"&indirizzo="+encodeURIComponent(indirizzo);
            
			GetPagina(url,container);
            document.getElementById(container).innerHTML = "<br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Invio in corso </b>";
            
		}
		else
		{
			alert(messaggio);
		}
	}

    function SecondoInvio()
	{
		var fullname = document.getElementById('fullname').value;
		var email = document.getElementById('email').value;
		var citta = document.getElementById('citta').value;
		var indirizzo = document.getElementById('indirizzo').value;
                var tipologia = document.getElementById('tipologia').value;
                var posizioni = document.getElementById('posizioni').value;
		var privacy = document.getElementById('privacy');
		var messaggio=false;
		var attachment = document.getElementById('attachment').value;
		TracciaSpostamentoSito('InvioCurriculum');

        if(messaggio==false)
		{
			if ((tipologia==-1))
			{
				messaggio="Errore nella scelta della tipologia";
			}
			else
			{
				messaggio=false;
			}
		}
        if(messaggio==false)
		{
			if ((posizioni==-1))
			{
				messaggio="Errore nella scelta della posizione";
			}
			else
			{
				messaggio=false;
			}
		}
		

		if(messaggio==false)
		{
			if ((indirizzo.length < 3) || (indirizzo.length > 30))
			{
				messaggio="Errore nell' indirizzo";
                                
			}
			else
			{
				messaggio=false;
			}
		}

		if(messaggio==false)
		{
			if ((fullname.length < 3) || (fullname.length > 30))
			{
				messaggio="Errore nel nome";
			}
			else
			{
				messaggio=false;
			}
		}

		if(messaggio==false)
		{
            
			if(isValidEmail(email))
			{
				messaggio=false;
			}
			else
			{
				messaggio="Errore nell' email";
			}
		}
        if(messaggio==false)
		{
			if ((citta.length < 3) || (citta.length > 30))
			{
				messaggio="Errore nella citta";
                
			}
			else
			{
				messaggio=false;

			}
		}
  
       	if(messaggio==false)
		{
			if(privacy.checked==true)
			{
				messaggio=false;
			}
			else
			{
				messaggio="Accettare la privacy";
			}
		}
       
       
       if(messaggio==false)
		{

			if ((attachment.length < 3) || (attachment.length > 30))
			{
				messaggio="Errore nell' attachment";

			}
			else
			{
				messaggio=false;

			}
		}
		if(messaggio==false)
		{
          
            var container="form_lavora";
            var url="invio_curriculum2.php?ajax=1&privacy=1&email="+encodeURIComponent(email)+
                "&fullname="+encodeURIComponent(fullname)+"&citta="+encodeURIComponent(citta)+
                "&attachment="+encodeURIComponent(attachment)+"&indirizzo="+encodeURIComponent(indirizzo);
            document.getElementById('sendcontact').disabled=true;
			GetPagina(url,container);
            document.getElementById(container).innerHTML = "<br><br><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b> Invio in corso </b>";

           
		}
		else
		{
			alert(messaggio);
		}
	}



    function Scrivici()
    {
        ResettaSottoMenu();
        YAHOO.util.Dom.addClass("m2_2", 'current');
        OscuraFinestre();
        tipo_schermo='form_invio';
        form_invio = true;
        testo_info=true;
        div_visualizzato='form_invio';
        VisualizzaFinestre();
        if(player)
        {
            StopPlayer();
        }
        if(cartina==false)
        {
            el='#testo_info';
            CaricaTesto('pagina.php?nome_articolo=Scrivici','#testo_info');
            CaricaPagina('contatti.php',tipo_schermo);
            //YAHOO.util.Event.onContentReady('contact',DED.core.init, DED.contactDetails);
            //YAHOO.util.Event.onContentReady('fullname', function() { this.focus(); });
        }
        else
        {
              Dimensiona('schermo_info',188);
        }
		TracciaSpostamentoSito('Scrivici');
    }
    function Panorama()
    {
         OscuraFinestre();
        schermo = true;
        form_ricerca = true;
        div_visualizzato='schermo';
        VisualizzaFinestre();
  
        if(player)
        {
            StopPlayer();
        }
        
         
            initialize_streetview();
        
    }
     function LavoraConNoi()
    {
        ResettaSottoMenu();
        YAHOO.util.Dom.addClass("m2_3", 'current');
        OscuraFinestre();
       
        form_lavora = true;
        testo_info=true;
       
        div_visualizzato='form_lavora';
        tipo_schermo='form_lavora';

        VisualizzaFinestre();

        if(player)
        {
             StopPlayer();
        }
        if(cartina==false)
        {
            el='#testo_info';
       
            CaricaTesto('pagina.php?nome_articolo=Lavora%20Con%20Noi',el);
            CaricaPagina('lavora_con_noi.php',tipo_schermo);
            //YAHOO.util.Event.onContentReady('work_us',DED.core.init, DED.workDetails);
            //YAHOO.util.Event.onContentReady('fullname', function() { this.focus(); });
            
        }
        else
        {
            Dimensiona('schermo_info',188);
      
        }
    	TracciaSpostamentoSito('LavoraConNoi');
    }
    function PuntiVendita()
    {
        ResettaSottoMenu();
        YAHOO.util.Dom.addClass("m2_4", 'current');
        div_visualizzato='cartina_info';
        OscuraFinestre();
       
        if(player)
        {
             StopPlayer();
        }
        if(cartina==false)
        {
           Dimensiona('schermo_info',400);
           
            form_ricerca = true;
            
            VisualizzaFinestre();
           
            //DisabilitaProvenienza();
          
        }
        else
        {
            cartina_info = true;
            form_ricerca = true;
            div_visualizzato='cartina_info';
            VisualizzaFinestre();
            CaricaPagina('cerca_sede.php','form_ricerca');
            initialize_mappe('italy');
            
        }
        TracciaSpostamentoSito('PuntiVendita');
        
    }
    function GestioneRegione(regione)
{

     GetDiv('cerca_province.php?regione='+ regione + '','sede_provincia');
     filtro_sedi='regione='+regione+'';
     filtro_regione=regione;
     filtro_provincia=null;
    filtro_citta=null;
    filtro_indirizzo=null;
    zoom_area=6;
     initialize_mappe('italy,'+ regione +'');
     //ZommaArea('regione');
    GetDiv('black.php','sede_citta');
    GetDiv('black.php','sede_indirizzi');
    DisabilitaProvenienza();
    //GetDiv('black.php','sede_provenienza');

}
function GestioneProvince(provincia)
{
    if(provincia!="0")
    {
    filtro_sedi='provincia='+provincia+'';

     filtro_provincia=provincia;
    filtro_citta=null;
    filtro_indirizzo=null;
     zoom_area=8;
     
     initialize_mappe('italy,'+ filtro_regione + "," + provincia +'');
    GetDiv('cerca_citta.php?provincia='+ provincia + '','sede_citta');
    //alert('cerca_citta.php?provincia='+ provincia + '');
   // CaricaPaginaMin('black.php','sede_citta');
    GetDiv('black.php','sede_indirizzi');
    DisabilitaProvenienza();
    //GetDiv('black.php','sede_provenienza');
    }
}
function GestioneCitta(citta)
{
      if(citta!="0")
    {
    filtro_sedi='citta='+citta+'';
     filtro_citta=citta;
    filtro_indirizzo=null;
     zoom_area=10;
     var regione = document.getElementById("regione").value ;
     var provincia = document.getElementById("provincia").value ;
     initialize_mappe('italy,' + regione + "," + provincia + "," + citta +'');
    GetDiv('cerca_indirizzo.php?citta='+ citta + '','sede_indirizzi');
   // CaricaPaginaMin('black.php','sede_citta');
    DisabilitaProvenienza();
    //GetDiv('black.php','sede_provenienza');
	TracciaSpostamentoSito('GestioneCitta/'+citta+'');
    }
}
function GestioneIndirizzo(indirizzo)
{

    if(indirizzo!="0")
    {
       //VisualizzaSchermo();
       //GetDiv('cerca_provenienza.php','sede_provenienza');
       AbilitaProvenienza();
        zoom_area=12;
        filtro_indirizzo=indirizzo;
        initialize_mappe('italy,'+ filtro_provincia +',' + filtro_citta + ',' +  indirizzo);

    }
}
function AbilitaProvenienza()
{

    document.filtra_mappa.from_provincia.disabled=false;
    document.filtra_mappa.from_citta.disabled=false;
    document.filtra_mappa.from_indirizzo.disabled=false;
    document.filtra_mappa.cal_percorso.disabled=false;
    document.filtra_mappa.panoramica.disabled=false;
    document.filtra_mappa.b_mappa.disabled=false;
    to="";
    from="";

}
function DisabilitaProvenienza()
{
    document.filtra_mappa.from_provincia.disabled=true;
    document.filtra_mappa.from_citta.disabled=true;
    document.filtra_mappa.from_indirizzo.disabled=true;
    document.getElementById("from_provincia").value="";
    document.getElementById("from_citta").value="";
    document.getElementById("from_indirizzo").value="";
    document.filtra_mappa.cal_percorso.disabled=true;
    document.filtra_mappa.panoramica.disabled=true;
    document.filtra_mappa.b_mappa.disabled=true;
    to="";
    from="";
}
 function CalcolaPercorso()
    {
      //var from = document.getElementById("from").value;
      //var to = document.getElementById("to").value;

  
      var regione = document.getElementById("regione").value;
      var provincia = document.getElementById("provincia").value;
      var citta = document.getElementById("citta").value;
      var indirizzo = document.getElementById("indirizzo").value;

      var from_provincia = document.getElementById("from_provincia").value;
      var from_citta = document.getElementById("from_citta").value;
      var from_indirizzo = document.getElementById("from_indirizzo").value;

      to = 'italia,' + regione + ',' + provincia + ',' + citta + ',' + indirizzo;
     
      from = 'italia,' + from_provincia + ',' + from_citta + ',' + from_indirizzo;
      
      setDirections(from, to, 'it');
      OscuraFinestre();
      stradario=true;
      cartina_info = true;
      VisualizzaFinestre();
      
    }
    function MostraMappa()
    {
      OscuraFinestre();
      form_ricerca=true;
      cartina_info = true;
      VisualizzaFinestre();
    }
    function IndietroRicerca()
    {
        OscuraFinestre();
         cartina_info = true;
        form_ricerca = true;
        VisualizzaFinestre();
    }
    function MostraPanorama()
    {
        OscuraFinestre();
      schermo=true;
      cartina_info = true;
      VisualizzaFinestre();
        
    }
    function StampaPercorso()
    {
        var indirizzo_google="http://maps.google.it/maps?f=d&source=s_d&ie=UTF8&z=11&layer=c&pw=2"+"&saddr="+to+"&daddr="+from ;
        window.open(indirizzo_google,"mywindow","width=800,height=600,toolbar=yes,scrollbars=yes,resizable=yes");
    }
    function Scrivici2()
    {
        el='#testo_info';
        CaricaTesto('pagina.php?nome_articolo=Scrivici','#testo_info');
    }
	function Privacy()
	{
		el='#testo_info';
        CaricaTesto('pagina.php?nome_articolo=Privacy',el);
	}
