Function.prototype.bind = function(object) {
	
  var __method = this;
	
  return function() {
    __method.apply(object, arguments);
  }
}
if (!Function.prototype.apply) {
  Function.prototype.apply = function(oScope, args) {
    var sarg = [];
    var rtrn, call;
    if (!oScope) oScope = window;
    if (!args) args = [];
    for (var i = 0; i < args.length; i++) {
      sarg[i] = "args["+i+"]";
    }     call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
    oScope.__applyTemp__ = this;
    rtrn = eval(call);
    return rtrn;
  }
}

/*****************************/
/* Estensione metodi String  */
/*****************************/

String.prototype.trim = function(){
	var output = this.ltrim();
	output = output.rtrim();
	return output;
	}
String.prototype.ltrim = function(){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
	return"";
	}
	var v_length = this.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
	if(this.charAt(iTemp) == w_space){
	}
	else{
	strTemp = this.substring(iTemp,v_length);
	break;
	}
	iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

String.prototype.rtrim = function(){
	var w_space = String.fromCharCode(32);
	var v_length = this.length;
	var strTemp = "";
	if(v_length < 0){
	return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
	if(this.charAt(iTemp) == w_space){
	}
	else{
	strTemp = this.substring(0,iTemp +1);
	break;
	}
	iTemp = iTemp-1;
	
	} //End While
	return strTemp;

} //End Function

String.prototype.isNumeric = function(){
	var filter  = /^([0-9])+$/;			
	if (!filter.test(this)) {
		return false;
		}else{
		return true;	
	};
}
/*******************************************/


var _e3Utility = function(){
	
	/* 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;
			
			};
		}
	
	/* 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;
		}
			
	this.getDim = function(el){
    for (var lx=0,ly=0;el!=null;
      lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
    return {x:lx,y:ly}
  }
	
	/*********************************************************/
	/* 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();
		}
	)
