function AC_Toggler(ID){
	if($('ACFinder' + ID).visible()){
		$('ACFinder' + ID).hide();
		$('ACViewer' + ID).show();
	}
	else{
		$('ACDigits' + ID).value='';
		$('ACViewer' + ID).hide();
		$('ACFinder' + ID).show();
		$('ACDigits' + ID).focus();
	};
	return false;
}

function SetIPE_Campo(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
			cancelControl: 'button'
			, cols: Cols
		}
	);
	return Editor;
}

function SetIPE_Testo(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
			 cancelControl: 'button'
			, cols         : Cols
			, rows: 2
		}
	);
	return Editor;
}

function SetIPE_Importo(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
			cancelControl: 'button'
			, cols: Cols
		}
	);
	return Editor;
}

function SetIPE_Boolean(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceCollectionEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
		  	collection: [['1', ' Si '], ['0', ' No ']] 
			, cancelControl: 'button'
			, cols: Cols
		}
	);
	return Editor;
}

function SetIPE_Required(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceCollectionEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
		  	collection: [['1', ' Richiesto '], ['0', ' -- ']] 
			, cancelControl: 'button'
			, cols: Cols
		}
	);
	return Editor;
}

function SetIPE_Included(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceCollectionEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
		  	collection: [['1', ' Incluso '], ['0', ' Escluso ']] 
			, cancelControl: 'button'
			, cols: Cols
		}
	);
	return Editor;
}

function SetIPE_UrlList(Item, Url){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceCollectionEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
		  	loadCollectionURL: Url 
			, cancelControl: 'button'
		}
	);
	return Editor;
}

function SetIPE_TipoTrattativa(Item, Cols){
	var ts = new Date(); //EVITA LA CACHE DEL FILE ;)
	var Editor = new Ajax.InPlaceCollectionEditor(Item, '/ajax/InPlaceEditor.php?T' + ts.getTime(),
		{
		  	collection: [['1', ' affitto '], ['0', ' vendita ']] 
			, cancelControl: 'button'
			, cols: Cols
		}
	);
	return Editor;
}

function IPE_Helper(ID, Value){
	var domID = $(ID);
	new Ajax.Request('/ajax/InPlaceEditor.php?T' + Math.random(),
		{
			asynchronous: true,
			method      : 'post',
			encoding    : 'UTF-8',
			parameters  : {editorId : ID, value : Value},
			onLoading   : function(rq){domID.update('Loading...');},
			onFailure   : function(rq){domID.update('-- ERRORE --');alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							if(rq.responseText.indexOf('<script')>=0){domID.update('--ERRORE--');rq.responseText.evalScripts();return false;}
							domID.update(rq.responseText);
						}
		}
	);
}

function Toggler(pLink, pItem){
	$(pItem).toggle();
	if($(pItem).visible()) pLink.innerHTML='<img src="/images/shared/msc_meno.gif" width="9" height="9" alt="-" title="chiudi" />';
	else                   pLink.innerHTML='<img src="/images/shared/msc_piu.gif"  width="9" height="9" alt="+" title="apri" />';
	return false;
}

function GetProvincie(Container, ID){
	var ddl = $(Container);
	if(parseInt(ID)==0){ddl.options.length=0;ddl.options[ddl.length]=new Option('--','',false,false);return false;}
	var ts  = new Date(); //EVITA LA CACHE DEL FILE ;)
	new Ajax.Request('/ajax/geo.php?T' + ts.getTime(),
			{
			asynchronous: true,
			method      : 'get',
			encoding    : 'UTF-8',
			parameters  : {Action : 'GetProvincie', IDRegione : ID},
			onLoading   : function(rq){ddl.options.length=0;ddl.options[ddl.length]=new Option('...caricamento...','',false,false);},
			onFailure   : function(rq){ddl.options.length=0;ddl.options[ddl.length]=new Option('--','',false,false);alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							ddl.options.length=0;
							ddl.options[ddl.options.length]=new Option("--", "",  false, false);
							if(!rq.responseText.isJSON()){alert('JSON: NOT A JSON RESPONSE.'); return false;}
							var obj = rq.responseText.evalJSON();
							if(obj.ResultCode!=0){alert(obj.ResultDesc); return false;}
							
							for (var i=0;i < obj.Items.length;i++){ddl.options[ddl.length]=new Option(obj.Items[i].Nome, obj.Items[i].ID, false, false);}
						}
			}
	);
}

function GetComuni(Container, ID){
	var ddl = $(Container);
	if(parseInt(ID)==0){ddl.options.length=0;ddl.options[ddl.length]=new Option('--','',false,false);return false;}
	var ts  = new Date(); //EVITA LA CACHE DEL FILE ;)
	new Ajax.Request('/ajax/geo.php?T' + ts.getTime(),
			{
			asynchronous: true,
			method      : 'get',
			encoding    : 'UTF-8',
			parameters  : {Action : 'GetComuni', IDProvincia : ID},
			onLoading   : function(rq){ddl.options.length=0;ddl.options[ddl.length]=new Option('...caricamento...','',false,false);},
			onFailure   : function(rq){ddl.options.length=0;ddl.options[ddl.length]=new Option('--','',false,false);alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							ddl.options.length=0;
							ddl.options[ddl.options.length]=new Option("--", "",  false, false);
							if(!rq.responseText.isJSON()){alert('JSON: NOT A JSON RESPONSE.'); return false;}
							var obj = rq.responseText.evalJSON();
							if(obj.ResultCode!=0){alert(obj.ResultDesc); return false;}
							
							for (var i=0;i < obj.Items.length;i++){ddl.options[ddl.length]=new Option(obj.Items[i].Nome, obj.Items[i].ID, false, false);}
						}
			}
	);
}

function GetZone(Container, ID){
	var ddl = $(Container);
	if(parseInt(ID)==0){ddl.options.length=0;ddl.options[ddl.length]=new Option('--','',false,false);return false;}
	var ts  = new Date(); //EVITA LA CACHE DEL FILE ;)
	new Ajax.Request('/ajax/geo.php?T' + ts.getTime(),
			{
			asynchronous: true,
			method      : 'get',
			encoding    : 'UTF-8',
			parameters  : {Action : 'GetZone', IDComune : ID},
			onLoading   : function(rq){ddl.options.length=0;ddl.options[ddl.length]=new Option('...caricamento...','',false,false);},
			onFailure   : function(rq){ddl.options.length=0;ddl.options[ddl.length]=new Option('--','',false,false);alert('Errore ' + rq.status + ' -- ' + rq.statusText);},
			onSuccess   : function(rq){
							ddl.options.length=0;
							ddl.options[ddl.options.length]=new Option("--", "",  false, false);
							if(!rq.responseText.isJSON()){alert('JSON: NOT A JSON RESPONSE.'); return false;}
							var obj = rq.responseText.evalJSON();
							if(obj.ResultCode!=0){alert(obj.ResultDesc); return false;}
							
							for (var i=0;i < obj.Items.length;i++){ddl.options[ddl.length]=new Option(obj.Items[i].Nome, obj.Items[i].ID, false, false);}
						}
			}
	);
}

function CountRedirect(intSeconds, strURL){
	if (intSeconds!=1){intSeconds-=1;}
	else{window.location.href = strURL; return;}
	setTimeout("CountRedirect(" + intSeconds + ", \'" + strURL + "\')",1000);
}

function ImgInserzione(IDInserzione){
	Lightview.show({
		href   : '/admin/applets/LB_InserzioniImmagini.php',
		rel    : 'ajax',
		options: {
			autosize       : true,
			closeButton    : false,
			ajax           : {
				method     : 'get',
				parameters : {IDInserzione: IDInserzione},
				evalScripts: true
			}
		}
	});
}
