		//GENERAL-PURPOSE
		function include(file) {
			var script  = document.createElement('script');
			script.src  = file;
			script.type = 'text/javascript';
		 	document.getElementsByTagName('head').item(0).appendChild(script);
		}
		String.prototype.trim = function() {
			var string = this;
			while (string.substring(0,1) == ' ') {
				string = string.substring(1, string.length);
			}
			while (string.substring(string.length-1, string.length) == ' ') {
				string = string.substring(0,string.length-1);
			}
			return string;
		}
		Array.prototype.linearSearch = function(item) {
		        for(var i=0;i<this.length;i++) {
				if(this[i]==item) return i;
			}
			return -1;
		}
		Array.prototype.linearDifference = function(array) {
			if(array==null || array.length==0) return this;
			var intersectionArray = new Array();
		        for(var i=0;i<this.length;i++) {
				if(array.linearSearch(this[i])==-1)
					intersectionArray[intersectionArray.length] = this[i];
			}
			if(intersectionArray.length == 0) intersectionArray = null;
			return intersectionArray;
		}
		Array.prototype.binarySearch = function(item) {
		        var left = -1,
			right = this.length,
			mid;
			
			while(right - left > 1) {
			    mid = (left + right) >>> 1;
			    if(this[mid] < item)
			      left = mid;
			    else
			      right = mid;
			}
			
			if(this[right] != item)
			    return -(right + 1);
			
			return right;
		}
		Array.prototype.linearUnique = function() {
		        var sourceArray = this;
			var targetArray = new Array();
			for(var i=0;i<sourceArray.length;i++) {
				var j;
				for(j=i-1;j>=0;j--) {
					if(sourceArray[i]==sourceArray[j]) break;
				}
				if(j<0) targetArray[targetArray.length] = sourceArray[i];
			}
			
			return targetArray;
		}
		//LIGHTBOX CLONE WRAPPER
		function showBox(title, url, width, height) {
			var defaultWidth = 380;
			var defaultHeight = 260;
			var relativeUrlPrefix = "../../";
			
			if(!url.match(/^[a-z]+:\/\//i) && !url.match(/^\/.*/)) url = relativeUrlPrefix + url;
			if(width==0) {
				GB_showPage(title, url);
			}
			else {
				if(!width) width = defaultWidth;
				if(!height) height = defaultHeight;
				GB_showCenter(title, url, height, width);
			}
			
			return false;
		}
		
		//FORM COMPONENTS RELATED
		function modifySelectItem(select, item) {
				var i;
				select.options[0].selected=true;
				if(item==select.options[0].value) return;
				
				for(i=0;i<select.length;i++) {
					if(select.options[i].text==item) {
						select.options[i].selected=true;
						return;
					}
				}
		}
		function populateSelect(select, array, firsttext, firstvalue) {
			select.length=0;
			var i=0, j=0;
			if(firsttext) {
				select.options[0]=new Option(firsttext);
				if(firstvalue) select.options[0].value=firstvalue;
				i=1;
			}
			for(;j<array.length;i++,j++)
				select.options[i]=new Option(array[j]);
			select.options[0].selected=true;
		}
		
		//SEARCH RELATED
		function searchOnEnter(myField,e) {
			var keycode;
			if (window.event) keycode = window.event.keyCode;
			else if (e) keycode = e.which;
			else return true;
			
			if (keycode == 13) {
			   search();
			   return false;
			}
			else   return true;
		}
		function search() {
			var ret;
			
			//Normalizing input
			eval(currentPagePrefix + "_normalizeInput();");
			//Validating search conditions
			if(clientSideAlertOnInvalidSearchConditions) {
				eval("ret = " + currentPagePrefix + "_validateSearchConditions();");
				if(!ret) return;
			}
			//Validating input
			if(clientSideAlertOnInvalidInput) {
				eval("ret = " + currentPagePrefix + "_validateInput();");
				if(!ret) return;
			}
			//Submit
			document.form.submit();
		}
		
		//FORM COMPONENTS SYNCHRONIZATION RELATED
		function synchronizeYearSelects() {
			var fromion = document.form.from.options[document.form.from.selectedIndex].text;
			var oldToSelection = null;
			if(document.form.to.selectedIndex>=0) oldToSelection=document.form.to.options[document.form.to.selectedIndex].text;
		
			var i;
			for(i=0;i<yearArray.length && yearArray[i]!=fromion;i++);
			document.form.to.length=0;
			var j;
			for(j=0;j<=i;j++)
				document.form.to.options[j]=new Option(yearArray[j]);
			if(oldToSelection!=null) {
				modifySelectItem(document.form.to, oldToSelection);
				if(document.form.to.options[document.form.to.selectedIndex].text!=oldToSelection)
					document.form.to.options[i].selected=true;
			}
			else document.form.to.options[i].selected=true;
		}
		function synchronizeRegionAndProvinceSelects() {
			if(document.form.region.selectedIndex==0) {
				populateSelect(document.form.province, provinceArray, "Tutte", "ANY");
			}
			else {
				populateSelect(document.form.province, provinceMap[document.form.region.selectedIndex-1], "Tutte", "ANY");
			}
		}
		function synchronizeRegionAndProvinceSelectsWithProvince(province) {
			if(document.form.region.selectedIndex==0) {
				var regionIndex = 0;
				for(var i=0;i<provinceMap.length;i++) {
					if(provinceMap[i].linearSearch(province)!=-1) {
						regionIndex = i+1;
						break;
					}
				}
				if(regionIndex>0) {
					document.form.region.selectedIndex = regionIndex;
					populateSelect(document.form.province, provinceMap[document.form.region.selectedIndex-1], "Tutte", "ANY");
					modifySelectItem(document.form.province, province);
				}
			}
			else {
				populateSelect(document.form.province, provinceMap[document.form.region.selectedIndex-1], "Tutte", "ANY");
				modifySelectItem(document.form.province, province);
			}
		}
		function synchronizeCriterionAndWordsComponents() {
			if(document.form.criterion.selectedIndex == 0) {
				document.getElementById("wordsTarget").style.display='inline';
				document.getElementById("wordsDelimiter").innerHTML = "contenute in";
			}
			else {
				document.getElementById("wordsTarget").style.display='none';
				document.getElementById("wordsDelimiter").innerHTML = "contenute nel titolo";
			}
		}
		function synchronizeMacroAreaAndAreaSelects() {
			if(document.form.macroArea.selectedIndex == 0) {
				document.form.area.length=1;
				document.getElementById("areaElement").style.display='none';
			}
			else {
				var areaArray = null;
				if(document.form.criterion.selectedIndex == 0)
					areaArray = ISIMap[document.form.macroArea.selectedIndex-1];
				else
					areaArray = IPCMap[document.form.macroArea.selectedIndex-1];
				populateSelect(document.form.area, areaArray, "Tutti i settori", "ANY");
				
				document.getElementById("areaElement").style.display='inline';
			}
		}
		
		//FORM CHECKING RELATED
		function hasKeywordTextFieldValidStopwords(formName, textField, minSize) {
			var words = getKeywordTextFieldWords(formName, textField);
			var stopwords = getKeywordTextFieldStopWords(formName, textField, minSize);
			if(stopwords==null) return true;
			
			var stopwordString = "'" + stopwords.join("', '") + "'";
			if(stopwords.length == words.length) {
				alert("La restrizione alle parole è troppo generica. Focalizzare la ricerca prima di continuare.");
				return false;
			}
			if(confirm("Alcune delle parole specificate sono troppo generiche (" + stopwordString + "). Premere 'OK' per continuare la ricerca ignorando tali parole o 'Annulla' per annullare e restringere la ricerca.")) {
				var targetWords = words.linearDifference(stopwords);
				document.getElementById(textField).value = targetWords.join(' ');
				
				return true;
			}
			else return false;
		}
		function getKeywordTextFieldStopWords(formName, textField, minSize) {
			var words = getKeywordTextFieldWords(formName, textField);
			if(words==null) return null;
			if(stopwordArray==null) return null;
			var targetStopWords = new Array();
			for(var i=0;i<words.length;i++) {
				if(words[i].length<minSize || stopwordArray.binarySearch(words[i].toLowerCase())>=0)
					targetStopWords[targetStopWords.length] = words[i];
			}
			if(targetStopWords.length==0) targetStopWords=null;
			
			return targetStopWords;
		}
		function getKeywordTextFieldWords(formName, textField) {
			var string;
			eval("string=document." + formName + "." + textField + ".value");
			if(string.length==0) return null;
			var tokens = string.trim().split(/\s+/);
			if(tokens.length==0) return null;
			return tokens;
		}
		//not used at the moment, minSize is incorporated in stopwords checking
		function isKeywordTextFieldValid(formName, textField, minSize) {
			var string;
			eval("string=document." + formName + "." + textField + ".value");
			if(string.length==0) return true;
			var tokens = string.trim().split(/\s+/);
			if(tokens.length==0) return false;
			for(var i=0;i<tokens.length;i++) {
				if(tokens[i].length<minSize) return false;
			}
			return true;
		}
		function isKeywordTextFieldFilled(formName, textField) {
			return isTextFieldFilled(formName, textField);
		}
		function isTextFieldValid(formName, textField, minSize) {
			var string;
			eval("string=document." + formName + "." + textField + ".value");
			if(string.length==0) return true;
			return (string.trim().length>=minSize);
		}
		function isTextFieldFilled(formName, textField) {
			return eval("document." + formName + "." + textField + ".value.length>0");
		}
		function isSelectSelected(formName, select) {
			return eval("document." + formName + "." + select + ".selectedIndex>0");
		}
		function normalizeTextField(formName, textField) {
			var string;
			eval("string=document." + formName + "." + textField + ".value");
			string = string.trim().replace(/\s+/g, ' ').toLowerCase();
			return string;
		}
		function normalizeKeywordTextField(formName, textField) {
			var words = getKeywordTextFieldWords(formName, textField);
			if(words==null)	return "";
			
			var targetWords = new Array();
			for(var i=0;i<words.length;i++) {
				targetWords[targetWords.length] = words[i].toLowerCase();
			}
			return targetWords.linearUnique().join(' ');
		}
		
		//LOADING RESULTS RELATED
		function beforeLoadingResults() {
			document.getElementById("lenslink").style.display = 'none';
			document.getElementById("resultloading").style.visibility = 'visible';
		}
		function afterLoadingResults() {
			document.getElementById("resultloading").style.visibility = 'hidden';
			document.getElementById("lenslink").style.display = 'block';
		}
		function onStopLoadingPage() {
			if(document.getElementById("resultloading"))
				document.getElementById("resultloading").style.visibility = 'hidden';
			if(document.getElementById("lenslink"))
				document.getElementById("lenslink").style.display = 'block';
		}
		
		//GLOBAL VARIABLES
		var currentPage = null;
		var currentPagePrefix = null;
		var clientSideAlertOnInvalidSearchConditions = true;   //default value overriden basing on ORP configuration file
		var clientSideAlertOnInvalidInput = true;              //default value overriden basing on ORP configuration file
		if(typeof document.onstop != "undefined") document.onstop = onStopLoadingPage; //WORKS ONLY IN IE
