activeGroup = 1;
activeForm = 1;


////////////////////////////////
// Caricamento Box

//Event.observe(window,'load',logoAppearAndObserve);
Event.observe(window,'load',getSearchForms);

function showLogo(){
	
	$('BIGlogoGIF').show();
	$('miniforms').hide();
}

function hideLogo(){

	$('BIGlogoGIF').hide();
	$('miniforms').show();
}


/*
function logoAppearAndObserve()
{
	var myLogoBox = $('BIGlogo');
	var  DIVClassName = "miniforms";
	
	if (myLogoBox != null) {
			myLogoBox.style.display = 'block';
			//Event.observe('BIGlogoGIF' , 'mouseover' , bigDiv.enter.bindAsEventListener(bigDiv));	
			//Event.observe(DIVClassName , 'mouseout' , bigDiv.exit.bindAsEventListener(bigDiv));
	}
}
*/

function getSearchForms()
{

		if(idTestata){
			//window.open('/ajax/SearchTestata.asp?IDCMS='+idTestata+'&s='+ sTestata);
			new Ajax.Request('/ajax/SearchTestata.asp?IDCMS='+idTestata+'&s='+ sTestata, {
				onSuccess: function(requester){
											var mStatus = $('miniforms').visible();
											$('miniforms').replace(requester.responseText);
											if (mStatus){
												$('miniforms').show();
											}else{
												$('miniforms').hide();
											}
											Event.observe('miniforms' , 'mouseout' , bigDiv.exit.bindAsEventListener(bigDiv));
											startSearchTestata();
										    },
				onFailure: function(){}
				});
		}

}
///////////////////////////////



function startSearchTestata()
{
	var  DIVClassName = "miniforms";
	var TimeMsg = "1>  " + TimeDemo();
  
	//obj.hide();	
	//Event.observe('BIGlogoGIF' , 'mouseover' , bigDiv.enter.bindAsEventListener(bigDiv));	
	//Event.observe(DIVClassName , 'mouseout' , bigDiv.exit.bindAsEventListener(bigDiv));

	//nasconde i gruppi di liv2 a parte il primo
  TimeMsg += "\n  a-  " + TimeDemo();		
	var liv2groups= $(DIVClassName).getElementsByClassName('liv2-group');
  TimeMsg += "\n  b-  " + TimeDemo();	
	for (var i=1; i < liv2groups.length ; i++) {
		liv2groups[i].hide();
	}
  TimeMsg += "\n  c-  " + TimeDemo();	
  TimeMsg += "\n2>  " + TimeDemo();

	//associa mostra/nascondi gruppo alle voci liv1
	var vociLiv1= $(DIVClassName).getElementsByClassName('liv1');
	for (i=0; i < vociLiv1.length ; i++  ) {
		Event.observe(vociLiv1[i], 'click' , sottoVoci.inverti.bindAsEventListener(sottoVoci));
	
	}
	
  TimeMsg += "\n3>  " + TimeDemo();	

	//associa handle/menu gruppo alle voci liv2
	var vociLiv2= $(DIVClassName).getElementsByClassName('liv2-OFF');
	for (i=0; i < vociLiv2.length ; i++) {
		Event.observe(vociLiv2[i], 'click' , miniForm.handle.bindAsEventListener(miniForm));
	}
	
  TimeMsg += "\n4>  " + TimeDemo();	
	
	//associa handle/menu gruppo alle voci liv2
	vociLiv2= $(DIVClassName).getElementsByClassName('liv2-ON');
	for (i=0; i < vociLiv2.length ; i++) {
		Event.observe(vociLiv2[i], 'click' , miniForm.handle.bindAsEventListener(miniForm));
	}	

  TimeMsg += "\n5>  " + TimeDemo();

	//visualizza disponibilità dettagliata
  Event.observe(document.f1_1.dispDett, 'click', dispDett.vis.bindAsEventListener(dispDett), false);
  Event.observe(document.f1_2.dispDett, 'click', dispDett.vis.bindAsEventListener(dispDett), false);
  Event.observe(document.f1_3.dispDett, 'click', dispDett.vis.bindAsEventListener(dispDett), false);	

    
  TimeMsg += "\n6>  " + TimeDemo(); 
 
  $('BIGlogo').show();
  
  //new Effect.Grow($('BIGlogo'));
  
  
  TimeMsg += "\n7>  " + TimeDemo();
  
  //alert(TimeMsg);
}


function TimeDemo()
{
  var d, s = "The current local time is: ";
  var c = ":";
  d = new Date();
  s += d.getHours() + c;
  s += d.getMinutes() + c;
  s += d.getSeconds() + c;
  s += d.getMilliseconds();
  return(s);
}



var sottoVoci = {
	inverti: function (event){
		var containerDiv = Event.findElement(event, 'div');
		var selectedGroup =  containerDiv.next();
		
		var oldId = 'formLabel_' + activeGroup + '_' + activeForm ;
		var old = $(oldId);
		//setta lo stile della vecchia label a OFF;
		Element.removeClassName(old,'liv2-ON');
		Element.addClassName(old,'liv2-OFF');
		//nasconde vecchio form
		$('form_' + activeGroup + '_' + activeForm).hide();
		$('groupLabel_' + activeGroup).next().hide();

		//var tmp = containerDiv.id.split('_'))
		activeGroup = containerDiv.id.split('_')[1]
		activeForm = 1;
		
		//accendere il gruppo di sottovoci
		selectedGroup.show();
		//accendere la label
		var nextLabel = $('formLabel_' + activeGroup + '_' + activeForm);
		Element.removeClassName(nextLabel,'liv2-OFF');
		Element.addClassName(nextLabel,'liv2-ON'); 		
		//mostrare il miniform 
		
		$('form_' + activeGroup + '_' + activeForm).show();
		

	}
} //sottoVoci


var miniForm = {
	handle: function (event){

		var oldId = 'formLabel_' + activeGroup + '_' + activeForm ;
		var old = $(oldId);
		//setta lo stile della vecchia label a OFF;
		Element.removeClassName(old,'liv2-ON');
		Element.addClassName(old,'liv2-OFF');
		//nasconde vecchio form
		$('form_' + activeGroup + '_' + activeForm).hide();


		var containerDiv = Event.findElement(event, 'div');	
		var tmp = containerDiv.id.split('_');
		activeGroup = tmp[1];
		activeForm = tmp[2];
		//setta lo stile della label a ON;
		Element.removeClassName(containerDiv,'liv2-OFF');
		Element.addClassName(containerDiv,'liv2-ON'); 
		//mostra nuovo form
		$('form_' + activeGroup + '_' + activeForm).show();
				
		//alert(activeGroup+', '+activeForm);
	}	
} //miniForm





var bigDiv = {
	enter: function(event){
		$('BIGlogoGIF').hide();
		$('miniforms').show();
			
	}, //enter

	exit: function(event){
		//var elt = Event.findElement(event, 'div');
    var reltg =  $( (event.relatedTarget) ? event.relatedTarget : event.toElement ); //browser dipendent !!!
    if(reltg == null)return;
    
    /*while (reltg  != $('DIV_PopData') && reltg.nodeName != 'HTML')    
      reltg = reltg.up();
    if (reltg == $('DIV_PopData')) return;*/
    
    //reltg =  $( (event.relatedTarget) ? event.relatedTarget : event.toElement ); //browser dipendent !!!
    while (reltg  != $('miniforms') && reltg.nodeName != 'HTML') 
				reltg = reltg.up();
		if ( reltg.id != 'miniforms') {
			$('miniforms').hide();
			//$('DIV_SearchPopData').update('');
			//fVisTags();                        //funzione contenuta in CalendaPopup.js
			$('BIGlogoGIF').show();
		}
	}//exit
} //bigDiv



	
var dispDett = {
	vis: function (event){
	   var ObjDispDett = $('form_' + activeGroup + '_' + activeForm).down('div.divdispo');
		//var ObjDispDett = $('divdispo_' + activeGroup + '_' + activeForm);
		if(ObjDispDett.visible())
	  {
      ObjDispDett.hide();
	  }
	  else
	  {
      ObjDispDett.show();
    }
	}
}
