

//per fare un pulsante submit con un elemneto non <input submit>
//<a href='' onclick='return $.submitParent(this)'></a>
jQuery.submitParent = function(orig,addpost) {
	var $orig = $(orig);
	var $pforms = $orig.parents('form');
	var $f = $pforms.eq(0);
	if(addpost) {
		for(k in addpost) {
			var ih = $("<input type='hidden' />");
			ih.attr('name',k);
			ih.val(addpost[k]);
			$f.append(ih);
		}
	}
	$f.submit();
	return false;
}



//metodo jquery per far si che i checkbox postino sempre
//i checkbox con attributo postoff=1 funzioneranno come sempre
//l'attributo valueoff verrà postato come valore false se presente senò '0'
jQuery.fn.fixChecks = function() {
	var $checks = $('input[type=checkbox][postoff!=1]:enabled',this);
	//per ogni checkbox
	$checks.each(function(){
		var $chk = $(this);
		//salto i check già fizati
		if($chk.data('fixChecks_done')) return;
		//rimovo il name al checkbox
		var name = $chk.attr('name');
		//se non ha un name salto avanti
		if(!name || !name.length) return;
		//tolgo il name al checkbox
		$chk.attr('name','');
		//setto che sono passato con fixChecks()
		$chk.data('fixChecks_done',true);
		//creo input hidden con lo stesso name e il value 0/1
		var $inp = $("<input type='hidden' />");
		$inp.attr('name',name);
		//valore vero o falso
		var true_value = $chk.val();
		if(true_value=='on') true_value = '1';
		var false_value = '0';
		var false_attr = $chk.attr('valueoff');
		if(false_attr!==undefined) false_value = false_attr;
		$inp.attr('value',$chk.attr('checked')?true_value:false_value);
		//appendo input hidden
		$chk.after($inp);
	});
	return this;
};


//metodo statico per copiare attributi da un selettore tra due elementi
//usati come root origine , root destinazione
jQuery.copyAttrs = function(sel,attrs,elto,elfrom) {
	var $elto = $(elto);
	var $elfrom = $(elfrom);
	var $from = $(sel,$elfrom);
	var fl = $from.length;
	var $to = $(sel,$elto);
	var tl = $to.length;
	
	var aattrs = null;
	if(typeof(attrs)=='string') {
	 	aattrs = [attrs];
	} else if(attrs && attrs.length) {
		aattrs = attrs;
	}
	
	if(!aattrs) return;
	
	if(fl>0 && fl==tl) {
		for(var i=0;i<fl;i++) {
			var $it = $to.eq(i);
			var $if = $from.eq(i);
			$.each(aattrs,function(i,v) {
				$it.attr(v, $if.attr(v) );
			});
		}
	}
};



//metodo statico per copiare lo stato dei campi form
//che non vengono mantenuti con .clone()
jQuery.copyFields = function(elto,elfrom) {
	
	//in IE e FF devo resettare la selezione dei:
	//select a selezione singola
	//TODO select a selezione multipla
	if(jQuery.browser.mozilla || jQuery.browser.msie) {
		$.copyAttrs('select','selectedIndex',elto,elfrom);
	}
	
	//in IE sembra necessario resettare anche i checkbox
	//in IE se l'elemento non è attaccato al DOM settare checked non fa nulla
	//alert("ie:"+jQuery.browser.msie);
	if(jQuery.browser.msie) {
		$.copyAttrs('input[type=checkbox]','checked',elto,elfrom);
	}
	
	//in firefox devo resettare il value dei textarea
	if(jQuery.browser.mozilla) {
		$.copyAttrs('textarea','value',elto,elfrom);
	}
};


/*
jQuery.resetFields = function(el) {
	var $el = $(el);
	
}
*/


//------------------------------------------------------------------------------

/*
//richiede plugin: cookie,batch
//todo: static per il cookie parsato
//      cfg icona aperto/icona chiuso
//      cfg oggetto css aperto / oggetto css chiuso
jQuery.fn.autohp = function(cfg) {
	var $els = this;
	if(!$els.length) return $els;
	//config
	var defcfg = {
		cookie_name: 'ahp',
		icon: $('<img style="float:right" src="../img/tog.gif">')
	};
	cfg = $.extend(defcfg,cfg);
	//evento salvataggio cookie, solo se sulla pagina c'è qualche pannello da gestire
	//if($els.length) {
		$(window).unload(function(){
				var ckval = $els.filter('[ahp=visible]').attrs('id').join(';');
				$.cookie(cfg.cookie_name,ckval);
		});
	//}
	//ripristino cookie
	var ck = $.cookie(cfg.cookie_name);
	var ckids = {};
	if(ck) {
		var ackids = ck.split(';');
		$.each(ackids,function(k,v){
			//var $el = $('#'+v);
			ckids[v] = 'visible';
		});
	}
	//per ogni elemento
  return $els.each(function(){
  	var $el = $(this);
  	var isvis = (ckids && ckids[$el.attr('id')])?true:false;
  	//console.log(this);
  	//console.log("isvis: "+isvis);
		//prependo l'icona
		var $btn = $(cfg.icon).clone(true)
		$el.prepend($btn);
		//console.log($btn);
		var fshow = function(e){
			//console.log('show');
			if(e && e.preventDefault) e.preventDefault();
			$el.css({
				'height': 'auto',
				'overflow-y': 'visible'
			});
			$el.attr('ahp','visible');
		};
		var fhide = function(e){
			//console.log('hide');
			if(e && e.preventDefault) e.preventDefault();
			$el.css({
				'height': '16px',
				'overflow-y': 'hidden'
			});
			$el.attr('ahp','hidden');
		};
		if(isvis) {
			fshow.call();
			$btn.toggle(fhide,fshow);
		} else {
			fhide.call();
			$btn.toggle(fshow,fhide);
		}
	});
};
*/


//gestione tabs semplice
/*
$('[tabs]').each(function(){
	var tabs = $('a[rel]',this);
	var tabactive = null;
	var i=0;
	tabs.each(function(){
		$this = $(this);
		if(!i) {
			$this.addClass('active');
			tabactive = $(this);
		}
		//console.log(i +" "+ tabs.length);
		if(i && tabs.length>1) {
			$('#'+$this.attr('rel')).hide();
		}
		$this.click(function(evt){
			$this = $(this);
			$('#'+tabactive.attr('rel')).hide();
			tabactive = $this;
			$('#'+$this.attr('rel')).show();
			tabs.removeClass('active');
			$this.addClass('active');
			evt.preventDefault();
			return false;
		});
		i++;
	});
});
*/


//gestione tabs semplice
//richiede plugin: cookie,batch
//todo: static per il cookie parsato
//      cfg aggiuntive??
jQuery.fn.ttabs = function(cfg) {
	var $els = this;
	if(!$els.length) return $els;
	//config
	var defcfg = {
		active_class: 'tabon',
		cookie_name: 'ttabs'
	};
	cfg = $.extend(defcfg,cfg);
	//salvataggio cookie
	$(window).unload(function(){
			var $ckels = $('a.'+cfg.active_class+'[rel]',$els);
			var ckval = $ckels.attrs('rel').join(';');
			$.cookie(cfg.cookie_name,ckval);
	});
	//ripristino cookie
	var ck = $.cookie(cfg.cookie_name);
	var ckids = {};
	var nckids = 0;
	if(ck) {
		var ackids = ck.split(';');
		$.each(ackids,function(k,v){ ckids[v] = true; nckids++; });
	}
	//ciclo elementi
	return $els.each(function(){
		//inizio each
		var $tabs = $('a[rel]',this);
		var tabactive = null;
		var i=0;
		$tabs.each(function(){
			var $tabbtn = $(this);
			var attrrel = $tabbtn.attr('rel');
			if( $tabs.length==1 || 
					(!nckids && !i) || 
					(nckids && ckids[attrrel])
			) {
				$tabbtn.addClass(cfg.active_class);
				tabactive = this;
			}
			//console.log(i +" "+ tabs.length);
			if(this!=tabactive && $tabs.length>1) {
				$(attrrel).hide();
			}
			$tabbtn.click(function(evt){
				var $tabactive = $(tabactive);
				$($tabactive.attr('rel')).hide();
				tabactive = this;
				$($tabbtn.attr('rel')).show();
				$tabs.removeClass(cfg.active_class);
				$tabbtn.addClass(cfg.active_class);
				evt.preventDefault();
				return false;
			});
			i++;
		});
		//fine each
	});
	//fine estensione
};



//gestione highlight righe tabelle
jQuery.fn.hTr = function(){
	var $els = this;
	return $els.each(function(){
		var hbg = $(this).attr('htr');
		$('tr:gt(0)',this).hover(function(){
			$(this).attr('prev_bg', $(this).css('background-color') );
			$(this).css('background-color',hbg);
		},function(){
			$(this).css('background-color', $(this).attr('prev_bg') );
		});
	});
};

//gestione highlight righe tabelle (con conf)
jQuery.fn.hTr2 = function(cfg){
	var $els = this;
	if(!$els.length) return $els;
	//config
	var defcfg = {
		selitems: 'tr:not(.nohtr)',
		hcolor: 'lightblue'
	};
	cfg = $.extend(defcfg,cfg);
	return $els.each(function(){
		var currhel = null;
		var $el = $(this);
		var $items = $(defcfg.selitems,$el);
		$items.hover(function(){
			if(currhel===this) return;
			if(currhel && currhel!==this) {
				var $cel = $(currhel);
				$cel.css('background-color', $cel.data('htr') );
				currhel = null;
			}
			var $item = $(this);
			$item.data('htr', $item.css('background-color') );
			$item.css('background-color',defcfg.hcolor);
			currhel = this;
		},function(){
			var $item = $(this);
			$item.css('background-color', $item.data('htr') );
			currhel = null;
		});
	});
};

//gestione select box dipendenti (in genere nazione,regione/provincia/comune)
jQuery.fn.selectLevels = function() {
	var $els = this;

	return $els.each(function(){
		//per ogni div che gestisce i select a cascata
		var $self = $(this);
		var url_page = $self.attr('selpage');
		var $sels = $('select',this);
		$sels.change(function(){
			var $this = $(this);
			//var sclear = '<option selected value=""></option>';
			var sclear = '';
			$this.parent().nextAll().children('select').html(sclear);
			var nextl = $this.attr('nextl');
			var value = $this.val();
			if(!value || !nextl) return;
			var url_curr = url_page.replace('{l}',nextl?nextl:'').replace('{pv}',value?value:'');
			//richesta ajax
			var selfsel = $this;
			$.ajax({
				type: "GET",
				url: url_curr,
				cache: false,
				success: function(sel_html) {
					var $nextsel = selfsel.parent().nextAll().children('select:eq(0)');
					$nextsel.html(sel_html);
				}
			});
			//fine change
		});
	});
};

//con offset 0,0 rispetto al mouse ha dei bug
//gestione tooltip semplice
jQuery.fn.ttip = function(cfg) {
	var defcfg = {
		offx: 20,
		offy: 10,
		attr: 'ttfor',
		show_on: 'mouseenter',//'click'
		follow_mouse: true,
		hide_on_over: true,
		hide_on_clickover: true
	};
	cfg = $.extend(defcfg,cfg);
	//per ogni elemento
  return this.each(function(){
    var $eltip = $(this);
    //per l'xhtml rimuovo il tootltip e lo metto nel body
    var tmp = $eltip.clone(true);
    $(document.body).append(tmp);
    $eltip.remove();
    $eltip = tmp;
    //trovo elementi che visualizzeranno il tooltip
		var tsel = $eltip.attr(cfg.attr);
		var $els = $(tsel);
		//event tooltip
		var ttfnc = {
			on: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				//console.log('on');
				$eltip.css({
						'left': (e.pageX + cfg.offx) + "px",
						'top' : (e.pageY - cfg.offy) + "px",
						'position': 'absolute',
						'display': 'none'
					}).fadeIn('normal');
			},
			off: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				//console.log('off');
				//verifico che non sia un sotto elemento del tooltip
				var $te = $(e.target || e.srcElement);
				var $ttp = $te.parents().filter(function(){return $eltip.get(0)==this;});
				//console.log($te);
				//console.log($ttp);
				if($ttp.length>0) return;
				$eltip.stop(true,true).css('display','none');
			},
			mouse_move: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				//console.log('move');
				$eltip.css({
						'left': (e.pageX + cfg.offx) + "px",
						'top' : (e.pageY - cfg.offy) + "px"
					});
			}
		};
		//setto eventi tooltip
		//console.log($els);
		$els.bind(cfg.show_on,ttfnc.on);
		if(cfg.hide_on_over) $els.bind('mouseleave',ttfnc.off);
		if(cfg.hide_on_clickover) $(document).click(ttfnc.off);
		if(cfg.follow_mouse) $els.mousemove(ttfnc.mouse_move);
  });
};

//metodo fileBox per rimozione box singoli
jQuery.fn.fileBox = function() {
	//per ogni elemento
  return this.each(function(){
    //evento rimozione box
		$('.delete[type=checkbox]',this).click(function(){
			var delbox = $(this).parents('.filebox');
			var hiddel = $('input.hidden_delete',delbox);
			var cntbox = $('.cnt',delbox);
			var delchecked = $(this).attr('checked');
			hiddel.val( (delchecked?'1':'0') );
			$('input',cntbox).attr('readonly',delchecked);
			$('input[type=file]',cntbox).attr('disabled',delchecked);
			cntbox.css('opacity', (delchecked?0.6:1) );
		});
  });
};

//metodo fileSet() per gestire aggiunta e rimozione box files
jQuery.fn.fileSet = function() {
	//per ogni elemento
  return this.each(function(){
    //evento per aggiungere un box
    var fileset = $(this);
    var fileol = $('ol',this);
    $('.addfile',fileset).click(function(){
    	var newbox = $('.filebox:first',fileol).clone(true);
    	var cntbox = $('.cnt',newbox);
    	//cntbox.css('opacity',1);
    	$('input[type!=checkbox]',newbox).val('');
    	$('input[type=checkbox]',newbox).attr('checked',false);
    	$('input',newbox).attr('readonly',false);
    	$('.fname',newbox).text('');
    	$('img.file',newbox).attr('src','../img/doc_types/icon_generic.gif');
    	$('input[type=file]',cntbox).attr('disabled',false);
			fileol.append(newbox);
		});
		//evento rimozione box
		$('.filebox',fileset).fileBox();
  });
};

//gestione validazione forms
jQuery.validateForm = function(form) {
	var form = $(form);
	//var privata
	var form_validators = {
		'email' : /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/,
		'notempty' : '^(.|\s|\w|\n|\r)+$',
		'numeric': '^\\d+$',
		'decimal': '^\\d+(,\\d+)?$',
		'alphanumeric': '^[a-zA-Z0-9]+$',
		'username': '^[a-zA-Z0-9_@\.]{6,25}$',
		'chars': '^[a-zA-Z]+$',
		'captcha': '^[a-zA-Z0-9]{5}$',
		'codfis':'^[a-zA-Z]{6}[\\d]{2}[a-zA-Z][\\d]{2}[a-zA-Z][\\d]{3}[a-zA-Z]$',
		'piva':'^\\d{7}\\d{3}\\d{1}$',
		'password': function(el) {
			//console.dir(el);
			el = $(el);
			//alert('x0');
			var rptel = $('#'+el.attr('repeatel'));
			//alert('x1');
			if(el.val() && el.val()===rptel.val() && (el.val().length>=4 && el.val().length<=25) ) {
				//alert('x2');
				el.removeClass('invalid');
				rptel.removeClass('invalid');
				return true;
			}
			//alert('x3');
			el.addClass('invalid');
			rptel.addClass('invalid');
			return false;
		}
	};

	var verify_fields = $('[verify]:enabled',form);
	if(verify_fields.length<1) return true;
	//alert("qui2");
	//sul submit verifico i campi
	var not_valid_els = [];
	verify_fields.each(function(){
		//console.log(this);
		var field = $(this);
		var validator = form_validators[field.attr('verify')];
		var is_valid = false;
		//alert(validator);
		
		//if(field.attr('disabled'))
		//	return true;
		
		if(field.attr('optional') && !field.val().length)
			return true;
		
		if(field.attr('type')=='checkbox') {
			 if(field.attr('checked')) is_valid = true;
		} else {
			if(typeof validator=='string') {
				var rx = new RegExp(validator);
				is_valid = rx.test( field.val() );
				//alert('qui3');
			} else if (validator && typeof validator['test']=='function'){
				//console.log("xx"+validator);
				is_valid = validator.test( field.val() );
			} else if(typeof validator=='function') {
				is_valid = validator(this);
				//alert('qui4');
			}
		}
		
		if(!is_valid) {
			//alert('qui5');
			var field_msg = field.attr('errmsg');
			if(!field_msg) field_msg = "Campo "+field.attr('name')+" non valido!";
			field.addClass('invalid');
			var errel = {
				'el': this,
				'msg': field_msg
			};
			not_valid_els.push(errel);
			//console.dir(errel);
		} else {
			field.removeClass('invalid');
		}
	});
	//alert("qui6");
	//finito ciclare campi
	if(not_valid_els.length) {
		//preparo messaggio per l'alert();
		var msg = '';
		for(i in not_valid_els) {
			var errel = not_valid_els[i];
			msg += "- "+errel.msg+"\n";
		}
		if(msg) alert(msg);
		return false;
	}
	return true;
};



//http://remysharp.com/2008/01/21/fixing-ie-overflow-problem/
// usage
//$('pre').fixOverflow();
(function ($) {
  $.fn.fixOverflow = function () {
    if ($.browser.msie) {
      return this.each(function () {
        if (this.scrollWidth > this.offsetWidth) {
          $(this).css({ 'padding-bottom' : '20px', 'overflow-y' : 'hidden' });
        }
      });            
    } else {
      return this;
    }
  };
})(jQuery);

//------------------------------------------------------------------

//gestione A(dd)R(em)M(ove)R(rows)
jQuery.armr = function(cfg,selitem,parent) {
	var defcfg = {
		addbtn: '.add',
		rembtn: '.rem',
		upbtn: '.up',
		downbtn: '.down',
		copyfields: true,
		domclone: false,
		//init: function(){}
		//add: function(){}
	 	//rem: function(){}
	 	//up: function(){}
		//down: function(){}
		minitems: 1,
		fade: true
	};
	cfg = $.extend(defcfg,cfg);
	//per ogni elemento
	var $els = $(selitem,parent);
	function armr_events() {
  	var $el = $(this);
  	
  	//init
  	if(cfg.init) cfg.init.apply(this);
  	
  	//add
  	if(cfg.addbtn) {
	  	$(cfg.addbtn,$el).click(function(){
				var $item = $(this).parents(selitem);
				//console.log($item);
				var $copy = cfg.domclone?$($item[0].cloneNode(true)):$item.clone();
				$item.after($copy);
				if(cfg.copyfields) $.copyFields($copy,$item);
				if(cfg.add) cfg.add.apply($item,[$copy]);
				armr_events.apply($copy);
				if(cfg.fade) $copy.css({'opacity':0}).animate({'opacity':1},"slow");
			});
		}
		//rem
		if(cfg.rembtn) {
			$(cfg.rembtn,$el).click(function(){
				var $item = $(this).parents(selitem);
				var nsibs = $item.siblings(selitem).length;
				if(cfg.rem) cfg.rem.apply($item);
				if(nsibs>=cfg.minitems) $item.remove();
			});
		}
		//up
		if(cfg.upbtn) {
			$(cfg.upbtn,$el).click(function(){
				var $item = $(this).parents(selitem);
				var $prev = $item.prev(selitem);
				if($prev.length) {
					var $copy = cfg.domclone?$item.eq(0).cloneNode(true):$item.clone();
					$item.remove();
					$prev.before($copy);
					if(cfg.copyfields) $.copyFields($copy,$item);
					if(cfg.up) cfg.up.apply($item,[$copy]);
					armr_events.apply($copy);
					if(cfg.fade) $copy.css({'opacity':0}).animate({'opacity':1},"slow");
				}
			});
		}
		//down
		if(cfg.downbtn) {
			$(cfg.downbtn,$el).click(function(){
				var $item = $(this).parents(selitem);
				var $next = $item.next(selitem);
				if($next.length) {
					var $copy = cfg.domclone?$item.eq(0).cloneNode(true):$item.clone();
					$item.remove();
					$next.after($copy);
					if(cfg.copyfields) $.copyFields($copy,$item);
					if(cfg.down) cfg.down.apply($item,[$copy]);
					armr_events.apply($copy);
					if(cfg.fade) $copy.css({'opacity':0}).animate({'opacity':1},"slow");
				}
			});
		}
  };
  return $els.each(armr_events);
};

jQuery.fn.rangepicker = function(dpcfg) {
		var $els = this;
		if(!$els.length) return $els;
	
		var def_dpcfg = {
			dateFormat: 'dd/mm/yy',
      changeMonth: true,
      changeYear: true,
      itemSelector: '.idate:visible'
		};
		dpcfg = $.extend(def_dpcfg,dpcfg);
		
		dpcfg.beforeShow = function(el) {
    	var mindate = $(el).prevAll(dpcfg.itemSelector).eq(0);
			if(mindate.length) $(el).datepicker('option','minDate',mindate.datepicker('getDate'));
			else $(el).datepicker('option','minDate',null);
    	var maxdate = $(el).nextAll(dpcfg.itemSelector).eq(0);
    	if(maxdate.length) $(el).datepicker('option','maxDate',maxdate.datepicker('getDate'));
    	else $(el).datepicker('option','maxDate',null);
    };
    
		dpcfg.onClose = function() {
    	var currdate = $(this).datepicker('getDate');
    	$(this).nextAll(dpcfg.itemSelector).eq(0).datepicker('option','minDate',currdate);
    	$(this).prevAll(dpcfg.itemSelector).eq(0).datepicker('option','maxDate',currdate);
    }
		
		return $els.datepicker(dpcfg);
};


jQuery.fn.maxchecks = function(cfg) {
		var $els = this;
		if(!$els.length) return $els;
	
		var def_cfg = {
			//parentSel: '.campo',
			itemSel: 'input:checkbox',
			max: 3
		};
		cfg = $.extend(def_cfg,cfg);
		
		return $els.each(function(){
			var $parent = $(this);
			var $checks = $(cfg.itemSel,this);
			$checks.click(function(){
				var cc = $('input:checked',$parent).length;
				if(cc>cfg.max) return false;
				return true;
			});
		});
};


//per confrontare due array jquery
$.fn.equals = function(compareTo) {
  if (!compareTo || !compareTo.length || this.length!=compareTo.length) return false;
  for (var i=0; i<this.length; i++) {
    if (this[i]!==compareTo[i]) return false;
  }
  return true;
};


(function($) {
	$.fn.ddm = function(cfg) {
		var $els = $(this);
		if(!$els.length) return $els;
		//config
		var defcfg = {
			duration: 300
		};
		cfg = $.extend(defcfg,cfg);
		//inizio ciclo elementi			
		return $els.each(function() {
			//$(".menu1 ul").css({display: "none"}); // Opera Fix
			var $menu = $(this);
			$("li",$menu).hover(function(){
				var $sm = $('ul:first',this).css({visibility:"visible",display:"none"});
				var inside_root_ul = $.data($(this).parent()[0])==$.data($menu[0]);
				if(inside_root_ul) $sm.animate({height:'show'},cfg.duration);
				else $sm.animate({width:'show'},cfg.duration);
			},function(){
				$('ul:first',this).css({visibility:"hidden"});
			});
		});
	}
})(jQuery);

//------------------------------------------------------------------------------

jQuery.makeSelector = function(e,exclasses) {
	//array parent e se stesso
	var ps = $.makeArray( $(e).parents() );
	ps.unshift(e);
	//console.dir(ps);
	
	//produco il selettore per l'elemento selezionato
	var asel = [];
	var lps = ps.length;
	while(lps) {
		var currsel = '';
		//console.log(lps);
		var p = ps[lps-1];
		//tagname
		var tagname = p.tagName.toLowerCase();
		currsel += tagname;
		//id elemento
		var id = $(p).attr('id');
		if(id.length) {
			currsel += "#"+id;
		}
		//classi? e come faccio a sapere quelle buone da tenere?
		//se c'è solo una classe la tengo
		var sclass = $.trim( $(p).attr('class') );
		var aclass = sclass.split(/\s+/);
		if(aclass.length && aclass[0].length) {
			var okclass = null;
			if($.isArray(exclasses)) {
				okclass = [];
				$.each(aclass,function(i,v){
					if($.inArray(v,exclasses)<0) okclass.push(v);
				});
			} else {
				okclass = aclass;
			}
			//console.log(okclass);
			if(okclass.length==1)
				currsel += "."+okclass[0];
		}
		//indice elemento
		//solo se non è html o body
		if(!$(p).is('body,html')) {
			// e se ci sono altri elementi dello stesso tipo come siblings
			if($(p).siblings(currsel).length) { 
				var oc = $(p).prevAll(currsel).length;
				currsel += ":eq("+oc+")";
			}
		}
		//salto di livello
		asel.push(currsel);
		lps--;
	}
	return asel.join(' > ');
}

//------------------------------------------------------------------------------

/*
$(document).ready(function(){
	//fix dei check prima del submit
	$('.formcnt form').submit(function(){
		$(this).fixChecks();
		return true;
	});

	//bindo eventi agli elementi già presenti sulla pagina
	bindItemEvents($('li.field'));
	
	//end
});
*/



//-----------------------------------------------------------------
