

Element.addMethods({
    onmouseenter: function(element,observer) {
        element = $(element);
        element.observe('mouseover',function(evt,currentTarget) {
        	try {
            var relatedTarget = $(evt.relatedTarget || evt.fromElement);
            if( relatedTarget!=currentTarget &&
relatedTarget.childOf(currentTarget)==false ) {
                observer();
            }
          } catch (e) { ; }
        }.bindAsEventListener({},element));
        return element;
    },
    onmouseleave: function(element,observer) {
        element = $(element);
        element.observe('mouseout',function(evt,currentTarget) {
        	try {
            var relatedTarget = $(evt.relatedTarget || evt.toElement);
            if( relatedTarget!=currentTarget &&
relatedTarget.childOf(currentTarget)==false ) {
                observer();
            }
          } catch (e) { ; }  
        }.bindAsEventListener({},element));
        return element;
    }
});
   
    function Portal(){
  
  	 document.getElementsByClassName('boxtondo').each(function(el,i){
  		 new Insertion.Top(el, '<div class="boxSopra"><div></div></div>');
  		 new Insertion.Bottom(el, '<div class="boxSotto"><div></div></div>');
  	 });

    }

  	// -----------------------------------------------------------------------------------
		function initCommon() {
      //myRoundedbox = Portal();
			x = new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "/nex/ajax.php", { tokens: '\n', paramName: "value", minChars: 2, /* frequency: 0.1,*/ /* indicator: 'load-autocomp', */ /* callback: function(a,q) { alert(q); return q; }, */ afterUpdateElement: function (a, b) {$('loc').value = b.id;$('verificaloc').value = true; $('inptsubmit').removeAttribute('disabled');}});
			x.onObserverEvent =  function() {
         this.changed = false;   
         this.tokenBounds = null;
         if(this.getToken().length>=this.options.minChars) {
           this.getUpdatedChoices();
          } else {
            this.active = false;
            this.hide();
          }
         this.oldElementValue = this.element.value;
         if(this.getToken().length>0){
         $('inptsubmit').setAttribute('disabled','disabled');
         } else {
         $('inptsubmit').removeAttribute('disabled');
         }
         unsetLocRadio();
        }
//      Event.observe($('autocomplete'), 'keydown', cLoc, false);
      
//      new Form.Element.Observer('autocomplete', 0.1,  cLoc);
     
    }
    
		Event.observe(window, 'load', initCommon, false);


		function fAll(layer)
    {
    	Effect.toggle(layer);
    }

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  output = output.replace ('+', ' ');
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  
  return output;
}

	var Tratta = Class.create();

		Tratta.prototype = {
      wdt:25,
      initialize: function(opt) {
        x = $(opt.containerId).select(opt.containerClass);
        x.each (function (el,i){

          var prt = $(el).identify();
          if($(prt).innerHTML.substring(2,4).toLowerCase() == "tr" || $(prt).innerHTML.substring(1,3).toLowerCase() == "tr"){
            /*
            var ev='tbody#'+prt+' div.infojson';
            $$(ev).each(function(ce,i){
               
               ello = '<div>prova</div>';
               new Insertion.Bottom(ce.up(), ello);
               
            });
            */
          }else{
            var prezzoMedio =  $(prt.replace('lister','przmed_')).innerHTML;
            var str_prezzoMedio =  (prezzoMedio != "")?"Costo indicativo da &euro;"+prezzoMedio:"";//Nessun prezzo dichiarato
            try {
            $(prt).up(1).innerHTML = '<div class="alert-offline" onclick="'
            +(' '+$(prt.replace('lister','inPut')).getAttribute('onclick')).replace(' function anonymous()\n{\n','').replace('\n}','')+'"><div>'
            +str_prezzoMedio+'</div></div>';
            } catch (e)
                {
                 $(prt).up(1).hide();
                }
            }
  			});
  			
        $(opt.containerLoad).hide();
  			$(opt.containerId).appear();

		  }

}