//Funzioni per la simulazione animazione accordin mootools
function aprichiudi(tagID, strOnOff){
	
	if(tagID != '' && document.getElementById(tagID) != null){
		
		if(strOnOff == 'ON'){
			document.getElementById(tagID).style.display = "block";
		}
		if(strOnOff == 'OFF'){
			document.getElementById(tagID).style.display = "none";
		}
	}
}

function changeColorToAccessLink(src, onLink, isAccessible){
	if(!isAccessible){
		if (onLink){
			src.style.color = "red";		
		}else{
			src.style.color = "#3D5F94";		
		}
	}
}
function changeColorToAccessLinkDOC(IDcontenuto, onLink, isAccessible){
	var idTag = "Titolo" + IDcontenuto;
	if(!isAccessible){
		if (onLink){
			document.getElementById(idTag).style.color = "red";
		}else{
			document.getElementById(idTag).style.color = "#3D5F94";
		}
		
	}
}

function TimerInEvidenza(totContenuti, pathimg){
	var tim = setTimeout('cambiaContenuto('+totContenuti+',"'+pathimg+'")', 5000);
}

function cambiaContenuto(maxElem, pathimg){
	var progressivo = calcolaprogressivo();
	
	//Aggiunta di 1 unità per proseguire
	progressivo += 1;

	if (progressivo >= maxElem) {
		progressivo = 1;
	}
	
	for (var i=1; i<maxElem; i++) { 
		if (i != progressivo){
			document.getElementById("panel"+i).className = "pannelloOFF";
			document.getElementById("img"+i).src = pathimg + "ballOFF.png";
			
		}else{
			document.getElementById("panel"+i).className = "pannelloON";
			document.getElementById("img"+i).src = pathimg + "ballON.png";
		}
	}
}

function calcolaprogressivo(){
	var elementi = new Array();
	elementi = document.getElementsByName("imgballs");
	
	for (var i=0; i<elementi.length; i++){
		presenza = elementi.item(i).src.indexOf('ON');
		
		if (presenza != -1){ 
			progressivo = i + 1;
			return progressivo;
		}
	}
}

function eliminatesto(el){
	if (el.value == el.defaultValue) 
		el.value = "";
}

function ripristina(el){
	if (el.value == "") 
			el.value = el.defaultValue;
}

function prec_di_1(totaleContenuti, pathimg) {
	
	clearInterval(this.tim);
	clearInterval(this.intervallo);
	
	var numpross = calcolaprogressivo();
	
	if(numpross >= 1) numpross -=1;
	if(numpross < 1) numpross = totaleContenuti-1;
	
	for (var i=1; i<totaleContenuti; i++) { 
		if (i != numpross){
			document.getElementById("panel"+i).className = "pannelloOFF";
			document.getElementById("img"+i).src = pathimg + "ballOFF.png";
			
		}else{
			document.getElementById("panel"+i).className = "pannelloON";
			document.getElementById("img"+i).src = pathimg + "ballON.png";
		}
	}
}

function succ_di_1(totaleContenuti, pathimg) {
	
	clearInterval(this.tim);
	clearInterval(this.intervallo);
	
	var numpross = calcolaprogressivo();
	
	if(numpross < totaleContenuti) numpross += 1;
	if(numpross == totaleContenuti) numpross = 1;
	
	for (var i=1; i<totaleContenuti; i++) { 
		if (i != numpross){
			document.getElementById("panel"+i).className = "pannelloOFF";
			document.getElementById("img"+i).src = pathimg + "ballOFF.png";
		}else{
			document.getElementById("panel"+i).className = "pannelloON";
			document.getElementById("img"+i).src = pathimg + "ballON.png";
		}
	}
}

function caricaimage(pathimage, pagecode){
	if (pagecode == "homepage"){
// Get the time now and convert to UTC seconds
		var today = new Date();
		var now = today.getUTCSeconds();
	}
// Get the cookie
	var cookie = document.cookie;
	var cookieArray = cookie.split('; ');

	if (cookie){	
		var num = Math.round(8*Math.random());
		document.getElementById('viewimg').src=pathimage+"testata/header"+num+".png";
	}
}

function contaImmagini (thefolder){
	var myObject, f, filesCount;
    myObject = new ActiveXObject ( "Scripting.FileSystemObject" );
    f = myObject.GetFolder ( thefolder );
    filesCount = f.files.Count;
    
    alert("There are "+i+" picture files in "+thefolder+"\n\nThey are:\n\n"+filesCount);
	
}

	
function calcolaprossimo(verso,prefisso){
	var elementi = new Array();
	elementi = document.getElementsByName(prefisso);
	var classe = "NO";
	
	for (var i=1; i<elementi.length; i++){
 
		classe = document.getElementById("GAL"+i).className;
		
		if (classe == "visibile"){
			if (verso == "d"){ progressivo = i + 1; }
			else { progressivo = i - 1; }
			
			return progressivo;
		}
	}
	
	if (verso == "s" && progressivo == elementi.length){ progressivo -= 1; }
	return progressivo;
}

function scorriimmagine(verso, id){
		
	var appo_numtotElementi = document.getElementsByName("numerototcomposito");
	var numtotElementi = appo_numtotElementi[0].value;
	
	var posizione = calcolaprossimo(verso, "imageGallery");
	
	if(posizione == numtotElementi ){
		document.getElementById("frecciadx").className = "novisibile";
		document.getElementById("frecciasx").className = "visibile";
	}
	if(posizione == 1 ){
		document.getElementById("frecciasx").className = "novisibile";
		document.getElementById("frecciadx").className = "visibile";
	}
	if(posizione > 1 && posizione < numtotElementi){
		document.getElementById("frecciasx").className = "visibile";
		document.getElementById("frecciadx").className = "visibile";
	}

	for (var i=1; i<=numtotElementi; i++) {
		
		if (posizione != i){
			document.getElementById("GAL"+i).className = "novisibile";
		} else {
			document.getElementById("GAL"+i).className = "visibile";
		}
	}
}


function printWindow() {
	Window.print();
} 

//Funz per la simulazione animazione accordin mootools
function accordin(tagID, numtotElem, tipoC){
	
	if(tagID != '' && document.getElementById(tagID) != null){
		if(document.getElementById(tagID).style.display == "block") {
			document.getElementById(tagID).style.display = "none";
		}else{
			document.getElementById(tagID).style.display = "block";
		}
	}

	if (tipoC != '' ){ parametro = "conta_"+ tipoC + "_";}
	else {parametro = "prop";}
	
	for(i=0; i < numtotElem; i++){
		if(document.getElementById(parametro + i).style.display == "block" && (parametro + i) != tagID  ){
			document.getElementById(parametro + i).style.display = "none";
		}
	}
}

function MessaggioBrowserObsoleto(page, url){
	var engine = null;
	if (window.navigator.appName == "Microsoft Internet Explorer"){
	// This is an IE browser. What mode is the engine in?
		if (document.documentMode >= 8){ // IE8 or later
			engine = document.documentMode;
		} else { // IE 5-7
			if(page != 'errorpage'){window.location = url;}
			else{
				engine = 5; // Assume quirks mode unless proven otherwise
				if (document.compatMode){
					if (document.compatMode == "CSS1Compat")
					engine = 7; // standards mode
				}
			// There is no test for IE6 standards mode because that mode  
			// was replaced by IE7 standards mode; there is no emulation.
			}
		}
		// the engine variable now contains the document compatibility mode.
	}
}

function mexErrorBrowser (testo, pathimg, url){
	var sengine = null;
	
	if (window.navigator.appName == "Microsoft Internet Explorer"){
	// This is an IE browser. What mode is the engine in?
		if (document.documentMode >= 8){ // IE8 or later
			engine = document.documentMode;
			window.location = url;
		}
		else // IE 5-7
		{
			engine = 5; // Assume quirks mode unless proven otherwise
			if (document.compatMode){
				if (document.compatMode == "CSS1Compat")
					engine = 7; // standards mode
			}
		// There is no test for IE6 standards mode because that mode  
		// was replaced by IE7 standards mode; there is no emulation.
			document.getElementById('MEXALLERTAVERSIE').innerHTML = '<img src="' + pathimg + '120px_warning_yellow.png" alt="Avviso" /><p>' + testo + '</p>';
		}
	// the engine variable now contains the document compatibility mode.
	}
}

function contenutorandom (totContent, tc) {
	
	var randomnumber = Math.floor(Math.random()*totContent);
	var id = 0;
	for (i=0; (i < totContent); i++){
		id = tc + i;
		if (i == randomnumber){
			document.getElementById(id).className = "displayON";
		}else {
			document.getElementById(id).className = "displayOFF";
		}
		
	}
}
