// <![CDATA]

var oFileNameTema = "suggest_tema.php";
var oUrlTema = "suggests=1";
var oFieldNameTema = "keywordTema";
window.onload = initTema;
function initTema() {
	// prevent browser from starting the autofill function
	document.getElementById('keyword').setAttribute("autocomplete", "off");
	document.getElementById('keywordTema').setAttribute("autocomplete", "off");    
}
/* ========================================= 
GET 
========================================= */

var xmlHttp = createXmlHttpRequestObject();


// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() {
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try {
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	} catch(e) {
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
									"MSXML2.XMLHTTP.5.0",
									"MSXML2.XMLHTTP.4.0",
									"MSXML2.XMLHTTP.3.0",
									"MSXML2.XMLHTTP",
									"Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
			try  { 
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else 
		return xmlHttp;
}
	
// ricava i valori dal db
function getSuggestionsTema() {
	
	var oKeyword = document.getElementById('keywordTema').value;
	if (oKeyword != '' && oKeyword.length >= 2) {
		var url = oFileNameTema + "?" + oUrlTema + "&" + oFieldNameTema + "=" + oKeyword;
		//"suggest.php?suggests=1&keyword=" + oKeyword;
		//var url = "suggest.php?suggests=1&keyword=" + oKeyword;
		xmlHttp.open('GET', url, true);
		xmlHttp.onreadystatechange = insertSuggestsTema;
		xmlHttp.send(null);
	} else {
		hideSuggestionsTema();
	}
}
	
// crea il codice html
function insertSuggestsTema() {

	// ricava 
	var oKeyword = document.getElementById('keywordTema').value;
	if (oKeyword != '') {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				if (xmlHttp.responseText!='') {
					document.getElementById('suggestsTema').innerHTML = xmlHttp.responseText;
					var oScroll = document.getElementById("scrollTema");
					oScroll.style.visibility = "visible";
					oScroll.style.display = "block";
				}
			}					
		}
	}
}



function fillInputTema(id,text) {
	document.getElementById('id_keywordTema').value = id;
	document.getElementById('keywordTema').value = text;
}
	
/* function that hides the layer containing the suggestions */
function hideSuggestionsTema() {
	var oScroll = document.getElementById("scrollTema");
	oScroll.style.visibility = "hidden";  
	oScroll.style.display = "none";  
}


//]]>
