// JavaScript Document

function loadObj()
{
	
	var net=new Object();				//Istanziazione di un oggetto, al momento vuoto
		
	net.READY_STATE_UNINITIALIZED=0;
	net.READY_STATE_LOADING=1;
	net.READY_STATE_LOADED=2;
	net.READY_STATE_INTERACTIVE=3;
	net.READY_STATE_COMPLETE=4;
	
	net.ContentLoader=function(url,onload,onerror)		//Definizione di un metodo costruttore dell'oggetto. Di cui solo url è necessario
	{
		this.url=url;
		this.req=null;
		this.onload=onload;
		this.onerror=(onerror) ? onerror : this.defaultError;		//Può gestire gli errori con una funzione definita a parte e nel caso non sia stata definita allora usa quella di default.
		this.loadXMLDoc(url);
	}

	net.ContentLoader.prototype=
	{
		loadXMLDoc:function(url)
		{
			if (window.XMLHttpRequest)
			{
				this.req=new XMLHttpRequest();
			} 
			else if (window.ActiveXObject)
			{
				this.req=new ActiveXObject("Microsoft.XMLHTTP");
			}
	
		if (this.req)
		{
			try
			{
				var loader=this;
				this.req.onreadystatechange=function()
				{
					loader.onReadyState.call(loader);
				}
		
				this.req.open('GET',url,true);
				this.req.send(null);
			}
			catch (err)
			{
				this.onerror.call(this);
			}
		}
	},
	
	
	onReadyState:function()
	{
		var req=this.req;
		var ready=req.readyState;
		if (ready==net.READY_STATE_COMPLETE)
		{
			var httpStatus=req.status;
			if (httpStatus==200 || httpStatus==0)
			{
				this.onload.call(this);
			}
			else
			{
				this.onerror.call(this);
			}
		}
	},
	
	defaultError:function()
	{
		alert	(	
					"error fetching data!"
					+"\n\nreadyState:"	+ this.req.readyState
					+"\nstatus: "		+ this.req.status
					+"\nheaders: "		+ this.req.getAllResponseHeaders()
				);
		}
	}
	
	var menu_news	= new net.ContentLoader('artax.xml', index);
}		
		//====================================================================================================================//

function index(xmldoc) 
{

	//Variabili globali
	var xmldoc = this.req.responseXML;
	var contentPlace = document.getElementById('content');
	
	var language = null;
	
	//Serve per memorizzare il colore del nav bar
	var navBarPreviousCss = null;
	
	// Images paths
	var imageMed	= './immagini/prodotti/immagini_med/';
	var imageHigh	= './immagini/prodotti/immagini_high/';
	
	var selectedPage = null;


	//Funzioni di servizio
	
	function nodeCleaner (nodeName)
	{
		var parentNode = document.getElementById(nodeName);
		
		if (parentNode.firstChild !== null)
		{
			while (parentNode.firstChild !== null)
			{
				parentNode.removeChild(parentNode.firstChild);
			}
		}
	}
	
	function nodeCleaner2 (nodeName)
	{
		var node = document.getElementById(nodeName);
		
		if (node !== null)
		{	
			if (node.firstChild !== null) 
			{
				while (node.firstChild !== null)
				{
					node.removeChild(node.firstChild);
				}
			}
			return node;
		}
		else
		{
			//alert('node not find');
			return null;
		}
		
	}
	
	function createDivWithIdAndAppendTo( idName, parentNodeNameToAppend )
	{
		var div = document.createElement('div');
		div.setAttribute('id', idName);
		parentNodeNameToAppend.appendChild(div);
		return div;
	}
	
	function div_css_creator(object, css)
	{
		if(object !== null)
		
		{
			var div = document.createElement('div');
			div.appendChild(object);
			div.className=css;
		}	
		return div;
	}
	
	function removeNodeById(nodeId)
	{
		var node = document.getElementById(nodeId);
	
		if (node != null)
		{
			var  parentNode = node.parentNode;
			parentNode.removeChild(node);	
		}
		
	}

	function setTitleByPageId(page_id)
	{
		var buttonFetch = xmldoc.getElementsByTagName('bottone'+language);
		
		var i = 0;
		
		for (var i=0; i < buttonFetch.length; i++)
		{
			if ( buttonFetch[i].getAttribute('page_id') == page_id) 
			{
				var titleDiv = div_css_creator(document.createTextNode(buttonFetch[i].firstChild.data), 'content_title_of_the_page');
		
				contentPlace.appendChild(titleDiv);
			}
		}	
	}
	
	function setTitleByText(text)
	{
		var titleDiv = div_css_creator(document.createTextNode(text), 'content_title_of_the_page');
		contentPlace.appendChild(titleDiv);	
	}

	//Funzioni per creazione elementi della pagina
		
	function createNavBar()
	{
		
		
		var menuFragment 	= document.createDocumentFragment();
		var menuButtons		= xmldoc.getElementsByTagName('bottone'+language);
		
		var ul = menuFragment.appendChild(document.createElement('ul'));
			ul.setAttribute('id','ul-nav-bar');
	
		var t = menuButtons.length;
		
		for (var i=0; i < menuButtons.length; i++)
		{
			t--;
			var visibility 	= menuButtons[t].getAttribute('visibile');
			var page_id 	= menuButtons[t].getAttribute('page_id');
			
			//Filtro sui bottoni
			if ( visibility == '1' )
			{
				var li 	= ul.appendChild(document.createElement('li'));				
					li.appendChild(document.createTextNode(menuButtons[t].firstChild.data)); 
					li.setAttribute('id', page_id);
					li.style.cursor='pointer';
					li.className ='li-nav-bar';
					li.onclick=navBarEventListener;
					li.onmouseover=navBarOnMouseOver;
					li.onmouseout=navBarOnMouseOut; //Some problems for safari
					
				ul.appendChild(li);
					
			}
			
		}
		var navBarPlace = document.getElementById('navigationBar');
			navBarPlace.appendChild(menuFragment);
		
		function navBarOnMouseOver ()
		{
			var selectedButton = document.getElementById(this.id);
			
			navBarPreviousCss = selectedButton.className;
			selectedButton.className='li-nav-bar-selected';
		}
		
		function navBarOnMouseOut()
		{
			var selectedButton = document.getElementById(this.id);
			selectedButton.className=navBarPreviousCss;
		}
	}

	function navBarSelectedButton(id)
	{
		//Ho aggiunto questa riga per safari che è molto attento al mouse out 
		navBarPreviousCss='li-nav-bar-selected'
		
		nodeCleaner('navigationBar');
		createNavBar();
		var selectedButton = document.getElementById(id);
		
		selectedButton.className='li-nav-bar-selected';
	}
	
	function createLanguageBar()
	{
		function identifyBrowserLanguage()
		{
			// Operatore condizionale per FF e SS prima e IE6 e IE7 poi
			var test=navigator.language? navigator.language : navigator.userLanguage
			switch (test) {
			
				case 'it':
					language = '_it';
				break;
					
				case 'fr':
					language = '_fr';
				break;
					
				case 'de':
					language = '_de';
				break;
					
				default:
					language = '_en';
			}
		}
		
		identifyBrowserLanguage();
		
		var langPlace 		= document.getElementById('languageBar');
		var langFragment 	= document.createDocumentFragment();
			
		var form = document.createElement('form');
		form.setAttribute('name','language');
		form.setAttribute('action','');
		langFragment.appendChild(form);
		
		var label = document.createElement('label');
		label.appendChild(document.createTextNode('Language: '))
		form.appendChild(label);

		var select = document.createElement('select');
		select.onchange=setLanguageEventListener;
		form.appendChild(select);
	
	
		function languageLabelInsert(language)
		{
			var option = document.createElement('option');
			option.appendChild(document.createTextNode(language));
			select.appendChild(option);
		}
		
		languageLabelInsert('select');
		languageLabelInsert('Italiano');
		languageLabelInsert('English');
		languageLabelInsert('Deutsch');
		languageLabelInsert('Français');
		
		langPlace.appendChild(langFragment);
		
		function setLanguageEventListener() 
		{
			if		(this.options[1].selected) language = '_it'; 
			else if	(this.options[2].selected) language = '_en';
			else if	(this.options[3].selected) language = '_de';
			else if	(this.options[4].selected) language = '_fr';
			
			nodeCleaner('navigationBar');
			nodeCleaner('content');
			createNavBar();
			homePage();
		}
	}
	
	function navBarEventListener()
	{
		selectedPage = this.id;

		function loadPage(page)
		{
			switch(page)
			{
				/*Ho eliminato filosofia ed aggiornato i numeri di riferimento togliendo 1*/
				
				case 'home':
				 	homePage(page);
				break;
				
				case 'philosophy':
				 	filosofia();
				break;
				
				case 'products':
				 	prodotti(page,1);
				break;
				
				case 'catalogue':
				 	catalogo(page);
				break;
				
				case 'news':
				 	//news(0);
				break;
				
				case 'future':
				 	prodotti(page,0);
				break;
			
				case 'form':
				 	//form();
				break;
				
				case 'contatcs':
				 	contatti(page);
				break;
							
				case 'awards':
				 	//news(1);
				break;	
				
				case 'catalogs':
				 	//news(1);
				break;  	
			}
		}
				
		navBarSelectedButton(selectedPage);
		loadPage(selectedPage);
	}

	//Pagine del sito internet
	
	function homePage(page)
	{
		nodeCleaner('content');
		
		var selectedButton = document.getElementById('home');
			
			selectedButton.className='li-nav-bar-selected';
		
		var homePageFragment = document.createDocumentFragment();
		
		var homePageImage = document.createElement('img');
			homePageImage.setAttribute('src', 'home.jpg');
			
			//definizione di formato momentanea
			//homePageImage.width='100%';
			//homePageImage.height='100%';
		
		var homePageImageDiv = div_css_creator(homePageImage, 'homePageimageDiv');

		
		homePageFragment.appendChild(homePageImageDiv);
		contentPlace.appendChild(homePageFragment);
	}

	function contatti(page)
		{
			nodeCleaner('content');
			setTitleByPageId(page);
			
			var contactsFragment = document.createDocumentFragment();
			
			function createDivAndCss (css_name)
			{
				var div = document.createElement('div');
					div.setAttribute('id', css_name); 
				return div;
			}
			
			var subContentDiv =	document.createElement('div');
				subContentDiv.className='contatti_SubContent';
				contactsFragment.appendChild(subContentDiv);
			
			var contatti_information_positionbox = createDivAndCss ('contatti_information_positionbox');
				subContentDiv.appendChild(contatti_information_positionbox);
				
			var contatti_information_content = createDivAndCss ('contatti_information_content');
				contatti_information_positionbox.appendChild(contatti_information_content);
					
			var contatti_googlemaps_positionbox = createDivAndCss ('contatti_googlemaps_positionbox');
				subContentDiv.appendChild(contatti_googlemaps_positionbox);
			
			var contatti_googlemaps_content = createDivAndCss ('contatti_googlemaps_content');
				contatti_googlemaps_positionbox.appendChild(contatti_googlemaps_content);	
			
			var contatti_titolo 		= xmldoc.getElementsByTagName('contatti_titolo' + language);
			
			var contatti_orari_titolo	= xmldoc.getElementsByTagName('contatti_orari_titolo' + language);
			var contatti_orari 			= xmldoc.getElementsByTagName('contatti_orari' + language);
			var contatti_telefono_label = xmldoc.getElementsByTagName('contatti_telefono_label' + language);
			var contatti_indirizzo_label= xmldoc.getElementsByTagName('contatti_indirizzo_label' + language);
			var contatti_email_label	= xmldoc.getElementsByTagName('contatti_email_label');
			var contatti_email 			= xmldoc.getElementsByTagName('contatti_email');
			var contatti_numero_tel 	= xmldoc.getElementsByTagName('contatti_numero_tel');
			var contatti_numero_fax 	= xmldoc.getElementsByTagName('contatti_numero_fax');
			
			var contatti_vacanze 		= xmldoc.getElementsByTagName('contatti_vacanze' + language);
			var googlemaps				= xmldoc.getElementsByTagName('contatti_googlemaps');
			
			
			//var contatti_immagine		= xmldoc.getElementsByTagName('contatti_immagine');
			
			
			var contatti_googlemaps_iframe_src 	= xmldoc.getElementsByTagName('contatti_googlemaps_iframe_src' + language);
			var contatti_googlemaps_link_src	= xmldoc.getElementsByTagName('contatti_googlemaps_link_src' + language);
			var contatti_googlemaps_link_testo	= xmldoc.getElementsByTagName('contatti_googlemaps_link_testo' + language);
			
			var googlemaps_width 	=  googlemaps[0].getAttribute('width');
			var googlemaps_height 	=  googlemaps[0].getAttribute('height');
			
			var googleFrame = document.createElement('iframe');
				contatti_googlemaps_content.appendChild(googleFrame);
				
				googleFrame.setAttribute('id', 'contatti_googlemaps_iframe');
				googleFrame.setAttribute('width', googlemaps_width);
				googleFrame.setAttribute('height', googlemaps_height);
				googleFrame.setAttribute('frameborder', '0');
				googleFrame.setAttribute('scrolling', 'no');
				googleFrame.setAttribute('marginheight', '0');
				googleFrame.setAttribute('marginwidth', '0');
				googleFrame.setAttribute('src', contatti_googlemaps_iframe_src[0].firstChild.data);
							
			var smallTag   = document.createElement('small');
			var googleLink = document.createElement('a');
				smallTag.appendChild(googleLink);
				googleLink.setAttribute('href', contatti_googlemaps_link_src[0].firstChild.data);
				googleLink.setAttribute('target', 'parent');
				googleLink.setAttribute('id','googleLink');
				googleLink.appendChild(document.createTextNode(contatti_googlemaps_link_testo[0].firstChild.data));
				googleLink.className='googleLink';
				contatti_googlemaps_content.appendChild(smallTag);
			
			
			function addParagraphAndCss (text, css)
			{
				if (text !== '---')
				{
					var paragraph = document.createElement('p');
					paragraph.appendChild(document.createTextNode(text));
					paragraph.className=css;	
					
					contatti_information_content.appendChild(paragraph);
					
					return paragraph;
				}	
			}
			
			addParagraphAndCss(contatti_orari_titolo[0].firstChild.data, 'contatti_orari_titolo');
			addParagraphAndCss(contatti_orari[0].firstChild.data, 'contatti_orari');

			
			function createRecord (label, data)
			{
			var contatti_table_recod_box = document.createElement('div');
				contatti_table_recod_box.className='contatti_table_recod_box';
				contatti_information_content.appendChild(contatti_table_recod_box);
					
			var contatti_table_label_box = document.createElement('div');
				contatti_table_label_box.className='contatti_table_label_box';
				contatti_table_label_box.appendChild(document.createTextNode(label));
				contatti_table_recod_box.appendChild(contatti_table_label_box);
			
			var contatti_table_data_box = document.createElement('div');
				contatti_table_data_box.className='contatti_table_data_box';
				contatti_table_data_box.appendChild(document.createTextNode(data));
				contatti_table_recod_box.appendChild(contatti_table_data_box);
			}
			
			createRecord(contatti_email_label[0].firstChild.data, contatti_email[0].firstChild.data);
			createRecord(contatti_telefono_label[0].firstChild.data, contatti_numero_tel[0].firstChild.data);
			createRecord('Fax:', contatti_numero_fax[0].firstChild.data);
			
			
			addParagraphAndCss(contatti_vacanze[0].firstChild.data, 'contatti_vacanze');
				
			contentPlace.appendChild(contactsFragment);	
			
			layout();					
		}				

	function prodotti(page,choice)
	{
		nodeCleaner('content');
		setTitleByPageId(page);
		
		var titleOfThePage = page;
		var contentAcciariniFragment 	= document.createDocumentFragment();
		var contentProductsListFragment = document.createDocumentFragment();
		
		function acciarini ()
		{
			var pf_family	 		= xmldoc.getElementsByTagName('pf_family');
			var pf_images			= xmldoc.getElementsByTagName('pf_images');

			var table = document.createElement('table');
				table.setAttribute('id', 'prodotti_tabella_acciarini'); 
			var subContentTable = div_css_creator(table, 'prodotti_SubContent');
									
			var header		= table.createTHead();
			
			function insertImage(imagePath, id, cellPlace)
			{
				var image = document.createElement('img');
					image.setAttribute('src', imagePath);
					image.setAttribute('id', id);
					image.onclick=productList;
					image.style.cursor='pointer';
				
				var tableCel = tableRow.insertCell(cellPlace);
					tableCel.appendChild(image);
					tableCel.className='prodotti_acciarini_td';
			}
			
			function insertLabel(labelNode, cellPlace)
			{
				var cell 	= tableRow.insertCell(cellPlace);
					cell.className='prodotti_acciarini_td';
				var label 	= document.createTextNode(labelNode);
				var div		= div_css_creator(label, 'prodotti_acciariniLabel');
					cell.appendChild(div);
			}
			
			var tableRow = header.insertRow(0);
							
			insertImage(pf_images[0].firstChild.data, 0 , 0);
			insertImage(pf_images[1].firstChild.data, 1 , 1);
			insertImage(pf_images[2].firstChild.data, 2 , 2);
			
			
			var tableRow = header.insertRow(1);
			
			insertLabel(pf_family[0].firstChild.data, 0);
			insertLabel(pf_family[1].firstChild.data, 1);
			insertLabel(pf_family[2].firstChild.data, 2);
			
			var tableRow = header.insertRow(2);
			
			insertImage(pf_images[3].firstChild.data, 3 , 0);
			insertImage(pf_images[4].firstChild.data, 4 , 1);
			insertImage(pf_images[5].firstChild.data, 5 , 2);
			
			var tableRow = header.insertRow(3);
			
			insertLabel(pf_family[3].firstChild.data, 0);
			insertLabel(pf_family[4].firstChild.data, 1);
			insertLabel(pf_family[5].firstChild.data, 2);

			contentPlace.appendChild(subContentTable);
		}

		//Acciarini non ha listener in quanto chiama direttamente ProductList e mediante id associato a div
		//ProductList riconosce il chiamante
		
		
		//Product list contiene tutte le altre pagine perchè tutte hanno SearchAndStatus box
		//Se volessi dividerle dovrei portare fuori tutte le variabili di riferimento	
		function productList ()
		{
			nodeCleaner('content');
			setTitleByPageId(titleOfThePage);
			
			// Variabili di ricerca
			var selected_production = choice;
			var selected_family 	= this.id;
			var selected_type		= '-1';
			var page = 0;	
			
			// Vecchie variabili mantenute ai fini della formattazione
			//var old_selected_family = null;
			//var old_selected_type 	= null;
			var old_selected_record = null;
			//var old_selected_id 	= null;
			
			var pf_family			= xmldoc.getElementsByTagName('pf_family');
			var pf_images_low		= xmldoc.getElementsByTagName('pf_images_low');
			var pt_type 			= xmldoc.getElementsByTagName('pt_type' + language);
				
			var pr_nome 			= xmldoc.getElementsByTagName('pr_nome');
			var pr_famiglia			= xmldoc.getElementsByTagName('pr_famiglia');
			var pr_tipo				= xmldoc.getElementsByTagName('pr_tipo');
			var pr_produzione		= xmldoc.getElementsByTagName('pr_produzione');
			
			var pr_image_med 		= xmldoc.getElementsByTagName('pr_image_med');
			var pr_image_high 		= xmldoc.getElementsByTagName('pr_image_high');
			var pr_descrizione 		= xmldoc.getElementsByTagName('pr_descrizione' + language);
			var messaggio 			= xmldoc.getElementsByTagName('messaggio' + language);
			
			//Informazioni per dettagli tecnici del prodotto
	
			var pr_codice 					= xmldoc.getElementsByTagName('pr_codice');
			var pr_mlaic1 					= xmldoc.getElementsByTagName('pr_mlaic1');
			var pr_mlaic2 					= xmldoc.getElementsByTagName('pr_mlaic2');
			var pr_mlaic3 					= xmldoc.getElementsByTagName('pr_mlaic3');
			var pr_calibro 					= xmldoc.getElementsByTagName('pr_calibro');
			var pr_rigatura 				= xmldoc.getElementsByTagName('pr_rigatura');
			var pr_passo_mm 				= xmldoc.getElementsByTagName('pr_passo_mm');
			var pr_passo_inc 				= xmldoc.getElementsByTagName('pr_passo_inc');
			var pr_lunghezza_totale_mm 		= xmldoc.getElementsByTagName('pr_lunghezza_totale_mm');
			var pr_lunghezza_totale_inc 	= xmldoc.getElementsByTagName('pr_lunghezza_totale_inc');
			var pr_peso_kg 					= xmldoc.getElementsByTagName('pr_peso_kg');
			var pr_peso_lbs 				= xmldoc.getElementsByTagName('pr_peso_lbs');
			var pr_proiettile1 				= xmldoc.getElementsByTagName('pr_proiettile1');
			var pr_proiettile2 				= xmldoc.getElementsByTagName('pr_proiettile2');
			var pr_mira1 					= xmldoc.getElementsByTagName('pr_mira1' + language);
			var pr_mira2 					= xmldoc.getElementsByTagName('pr_mira2' + language);
			var pr_scatto 					= xmldoc.getElementsByTagName('pr_scatto' + language);
			var pr_note 					= xmldoc.getElementsByTagName('pr_note' + language);
			
			var pr_lunghezza_canna_lama_flettente_mm = xmldoc.getElementsByTagName('pr_lunghezza_canna_lama_flettente_mm');
			var pr_lunghezza_canna_lama_flettente_inc = xmldoc.getElementsByTagName('pr_lunghezza_canna_lama_flettente_inc');

			var det_nome 					= xmldoc.getElementsByTagName('det_nome' + language);
			var det_acciarino				= xmldoc.getElementsByTagName('det_acciarino' + language);
			var det_tipo					= xmldoc.getElementsByTagName('det_tipo' + language);
			var det_codice 					= xmldoc.getElementsByTagName('det_codice' + language);
			var det_mlaic 					= xmldoc.getElementsByTagName('det_mlaic' + language);
			var det_calibro 				= xmldoc.getElementsByTagName('det_calibro' + language);
			var det_rigatura 				= xmldoc.getElementsByTagName('det_rigatura' + language);
			var det_passo 					= xmldoc.getElementsByTagName('det_passo' + language);
			var det_lunghezza_canna 		= xmldoc.getElementsByTagName('det_lunghezza_canna' + language);
			var det_lunghezza_lama 			= xmldoc.getElementsByTagName('det_lunghezza_lama' + language);
			var det_lunghezza_flettente 	= xmldoc.getElementsByTagName('det_lunghezza_flettente' + language);
			var det_lunghezza_totale		= xmldoc.getElementsByTagName('det_lunghezza_totale' + language);
			var det_peso 					= xmldoc.getElementsByTagName('det_peso' + language);
			var det_proiettile 				= xmldoc.getElementsByTagName('det_proiettile' + language);
			var det_mira 					= xmldoc.getElementsByTagName('det_mira' + language);
			var det_scatto 					= xmldoc.getElementsByTagName('det_scatto' + language);
			var det_note					= xmldoc.getElementsByTagName('det_note' + language);
					
			var productFragment = document.createDocumentFragment();
			
			var subContentProductDiv_layer 	= createDivWithIdAndAppendTo('subContentProductDiv_layer', productFragment);
			var subContentProductDiv_box 	= createDivWithIdAndAppendTo('subContentProductDiv_box', subContentProductDiv_layer);
			
			var searchAndStatus_layer 		= createDivWithIdAndAppendTo('searchAndStatus_layer', subContentProductDiv_box);
			var searchAndStatus_box 		= createDivWithIdAndAppendTo('searchAndStatus_box', searchAndStatus_layer);
								
			contentPlace.appendChild(productFragment);
			
			function initialize()
			{
				var productList_layer 			= createDivWithIdAndAppendTo('productList_layer', subContentProductDiv_box);
				var productPreview_layer 		= createDivWithIdAndAppendTo('productPreview_layer', subContentProductDiv_box);
				
				var productList_box 			= createDivWithIdAndAppendTo('productList_box', productList_layer);
				var productPreview_box 			= createDivWithIdAndAppendTo('productPreview_box', productPreview_layer);
			}
			
			// SearchAndStatus_box: menù di preselezione del prodotto
			function create_searchAndStatus_box(selected_family)
			{
				nodeCleaner ('searchAndStatus_box');
				
				var searchAndStatus_box = document.getElementById('searchAndStatus_box');
				
				var imageDiv					= createDivWithIdAndAppendTo('searchAndStatus_image_div', searchAndStatus_box);
				var searchAndStatus_family_div 	= createDivWithIdAndAppendTo('searchAndStatus_family_div', searchAndStatus_box);
				
				for (i=0; i<pf_family.length; i++ )
				{
					var familyDiv 	= createDivWithIdAndAppendTo( i, searchAndStatus_family_div);
					
					//var familyDiv = document.createElement('div');
						//familyDiv.setAttribute('id', i);
						familyDiv.appendChild(document.createTextNode(pf_family[i].firstChild.data));
						familyDiv.onclick=searchAndStatusProductFamilyListener;
						familyDiv.style.cursor='pointer';
						
						if( selected_family == i)
						{
							familyDiv.className='searchAndStatus_selected_buttons';
							old_selected_family = familyDiv;
						}
						else
						{
							familyDiv.className='searchAndStatus_buttons';
						}
						//searchAndStatus_family_div.appendChild(familyDiv);
				}
				
				var typeDiv = document.createElement('div');
					typeDiv.setAttribute('id', 'searchAndStatus_type_div');
					searchAndStatus_box.appendChild(typeDiv);
				
				update_searchAndStatus_box();
				create_productPreview_box(null);
				
				create_productList_box(choice, selected_family, '-1');	
			}
			
			function update_searchAndStatus_box()
			{
				var searchAndStatus_image_div = nodeCleaner2 ('searchAndStatus_image_div');
				var acciarino_image = document.createElement('img');
					acciarino_image.setAttribute('src', pf_images_low[selected_family].firstChild.data);
				searchAndStatus_image_div.appendChild(acciarino_image);
				
				var searchAndStatus_type_div = nodeCleaner2('searchAndStatus_type_div');
						
				var type_all_div = createDivWithIdAndAppendTo('-1', searchAndStatus_type_div);
					type_all_div.appendChild(document.createTextNode(messaggio[2].firstChild.data));
					type_all_div.onclick=searchAndStatusProductTypeListener;
					type_all_div.style.cursor='pointer';	
				
				if( selected_type == -1)
				{
					type_all_div.className='searchAndStatus_selected_buttons';
					old_selected_type = type_all_div;
				}
				else
				{
					type_all_div.className='searchAndStatus_buttons';
				}
				
				for (t=0; t<5; t++) //Aumentare qui il numero di sottocategorie per famiglia, ora sono 4.
				{
					
					var pt_type_selected = pf_family[selected_family].getAttribute('ptype'+t);
					
					if (pt_type_selected !== '-')
					{
						var type_div = document.createElement('div');
							type_div.setAttribute('id', pt_type_selected);
							type_div.appendChild(document.createTextNode(pt_type[pt_type_selected].firstChild.data));
							type_div.onclick=searchAndStatusProductTypeListener;
							type_div.style.cursor='pointer';
							type_div.className='searchAndStatus_buttons';
							searchAndStatus_type_div.appendChild(type_div);	
					}
				}
			}
			
			function searchAndStatusProductFamilyListener()
			{
				page = 0;
				
				removeNodeById('productDettail_table_layer_1');
				removeNodeById('productDettail_table_layer_2');
				
				//Mi serve per capire in quale layout mi trovo
				var productList_box = document.getElementById('productList_box');	
				
				//La famiglia di prodotti selezionata precedentemente viene riformattata
					old_selected_family.className='searchAndStatus_buttons';					
				
				if (selected_family != this.id || productList_box === null)
				{
					//debugger;
					//Ogni volta che viene selezionato un nuovo accacciarino il valore
					//predefinito per la tipologia di prodotti è: tutti, quindi -1
					selected_type = -1
					
					//La famiglia di prodotti selezionata precedentemente viene riformattata
					old_selected_family.className='searchAndStatus_buttons';					
					
					//La nuova famiglia viene formatatta e memorizzata
					this.className='searchAndStatus_selected_buttons';
					selected_family = this.id;
					old_selected_family = this;
					
					//Questa funzione aggiorna immagine e tipologia di prodotto per famiglia
					update_searchAndStatus_box();	
				
					create_productList_box(selected_production, selected_family, selected_type);
				}
					
				
				// Nel caso in cui productPreview_box sia stato pulito, lo ripristina
				var test = document.getElementById('productPreview_box');
				if ( test.firstChild == null)
				{
					create_productPreview_box(old_selected_id);
				}
				
			}
			
			function searchAndStatusProductTypeListener()
			{
				page = 0;
				
				removeNodeById('productDettail_table_layer_1');
				removeNodeById('productDettail_table_layer_2');
				
				// id è -2 quando la funzione viene chiamata da productDettail.
				if (this.id != '-2')
				{
					old_selected_type.className = 'searchAndStatus_buttons'; 			
					this.className='searchAndStatus_selected_buttons';
					old_selected_type = this; 
					selected_type = this.id;
				}
				
				
				
				create_productList_box(selected_production, selected_family, selected_type);
				
				// Nel caso in cui productPreview_box sia stato pulito, lo ripristina
				var test = document.getElementById('productPreview_box');
				if ( test.firstChild == null)
				{
					create_productPreview_box(old_selected_id);
				}
			}

			//ProductList: lista dei prodotti filtrati da SearchAndStatux_box
			function create_productList_box(production_product, family_product, type_product)
			{
				var productList_box = nodeCleaner2 ('productList_box');
				
				var rightProduct = new Array(); 

				if (productList_box == null)
				{
					initialize();
					var productList_box = document.getElementById('productList_box');
					removeNodeById('productDettail_picture_layer');
					removeNodeById('productDettail_description_layer');
				
				}
				
				var productList_title = document.createElement('div');
					productList_title.setAttribute('id', 'productList_title');
					productList_box.appendChild(productList_title);
					
				var record_title_box = document.createElement('div');
					record_title_box.className='record_title_box';
					//record_title_box.appendChild(document.createTextNode('Nome prodotto'));
					//record_title_box.appendChild(document.createTextNode(pf_family[selected_family].firstChild.data));
					record_title_box.appendChild(document.createTextNode(messaggio[3].firstChild.data));
					
					
					
					productList_title.appendChild(record_title_box);
					
				var record_type_box = document.createElement('div');	
					record_type_box.className='record_type_box';	
					//record_type_box.appendChild(document.createTextNode('Tipo'));
					
					var type_label = messaggio[4].firstChild.data;
					
					record_type_box.appendChild(document.createTextNode(type_label));
					
					productList_title.appendChild(record_type_box);

				var productList_list = document.createElement('div');
					productList_list.setAttribute('id', 'productList_list');
					productList_box.appendChild(productList_list);
				
				
				var notFoundTester = 0;
				
				var rightProductCounter = 0;
				
				for (i=0; i<pr_nome.length; i++)
				{
					//L'ordine degli if è stato organizzato per escludere quanti più record al primo ciclo
					if ( pr_famiglia[i].firstChild.data ==  selected_family )
					{
						if ( pr_tipo[i].firstChild.data == type_product || type_product == '-1' )
						{
							if ( pr_produzione[i].firstChild.data == production_product )
							{
								//Array che archivia gli indici che soddisfano i criteri di selezione
								rightProduct [rightProductCounter]=i;
								rightProductCounter++;
							}
						}
					}	
				}
				
				
				function productListUpdate(rightProduct, selectedPage) 
				{
					var recordNumber = 12;
					
					//Arrotonda per eccesso la divisione
					var pagesNumber = Math.ceil(rightProduct.length/recordNumber);
					
					var firstProduct = selectedPage * recordNumber;
					
					if ( (firstProduct + recordNumber) < rightProduct.length)
					{
						var lastProduct = firstProduct + recordNumber;
					}
					else 
					{
						//var lastProduct = rightProduct.length;
						var lastProduct = firstProduct + recordNumber;
					}
					
					for (i=firstProduct; i< lastProduct; i++)
					{
						var record_layer = document.createElement('div');
							record_layer.className='record_layer';
								
						var record_box = document.createElement('div');
							record_layer.appendChild(record_box);
					
						if ( i < rightProduct.length )
						{
								//if ( i != old_selected_id )
								//{
									record_box.className='record_box';
								//}
								//else
								//{
									//record_box.className='record_selected_box';
								//}
								record_box.style.cursor='pointer';
								record_box.setAttribute('id', rightProduct[i]);
								record_box.onclick=productListListener;
								
							
							var record_title_box = document.createElement('div');
								record_title_box.className='record_title_box';
								record_title_box.appendChild(document.createTextNode(pr_nome[rightProduct[i]].firstChild.data));
								record_box.appendChild(record_title_box);
								
							var record_type_box = document.createElement('div');	
								record_type_box.className='record_type_box';
							
							//var indice = pr_tipo[i].firstChild.data;
								record_type_box.appendChild(document.createTextNode(pt_type[pr_tipo[rightProduct[i]].firstChild.data].firstChild.data));
								record_box.appendChild(record_type_box);
							
							productList_list.appendChild(record_layer);
							notFoundTester++;
						}
						// Questa doppia condizione serve per quanto specificato sotto e per evitare spazi vuoti in caso di nessun record presente
						if ( i >= rightProduct.length && rightProduct.length > 0)
						//Soluzione poco elegante per mantenere la barra della pagina alla stessa altezza con linee vuote ed invisibili
						{
							record_box.className='record_box_hidden';
							var record_title_box = document.createElement('div');
								record_title_box.className='record_title_box_hidden';
								record_title_box.appendChild(document.createTextNode('vuota'));
								record_box.appendChild(record_title_box);
								productList_list.appendChild(record_layer);
								
						}
					
					}
					
				
					if ( rightProduct.length > recordNumber)
					{
						var productListPage_layer 	= createDivWithIdAndAppendTo('productListPage_layer', productList_box);
						var productListPage_box 	= createDivWithIdAndAppendTo('productListPage_box', productListPage_layer);
						

						productListPage_box.appendChild(document.createTextNode(messaggio[7].firstChild.data));
						for (i=0; i<pagesNumber; i++ )
						{
							productListPage_box.appendChild(document.createTextNode(' '));
							var productListPage = document.createElement('div');
								
								if (i == selectedPage)
								{
									productListPage.className='productListPage_selected'
								}
								else
								{
									productListPage.className='productListPage';
								}

								productListPage.style.cursor='pointer';
								productListPage.appendChild(document.createTextNode(i+1));
								productListPage.setAttribute('id', i);
								productListPage.onclick=pageSelect;
								productListPage_box.appendChild(productListPage);
								
						}
						
					}
				
					if (notFoundTester == 0)
					{
						//var productList_box = nodeCleaner2 ('record_layer');
						var noItemFound = createDivWithIdAndAppendTo('productList_noItemFound', productList_list);
						noItemFound.appendChild(document.createTextNode(messaggio[0].firstChild.data));
					}
				}
				
				function pageSelect()
				{
					page = this.id;
					create_productList_box(production_product, family_product, type_product);
				}
				
				
				productListUpdate(rightProduct, page);
				
			}
			
			function productListListener ()
			{
				var prova = old_selected_record;
				//debugger;
				if (old_selected_record != null)
				{
					old_selected_record.className='record_box';
				}
				this.className='record_selected_box';
				old_selected_record = this;
				old_selected_id = this.id;
				create_productPreview_box(this.id);

			}
			
			//Product_preview: box di anteprima del prodotto selezionato con bottone per passaggio alla pagina succesiva
			function create_productPreview_box(index)
			{

				var previewDiv = nodeCleaner2 ('productPreview_box');
				
				var productPreview_box = document.getElementById('productPreview_box');
				
				var title = document.createElement('div');
					title.setAttribute('id', 'product_preview_title');
					//title.appendChild(document.createTextNode(pr_nome[index].firstChild.data));
				previewDiv.appendChild(title);
				
				var image_layer = document.createElement('div');
					image_layer.setAttribute('id', 'product_preview_image_layer');
					
				previewDiv.appendChild(image_layer);
								
				var image_box = document.createElement('div');
					image_box.setAttribute('id', 'product_preview_image_box');
					image_box.style.cursor='pointer';
					
					
				function light()
				{
					
					var link = document.createElement('a');
						link.setAttribute('href', imageHighTemp);
						link.setAttribute('id', 'imageLinkLight');
						link.setAttribute('rel', 'lightbox');
					
					//initialize();
					myLightbox.start(link);
				}
					
				image_layer.appendChild(image_box);
				
				var preview_link = document.createElement('div');
				preview_link.setAttribute('id', 'product_preview_link');
				//preview_link.appendChild(document.createTextNode('Dettagli prodotto'));
				preview_link.onclick=productPreviewListener;
				preview_link.style.cursor='pointer';
				productPreview_box.appendChild(preview_link);
	
				//document.getElementById('image_box').style.background = 'url(.\immagini\prodotti\immagini_med\MR11DOM_med.gif);';
				
				var imageHighTemp = null;
				
				if (index != null)
				{
					
					title.appendChild(document.createTextNode(pr_nome[index].firstChild.data));
					
					var imageHighTemp = imageHigh + pr_image_high[index].firstChild.data;
					image_box.onclick=light;
					
					
					var imageX = new Image()
						imageX.src = imageMed + pr_image_med[index].firstChild.data;
						imageX.id = 'product_preview_image';
					image_box.appendChild(imageX);
						
					preview_link.appendChild(document.createTextNode(messaggio[1].firstChild.data));
				}
			}
			
			function productPreviewListener ()
			{
				removeNodeById('productList_layer');
				removeNodeById('productPreview_layer');
				productDettail();	
			}
			
			
			//ProductDettail: pagina dei dettagli tecnici del prodotto.
			function productDettail()
			{
				var productDettail_picture_layer 	= createDivWithIdAndAppendTo('productDettail_picture_layer', subContentProductDiv_box);
				var productDettail_description_layer= createDivWithIdAndAppendTo('productDettail_description_layer', subContentProductDiv_box);
				
				var productDettail_picture_box 		= createDivWithIdAndAppendTo('productDettail_picture_box', productDettail_picture_layer);
				var productDettail_description_box 	= createDivWithIdAndAppendTo('productDettail_description_box', productDettail_description_layer);
				
				var productDettail_image_layer 	= createDivWithIdAndAppendTo('productDettail_image_layer', productDettail_picture_box);
				var productDettail_image_box	= createDivWithIdAndAppendTo('productDettail_image_box', productDettail_image_layer);
				var productDettail_link_layer	= createDivWithIdAndAppendTo('productDettail_link', productDettail_picture_box);
				
				var productDettail_title		= createDivWithIdAndAppendTo('productDettail_title', productDettail_description_box);
				var productDettail_description	= createDivWithIdAndAppendTo('productDettail_description', productDettail_description_box);
				var productDettail_back			= createDivWithIdAndAppendTo('productDettail_back', productDettail_description_box);
				
				function light()
				{
					
					var link = document.createElement('a');
						link.setAttribute('href', imageHigh + pr_image_high[old_selected_id].firstChild.data);
						link.setAttribute('id', 'imageLinkLight');
						link.setAttribute('rel', 'lightbox');
					myLightbox.start(link);
				}
				
				var imageX = new Image()
					imageX.src = imageMed + pr_image_med[old_selected_id].firstChild.data;
					imageX.id = 'product_preview_image';
					productDettail_image_box.appendChild(imageX);
					productDettail_image_box.onclick=light;
					productDettail_image_box.style.cursor='pointer';
			
				productDettail_link_layer.appendChild(document.createTextNode(messaggio[5].firstChild.data));
				productDettail_link_layer.style.cursor='pointer';
				productDettail_link_layer.onclick=productDettail_page;
				
				productDettail_title.appendChild(document.createTextNode(pr_nome[old_selected_id].firstChild.data));
				productDettail_description.appendChild(document.createTextNode(pr_descrizione[old_selected_id].firstChild.data));
				
				productDettail_back.appendChild(document.createTextNode(messaggio[6].firstChild.data));
				productDettail_back.style.cursor='pointer';
				productDettail_back.setAttribute('id', '-2');
				productDettail_back.className='productDettail_back';
				productDettail_back.onclick=searchAndStatusProductTypeListener;
				
				
				
				function productDettail_page()
				{
					removeNodeById('productDettail_picture_layer');
					removeNodeById('productDettail_description_layer');
					
					var productDettail_table_layer_1 	= createDivWithIdAndAppendTo('productDettail_table_layer_1', subContentProductDiv_box);
					var productDettail_table_layer_2	= createDivWithIdAndAppendTo('productDettail_table_layer_2', subContentProductDiv_box);
					
					var productDettail_table_box_1 	= createDivWithIdAndAppendTo('productDettail_table_box_1', productDettail_table_layer_1);
					var productDettail_table_box_2 	= createDivWithIdAndAppendTo('productDettail_table_box_2', productDettail_table_layer_2);
				
					var productDettail_table_1 = createDivWithIdAndAppendTo('productDettail_table_1', productDettail_table_box_1);
					var productDettail_table_2 = createDivWithIdAndAppendTo('productDettail_table_1', productDettail_table_box_2);
					
					
					
					function addLineToTable(column, label_1, data_1, data_2, data_3)
					{
						if (column == 1)
						{
							var parentTable = productDettail_table_1
						}
						else 
						{
							var parentTable = productDettail_table_2
						}
						
						
						if ( (data_1 != null) && (data_1 !='---') )
						{
							var productDettail_table_recod_box = document.createElement('div');
								productDettail_table_recod_box.className='productDettail_table_recod1_box';
								parentTable.appendChild(productDettail_table_recod_box);
									
							var productDettail_table_label_box = document.createElement('div');
								productDettail_table_label_box.className='productDettail_table_label_box';
								productDettail_table_label_box.appendChild(document.createTextNode(label_1));
								productDettail_table_recod_box.appendChild(productDettail_table_label_box);
							
							var productDettail_table_data1_box = document.createElement('div');
								productDettail_table_data1_box.className='productDettail_table_data_box';
								productDettail_table_data1_box.appendChild(document.createTextNode(data_1));
								productDettail_table_recod_box.appendChild(productDettail_table_data1_box);
						
							if ( data_2 != null && data_2 !='---')
							{
								var productDettail_table_label_box = document.createElement('div');
									productDettail_table_label_box.className='productDettail_table_label_box';
									productDettail_table_recod_box.appendChild(productDettail_table_label_box);
								
								var productDettail_table_data2_box = document.createElement('div');
									productDettail_table_data2_box.className='productDettail_table_data_box';
									productDettail_table_data2_box.appendChild(document.createTextNode(data_2));
								
									productDettail_table_recod_box.appendChild(productDettail_table_data2_box);
									productDettail_table_recod_box.className='productDettail_table_recod2_box';
							
							
								if ( data_3 != null && data_3 !='---')
								{
									var productDettail_table_label_box = document.createElement('div');
										productDettail_table_label_box.className='productDettail_table_label_box';
										productDettail_table_recod_box.appendChild(productDettail_table_label_box);
										
									var productDettail_table_data3_box = document.createElement('div');
										productDettail_table_data3_box.className='productDettail_table_data_box';
										productDettail_table_data3_box.appendChild(document.createTextNode(data_3));
										
										productDettail_table_recod_box.appendChild(productDettail_table_data3_box);
										productDettail_table_recod_box.className='productDettail_table_recod3_box';
								}
							}			
						}	
					}
					addLineToTable( 1, det_nome[0].firstChild.data, pr_nome[old_selected_id].firstChild.data);
					
					addLineToTable( 1, det_acciarino[0].firstChild.data, pf_family[pr_famiglia[old_selected_id].firstChild.data].firstChild.data );
					addLineToTable( 1, det_tipo[0].firstChild.data, pt_type[pr_tipo[old_selected_id].firstChild.data].firstChild.data );
					addLineToTable( 1, det_codice[0].firstChild.data, pr_codice[old_selected_id].firstChild.data);
					addLineToTable( 1, det_mlaic[0].firstChild.data, pr_mlaic1[old_selected_id].firstChild.data, pr_mlaic2[old_selected_id].firstChild.data, pr_mlaic3[old_selected_id].firstChild.data);
					
					addLineToTable( 2, det_calibro[0].firstChild.data, pr_calibro[old_selected_id].firstChild.data);
					addLineToTable( 2, det_rigatura[0].firstChild.data, pr_rigatura[old_selected_id].firstChild.data);
					addLineToTable( 2, det_passo[0].firstChild.data, pr_passo_inc[old_selected_id].firstChild.data, pr_passo_mm[old_selected_id].firstChild.data);
					addLineToTable( 2, det_lunghezza_totale[0].firstChild.data, pr_lunghezza_totale_inc[old_selected_id].firstChild.data, pr_lunghezza_totale_mm[old_selected_id].firstChild.data);
					
					//In base alla tipologia del prodotto ne decide la dicitura corretta.
					var familyLabel = null;
					
					switch (pr_tipo[old_selected_id].firstChild.data)
					{
						case '0':
							familyLabel = det_lunghezza_canna[0].firstChild.data;
						break;
						
						case '1':
							familyLabel = det_lunghezza_canna[0].firstChild.data;
						break;
						
						case '2':
							familyLabel = det_lunghezza_flettente[0].firstChild.data;
						break;
						
						case '3':
							familyLabel = det_lunghezza_flettente[0].firstChild.data;
						break;
						
						case '4':
							familyLabel = det_lunghezza_flettente[0].firstChild.data;
						break;
						
						case '5':
							familyLabel = det_lunghezza_lama[0].firstChild.data;
						break;
							
					}
					

					addLineToTable( 2, familyLabel, pr_lunghezza_canna_lama_flettente_inc[old_selected_id].firstChild.data, pr_lunghezza_canna_lama_flettente_mm[old_selected_id].firstChild.data);
					addLineToTable( 2, det_peso[0].firstChild.data, pr_peso_lbs[old_selected_id].firstChild.data, pr_peso_kg[old_selected_id].firstChild.data);
					addLineToTable( 2, det_proiettile[0].firstChild.data, pr_proiettile1[old_selected_id].firstChild.data, pr_proiettile2[old_selected_id].firstChild.data);
					addLineToTable( 2, det_mira[0].firstChild.data, pr_mira1[old_selected_id].firstChild.data, pr_mira2[old_selected_id].firstChild.data);
					addLineToTable( 2, det_scatto[0].firstChild.data, pr_scatto[old_selected_id].firstChild.data);
					
				
				
					var productDettail_table_recod_box = document.createElement('div');
						productDettail_table_recod_box.className='productDettail_table_recod1_box';
						productDettail_table_1.appendChild(productDettail_table_recod_box);
							
					var productDettail_table_label_box = document.createElement('div');
						productDettail_table_label_box.className='productDettail_table_label_note_box';
						productDettail_table_label_box.appendChild(document.createTextNode(det_note[0].firstChild.data));
						productDettail_table_recod_box.appendChild(productDettail_table_label_box);
					
					var productDettail_table_data1_box = document.createElement('div');
						productDettail_table_data1_box.className='productDettail_table_data_note_box';
					if (pr_note[0].firstChild.data != '---')
					{	
						productDettail_table_data1_box.appendChild(document.createTextNode(pr_note[0].firstChild.data));
					}
						productDettail_table_recod_box.appendChild(productDettail_table_data1_box);
						
						productDettail_table_recod_box.className='productDettail_table_recod_note_box';
					
					
				var productDettail_back			= createDivWithIdAndAppendTo('productDettail_back', productDettail_table_1);
					productDettail_back.appendChild(document.createTextNode(messaggio[6].firstChild.data));
					productDettail_back.style.cursor='pointer';
					productDettail_back.setAttribute('id', '-2');
					productDettail_back.className='productDettail_back_2';
					productDettail_back.onclick=searchAndStatusProductTypeListener;
					
					
					
					
				}
				
			}
							
			//local Main
			initialize();
			create_searchAndStatus_box(selected_family);
			//layout();	
		}
		
		//local Main
		acciarini ();
	}

	function catalogo(page)
	{
		nodeCleaner('content');
		setTitleByPageId(page);
		
		var catalogoFragment = document.createDocumentFragment();
		
		var subContentDiv =	document.createElement('div');
			subContentDiv.className='catalogo_SubContent';
			catalogoFragment.appendChild(subContentDiv);
		
		var catalogo_description_box	= createDivWithIdAndAppendTo ( 'catalogo_description_box', subContentDiv );
		var catalogo_description_layer 	= createDivWithIdAndAppendTo ( 'catalogo_description_layer', catalogo_description_box );
		var catalogo_files_box 			= createDivWithIdAndAppendTo ( 'catalogo_files_box', subContentDiv );
		var catalogo_files_layer 		= createDivWithIdAndAppendTo ( 'catalogo_files_layer', catalogo_files_box );
		
		var catalogo_files_copertina_box= createDivWithIdAndAppendTo ( 'catalogo_files_copertina_box', catalogo_files_layer );	
		var catalogo_files_link_box		= createDivWithIdAndAppendTo ( 'catalogo_files_link_box', catalogo_files_layer );
		
		var catalogo_file_label			= xmldoc.getElementsByTagName('catalogo_file_label' + language);	
		var catalogo_file_path			= xmldoc.getElementsByTagName('catalogo_file_path');
		var catalogo_title				= xmldoc.getElementsByTagName('catalogo_title' + language);
		var catalogo_paragraph			= xmldoc.getElementsByTagName('catalogo_paragraph' + language);
		var catalogo_software_name		= xmldoc.getElementsByTagName('catalogo_software_name');
		var catalogo_software_link		= xmldoc.getElementsByTagName('catalogo_software_link');
		var catalogo_immagine_copertina = xmldoc.getElementsByTagName('catalogo_immagine_copertina');

		function makeParagraphWithCssAndAppendTo (text, css, parentNode)
		{
			if (text !== '---')
			{
				var paragraph = document.createElement('p');
				paragraph.appendChild(document.createTextNode(text));
				paragraph.className=css;	
				
				parentNode.appendChild(paragraph);
				
				//return paragraph;
			}	
		}
		
		function makeLinkWithCssAndAppendTo (text, readerLink, css, parentNode)
		{
			if (text !== '---')
			{
				var link = document.createElement('a');
					link.appendChild(document.createTextNode(text));
					link.setAttribute('href', readerLink);
					link.setAttribute('target', 'parent');
					link.className=css;	
				
				parentNode.appendChild(link);
			}	
		}
		
		makeParagraphWithCssAndAppendTo(catalogo_title[0].firstChild.data, 'catalogo_titolo',catalogo_description_layer );
		
		for (i=0; i<catalogo_paragraph.length; i++)
		{
			makeParagraphWithCssAndAppendTo( catalogo_paragraph[i].firstChild.data, 'catalogo_paragraph',catalogo_description_layer );
		}
		
		for (i=0; i<catalogo_software_name.length; i++)
		{
			makeLinkWithCssAndAppendTo( catalogo_software_name[i].firstChild.data, catalogo_software_link[i].firstChild.data, 'catalogo_reader_link', catalogo_description_layer );
		}
		
		var image = document.createElement('img');
			image.setAttribute('src', catalogo_immagine_copertina[0].firstChild.data);
			image.setAttribute('id', 'catalogo_immagine_copertina');
			catalogo_files_copertina_box.appendChild(image);
			
		for (i = 0; i < catalogo_file_label.length; i++) 
		{
			makeLinkWithCssAndAppendTo(catalogo_file_label[i].firstChild.data, catalogo_file_path[i].firstChild.data, 'catalogo_link', catalogo_files_link_box);
		}
		
			
		contentPlace.appendChild(catalogoFragment);
	}
	//Main
	createLanguageBar();
	createNavBar();
	homePage();
}
	
