/*---------------------------------------------------------------------------------------*/
var modello;

function _startLoad(sSrc,obj,idrub) {
	
	//alert(modello)
	modello=document.getElementById('idcat_modello');
	if(modello)
	{
		modello.innerHTML='<select class="field" style="width:150px;" name="idcat"><option value="0">LOADING...</option></select>';
		
		idcat = obj.value
		sSrc = sSrc+"?idcat="+idcat+"&idrub="+idrub;
		
		//alert(sSrc)
		
		var xmlHttp = XmlHttp.create();
		
		timer_onloading=window.setTimeout("onLoading(true)","500");
		
		xmlHttp.open("GET", sSrc, true);	// async
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				
				//alert(xmlHttp.responseText)
				
				_modelloLoaded(xmlHttp.responseText);
				
				window.clearTimeout(timer_onloading)
				onLoading(false);
			}
		};
		// call in new thread to allow ui to update
		window.setTimeout(function () {
			xmlHttp.send(null);
		}, 10);
	}
}

function _modelloLoaded(oXmlDoc) 
{
	//alert(oXmlDoc)
	if(modello)
		modello.innerHTML = oXmlDoc;
}
//LOGIN IN AJAX ---------------------------------------------------------
var proc="";
//var titcomm="";
var descomm="";
var idrubs="";
function _loginAjax(rnd)
{
	f=document.forms['formloginajax']
	div_le = document.getElementById('div_loginerror');
	
	sSrc="/LoginAjax.jsp?username="+f.username.value+"&password="+f.password.value+"&rnd="+rnd;
	//alert(sSrc)
	timer_onloading=window.setTimeout("onLoading(true)","500");
	
	var xmlHttp = XmlHttp.create();
	xmlHttp.open("GET", sSrc, true);	// async
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {			
			window.clearTimeout(timer_onloading)
			onLoading(false);
			if(xmlHttp.responseText.indexOf("logged=true")!=-1)
			{
				f2=document.forms['formproc']
				proc=f2.proc.value
				//titcomm=f2.tit1.value
				descomm=f2.des.value 
				idrubs=f2.idrubs.value
				_loadFormComm(idrubs)
			}
			else
			{
				div_le.innerHTML="Username o password errata"
				f.username.value="";
				f.password.value="";
			}
		}
	};
	// call in new thread to allow ui to update
	window.setTimeout(function () {
		xmlHttp.send(null);
	}, 10);
}

function _loadFormComm(idrubs) {
	
		var div_comm = document.getElementById('divcomm');
		
		sSrc = "/include/mod/comp/proc/addcomm.jsp?idrubs="+idrubs;
		
		timer_onloading=window.setTimeout("onLoading(true)","500");
		
		var xmlHttp = XmlHttp.create();
		xmlHttp.open("GET", sSrc, true);	// async
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				window.clearTimeout(timer_onloading)
				onLoading(false);
				
				div_comm.innerHTML = xmlHttp.responseText;
				
				f2=document.forms['formproc']
				f2.proc.value=proc
				//f2.tit1.value=titcomm
				f2.des.value=descomm
				f2.idrubs.value=idrubs
			}
		};
		// call in new thread to allow ui to update
		window.setTimeout(function () {
			xmlHttp.send(null);
		}, 10);
	
}
