// JavaScript Document
function eventRollHover(id,tag){
	if (!tag) tag = "A";
	var sfEls = $(id).getElementsByTagName(tag);
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {	
			if (this.className.search("bckRollOver")>=0){
				if (this.style.backgroundImage.search("jpg")>=0){
					this.style.backgroundImage=this.style.backgroundImage.replace('.jpg','_a.jpg');
				}else{
					this.style.backgroundImage=this.style.backgroundImage.replace('.gif','_a.gif');
				}
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className.search("bckRollOver")>=0){
				if (this.style.backgroundImage.search("jpg")>=0){
					this.style.backgroundImage=this.style.backgroundImage.replace('_a.jpg','.jpg');
				}else{
					this.style.backgroundImage=this.style.backgroundImage.replace('_a.gif','.gif');
				}
			}
		}
	}
}

function eventHover(id,tag){
	var sfEls = $(id).getElementsByTagName(tag);
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {	
			if (this.className.search("rollOver")>=0){
				if (this.src.search("jpg")>=0){
					this.src=this.src.replace('.jpg','_a.jpg');
				}else{
					this.src=this.src.replace('.gif','_a.gif');
				}
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className.search("rollOver")>=0){
				if (this.src.search("jpg")>=0){
					this.src=this.src.replace('_a.jpg','.jpg');
				}else{
					this.src=this.src.replace('_a.gif','.gif');
				}
			}
		}
	}
}

function Right(str, n){
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}
	
var totalfaq=0;

function setToggle(id,image,bck) {
	
	var sfEls = document.getElementById(id).getElementsByTagName("DIV");
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id.substring(0,4)=="main") totalfaq++;
	}	
							
	for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
	}
	
	//window.addEvent('domready', function() {
		for (var i=1;i<=totalfaq;i++){
			 eval("slide"+i+".hide();");
		}
	//});
	
	for (var i=1;i<=totalfaq;i++){
		$('toggle'+i).addEvent('click',function(e){
			i=parseInt(Right(this.id,2));
			if (isNaN(i)) i=parseInt(Right(this.id,1));									
			e = new Event(e);
			eval("slide"+i+".toggle();");
			e.stop();
			if (image)
				if (Right($('img'+i).src,7)=='piu.gif'){ 
					$('img'+i).src=$('img'+i).src.replace('piu.gif','meno.gif');
					//$('section'+i).style.visibility='hidden';
					//$('main'+i).style.background='#f4eef8';
					if (bck) { $('toggle'+i).style.background='#f2f2f2'; $('toggle'+i).style.borderBottom='none'; }
				}else {
					$('img'+i).src=$('img'+i).src.replace('meno.gif','piu.gif');
					//$('section'+i).style.visibility='visible';
					if (bck) { $('toggle'+i).style.background='#e6f5fa'; $('toggle'+i).style.borderBottom='1px solid #e4e4e4'; }
				}
		});
	}
		
	for (var i=1;i<=totalfaq;i++){
		eval("slide"+i+".addEvent('complete', function() { i=Right(this.id,2); if (isNaN(i)) i=parseInt(Right(this.id,1)); });"); 
		//if (!slide"+i+".open) $('main"+i+"').style.background='#ffffff';
	}
}

function Apri(){
	for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
		if ($('img'+i)) $('img'+i).src=$('img'+i).src.replace('piu.gif','meno.gif');
		eval("slide"+i+".show();");
		//$('main'+i).style.background='#f4eef8';
	}
}

function Chiudi(){
	for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
		if ($('img'+i)) $('img'+i).src=$('img'+i).src.replace('meno.gif','piu.gif');
		eval("slide"+i+".hide();");
		//$('main'+i).style.background='#ffffff';
	}
}

function ApriScheda(i){
	//for (var i=1;i<=totalfaq;i++){
		eval("var slide"+i+" = new Fx.Slide('section"+i+"')");
		if ($('img'+i)) $('img'+i).src=$('img'+i).src.replace('piu.gif','meno.gif');
		eval("slide"+i+".show();");
		//$('main'+i).style.background='#f4eef8';
	//}
}
	
function SubmitSearchWebSite(){
	if (document.getElementById("cerca").queryStr.value == "parola cercata...") document.getElementById("cerca").queryStr.value = ''; 
	document.getElementById("cerca").submit();
}

function toggleSitemap(id) {
	if ($('img'+id)) {
		if (Right($('img'+id).src,7)=='piu.gif')
			$('img'+id).src=$('img'+id).src.replace('piu.gif','meno.gif');
		else
			$('img'+id).src=$('img'+id).src.replace('meno.gif','piu.gif');
	}
	if ($(id)) {
		if ($(id).style.display == 'none') $(id).style.display='block';
		else $(id).style.display='none';
	}
}
var countItem;
countItem = 0;
function toggleAllSitemap() {
	if (countItem > 0){
		for (i=0; i<=countItem; i++) { 
			toggleSitemap('titolo'+i);
		}
	}
}

function toggleSitemapSubEmpty(id) {
	if ($('img'+id)) {
		if (Right($('img'+id).src,7)=='piu.gif')
			$('img'+id).src=$('img'+id).src.replace('piu.gif','menuSelect.gif');
	}
}
