/********************* JQuery scrollTo 1.4.1 ***************************/

(function($){var m=$.scrollTo=function(b,h,f){$(window).scrollTo(b,h,f)};m.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1};m.window=function(b){return $(window).scrollable()};$.fn.scrollable=function(){return this.map(function(){var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement})};$.fn.scrollTo=function(l,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){d=n(d);break}d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()}$.each(a.axis.split(''),function(b,h){var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0}g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]}else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){if(r!=g[c])t(a.onAfterFirst);delete g[c]}});t(a.onAfter);function t(b){o.animate(g,j,a.easing,b&&function(){b.call(this,l,a)})};function u(b){var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);

/********************* JQuery ellipsis ***************************/

(function($) {
	$.fn.ellipsis = function(enableUpdating){
		var s = document.documentElement.style;
		if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){
				var el = $(this);
				if(el.css("overflow") == "hidden"){
					var originalText = el.html();
			        var w = el.width();
			        var t = $("#_ellipsis_calc");
			        var ex = t.length < 1;
			        if(ex){
			        	t = $("<span id='_ellipsis_calc'/>").html(originalText).hide().appendTo("body");
			        }	
			        
			        var text = originalText;
			        while(text.length > 0 && t.width() > el.width()){
			        	text = text.substr(0, text.length - 1);
			        	t.html(text + "...");
			        }
			        el.html(t.html());
			        if(!ex)t.remove();
			        
			        if(enableUpdating == true){
						var oldW = el.width();
			       		setInterval(function(){
				      		if(el.width() != oldW){
				      			oldW = el.width();
				      			el.html(originalText);
				      			el.ellipsis();
				      		}
				      	}, 200);
			        }
			    }  
			});   
	    } else return this;   
	};		
	
})(jQuery);	



/********************* JQuery Loader  ***************************/

(function($) {
	
	$.fn.addLoader = function(className){
	    className = (className == undefined) ? "" : " " + className; 
	    var isIE6 = ($.browser.msie && parseFloat($.browser.version)<=6);	    
	    return this.each(function(){
	        var el = $(this);
            var of = el.offset();
            if(isIE6) el.find("select").css({ visibility: "hidden" });
            var sz = {width: el.width(), height: el.height()}
            $("body").append("<div id='Loader" + this.id + "' class='Loader" + className + "' style='top:" + of.top + "px; left:" + of.left + "px; width:" + sz.width + "px; height:" + sz.height + "px;'><div class='Cp'></div><div class='Tx'>Loading...</div></div>"); 
	    }); 		    
	    
	};
	
	$.fn.removeLoader = function(){
	    var isIE6 = ($.browser.msie && parseFloat($.browser.version)<=6);
	    return this.each(function(){
	       var el = $(this);
	       if(isIE6) el.find("select").css({ visibility: "visible" });
           $("#Loader" + this.id).remove(); 
	    }); 
	};
	
	
})(jQuery);	


  
/********************* Richiamano funzioni spevcifiche per ogni update panel ***************************/

function getUpdatePanelName(sender){
    var updID;
    var el = (sender._postBackSettings) ? sender._postBackSettings.sourceElement : null;
    if(el) {
       updID = sender._postBackSettings.panelID.split("|")[0];
       if(updID.indexOf("$") != -1) updID = updID.substring(updID.lastIndexOf("$")+1)    
    }
    return updID;
} 
function beginRequest(sender, args){
   var updID = getUpdatePanelName(sender);          
   if(updID){
       if(eval("typeof(" + updID + "_beginRequest) == 'function'")) {
           window[updID + "_beginRequest"].apply(null,[sender,args])
       }
   }     
}
function endRequest(sender, args) {
   var updID = getUpdatePanelName(sender);          
   if(updID){
       if(eval("typeof(" + updID + "_endRequest) == 'function'")) {
          window[updID + "_endRequest"].apply(null,[sender,args])
       }
   }  
}



  
/********************* Startup ***************************/

function startupCode(){    
    $('input.ClearOnReady').val('');   /* Usato nei controlli che non devono mantenere il valore precedente al PostBack */       
    $("div.Ellipsis").ellipsis(true);  /* Ellips */
    
    if(typeof(Sys) === "object") {
       var inst = Sys.WebForms.PageRequestManager.getInstance();
       inst.add_beginRequest(beginRequest); 
       inst.add_pageLoaded(endRequest); 
    }   
}
$(document).ready(startupCode);

