var IFrameObj; 
function callToServer(theFormName) {
	if (!document.createElement) {return true};
	var IFrameDoc;
	//alert('pippo');
	var reg    = document.forms[theFormName].reg;
	var idreg  = reg.options[reg.selectedIndex].value;
	var prov   = document.forms[theFormName].prov;
	var idprov = prov.options[prov.selectedIndex].value;
	var cat    = document.forms[theFormName].cat;
	var submit = document.forms[theFormName].submitX;
	//alert(cat);
	//var idcat  = cat.options[prov.selectedIndex].value
	//if( cat.options[prov.selectedIndex].value ) var idcat  = cat.options[prov.selectedIndex].value;
	//alert(idcat);
	var URL = 'data.php?idprov=' + idprov + '&idreg='+ idreg + '&idcat=';//+ idcat; 
	//var responseMessage = document.getElementById('responseMessage');
	//responseMessage.style.display = 'inline';
	//alert(URL);
	if (!IFrameObj && document.createElement) {

		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				IFrameObj = document.frames['RSIFrame'];
			}
		} catch(exception) {
			
			iframeHTML='<iframe id="RSIFrame" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		setTimeout('callToServer("'+theFormName+'")',10);
		return false;
	}
	
	if (IFrameObj.contentDocument) {
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	
	IFrameDoc.location.replace(URL);  
	cat.previousSibling.nodeValue  = 'Attendere.';
	submit.style.visibility="hidden";
	return false;
}

function handleResponse(st, doc) {
	var cat = document.forms.searchForm.cat
	
	cat.length = 0
	var data = doc.getElementById(st)
	namesColl = data.childNodes
	var numNames = namesColl.length
	
	for (var q=0; q<numNames; q++) {
		if (namesColl[q].nodeType!=1) continue; 
		var idCat = doc.getElementById(namesColl[q].id).childNodes
	    if (idCat[0].nodeType!=1) continue; 
		var opt = document.createElement('option'); 
			opt.innerHTML = namesColl[q].id;
			opt.value = idCat[0].id;
			cat.appendChild( opt );
		}
	
	cat.previousSibling.nodeValue  = 'Categorie ';
	var submit = document.forms.searchForm.submitX;
	submit.style.visibility="visible";
	//var responseMessage = document.getElementById('responseMessage');
	//responseMessage.innerHTML = 'loaded records from <a href="'+doc.location+'">this external file<\/a>.';
}


