/*	tinibox - per form 'segnalaci' 	*/
var TINY={};function T$(i){return document.getElementById(i)}TINY.box=function(){var p,m,b,fn,ic,iu,iw,ih,ia,f=0;return{show:function(c,u,w,h,a,t){if(!f){p=document.createElement('div');p.id='tinybox';cb=document.createElement('div');cb.id='tinyclose';m=document.createElement('div');m.id='tinymask';b=document.createElement('div');b.id='tinycontent';document.body.appendChild(m);document.body.appendChild(p);p.appendChild(cb);p.appendChild(b);m.onclick=TINY.box.hide;cb.onclick=TINY.box.hide;window.onresize=TINY.box.resize;f=1}if(!a&&!u){p.style.width=w?w+'px':'auto';p.style.height=h?h+'px':'auto';p.style.backgroundImage='none';b.innerHTML=c}else{b.style.display='none';p.style.width=p.style.height='100px'}this.mask();ic=c;iu=u;iw=w;ih=h;ia=a;this.alpha(m,1,80,3);if(t){setTimeout(function(){TINY.box.hide()},1000*t)}},fill:function(c,u,w,h,a){if(u){p.style.backgroundImage='';var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');x.onreadystatechange=function(){if(x.readyState==4&&x.status==200){TINY.box.psh(x.responseText,w,h,a)}};x.open('GET',c,1);x.send(null)}else{this.psh(c,w,h,a)}},psh:function(c,w,h,a){if(a){if(!w||!h){var x=p.style.width,y=p.style.height;b.innerHTML=c;p.style.width=w?w+'px':'';p.style.height=h?h+'px':'';b.style.display='';w=parseInt(b.offsetWidth);h=parseInt(b.offsetHeight);b.style.display='none';p.style.width=x;p.style.height=y}else{b.innerHTML=c}this.size(p,w,h,4)}else{p.style.backgroundImage='none'}},hide:function(){TINY.box.alpha(p,-1,0,3)},resize:function(){TINY.box.pos();TINY.box.mask()},mask:function(){m.style.height=TINY.page.theight()+'px';m.style.width='';m.style.width=TINY.page.twidth()+'px'},pos:function(){var t=(TINY.page.height()/2)-(p.offsetHeight/2);t=t<10?10:t;p.style.top=(t+TINY.page.top())+'px';p.style.left=(TINY.page.width()/2)-(p.offsetWidth/2)+'px'},alpha:function(e,d,a,s){clearInterval(e.ai);if(d==1){e.style.opacity=0;e.style.filter='alpha(opacity=0)';e.style.display='block';this.pos()}e.ai=setInterval(function(){TINY.box.twalpha(e,a,d,s)},20)},twalpha:function(e,a,d,s){var o=Math.round(e.style.opacity*100);if(o==a){clearInterval(e.ai);if(d==-1){e.style.display='none';e==p?TINY.box.alpha(m,-1,0,2):b.innerHTML=p.style.backgroundImage=''}else{e==m?this.alpha(p,1,100,5):TINY.box.fill(ic,iu,iw,ih,ia)}}else{var n=o+Math.ceil(Math.abs(a-o)/s)*d;e.style.opacity=n/100;e.style.filter='alpha(opacity='+n+')'}},size:function(e,w,h,s){e=typeof e=='object'?e:T$(e);clearInterval(e.si);var ow=e.offsetWidth,oh=e.offsetHeight,wo=ow-parseInt(e.style.width),ho=oh-parseInt(e.style.height);var wd=ow-wo>w?-1:1,hd=(oh-ho>h)?-1:1;e.si=setInterval(function(){TINY.box.twsize(e,w,wo,wd,h,ho,hd,s)},20)},twsize:function(e,w,wo,wd,h,ho,hd,s){var ow=e.offsetWidth-wo,oh=e.offsetHeight-ho;if(ow==w&&oh==h){clearInterval(e.si);p.style.backgroundImage='none';b.style.display='block'}else{if(ow!=w){e.style.width=ow+(Math.ceil(Math.abs(w-ow)/s)*wd)+'px'}if(oh!=h){e.style.height=oh+(Math.ceil(Math.abs(h-oh)/s)*hd)+'px'}this.pos()}}}}();TINY.page=function(){return{top:function(){return document.body.scrollTop||document.documentElement.scrollTop},width:function(){return self.innerWidth||document.documentElement.clientWidth},height:function(){return self.innerHeight||document.documentElement.clientHeight},theight:function(){var d=document,b=d.body,e=d.documentElement;return Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight))},twidth:function(){var d=document,b=d.body,e=d.documentElement;return Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))}}}();

$(function() {
	
	mainNav();
		   
	$('body').delegate('submit', {
    	'.formSegnalaci': function(e) {
			var lang = $.trim($('input#lang').val());
			var scheda = $.trim($('a#btnSegnalaci').attr('class'));
			var nome = $.trim($('input#nome').val());
			var cognome = $.trim($('input#cognome').val());
			var email = $.trim($('input#email').val());
			var messaggio = $.trim($('#messaggio').val());
			var autorizzo = $('input#autorizzo').attr('checked');
			if (checkInput().length != 0){
				if (lang == 'it')
					$('p#response').html("I campi evidenziate devono essere compilati").slideDown();
				else if (lang == 'en')
					$('p#response').html("Marked fields are mandatory").slideDown();
				return false;
			}
			if (!checkMail(email)){
				if (lang == 'it')
					$('p#response').html("Il formato dell' email non &egrave; corretto.").slideDown();
				else if (lang == 'en')
					$('p#response').html("Wrong email format.").slideDown();
				$('input#email').addClass('errore');
				return false;
			}
			if ($('input#autorizzo').attr('checked') != true) {
				if (lang == 'it')
					$('p#response').html("E' obbligatorio autorizzare l'uso dei dati personali").slideDown();
				else if (lang == 'en')
					$('p#response').html("It is mandatory to accept our privacy policy").slideDown();
				return false;
			}
			$.ajax({
					type: "POST",
				   	url: "form2.php",
				   	data: "nome=" + nome + "&cognome=" + cognome + "&email=" + email + "&messaggio=" + messaggio + "&autorizzo=" + autorizzo + "&scheda=" + scheda,
				   	success: function(response){
						var check = response.charAt(0);
						if (check == '3' ){
							if (lang == 'it')
								$(response).html("Si &egrave; verificato un errore mell'invio della mail.<br />Ti preghiamo di riprovare pi&ugrave; tardi.").slideDown();
							else if (lang == 'en')
								$(response).html("Error in send mail.<br />Please try leater.").slideDown();
							return;
						}
						if (lang == 'it')
							$('p#response').html("La mail &egrave; stata correttamente inviata.<br />Ti ringraziamo per il l'interesse mostrato").slideDown();
						else if (lang == 'en')
							$('p#response').html("Your email has been sent.<br />Thanks for your interest.").slideDown();
						$('form').slideUp();
				   	}
				});
			return false;
		}
	});
});


var helvetica = {
	 src: 'flash/helvetica.swf'
};
var helveticaBold = {
	 src: 'flash/helveticaBold.swf'
};

sIFR.activate(helvetica);
sIFR.activate(helveticaBold);
addOnloadEvent(function(){titoli()});

function titoli(){
	sIFR.replace(helvetica,
			 { selector: 'h2.app',
			   css: { '.sIFR-root': { 'color': '#4f4f4f' } },
			   wmode: 'transparent'
			 }),
	sIFR.replace(helvetica,
			 { selector: 'h2',
			   css: { '.sIFR-root': { 'color': '#00aeef' } },
			   wmode: 'transparent'
			 }),
	sIFR.replace(helveticaBold,
			 { selector: 'h3',
			   css: { '.sIFR-root': { 'color': '#000000'  } },
			   wmode: 'transparent'
			 })
	sIFR.replace(helvetica,
			 { selector: 'h5',
			   css: { '.sIFR-root': { 'color': '#000000'  } },
			   wmode: 'transparent'
			 })
}

function checkMail(mail){
	var p = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{1,4})$/;
	if (!(p.test(mail))){
		return false;
	}
	return true;
}

/*   selezione voce navigazione   */
function mainNav(){
	var bd = document.getElementsByTagName('body')[0].className;
	document.getElementById(bd).className='sel';
}
function appNav(){
	var bd = document.getElementsByTagName('body')[0].id;
	var btn = 'btn' + bd;
	document.getElementById(btn).parentNode.className='sel';
}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}
function checkInput(){
	var campi = new Array();
	$('input[type=text],textarea').each(function(){
		$(this).removeClass('errore');
		var value = $.trim($(this).val());
		if (value == '') {
			$(this).addClass('errore');
			campi.push($(this).attr('id'));
		}
	});
	return campi;
}

	

