

var _e3Utility = function(){
	this.startMouseMove = function (){
		var IE = document.all?true:false
		if (!IE) document.captureEvents(Event.MOUSEMOVE)	
		document.onmousemove = e3Utility.getMouseXY;		
		
	};
	this.getMouseXY = function(e) {
		var ie = document.all?true:false;	
		if (ie) { // grab the x-y pos.s if browser is IE
			e3MouseCoords.x = event.clientX + document.documentElement.scrollLeft
			e3MouseCoords.y = event.clientY + document.documentElement.scrollTop;

		} else {  // grab the x-y pos.s if browser is NS
			e3MouseCoords.x = e.pageX
			e3MouseCoords.y = e.pageY
		}  
		// catch possible negative values in NS4
		if (e3MouseCoords.x < 0){e3MouseCoords.x = 0}
		if (e3MouseCoords.y < 0){e3MouseCoords.y = 0}  
		
		return true
	}
	/* aggiunta, rimozione, sostituzione e verifica presenza classe dei fogli di stile in un elemento*/
	this.jscss = function(action,object,class1,class2){
		switch (action){
			case 'swap':
				object.className=!this.jscss('check',object,class1)?object.className.replace(c2,class1): 
				object.className.replace(class1,c2);
			break;
			case 'add':
				if(!this.jscss('check',object,class1)){object.className+=object.className?' '+class1:class1;}
			break;
			case 'remove':
				var rep=object.className.match(' '+class1)?' '+class1:class1;
				object.className=object.className.replace(rep,'');
			break;
			case 'check':
				var className = object.className;
				
				if (className.length>0){
					var vericifa = new RegExp(eval("/"+class1+" /"));
					return vericifa.test(className+" ");
				}else{
					
					return false;
					}
			break;
			
			};
		}
		
	/* Ricava position reale */
	this.getStylePosition= function (el) {
		
		if(el.currentStyle)
			return el.currentStyle.position;
		if(document.defaultView)
			return document.defaultView.getComputedStyle(el, '').getPropertyValue("position");
		return false;
	}
	/* Aggiunta eventi*/
	 
	this.addEvent  = function(obj, evType, fn)
			{
				if (obj.addEventListener){
				   obj.addEventListener(evType, fn, true);
				   
				   return true;
				 } else if (obj.attachEvent){
				   var r = obj.attachEvent("on"+evType, fn);
				   return r;
				 } else {
				   return false;
				 } 
			}
	/* Rimozione eventi*/
	this.removeEvent  = function(obj, evType, fn)
		{
			if ( obj.detachEvent ) {
				obj.detachEvent( 'on'+evType, obj[evType+fn] );
				obj[evType+fn] = null;
			} else
				obj.removeEventListener( evType, fn, false );
		}
	/* Cerca attributi all'interno dell'attributo class, per mantenere valido il documento XHTML */
	/*this.attribute = new _e3Attribute();*/
	
	
	this.findAll = function(){
		
		var value = this.attribute.findFromCss("popup","A");
		var elencoTag = this.attribute.resultSearch;

		for (var i=0;i<elencoTag.length;i++){					
			elencoTag[i].onclick = this.Bind(this.popup, elencoTag[i]);
			
		}
		
		var value = this.attribute.findFromCss("visDiv","INPUT");
		
		var elencoTag = this.attribute.resultSearch;
		
		for (var i=0;i<elencoTag.length;i++){					
			elencoTag[i].onclick = this.Bind(this.visDiv, elencoTag[i]);
			this.visDiv(elencoTag[i]);
		}
		
	}
	
	this.visDiv = function(obj){
		
		var visDiv = obj.getAttribute("visDiv");
		var visDivObj = document.getElementById(visDiv);
		if (visDivObj){
			if (obj.checked){
				visDivObj.style.display="block";
			}else{
				visDivObj.style.display="none";
			}
		}
	}
	
	this.Bind=function(fn, arg)
	{
  	return function () { return fn(arg);};
	}
	
					
	this.popup=function(obj){
		
		var valori = obj.getAttribute("popup").split(",");
		var name = valori[0];
		var width = valori[1];
		var height = valori[2];
		
		var popup = window.open(obj.href,"popup","WIDTH="+width+",HEIGHT="+height);
		popup.focus();
		
		return false;
		}
	// Restituisce il posizionamento assoulo di un elemento all'interno della pagina
	// !!!! deprecata 
	this.getDim = function(el){
		var lw = el.offsetWidth;
		var lh = el.offsetHeight;
		
		for (var lx=0,ly=0;el!=null;
		  lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
		
	
		return {x:lx,y:ly,w:lw,h:lh}
  	}
	
	this.tableAlign=function(){
		var tables=document.getElementsByClassName("[align]");
		
		var columnWidth = new Array();
		var rows=new Array();
		
		for(var i=0;i<tables.length;i++){
			var tmpRow = tables[i].getElementsByTagName('tr')
			for(var i2=0;i2<tmpRow.length;i2++){
				
				rows.push(tmpRow[i2]);
			}
		}
		
		for(var i=0;i<rows.length;i++){
			var colonne = rows[i].getElementsByTagName("TD");
			for (var i2=0;i2<colonne.length;i2++){
				
				var tmpWidth = document.getElementInformations(colonne[i2]).width;
				if (isNaN(columnWidth[i2])) columnWidth[i2] = 0
				
				if (tmpWidth > columnWidth[i2]){
				
					columnWidth[i2] = tmpWidth;
				}
				
			}
			
		}
		for (var i=0;i<columnWidth.length;i++){
			
			for(var i2=0;i2<rows.length;i2++){
				//rows[i2].getElementsByTagName('td')[i].style.backgroundColor = "#FF0";
				rows[i2].getElementsByTagName('td')[i].style.width=columnWidth[i];
			}
		}
		
	};
	this.selectAllText = function(fieldName) {


	  var tempval=eval("document."+fieldName);
	  
	  tempval.focus();
	  tempval.select();
	}
	
	this.setHash=function(className){
		
			
			var allElm;
			if (className==null){
				allElm=document.getElementsByTagName("*");
			}else{
				allElm=document.getElementsByClassName(className);
			}
			for(var i=allElm.length;i--;){
//			for(var i=0;i<allElm.length;i++){
				if(!allElm[i].id){
					allElm[i].id='!hash'+this.idHash;
					this.idHash++;
					if (className!=null){
						allElm[i].getElementsByTagName('div')[0].id='!hash'+this.idHash;
						this.idHash++
					}
				}
			}
	
		
		
	}
	this.idHash = 1;
	this.attachNote=function(el,msOver,msOut,visClass,hidClass){
		
		var a=document.getElementsByClassName(el);
		for(var i=a.length;i--;){
//		for(var i=0;i<a.length;i++){
			var divObj = a[i].getElementsByTagName('div')[0];
			if (divObj){
				if (!divObj.id){
					divObj.id="!hash"+this.idHash;
					this.idHash++
				}
			}
			
			a[i].onmouseover=function(){
				var nChild=this.getElementsByTagName('div')[0];
				if(nChild){
					
					var ids=nChild.id;
					e3Utility.showHide(ids,true,msOver,0,visClass,hidClass);
				}
			}
			a[i].onmouseout=function(){
				var nChild=this.getElementsByTagName('div')[0];
				if(nChild){
					var ids=nChild.id;
					e3Utility.showHide(ids,false,msOut,1,visClass,hidClass);
				}
			}
		}
		};
	
	
	this.showHideTimeout;
	
	this.showHide=function(divId,visibility,ms,show,visClass,hidClass){
		var div=document.getElementById(divId);
		if(!visClass) visClass='visible';
		if(!hidClass) hidClass='';
		switch (show){
			case 0:
				if(!ms) var milliSec=1000;
				else var milliSec=ms;
				div.removeAttribute("setTimeout");				
				this.showHideTimeout = setTimeout('e3Utility.showHide("'+divId+'",'+visibility+','+milliSec+',"","'+visClass+'","'+hidClass+'")',milliSec);
				return false;
			case 1:
				if(!ms) var milliSec=200;
				else var milliSec=ms;
				clearTimeout(this.showHideTimeout)
				div.setAttribute("setTimeout","stop");				
				this.showHideTimeout = setTimeout('e3Utility.showHide("'+divId+'",'+visibility+','+milliSec+',"","'+visClass+'","'+hidClass+'")',milliSec);
				return false;
			default:
				var allElm=document.getElementsByTagName('DIV');
				for(var i=0;i<allElm.length;i++){
					
					if(allElm[i].getAttribute("setTimeout")!=null){
						allElm[i].className=hidClass;
					}
				}
				if(visibility){
					div.className=visClass;
				}
		}
	}
	
	/*********************************************************/
	/* Definisce il metodo scatenato all'onload della pagina */
	/*********************************************************/
	
	this.Main = function(source){
			this.addEvent(window,"load",source);
			try{
				if (e3Validate)	{
					this.addEvent(window,"load",function(){e3Validate.verifyForm();});
				
				}
			}catch(error){}
		}
	
	};


/*

var _e3Attribute = function(){
	
	this.findFromCss = function(attributeName,tagName){
		this.resultSearch = new Array();
		var value;
		value = ""
		var elencoTag = document.getElementsByTagName(tagName);
		for (var i=0;i<elencoTag.length;i++){
			
			if (elencoTag[i].className.indexOf("["+attributeName+"=")>-1){
				var elencoAttr = elencoTag[i].className.split(" ");
				for (var i2=0;i2<elencoAttr.length;i2++){
					if (elencoAttr[i2].indexOf("["+attributeName+"=")>-1){
								var keyValue =elencoAttr[i2].split("=");
								value = keyValue[1].substr (0,keyValue[1].length-1);
								elencoTag[i].setAttribute(attributeName,value);	
								this.resultSearch.push(elencoTag[i]);
								break;											 
						}
					}
				
			}
		}
		
		return value;
		}
		this.resultSearch =new Array();
	}
var e3Attribute = new _e3Attribute();
*/
var e3Utility = new _e3Utility();
e3Utility.Main (
	function(){
				//e3Utility.findAll();
				//e3Utility.tableAlign();
			
			
				//document.forceMaxHeight("[height]");
		}
	)

