function primo_piano() {

	var delay = 5000;
	var start_frame = 0;

	new Effect.Appear('primopiano_slide_show');
	var lis = $('primopiano_slides').getElementsByTagName('li');
	
	for( i=0; i<lis.length; i++){
		if(i!=0){
			lis[i].style.display = 'none';
		}
	}
	end_frame = lis.length -1;
	
	start_slideshow(start_frame, end_frame, delay, lis);
	
	
}

function tratta(){
	$('tratta').setStyle({display:'none'});
	}

function start_slideshow(start_frame, end_frame, delay, lis) {
	setTimeout(fadeInOut(start_frame,start_frame,end_frame, delay, lis), delay);
}


function fadeInOut(frame, start_frame, end_frame, delay, lis) {
	return (function() {
		lis = $('primopiano_slides').getElementsByTagName('li');
		Effect.Fade(lis[frame]);
		if (frame == end_frame) { frame = start_frame; } else { frame++; }
		lisAppear = lis[frame];
		setTimeout("Effect.Appear(lisAppear);", 0);
		setTimeout(fadeInOut(frame, start_frame, end_frame, delay), delay);
	})
	
}

function login() {
	var x = $('login_panel').getStyle('top')
	
	if (x == '110px') {
	new Effect.Move('login_panel', { x: 550, y: 38, mode: 'absolute', queue: 'end' });
	}
	else {
	new Effect.Move('login_panel', { x: 550, y: 110, mode: 'absolute', queue: 'end' });	
	}
}

function dologin() { //alert('popop') ;
	var login = document.formLogin.login.value ;
	var passwd = document.formLogin.passwd.value ;
	var url = "ajax/ajax.php?center=dologinFront&login="+login+"&passwd="+passwd ;
	
	 
	
	var ajaxObj = new ClassAJAX();
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.runAJAX(url) ;

	var html = "" ;
	var htmlOld = "" ;

	myInterval = window.setInterval(
	function() {
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		if (html != false) {
		
			if (htmlOld == html) {

				window.clearInterval(myInterval);
				if(html =="OK") {
					window.location.reload();
				} else {
					var elem =document.getElementById('response') ; 
					elem.style.display='' ;
					elem.innerHTML=html ;
				}	
			}

		} else {
			
		}
	}
	,1) ;
}

function in_toggle(a) {
	var x = Math.round($(a).getHeight());
	var y = Math.round($(a).firstDescendant().next().firstDescendant().firstDescendant().next().getHeight())+80; 
	var z = Math.round(x/y*100);
	var zz = Math.round(100*x/30);
	allLI = document.getElementsByTagName('DIV') ;
	for (i=0; i < allLI.length; i++) {
	if(allLI[i].id.substring(0,2) == "d_") {
 			var altezza = $(allLI[i]).getHeight();
 			var altezzaLi = Math.round(100*altezza/30);
			if (altezza > 30) {
				new Effect.Scale(allLI[i].id, 100, {scaleX: false, scaleMode:{originalHeight: 30}, scaleFrom: altezzaLi, scaleContent: false}); 		
			}
	}
 
	
	}
	if (x < y) {
		new Effect.Scale(a, 100, {scaleX: false, scaleMode:{originalHeight: y}, scaleFrom: z, scaleContent: false}); 
		//$(a).firstDescendant().firstDescendant().onmouseover=function(){this.setStyle({fontWeight: 'bold', color: '#ffffff'});};
		//$(a).firstDescendant().firstDescendant().onmouseout=function(){this.setStyle({fontWeight: 'bold', color: '#ffffff'});};		
		} else if (x > 30) {
		new Effect.Scale(a, 100, {scaleX: false, scaleMode:{originalHeight: 30}, scaleFrom: zz, scaleContent: false}); 
		//$(a).firstDescendant().firstDescendant().onmouseover=function(){this.setStyle({fontWeight: 'bold', color: '#ffffff'});};
		//$(a).firstDescendant().firstDescendant().onmouseout=function(){this.setStyle({fontWeight: '', color: '#3c3c3c'});};
		}
	}


function OpenDialog(fileName) {
   var winFeatures = "dialogWidth:700px; dialogHeight=400px; center:1;";
   window.showModalDialog(fileName, "winDialog", winFeatures);
}

var win = null;
function OpenWindow(fileName) {
  var winW = 700;
  var winH = 400;
  var winX = (screen.width - winW) / 2;
  var winY = (screen.height - winH) / 2;
  var winOpt = 'height='+winH+',width='+winW+',top='+winY+',left='+winX+',scrollbars=1,resizable=0';

   if (win) win.close();

   win = window.open(fileName, 'window', winOpt);
}

/* LASZLO START HERE */
function getSelectionId(text, li) { 
	var fascia = li.id ;
   new Ajax.Updater('vediFascia', './ajax/ajax.php?center=fascia&fascia='+fascia, {});

}

function getResult() {
	var comunePartenza = document.getElementById('comunepartenza').value;
	var comuneArrivo = document.getElementById('comunearrivo').value;
	var sw_interscambio = document.form.sw_interscambio.value ; 
	new Ajax.Updater('searchResult', './ajax/ajax.php?center=arrivopartenza&sw_interscambio='+sw_interscambio+'&comunePartenza='+comunePartenza+"&comuneArrivo="+comuneArrivo, {
	}); 
}

function toggleDisplay(fO){

	var ns4 = (document.layers);
	var ie4 = (document.all && !document.getElementById);
	var ie5 = (document.all && document.getElementById);
	var ns6 = (!document.all && document.getElementById);
	
	document.getElementById('opzione1').style.display='none' ;
	document.getElementById('opzione2').style.display='none' ;
	document.getElementById('opzione3').style.display='none' ;
	
	if(ie5 || ns6){
		if (document.getElementById(fO).style.display=="none") {
		document.getElementById(fO).style.display="inline";
		}else{
		document.getElementById(fO).style.display="none";
		}
	}
	
	if(ie4){
		if (document.all[fO].style.display=="none") {
		document.all[fO].style.display="inline";
		}else{
		document.all[fO].style.display="none";
		}
	}	
}


function checkform() {
	var sw = 0;
	var msg = '';
	
	var login = document.docform.login.value;
	var password = document.docform.password.value;
	var email = document.docform.email.value;


	var the_box1 = document.docform.checklegge[0].checked;
		
		var x = document.docform.email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {
		//alert('YES! Correct email address');
		} else {
		
		msg += "Indirizzo email inesatto.\n" ;
		sw = 1 ;	
		} 

		if (!login) {
		msg += "devi inserire il login.\n" ;
		sw = 1 ;
		}
		
		if (!password) {
		msg += "devi inserire la password.\n" ;
		sw = 1 ;
		}

		if (!email) {
		msg += "devi inserire l\' email.\n" ;
		sw = 1 ;
		}


		if (the_box1 == true) {
		msg += "Devi accettare la clausola.\n" ;	
		sw = 1 ;
		}
	
		if(sw == 1 ) {		
			alert(msg);
			return false ;
		}
}

function checkform_pv() {
	var sw = 0;
	var msg = '';
	
	var denominazione = document.contatto_pv.denominazione.value;
	var ragione_sociale = document.contatto_pv.ragione_sociale.value;
	var email = document.contatto_pv.email.value;
	var indirizzo = document.contatto_pv.indirizzo.value;
	var civico = document.contatto_pv.civico.value;
	var comune = document.contatto_pv.comune.value;
	var cap = document.contatto_pv.cap.value;
	var telefono = document.contatto_pv.telefono.value;
	var apertura = document.contatto_pv.apertura.value;
	var chiusura = document.contatto_pv.chiusura.value;
	var riposo = document.contatto_pv.riposo.value;
	var piva = document.contatto_pv.piva.value;
	var referente = document.contatto_pv.referente.value;
	var tel_referente = document.contatto_pv.tel_referente.value;


	var the_box1 = document.contatto_pv.checklegge[0].checked;
		
		var x = document.contatto_pv.email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {
		//alert('YES! Correct email address');
		} else {
		
		msg += "Indirizzo email inesatto.\n" ;
		sw = 1 ;	
		} 

		if (!denominazione) {
		msg += "devi inserire la denominazione.\n" ;
		sw = 1 ;
		}
		
		if (!ragione_sociale) {
		msg += "devi inserire la ragione sociale.\n" ;
		sw = 1 ;
		}

		if (!indirizzo) {
		msg += "devi inserire l\' indirizzo.\n" ;
		sw = 1 ;
		}

		if (!civico) {
		msg += "devi inserire il civico.\n" ;
		sw = 1 ;
		}

		if (!comune) {
		msg += "devi inserire il comune.\n" ;
		sw = 1 ;
		}

		if (!cap) {
		msg += "devi inserire il cap.\n" ;
		sw = 1 ;
		}		

		if (!telefono) {
		msg += "devi inserire il telefono.\n" ;
		sw = 1 ;
		}		

		if (!apertura) {
		msg += "devi inserire l\' orario di apertura.\n" ;
		sw = 1 ;
		}		

		if (!chiusura) {
		msg += "devi inserire l\' orario di chiusura.\n" ;
		sw = 1 ;
		}	
		
		if (!riposo) {
		msg += "devi inserire il riposo settimanale.\n" ;
		sw = 1 ;
		}	

		if (!piva) {
		msg += "devi inserire la partita iva.\n" ;
		sw = 1 ;
		}

		if (!referente) {
		msg += "devi inserire il referente.\n" ;
		sw = 1 ;
		}

		if (!tel_referente) {
		msg += "devi inserire il telefono del referente.\n" ;
		sw = 1 ;
		}
		
		if (!email) {
		msg += "devi inserire l\' email.\n" ;
		sw = 1 ;
		}


		if (the_box1 == true) {
		msg += "Devi accettare la clausola.\n" ;	
		sw = 1 ;
		}
	
		if(sw == 1 ) {		
			alert(msg);
			return false ;
		}
}

function  setDefaultStyle(stile) {
	
	var ajaxObj = new ClassAJAX();
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	ajaxObj.runAJAX('./ajax/ajax.php?center=setDefaultStyle&stile='+stile) ;

	var html = "" ;
	var htmlOld = "" ;

	myInterval = window.setInterval(
	function() {
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		if (html != false) {

			if (htmlOld == html) {

				window.clearInterval(myInterval);
//alert(html) ;
				 
			}

		} else {
			//alert ("") ;
		}
	}
	,1) ;

	
}
/* LASZLO STOP HERE */

function schema() {
	var schema_container = document.createElement('div');
	schema_container.setAttribute('id','schema_container');
	document.body.appendChild(schema_container); 
	var schema_container_bg = document.createElement('div');
	schema_container_bg.setAttribute('id','schema_container_bg');
	schema_container.appendChild(schema_container_bg); 
	var schema_container_content = document.createElement('div');
	schema_container_content.setAttribute('id','schema_container_content');
	schema_container.appendChild(schema_container_content);	
	// new Ajax.Updater('vini_container_content', a, {queue: 'front'});
	$('schema_container').setStyle({
  		height: '600px',
  		width: '950px',
  		position: 'absolute',
  		left: '50%',
  		margin: '0 0 0 -475px',
  		top: '0px',
  		display: ''
	});
	$('schema_container_bg').setStyle({
		backgroundColor: '#ffffff',
  		fontSize: '12px',
  		height: '100%',
		width: '100%',
  		position: 'absolute',
  		left: '0px',
  		top: '0px',
  		display: 'none'
	});
	$('schema_container_content').setStyle({
  		position: 'absolute',
  		top: '0px',
  		display: 'none'
	});	
	new Effect.Appear('schema_container_bg', {from: 0, to: 1, queue: 'end'});
//	new Effect.Scale('vini_container_bg', 100, {scaleMode: {originalWidth: 950, originalHeight: 411}, scaleFrom: 3, scaleY: false, scaleContent: false, scaleFromCenter: false,  queue: 'end'});


// 	new Ajax.Updater('schema_container_content', url, {
// 		method: 'get',
//   		onComplete: function() {
//     	new Effect.Appear('schema_container_content', {queue: 'end'});	
//   		}
// 		});
 };


		function costiera() {
			var partenza = $('comunepartenza').value;
			var arrivo = $('comunearrivo').value;
			if (partenza == 'SORRENTO') {
				var costiera_alert = document.createElement('div');
				costiera_alert.setAttribute('id','costiera_alert');
				$('searchResult').appendChild(costiera_alert); 
				costiera_alert.appendChild(document.createTextNode("Next page"));
			}
		}
