//Ultima modifica: domenica, 10 febbraio 2008

/********************************************************************
 ************************ VARIABILI GLOBALI *************************
 ********************************************************************/
//set image paths
src = ["imm_trad_amatoriali/evidenza_1.jpg", "imm_trad_amatoriali/evidenza_2.jpg", "imm_trad_amatoriali/evidenza_3.jpg", "imm_trad_amatoriali/evidenza_4.jpg", "imm_trad_amatoriali/evidenza_5.jpg"]
//set corresponding urls
url = ["traduzioni/dune.html", "traduzioni/thief2.html", "traduzioni/darwinia.html", "traduzioni/shogun.html", "traduzioni/orion3.html"]
//set duration for each image
duration = 3;
//Please do not edit below
ads = [];
ct = 0;


/********************************************************************
 *********************** SCRIPT POP-UP VARIE ************************
 ********************************************************************/

/* Script di accesso all'area privata con gli annunci per lo staff */
function area_privata()
{
	window.open('staff/area_privata.html', '', 'width=543, height=400, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
}
function area_privata_liv1()
{
	window.open('../staff/area_privata.html', '', 'width=543, height=400, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
}

/* Script di accesso alla pagina di informazioni in inglese sul gruppo */
function english_info()
{
	window.open('english_info.html', '', 'width=543, height=400, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
}
function english_info_liv1()
{
	window.open('../english_info.html', '', 'width=543, height=400, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
}

/* Script di accesso alla pagina di informazioni sui membri del gruppo */
function git_info(name)
{
	var page = 'git/' + name + '.html';
	window.open(page, '', 'width=543, height=350, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
}


/********************************************************************
 ********************** SCRIPT PER LA RICERCA ***********************
 ********************************************************************/

/* Script di accesso alla pagina di ricerca */
function ricerca()
{
	/*var url_ricerca = 'ricerca.html?src=' + window.document.all.search_box.value + "&opz=1-2-3-4-5";*/
	var box_ricerca = window.document.getElementById('search_box');
	var url_ricerca = 'ricerca.html?src=' + box_ricerca.value + "&opz=1-2-3-4-5";
	/*var url_ricerca = 'ricerca.html?src=' + window.document.form1["search_box"].value + "&opz=1-2-3-4-5";*/
	window.location = url_ricerca;
}
function ricerca_int()
{
	var state = "";
	var name_ricerca = window.document.getElementById('search_name');
	var state_incorso = window.document.getElementById('search_state_incorso');
	var state_betatest = window.document.getElementById('search_state_betatest');
	var state_release = window.document.getElementById('search_state_release');
	var state_completato = window.document.getElementById('search_state_completato');
	var state_sospeso = window.document.getElementById('search_state_sospeso');
	
	if (state_incorso.checked == true)
		state = "1";
	if (state_betatest.checked == true)
	{
		if (state.length > 0)
			state = state + "-2";
		else
			state = "2";
	}
	if (state_release.checked == true)
	{
		if (state.length > 0)
			state = state + "-3";
		else
			state = "3";
	}
	if (state_completato.checked == true)
	{
		if (state.length > 0)
			state = state + "-4";
		else
			state = "4";
	}
	if (state_sospeso.checked == true)
	{
		if (state.length > 0)
			state = state + "-5";
		else
			state = "5";
	}
		
	var url_ricerca = 'ricerca.html?src=' + name_ricerca.value + "&opz=" + state;
	window.location = url_ricerca;
}


/********************************************************************
 ******************** SCRIPT IMMAGINI SCORREVOLI ********************
 ********************************************************************/

/* Script di selezione di immagine casuale per la pagina "traduzioni amatoriali" */
function imm_casuale()
{
	if (document.images)
		switchAd();
}
function switchAd()
{
	var n = (ct + 1) % src.length;
	if (ads[n] && (ads[n].complete || ads[n].complete == null))
	{
		document["imm_casuale"].src = ads[ct = n].src;
	}
	ads[n = (ct + 1) % src.length] = new Image;
	ads[n].src = src[n];
	setTimeout("switchAd()", duration * 1000);
}
function doLink()
{
	location.href = url[ct];
}


/********************************************************************
 *************************** ALTRI SCRIPT ***************************
 ********************************************************************/

/* Script di chiudura finestra */
function close_window()
{
	window.close();
}


/********************************************************************
 *********************** G.I.T. SEARCH ENGINE ***********************
 ********************************************************************/

/* Script per la ricerca */
function start()
{
	var cercata = document.getElementById('parola_cercata');
	var box_search = document.getElementById('search_name');
	var state_incorso = window.document.getElementById('search_state_incorso');
	var state_betatest = window.document.getElementById('search_state_betatest');
	var state_release = window.document.getElementById('search_state_release');
	var state_completato = window.document.getElementById('search_state_completato');
	var state_sospeso = window.document.getElementById('search_state_sospeso');
	
	ricerca_tot = window.location.search.substring(1);
	var pos = ricerca_tot.indexOf('=');
	var pos_and = ricerca_tot.indexOf('&');
 	ricerca = ricerca_tot.substring(pos + 1, pos_and);
	
	var parola_cercata = ricerca.replace(/%22/g, "\"");
	parola_cercata = parola_cercata.replace(/%20/g, " ");
	cercata.value = parola_cercata;
	box_search.value = parola_cercata;
	
	checkbox_tot = ricerca_tot.substring(pos_and + 1);
	var pos_chk = checkbox_tot.indexOf('=');
	checkbox = checkbox_tot.substring(pos_chk + 1);
	ar_checkbox = checkbox.split("-");
	for (s = 0; s < ar_checkbox.length; s++)
	{
		if (ar_checkbox[s] == "1")
			state_incorso.checked = true;
		else if (ar_checkbox[s] == "2")
			state_betatest.checked = true;
		else if (ar_checkbox[s] == "3")
			state_release.checked = true;
		else if (ar_checkbox[s] == "4")
			state_completato.checked = true;
		else if (ar_checkbox[s] == "5")
			state_sospeso.checked = true;
	}
	
	importXML();
}
function importXML()
{
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = createTable;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function ()
		{
			if (xmlDoc.readyState == 4)
				createTable()
		}
	}
	else
	{
		alert('La funzione di ricerca non č compatibile con questo browser');
		return;
	}
	xmlDoc.load("search.xml");
}
function createTable()
{
	var record = 0; //se resta uguale a 0, nessun record trovato
	var x = xmlDoc.getElementsByTagName('traduzione');
	var newEl = document.createElement('TABLE');
	newEl.setAttribute('cellPadding', 4);
	newEl.setAttribute('width', '100%');
	var tmp = document.createElement('TBODY');
	newEl.appendChild(tmp);
	var row = document.createElement('TR');

	for (j = 0; j < x[0].childNodes.length; j++)
	{
		if (x[0].childNodes[j].nodeType != 1)
			continue;
		var container = document.createElement('TH');
		var theData = document.createTextNode(x[0].childNodes[j].nodeName);
		container.appendChild(theData);
		row.appendChild(container);
	}

	tmp.appendChild(row);

	for (i = 0; i < x.length; i++)
	{
		var row = document.createElement('TR');

		//se corrisponde alla ricerca, inserisco il dato
		if (document.implementation && document.implementation.createDocument) //Firefox
		{
			low_1 = x[i].childNodes[1].firstChild.nodeValue.toLowerCase();
			state_1 = x[i].childNodes[5].firstChild.nodeValue.toLowerCase();
		}
		else
		{
			low_1 = x[i].childNodes[0].firstChild.nodeValue.toLowerCase();
			state_1 = x[i].childNodes[2].firstChild.nodeValue.toLowerCase();
		}
		low_2 = ricerca.toLowerCase();

		/***** CONTROLLO CARATTERI SPECIALI - INIZIO ****/
		var controllo = false;
		var controllo_stato = false;

		//controllo presenza caratteri virgolette e pių
		if (((low_2.substring(0, 3) == "%22" || low_2.substring(0, 1) == "\"") && (low_2.substring(low_2.length - 3, low_2.length) == "%22" || low_2.substring(low_2.length - 1, low_2.length) == "\"")) || (low_2.indexOf("+") >= 0))
		{
			low_2 = low_2.replace(/%22/g, "");
			low_2 = low_2.replace(/\"/g, "");
			low_2 = low_2.replace(/\+/g, " ");
			low_2 = low_2.replace(/%20/g, " ");

			if (low_1.indexOf(low_2) >= 0)
				controllo = true;
		}
		else
		{
			low_3 = low_2.split("%20");

			//esistono parole pių lunge di due caratteri?
			var controllo_lunghezza = false;
			for (h = 0; h < low_3.length; h++)
			{
				if (low_3[h].length > 2)
					controllo_lunghezza = true;
			}
		
			for (k = 0; k < low_3.length; k++)
			{
				if (((controllo_lunghezza == true) && (low_3[k].length > 2)) || (controllo_lunghezza == false))
				{
					if (low_1.indexOf(low_3[k]) >= 0)
						controllo = true;
				}
			}
		}
		/***** CONTROLLO CARATTERI SPECIALI - FINE ****/

		/***** CONTROLLO STATO - INIZIO ****/
		for (s = 0; s < ar_checkbox.length; s++)
		{
			if ((ar_checkbox[s] == "1") && (state_1.toLowerCase() == "traduzione"))
				controllo_stato = true;
			else if ((ar_checkbox[s] == "2") && (state_1.toLowerCase() == "beta test"))
				controllo_stato = true;
			else if ((ar_checkbox[s] == "3") && (state_1.toLowerCase() == "release"))
				controllo_stato = true;
			else if ((ar_checkbox[s] == "4") && (state_1.toLowerCase() == "completato"))
				controllo_stato = true;
			else if ((ar_checkbox[s] == "5") && (state_1.toLowerCase() == "sospeso"))
				controllo_stato = true;
		}
		/***** CONTROLLO STATO - FINE ****/
		
		if ((controllo == true) && (controllo_stato == true))
		{
			record = record + 1;
			for (j = 0; j < x[i].childNodes.length; j++)
			{
				if (x[i].childNodes[j].nodeType != 1)
					continue;
				var container = document.createElement('TD');
				container.setAttribute('align', 'center');
				var valore = x[i].childNodes[j].firstChild.nodeValue;
										
				if (valore.indexOf("#") < 0)
				{
					theData = document.createTextNode(valore);
				}
				else
				{
					var pos_sharp = valore.indexOf("#");
					var valore_reale = valore.substring(0, pos_sharp);
					var valore_link = valore.substring(pos_sharp + 1);
					theData = document.createElement('a');
					theData.setAttribute('href', valore_link);
					var theData2 = document.createTextNode(valore_reale);
					theData.appendChild(theData2);
				}

				container.appendChild(theData);
				row.appendChild(container);
			}
			tmp.appendChild(row);
		}
	}

	if (record == 0)
	{
		var row = document.createElement('TR');
		var container = document.createElement('TD');
		var theData = document.createTextNode('Nessuna traduzione corrispondente alla ricerca');
		container.appendChild(theData);
		row.appendChild(container);
		tmp.appendChild(row);
	}

	document.getElementById('trad_trovate').value = record;
	document.getElementById('barra_caricamento').src = "";
	document.getElementById('barra_caricamento').height = 0;
	document.getElementById('barra_caricamento').width = 0;
	document.getElementById('risultati_ricerca').appendChild(newEl);
}


/********************************************************************
 ************************ G.I.T. NEWS ENGINE ************************
 ********************************************************************/

/* Gestione vecchie news */
function start_news()
{
	num_news_tot = window.location.search.substring(1);
	var pos = num_news_tot.indexOf('=');
 	num_news = num_news_tot.substring(pos + 1);

	carica_news();
}
function carica_news()
{
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc2 = document.implementation.createDocument("", "", null);
		xmlDoc2.onload = createNews;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc2 = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc2.onreadystatechange = function ()
		{
			if (xmlDoc2.readyState == 4)
				createNews()
		}
	}
	else
	{
		alert('Questa funzione non č compatibile con il browser');
		return;
	}
	xmlDoc2.load("news.xml");
}
function createNews()
{
	var x = xmlDoc2.getElementsByTagName('notizia');
	
	if (num_news == '')
		num_news = x.length;
		
	var i = num_news - 1;
	titolo = document.createTextNode(x[i].getElementsByTagName('Titolo')[0].firstChild.nodeValue);
	prima_parte = document.createTextNode(x[i].getElementsByTagName('Prima_parte')[0].firstChild.nodeValue);
	immagine = x[i].getElementsByTagName('Immagine')[0].firstChild.nodeValue;
	commento_immagine = document.createTextNode(x[i].getElementsByTagName('Commento_immagine')[0].firstChild.nodeValue);
	seconda_parte = document.createTextNode(x[i].getElementsByTagName('Seconda_parte')[0].firstChild.nodeValue);
	
	var pos_sharp = immagine.indexOf("#");
	var alt = immagine.substring(0, pos_sharp);
	var nome_immagine = immagine.substring(pos_sharp + 1);
	var theData = document.createElement('img');
	theData.setAttribute('src', nome_immagine);
	theData.setAttribute('alt', alt);
	theData.setAttribute('width', 161);
	theData.setAttribute('height', 105);
	
	document.getElementById('titolo_news').appendChild(titolo);
	document.getElementById('prima_parte_news').appendChild(prima_parte);
	document.getElementById('immagine_news').appendChild(theData);
	document.getElementById('commento_immagine_news').appendChild(commento_immagine);
	document.getElementById('seconda_parte_news').appendChild(seconda_parte);
}


/********************************************************************
 ************************** RSS TRADUTTORE **************************
 ********************************************************************/

//Fine del documento

