
//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) );
		});
  });
};

/*
//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('in');
				$eltip.css({
						'left': (e.pageX + cfg.offx) + "px",
						'top' : (e.pageY - cfg.offy) + "px",
						'position': 'absolute',
						'display': 'none'
					}).fadeIn('fast');
			},
			off: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				//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.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);
  });
};
*/

//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();
				var $te = $(e.target || e.srcElement);
				//console.log('in');
				$eltip.css({
					'left': (e.pageX + cfg.offx) + "px",
					'top' : (e.pageY - cfg.offy) + "px",
					'position': 'absolute',
					'display': 'none'
				}).fadeIn('fast');
				//chiamo callback avvio tooltip se specificata
				if(typeof cfg.show == 'function') {
					cfg.show.call($eltip,$eltip,$te); // function show($ttip,$te)
				}
			},
			off: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				//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.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);
  });
};



//------------------------------------------------------------------------------
/*
//gestione tooltip2
jQuery.fn.xtip = function(cfg) {
	var defcfg = {
		offx: 20,
		offy: 10,
		//ttfor: 'ttfor', //se specificato userà gli elementi sul quale è stato incocato come tooltip
		                  //al contrario saranno i target dei tooltip
		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(){
    if(cfg.ttfor) {
    	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);
		} else {
			var ctip = function() {
				var $tip = $('<div class="zoomtip">');
				$(document.body).append($tip);
				return $tip;
			};
			var $els = $(this);
			console.log('activator:');
			console.log($els);
		}
		
		//event tooltip
		var ttfnc = {
			on: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				var $te = $(e.target || e.srcElement);
				if(ctip && !$te.data('zt')) {
					var $eltip = ctip();
					$te.data('zt',$eltip);
				}
				//console.log('in');
				$eltip.css({
					'left': (e.pageX + cfg.offx) + "px",
					'top' : (e.pageY - cfg.offy) + "px",
					'position': 'absolute',
					'display': 'none'
				}).fadeIn('fast');
				//chiamo callback avvio tooltip se specificata
				if(typeof cfg.show == 'function') {
					return cfg.show.call($eltip,$eltip,$te); // function show($ttip,$te)
				}
			},
			off: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				//verifico che non sia un sotto elemento del tooltip
				var $te = $(e.target || e.srcElement);
				if(ctip) {
					var $eltip = $te.data('zt');
					if(!$eltip) return;
				}
				var $ttp = $te.parents().filter(function(){return $eltip.get(0)==this;});
				//console.log($te);
				//console.log($ttp);
				if($ttp.length>0) return;
				if(!ctip) {
					$eltip.css('display','none');
				} else {
					console.log('deltip');
					$eltip.remove();
				}
			},
			mouse_move: function(e){
				if(!e) return;
				if(e.stopPropagation) e.stopPropagation();
				var $te = $(e.target || e.srcElement);
				//console.log('move');
				if(ctip) {
					var $eltip = $te.data('zt');
					if(!$eltip) return;
				}
				$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);
  });
};
*/

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

//tree menu
function toggleSrc(img,array_src) {
	var cur_src = img.src.toLowerCase();
	var val0 = array_src[0].toLowerCase();
	if( cur_src.indexOf('tree_')>-1 )
		img.src = cur_src.indexOf(val0)>0?array_src[1]:array_src[0];
}

//utile per captcha
function reload_img(img)
{
	if(typeof img == 'string')
		img = document.getElementById(img);
	
	if(!img.orig_url)
		img.orig_url = img.src;
	
	var now = new Date();
	if(img.orig_url.indexOf('?')>-1)
		img.src = img.orig_url + "&js_rand=" + now.getTime();
	else
		img.src = img.orig_url + "?js_rand=" + now.getTime();
}

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

//page enlivement
$(document).ready(function(){

	//espande/contrae tree cats
	var imgs = $(".catmenu img.tm_icon");
	imgs.click(function(evt){
		evt.stopPropagation();
		var subul = $(">ul",this.parentNode.parentNode);
		if(subul.length) {
			toggleSrc( this,['img/tree_open.png','img/tree_close.png'] );
			subul.slideToggle();
			subul.toggleClass('tm_espanded');
			subul.toggleClass('tm_collapsed');
		}
	});
	
	//unload pagina: salvo lo stato del tree cats
	$(window).unload(function(){
		//if($(".catmenu").length)
		//	$.cookie('catmenu',$(".catmenu ul.tm_espanded").attrs('id').join(';'));
	});
	
	//ripristino lo stato dal cookie
	/*var menu_state = $.cookie('catmenu');
	if(menu_state) {
		$.each(menu_state.split(';'),function(k,v){
			var ulel = $('#'+v);
			var $timg = $('>div img.tm_icon',ulel.parent());
			var isrc = $timg.attr('src');
			if(isrc && isrc.indexOf('tree_')>-1) //solo se l'immagine coniene 'tree_'
				$timg.attr('src','img/tree_close.png');
			ulel.addClass('tm_espanded').removeClass('tm_collapsed');
			//$('#'+v).addClass('tm_espanded').removeClass('tm_collapsed');
		});
	}*/
	
	
	//attivazione slide notizie homepage
	$('.homeslide').serialScroll({
		target: '.sects',
		items: 'li',
		prev: 'img.prev',
		next: 'img.next',
		axis: 'xy',
		navigation:'.navlinks a',
		duration: 700,
		force: true,
		interval:12000,
		step:1,
		
		onBefore:function( e, elem, $pane, $items, pos ){
			//alert('before');
			//$(this).css('border','1px solid red');
		},
		onAfter:function( elem ){
			//alert('after');
		}
	});
	
	//line height box slide homepage
	//$('.slideitem').autolineheight();
	
	//input ricerca rapida
	var stxt = 'Cerca...';
	var $qs = $('#quicktext');
	//salvo ricerca rapida
	$(window).unload(function(){
		$.cookie('qts',$qs.val());
	});
	//ripristino ricerca
	var cqt = $.cookie('qts');
	if(cqt) $qs.val(cqt);
	
	if(!$qs.attr('value') || $qs.attr('value')==stxt) $qs.val(stxt);
	$qs.click(function(){
		if(this.value==stxt) this.value="";
	}).blur(function(){
		if(!this.value || this.value==stxt) this.value=stxt;
	});
	
	//validazione forms
	var form_validators = {
		'email' : /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/,
		'notempty' : '^(.|\s|\w|\n|\r)+$',
		'numeric': '^\\d+$',
		'alphanumeric': '^[a-zA-Z0-9]+$',
		'data': /^\d{2}\/\d{2}\/\d{4}$/,
		'username': '^[a-zA-Z0-9_@\.]{6,25}$',
		'chars': '^[a-zA-Z]+$',
		'charsws': '^[a-zA-Z\\s]+$',
		'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]$',
		'cell':'^\\+?[\\d -]+$',
		'tel':'^\\+?[\\d -]+$',
		'piva':'^\\d{7}\\d{3}\\d{1}$',
		'nottel':function(el){
			var v = $(el).val();
			var chiocc = v.indexOf('@');
			var am = v.match(/\d{5,}/);
			var em = v.match(/^(.|\s|\w|\n|\r)+$/);
			if(am || !em || chiocc>-1) return false;
			return true;
		},
		'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;
		},
		'selita': function(el) {
			var sels = $('select',el);
			var naz = sels.eq(0).val();
			var reg = sels.eq(1).val();
			var prov = sels.eq(2).val();
			var comu = sels.eq(3).val();
			//alert(naz);
			if(sels.length==3 && naz=='it' && (!reg || !prov)) return false;
			if(sels.length==4 && naz=='it' && (!reg || !prov || !comu)) return false;
			else if(!naz) return false;
			return true;
		},
		'selita_reg': function(el) {
			var sels = $('select',el);
			var naz = sels.eq(0).val();
			var reg = sels.eq(1).val();
			var prov = sels.eq(2).val();
			var comu = sels.eq(3).val();
			//alert(naz);
			
			var regs = ['8229','8234','8230','8231','8233','8232'];
			var isreg = $.inArray(reg,regs)==-1?false:true;
			
			//console.log(isreg);
			
			if( sels.length==3 && naz=='it' && ((!reg && !isreg) || (!prov && !isreg)) ) return false;
			//if(sels.length==4 && naz=='it' && (!reg || !prov || !comu)) return false;
			else if(!naz) return false;
			return true;
		},
		'scurraculim': function (el) {
			//console.log(el);
			if(!$(el).is(':visible')) return true;
			var ret = true;
			$(':input',el).each(function(){
				if(!$(this).val().length) ret = false;
				return false;
			});
			return ret;
		},
		'oneopt': function (el) {
			var f = $(el).parents('form');
			var fcopt = $('[name="'+$(el).attr('name')+'"]:checked',f);
			return fcopt.length?true:false;
		}
	};
	
	$('form').each(function(){
		var form = $(this);
		//if(verify_fields.length) {
			//alert("qui1");
			form.submit(function(){
				var verify_fields = $('[verify]',form);
				//console.log(verify_fields);
				//return false;
				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);
					//console.log('1');
					var field = $(this);
					var validator = form_validators[field.attr('verify')];
					var is_valid = false;
					//alert(validator);
					
					//console.log('2');
					//console.log("bv: "+field.attr('bypassvalidation'));
					//console.log("check: "+field.attr('checked'));
					if(field.attr('bypassvalidation') && !field.attr('checked')) {
						//console.log('3');
						return false;
					}
					
					if(field.attr('disabled'))
						return true;
						
					//console.log('3');
					
					//var xxx = field.val();
					if( (field.attr('optional') && field.attr('optional')!='false') )
						return true;
						
					//console.log('4');
					
					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;
			});
		//}
	});
	
	//gestione select box dipendenti (regione/provincia/comune)
	$('[selpage]').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);
			$this.nextAll('select').html('<option selected value=""></option>');
			var nextl = $this.attr('nextl');
			var value = $this.val();
			if(!value || !nextl) return;
			var $nextsel = $($this.nextAll('select'));
			//console.log($nextsel);
			if(!$nextsel.length) 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.nextAll('select').get(0));
					$nextsel.html(sel_html);
				}
			});
			//fine change
		});
	});
	
	//gestione campi mascherati
	$('[mask]').each(function(){
		$(this).mask( $(this).attr('mask') );
	});
	
	//gestione tabs
	$('[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 selectbox colori
	function colore_change() {
		var $selel = $(this);
		//var color = $('option[selected]',$selel).css('background-color');
		//console.log( color );
		//console.log( $selel );
		//if(color) $selel.css('background-color',color);
		var cval = $selel.val();
		$selel.css( 'background-color', "#"+(cval?cval:'FFF') );
	}
	$('select.colori').each(colore_change);
	$('select.colori').change(colore_change);
	
	//gestione box file
	$('.filebox').fileBox();
	
	/*
	//gestione select per ie6 (width)
	//remmato, non funzia bene
	if($.browser.msie) {
		$('select').each(function(){
			var $this = $(this);
			if(!$this.css('width')) return;
			$this.hover(function(){
				//alert('hover in');
				$this.attr('prev_width',$this.css('width'));
				$this.css('width','auto');
			},function(){
				//alert('hover out');
				$this.css('width',$this.attr('prev_width'));
			});
		});
	}
	*/
	
	//gestione attivazione pulsante attiva servizio
	$('table.servizi input[type=radio]').click(function(){
		$('fieldset.servizi .isubmit').removeAttr('disabled');	
	});
	/*
	var $servtab = $('table.servizi');
	
	function refreshServizi() {
		var $achecks = $('input:checked',$servtab);
		var sum = 0;
		$achecks.each(function(){
			if($(this).attr('disabled')) return;
			sum += parseInt($(this).attr('crediti'));
		});
		$('span.sumprezz',$servtab).text( sum );
	}
	
	refreshServizi();
	$('table.servizi input[type=checkbox]').click(function(){
		refreshServizi();	
	});
	*/
	
	//lista profili submit on change
	$('#list_prof_sel_tipo').change(function(){
		$(this).parents('form').submit();
	});
	
	//gestione highlight righe tabelle
	$('table[htr]').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 tooltip (per ora usati solo nel form di registrazione)
	/*
	$('[tt]').each(function(){
		//console.log(this);
		$this = $(this);
		var tt = $this.attr('tt');
		//console.log(tt);
		var tt_opts = {
			id: tt,
			fade: true,
			track: true, 
    	delay: 0, 
    	top: 0,
    	left: 0
		};
		$this.tooltip(tt_opts);
		//console.dir(tt_opts);
	});
	*/
	
	/*
	$('.regbox img.help').tooltip({
		id: 'ttreg',
		fade: true,
		track: true, 
  	delay: 50, 
  	top: 0,
  	left: 0
	});
	*/
	
	
	//attivazione tooltip
	$('[ttfor]').ttip({
		offx: 10,
		offy: 20,
		attr: 'ttfor'
	});
	
	//gestione input/textarea dove si copia e incolla sempre tutto il contenuto
	$('[allsel]').each(function(){
		var $this = $(this);
		$this.click(function(){
			this.select();
		});
	});
	
	//gestione click su righe tabella servizi con crediti insufficienti
	$('.tabpriv tr.notbuyable').css('cursor','pointer').click(function(){
		window.location.href = '?sez=userpriv&subsez=crediti';
	});
	
	//gestione select natgiu nel form datifatturazione
	//dipendenze campi
	/*
		#df_seppriv,
		#df_sepaz,
		#df_piva,
		#df_codfis,
		#df_ragsoc,
		#df_data
	*/
	
	
	var fattf = function(){
		var $t = $(this);
		var $f = $(this).parents('form');
		var $df = $('#df_ragsoc,#df_nome,#df_cognome,#df_piva,#msgcfaz');
		if(!$t.val()) {
			return;
		}
		$df.css('display','none').find('input,select,textarea').attr('disabled','disabled');
		if( $t.val() == 'S' ) { //azienda
			//console.log('AZIENDA');
			$('#df_ragsoc,#df_piva,#msgcfaz').css('display','').find('input,select,textarea').removeAttr('disabled');
		} else { //privato/estero
			//console.log('PRIVATO/ESTERO');
			$('#df_nome,#df_cognome').css('display','').find('input,select,textarea').removeAttr('disabled');
		}
	};
	
	var $selfatt = $('.datifatt select.selnatgiu');
	fattf.apply($selfatt);
	$selfatt.change(fattf);
	
	
	
	
	//attivo cycle immagini
	$("#cycle_profimgs").cycle({ 
    fx:     "fade",
    after: function(curr, next, opts) {
			
		},
		before: function() {
			var $img = $(this);
			var imgtit = $img.attr('title');
			var tipop = $img.attr('tipop');
			var $divcap = $img.parent().siblings('.cap');
			$divcap.html('');
			$divcap.append($("<img src='"+prof_imgs[tipop]+"'>"));
			$divcap.append(imgtit);
		},
		timeout: 3000 
	});
	
	//gestisco form tooltip ajax per invio link amico
	$('.hidform').ttip({
		offx: -320,
		offy: -5,
		attr: 'ttfor',
		show_on: 'click',
		follow_mouse: false,
		hide_on_over: false,
		hide_on_clickover: true
	});
	var $fform = $('.hidform form');
	$fform.ajaxForm({
		success: function(responseText,statusText){
			//console.dir(this);
			//console.dir(arguments);
			$fform.parents('.hidform').css('display','none');
			alert("Messaggio inviato con successo!"); 
		}
	});
	
	//zoom immagini (tooltip)
	/*
	$('a[rel=zoomtip]').xtip({
		offx: -295,
		offy: 0,
		show_on: 'mouseenter', //click
		follow_mouse: true,
		hide_on_over: true,
		hide_on_clickover: true,
		ttfor: null,
		show: function($t,$e) {
			//console.log($t);
			//console.log($e);
			console.log(arguments);
			var href = $e.attr('href');
			$t.append($('<img src='+href+'>'));
			//$t.text(href);
			return false;
		}
	});
	*/
	
	
	var $az = $('a[rel=zoomtip]');
	var azc = {
		xoff: 10,
		yoff: 10,
		tid: 'preview'
	};
	$az.click(function(){return false;})
	$az.hover(function(e){
		//this.t = this.title;
		//this.title = "";	
		//var c = (this.t != "") ? "<br/>" + this.t : "";
		var c = $(this).attr('title');
		var $p = $("<div>");
		$p.attr('id',azc.tid);
		$p.addClass('zoomtip');
		var $capdiv = $("<div>");
		$capdiv.addClass('caption');
		if(c) {
			$capdiv.text(c);
			$p.append($capdiv);
		}
		var $img = $("<img>");
		$img.attr('src',this.href);
		if(c) {
			$img.attr('alt',c);
			$img.attr('title',c);
		}
		$p.append($img);
		
		$("body").append($p);								 
		$("#"+azc.tid).css({
			"top": (e.pageY - azc.xoff) + "px",
			"left": (e.pageX + azc.yoff) + "px"
		}).fadeIn("fast");						
  },function(){
			//this.title = this.t;	
			$("#"+azc.tid).remove();
  });
  
	$az.mousemove(function(e){
		$("#"+azc.tid).css({
			"top": (e.pageY - azc.xoff) + "px",
			"left": (e.pageX + azc.yoff) + "px"
		});
	});			
	
	//gestione tooltip form invia messaggio
	$('#ttquickmsg').ttip({
		attr: 'ttfor_msg',
		offx: -310,
		offy: 0,
		show_on: 'click',
		follow_mouse: false,
		hide_on_over: false,
		hide_on_clickover: true,
		show: function($t,$e) {
			var idu = $e.attr('idusr');
			$('input.idusr',$t).val(idu);
			//alert( $('input.idusr',$t).val() );
		}
	});
	$('#ttquickmsg form').ajaxForm({
		success: function(responseText,statusText){
			//console.dir(this);
			//console.dir(arguments);
			$('#ttquickmsg').css('display','none');
			//alert("Messaggio inviato!");
			alert(responseText); 
		}
	});
	
	//gestione radio user_annunci
	$('#anntipo').change(function(){
		if($(this).val()!='O') {
			$('#tabcnt_annunci .curr3_CALCIATORE').hide().find(':input').attr('disabled',true);
			$('#tabcnt_annunci .curr3_ALLENATORE').hide().find(':input').attr('disabled',true);
			$('#tabcnt_annunci .curr3_TECNICO').hide().find(':input').attr('disabled',true);
		} else {
 			$('#tabcnt_annunci .curr3_'+$('#tabcnt_annunci .rad:checked').val()).show().find(':input').attr('disabled',false);
		}
	});
	$('#tabcnt_annunci .rad').click(function(){
		$('#tabcnt_annunci .curr3_CALCIATORE').hide().find(':input').attr('disabled',true);
		$('#tabcnt_annunci .curr3_ALLENATORE').hide().find(':input').attr('disabled',true);
		$('#tabcnt_annunci .curr3_TECNICO').hide().find(':input').attr('disabled',true);
		if($('#anntipo').val()=='O') $('#tabcnt_annunci .curr3_'+$(this).val()).show().find(':input').attr('disabled',false);
	});
	
	$('a.aoffr').click(function(){
		var ntr = $(this).parents('tr').next();
		ntr.toggleClass('nodisp');
		return false;
	});
	
});





