/////////////////////////////////////////////////////////////////////////////////////////////
var Finint = {};
/////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////// EVENT - ADD EVENT LISTENER
Finint.CustEvent = function( element, eventType, handler, capture ){
	//////////////////////////////////// 
	try	{
		if( element.addEventListener ){
			element.addEventListener(eventType, handler, capture);
		}	else if( element.attachEvent ){
			element.attachEvent('on' + eventType, handler);
		} else {
			alert("Unsupported method [customEvent]!" + "\n" + handler)
			return;
		}
		return handler;
	}
	//////////////////////////////////// 
	catch (e) { /* alert('customEvent Error [' + element + ']' + "\n" + e + "\n" + handler ); */ }
	//////////////////////////////////// 
};
///////////////////////////////////////////////////////////////////////////////////////////// EVENT - REMOVE ECENT LISTENER
Finint.CustEventRemove = function( element, eventType, handler, capture ){
	//////////////////////////////////// 
	try	{
		if( element.removeEventListener ){
			element.removeEventListener(eventType, handler, capture);
		}	else if( element.detachEvent ){
			element.detachEvent('on' + eventType, handler, capture);
		} else {
			alert("Unsupported method [customEventRemove]!" + "\n" + handler)
		}
	}
	//////////////////////////////////// 
	catch (e) { /* alert('customEventRemove Error [' + element + ']' + "\n" + e + "\n" + handler  ); */  }
	//////////////////////////////////// 
};
/////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////// DIV STYLE - GET
Finint.getStyle = function( xTg ){
	////////////////////////////////////
	if( document.layers ){ 
		return eval('document.'+xTg); 
	}
	var xDiv = document.getElementById(xTg);
	if( xDiv ){
		if( xDiv.style ) return xDiv.style;
	}
	////////////////////////////////////
	return null;
	////////////////////////////////////
}



///////////////////////////////////////////////////////////////////////////////////////////// AJAX CONNECTION
Finint.AJAXconn = function( _Self, URL, FormAction, Dati ){ 
	//////////////////////////////////// 
	try{
		///////////////////////////////		
		if( navigator.userAgent.indexOf("MSIE") != (-1)){
			///////////////////////////////
			var Class = "Msxml2.XMLHTTP";
			if( navigator.appVersion.indexOf("MSIE 5.5")!=(-1) ){
				Class = "Microsoft.XMLHTTP";
			} 
			try	{
				_Self.XMLHTTP = new ActiveXObject(Class);
				_Self.XMLHTTP.onreadystatechange = function(){		_Self.RequestStep();		}
			} catch(e) {
				alert("Errore: l'ActiveX non verrà eseguito!");
				return false;
			}
			///////////////////////////////
		} else if (navigator.userAgent.indexOf("Mozilla") != (-1)) {
			///////////////////////////////
			_Self.XMLHTTP = new XMLHttpRequest();
			_Self.XMLHTTP.onload = 	function(){		_Self.RequestStep();		}
			_Self.XMLHTTP.onerror = function(){		_Self.RequestStep();		}
			///////////////////////////////
		} else {
			///////////////////////////////
			alert("ERRORE! Browser!");
			return false;
			///////////////////////////////
		}
		///////////////////////////////
		var ArrURL = new Array();
		if( !Dati ){
			ArrURL = URL.split("?");
		} else {
			ArrURL = new Array(URL, Dati);
		}
		if( !FormAction || FormAction=='GET' ){
			_Self.XMLHTTP.open("GET", ArrURL[0]+"?"+ArrURL[1], true);
			_Self.XMLHTTP.send( null );
		} else {
			_Self.XMLHTTP.open("POST", ArrURL[0], true);
			//Send the proper header information along with the request
			_Self.XMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			_Self.XMLHTTP.setRequestHeader("Content-length", ArrURL[1].length);
			_Self.XMLHTTP.setRequestHeader("Connection", "close");
			_Self.XMLHTTP.send( ArrURL[1] );
		}
		///////////////////////////////
	} catch(e) {
		///////////////////////////////
		alert("Errore: " + e);
		return false;
		///////////////////////////////
	}
	///////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////////////////////////////////////// 
Finint.PROTO_AddresComune = function( cmpFrom, cmpTo ){
	///////////////////////////////	
	this.From = cmpFrom;
	this.To = cmpTo;
	this.URL = '../tool/ajax.aspx?s=address&t=comuni&fm=list&prov=';
	///////////////////////////////	
	this.tgFrom = document.getElementById(this.From);
	this.tgTo = document.getElementById(this.To);

	///////////////////////////////	
	var _Self = this;
	Finint.CustEvent( this.tgFrom, 'change', function(){
		_Self.Change();
			}, false );

	this.Disable(true);
	///////////////////////////////	
}
//////////////////////////////////// 	
Finint.PROTO_AddresComune.prototype.SetURL = function(){
	///////////////////////////////	
	return this.URL + this.tgFrom.value;
	///////////////////////////////	
}
//////////////////////////////////// 	
Finint.PROTO_AddresComune.prototype.Change = function(){
	///////////////////////////////
	var xURL = this.SetURL();
	this.RESULT = null;
	Finint.AJAXconn( this, xURL, 'POST' );
	//////////////////////////////////// 	
}
//////////////////////////////////// 	
Finint.PROTO_AddresComune.prototype.Disable = function( xDisable ){
	///////////////////////////////	
	this.tgTo.disabled = xDisable;
	///////////////////////////////	
}
/////////////////////////////////////////////////////////////////////////////////////////////
Finint.PROTO_AddresComune.prototype.RequestStep = function(){
	///////////////////////////////
	if( this.XMLHTTP.readyState==4 ){
		///////////////////////////////
		this.RESULT = this.XMLHTTP.responseText.split('\n');
		if( this.RESULT.length==0 || this.RESULT[0]=='ERROR' ){
			///////////////////////////////
			alert("ERRORE!" + '\n' + this.RESULT[2]);
			///////////////////////////////
		} else {
			///////////////////////////////

/*
var TESTSTR = '';
for( var i=0; i<this.RESULT.length; i++ ){
	TESTSTR += i + ' ' + this.RESULT[i] + '\n';
}
alert(TESTSTR)
*/

			///////////////////////////////
			var Tot = this.tgTo.options.length;
			for( var i=0; i<Tot; i++ ){
				this.tgTo.remove(0);
			}
			///////////////////////////////
			Tot = this.RESULT[0];
			if( isNaN(Tot)==false && Tot>0 ){
				///////////////////////////////
				this.AddOption( "", "" );
				for( var i=0; i<Tot; i++ ){
					this.AddOption( this.RESULT[i*2+2], this.RESULT[i*2+1] );
				}
				this.Disable( false );
				///////////////////////////////
			} else {
				///////////////////////////////
				this.Disable( true );
				///////////////////////////////
			}
			///////////////////////////////
		}
		///////////////////////////////
	}
	///////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////
Finint.PROTO_AddresComune.prototype.AddOption = function( Text, Value ){
	///////////////////////////////
	var OptNew = document.createElement('option');
	OptNew.text = Text;
	OptNew.value = Value;
	if( this.Selected==Value ){
		OptNew.selected = true;
	}
	///////////////////////////////
	try {
		this.tgTo.add(OptNew, null); 		// standards compliant; doesn't work in IE
	}	catch(ex) {
		this.tgTo.add(OptNew); 					// IE only
	}
	///////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////// 
Finint.PROTO_LuogoNascita = function(){
	///////////////////////////////	
	this.tgLuogo = document.getElementById('formitem9');
	this.tgOpt10 = Finint.getStyle('formdiv10');
	this.tgOpt11 = Finint.getStyle('formdiv11');
	this.tgOpt12 = Finint.getStyle('formdiv12');
	///////////////////////////////	
	var _Self = this;
	Finint.CustEvent( this.tgLuogo, 'change', function(){
		_Self.Change();
			}, false );
	this.Change();
	///////////////////////////////	
}
//////////////////////////////////// 	
Finint.PROTO_LuogoNascita.prototype.Change = function(){
	///////////////////////////////
	if( this.tgLuogo.value=='121' ){
		this.tgOpt10.display = '';
		this.tgOpt11.display = '';
		this.tgOpt12.display = 'none';
	} else {
		this.tgOpt10.display = 'none';
		this.tgOpt11.display = 'none';
		this.tgOpt12.display = '';
	}
	//////////////////////////////////// 	
}
///////////////////////////////////////////////////////////////////////////////////////////// 



///////////////////////////////////////////////////////////////////////////////////////////// 

function curDate(){
	//////////////////////////////////// 
	var d = new Date();
	document.getElementById("footerDate").innerHTML = d.getFullYear();
	//////////////////////////////////// 
}

///////////////////////////////////////////////////////////////////////////////////////////// 