function showList(alink, key, statusOn, statusOff) {

 	var list = document.getElementById('tornei' + key);

	if (statusOn == alink.innerHTML) {
		list.style.visibility = 'hidden';
		list.style.display = 'none';
		alink.innerHTML = statusOff;
	}
	else {
		list.style.visibility = 'visible';
		list.style.display = 'block';
		alink.innerHTML = statusOn;
	}
	return false;
}

function setArrow(thisBut) {

	var buttons = 10;
	for (b=0; b < buttons; b++)
		document.getElementById('fr' + b).style.backgroundImage = 'url(../img/punta_matita.png)';
	var arrow = document.getElementById('fr' + thisBut).style;
	arrow.backgroundImage = 'url(../img/punta_matita_sel.png)';
}

function getContent(filename, thisBut, tID, sez, lang) {

	ajaxRun(filename + '.php?tID=' + tID + '&q=' + sez + '&l=' + lang, 'ajaxcontent');
	setArrow(thisBut);
}

function getData(filename, tID) {

	ajaxScript(filename + '.php?tID=' + tID);
}

function ajaxRun(request, div) {

            var oXmlHttp = zXmlHttp.createRequest();
            oXmlHttp.open("get", request + "&div=" + div, true);
            oXmlHttp.onreadystatechange = function () {
                if (oXmlHttp.readyState == 4) {
                    if (oXmlHttp.status == 200) {
						if (request.indexOf('mappa') != -1) {
							var data = oXmlHttp.responseText.split("||");
							showInfo(data[0], div);
							setvisible('', 0, 'map');
							GoogleLoad(data[1],data[2],data[3]);
						}
                        else showInfo(oXmlHttp.responseText, div);
                    } else {
                        showInfo("Impossibile recuperare i dati: " + oXmlHttp.statusText, div); //statusText is not always accurate
                    }
                }            
            };
            oXmlHttp.send(null);
}

function ajaxScript(request) {

            var oXmlHttp = zXmlHttp.createRequest();
            oXmlHttp.open("get", request, true);
            oXmlHttp.onreadystatechange = function () {
                if (oXmlHttp.readyState == 4) {
                    if (oXmlHttp.status == 200) {
						var data = oXmlHttp.responseText;
						eval(data);
					} else {
                        showInfo("Impossibile recuperare i dati: " + oXmlHttp.statusText, div); //statusText is not always accurate
                    }
				}
            };
            oXmlHttp.send(null);
}

function replaceAll (text, strTarget, strSubString) {

	var intIndexOfMatch = text.indexOf(strTarget);
	while (intIndexOfMatch != -1){
		text = text.replace(strTarget, strSubString);
		intIndexOfMatch = text.indexOf(strTarget);
	}
	return text;
}

function showInfo(sText, div) {

	var htmlent = new Array("&agrave;", "&egrave;", "&eacute;", "&igrave;", "&ograve;", "&oacute;", "&ugrave", "&euro;", "", "&#39;");
	var utf8 = new Array("à", "è", "é", "ì", "ò", "ó", "ù", "€", "\\", "'");
	var place = document.getElementById(div);
	for (i=0; i < htmlent.length; i++) sText = replaceAll(sText, utf8[i], htmlent[i]);
	place.innerHTML = sText;
}

function initHidden(div, liv) {

	for (i=0; i < liv; i++) {
		var dom = document.getElementById(div + i).style;
		dom.display = 'none';
	}
}

function setvisible(div, numdiv, actual) {

	for (i=0; i < numdiv; i++) document.getElementById(div + i).style.display = 'none';
	var dom = document.getElementById(div + actual).style;
	dom.display = 'block';
}

function toggleTransl(div, numdiv) {
	last = parseInt(numdiv) - 1;
	if (document.getElementById(div + last).style.display == 'block') status = 'none';
	else status = 'block';
	for (i=0; i < numdiv; i++) document.getElementById(div + i).style.display = status;
}

function activeChoice(div, numq) {

	var langs = new Array ("it","en","es","de","fr");

	for (i=0; i < numq; i++) {
		var dom = document.getElementById(div + '_' + i);

		if (dom.disabled == true) {
			if (document.getElementById(div + '_td'))
				document.getElementById(div + '_td').className = 'active';
			dom.disabled = false;
			dom.className = 'active';
			for (x=0; x < langs.length; x++)
				document.getElementById(div + '_' + langs[x] + '_' + i).className = 'active';
		}
		else if (dom.disabled == false) {
			if (document.getElementById(div + '_td'))
				document.getElementById(div + '_td').className = 'deactive';
			dom.disabled = true;
			dom.className = 'deactive';
			for (x=0; x < langs.length; x++)
				document.getElementById(div + '_' + langs[x] + '_' + i).className = 'deactive';
		}
	}
}

function activeRow(div, numq) {

	for (i=0; i < numq; i++) {
		var dom = document.getElementById(div + '_' + i);

		if (dom.className == 'deactive') {
			dom.className = 'active';
		}
		else if (dom.className == 'active') {
			dom.className = 'deactive';
		}
	}
}

function mapCoordinate(oForm) {
	
	var value = oForm.maplink.value;
	var chop = value.split('&ll=');
	var grades = chop[1].split('&');
	var coord = grades[0].split(',');
	oForm.mapLAT.value = coord[0];
	oForm.mapLONG.value = coord[1];
	oForm.maplink.value = '';
}

function myFader(tot) {
	
	this.tot = tot;
	this.index = 1;
	this.delay = 4000;
	this.toFade = function() {
		if (document.getElementById('fade'+this.index)) {
			var fadeid = document.getElementById('fade'+this.index);
			for (var j=this.index-1;j>=1;j--) {
				var fadeids = document.getElementById('fade'+j);
				fadeids.style.zIndex = j+1;
			}
			fadeid.style.zIndex = 1;
		}
		this.index--;
		if (this.index == 0) this.index = this.tot;
	}
	this.start = function() {
		for (var x=1;x<=this.tot;x++) {
			if (!document.getElementById('fade'+x)) {
				this.index = x-1;
				this.tot = this.index;
				break;
			}
		}
		var thisObj = this;
		setInterval(function() {thisObj.toFade();}, this.delay);
	}
}