var Accordion = Class.create({
	
    initialize: function(ObjID, options){		
		var accordion = this;		
        this.ContainerID 	= ObjID;
		this.ActiveItem 	= false;		
        var items = $$('#' + this.ContainerID + ' H4').each(function(item, i){			
            item.onclick = function(){
				accordion.toggleItem(item.identify());
            }
			item.onmouseover = function(){
                this.style.cursor = 'pointer';
            }
        });
        if (options != null && options.openedItem != null) 
            this.toggleItem(options.openedItem);        
    },
    
    toggleItem: function(itemID){
        this.reset();
        if (this.ActiveItem != $(itemID)) {
            $(itemID).next(1).style.display = 'block';
            new Effect.Morph($(itemID).next(1), {
                style: {
                    height: $(itemID).next(1).childElements()[0].offsetHeight + 'px'
                },
                duration: .4
            });
            Element.addClassName($(itemID), 'on');
            this.ActiveItem = $(itemID);
        }
        else 
            this.ActiveItem = false;
    },
    
    reset: function(){
        var items = $$('#' + this.ContainerID + ' H4').each(function(item, i){
            if (Element.hasClassName(item, "on")) {
                new Effect.Morph(item.next(1), {
                    style: {
                        height: '0px'
                    },
                    duration: .4
                });
                Element.removeClassName(item, 'on');                
            }
        });
    }
});


function openFaq(u,w,h){
	window.open(u,'FAQ','height='+h+',width='+w+',scrollbars=no,menubar=no,resizable=0,status=no');	
}

function loadPage(u,t){
 var links = $('accordion').getElementsByTagName('A');
 for(var i=0;i<links.length;i++){  
  links[i].style.color = "#666666";
 }
 t.style.color = "#e1011b"; 
 
 $('content').innerHTML = '<div style="text-align:center; padding:50px 0; color:#666; font-size:12px;">Caricamento...<br /><img src="/ucfin/htdocs/i/faq/loading.gif" alt="loading..." /></div>';
 new Ajax.Updater('content',u,{method:'get',asynchronous:true,evalScripts:true,parameters:{type:t.innerHTML}});

 var h4 = t.up('div.accordionItem').previous('h4');
	var res = h4.innerHTML;
	var txt = res.split('>')[res.split('>').length-1];

 $('path').innerHTML = 'Home &gt; '+ txt +' &gt; '+ t.innerHTML;
}

function loadPageSearch(u,t){
    
    var param=document.forms[0].stringa.value;
    var length = param.length;
    if(length==0)
    {
      alert("Attenzione devi cercare almeno una parola!!");
    }
    else
    {
	new Ajax.Updater('content',u+param,{method:'get',asynchronous:true,evalScripts:true,parameters:{type:t.innerHTML}});
	}
}

function loadForm(t){
	if(t){
		var idFaq = t.id;
		var strTesto =  t.parentNode.innerHTML.split('linkReq')[0];		
		var lastChar = strTesto.substr(strTesto.length-1,strTesto.length);
		if(lastChar=='"'){var xyz = 10;}else{var xyz = 9;}		
		var testo = strTesto.substr(0,strTesto.length-xyz);
		var title = t.parentNode.parentNode.previous(1);		
		var tit = title.innerHTML;
		var sub = $('path').innerHTML;
		var uffCat=t.parentNode.parentNode.ufficioCategoria;
		var mail = t.parentNode.mailUfficio;
		if((typeof(mail))=='undefined'){mail='no';}
		if(sub=='&nbsp;'){
			var h4Form = t.up('div.accordionItem').previous('h4');
			var resForm = h4Form.innerHTML;
			var txtForm = resForm.split('>')[resForm.split('>').length-1];
			sub = 'Home &gt; '+ txtForm;	
			
		}
		else
		{	
				
			if( ( uffCat!='' && 'Home > '+ uffCat != sub.replace(/&gt;/g,'>')) && !((typeof(uffCat))=='undefined')   ){
		
			var h4CercaForm = t.up('div.accordionItem').previous('h4');
			var resCercaForm = h4CercaForm.innerHTML;
			var txtCercaForm = resCercaForm.split('>')[resCercaForm.split('>').length-1];
		    sub = 'Home &gt; '+ txtCercaForm;
			
			}
			else{
			sub = $('path').innerHTML;
			
			}
		}
		new Ajax.Updater('content','/ucfin/jsp/faq/faqForm.jsp',{
						 onComplete:function(){
								if($('question')){									
										$('question').innerHTML = '<h4>'+tit+'</h4><p>'+testo+'</p>';
										$('idFaq').value = idFaq;
										$('percorso').value = sub;
										$('domanda').value = tit;
										$('risposta').value = testo;
										$('mailUfficio').value = mail;
									}
							},
						method:'get', 
						asynchronous:true,
						evalScripts:true
			});
	}else{
		var sub = $('path').innerHTML;
		if(sub=='&nbsp;'){
			sub = 'Home';	
		}
		new Ajax.Updater('content','/ucfin/jsp/faq/faqForm.jsp',{
			             onComplete:function(){
			                    if($('question')){
			                    	    $('question').innerHTML = '';
			                    	    $('percorso').value = sub;
			                    	    $('mailUfficio').value = mail;
			                     }
			               },
			               method:'get',
			               asynchronous:true,
			               evalScripts:true
			               });
		
	}
}


window.onload = function(){
	if($('accordion')){
		img1= new Image(35,35);
		img1.src="/ucfin/htdocs/i/faq/loading.gif";
		new Accordion ('accordion');
	}
}

function show() {
	//im = document.body;
	//altz=im.scrollHeight;
	overlayer=document.getElementById('overlay');
	overlayer.style.display='block';
	//overlayer.style.height=altz;
	document.getElementById('lightbox').style.display='block';
	document.getElementById('over_1').style.display='block';
}

function closeP(overClose) {
	document.getElementById('overlay').style.display='none';
	IDClose=overClose.parentNode.parentNode.parentNode.id;
	document.getElementById(IDClose).style.display='none';
}

