//#IF b=gecko $import:Scripts/Gecko.IEExtension.js
if(typeof(console) == 'undefined') console = {log:function (obj){window.status=obj.toString()}};
/*console disactivation for IE*/
if(typeof(isIE) == 'undefined') isIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1) ;
if(typeof(isMoz) == 'undefined')  isMoz = !isIE;

/********	ARRAY ********/
/*
SHORT DESCRIPTOR NOTATION
Standard >>>>>>>>>>>>>>>>>>
E[|id] = Estensione di oggetto predefinito es. Array.prototype.indexOf
Es[|id] = Membro static di un oggetto es. Array.From
Fv[|id] = funzione assegnata a var es. var fx = function (){ ...}
Jo[|id] = oggetto JSON var o={m:v,f:function(){}}
Ot[|id] = template oggetto classico 
Extra >>>>>>>>>>>>>>>>>>>>>
A^[id] = alias of id
*/

Array.prototype.indexOf/*E*/ = function(e){	
	var i=this.length;
	while(--i>-1){if(this[i]==e) return i;}
	return i; // = -1
}

Array.prototype.indexOfInvariant/*E*/ = function(e){ 
	var i=this.length;
	while(--i>-1){ if(this[i].toString().invariantCompare(e.toString())==0) return i;}
	return i; // = -1  
}
Array.prototype.swapIndex = function (x,y){
	var e1 = this[x],e2 = this[y];
	this[x] = e2; this[y] = e1;
	return this;
}
Array.prototype.swapElements = function (e1,e2){
	var x = this.indexOf(e1),y = this.indexOf(e2);
	if(x>-1 && y>-1) return this.swapIndex(x,y);
	return null;
}

Array.prototype.add/*E*/ = function(e){ 
	this.push(e);
	return e
}

Array.prototype.addRange/*E*/ = function(r){ 
	var a = this;
	r.foreach(function (e){a.add(r)})
	return this;
}

Array.prototype.remove/*E*/ = function(e){ 
    var i=this.indexOf(e);
    if (i!=-1) this.splice(i,1);
}

Array.prototype.replace/*E*/ = function(oldE,newE){ 
    var i=this.indexOf(oldE);
    if (i!=-1) this.splice(i,1,newE);
}

Array.prototype.contains/*E*/ = function(e){ 
	var i=this.length;
	while(--i>-1){if(this[i]==e) return true;}
    return false;
}

Array.prototype.find/*E*/ = function(matchCallback){ 
    if(typeof(matchCallback)=="function"){
		var i=-1;
		while(++i<this.length){if(matchCallback(this[i])) return this[i];}
    }
    return null;
}

Array.prototype.findAll/*E*/  = function(matchCallback){ 
    var r=[];
    if(typeof(matchCallback)=="function"){
        for(var i=0; i<this.length;i++) {
            if(matchCallback(this[i])) r.add(this[i]);
        }
    }
    return r;
}

Array.prototype.foreach/*E*/ = function(callback){ 
    if(typeof(callback)=="function"){
        for(var i=0; i<this.length;i++) {
            callback(this[i],i);/* element , index */
        }
    }
}

Array.prototype.trueForAny/*E*/ = function(matchValue){ 
    for(var i=0; i<this.length;i++) {
        if(this[i]==matchValue) return true;
    }
    return false;
}

Array.prototype.copy/*E*/ = function (startIndex,length){ 
	var result = [];
	var i = startIndex;
	var c = 0;
	while(i<length) {if(i >= this.length) break;result.push(this[i]);i++};
	return result;
}

Array.prototype.trueForAll/*E*/ = function(matchValue){ 
    for(var i=0; i<this.length;i++) {
        if(this[i]!=matchValue) return false;
    }
    return true;
}

Array.prototype.match/*E*/ = function(matchCallback){ 
    if(typeof(matchCallback)=="function"){
        for(var i=0; i<this.length;i++) {
           if(matchCallback(this[i])) return true;
        }
    }
    return false;
}

Array.prototype.toElements/*E*/ = function (){ 
    var a = []
    for(var i=0; i<this.length;i++) {
            var e= $(this[i]);
            if(!isNull(e)) a.add(e);
    }
    return  a;
}

Array.prototype.clear/*E*/ = function (){ 
	 this.length = 0;
}

var $A/*A^1*/ = Array.from/*Es|1*/ = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}



/********	STRING ********/


String.prototype.formatNumber/*E*/ = function (decimals,decimalChar,sepChar) {
	var s = this;
	
	s = s.replace(new RegExp("\\" + sepChar + "+","g"),"");
	if (decimalChar!=".")  s = s.replace(new RegExp("\\" + decimalChar + "+","g"),".");
	var parts = s.split (".");
	if (parts.length == 2)  {
		parts[1] = parts[1].substring(0,decimals);
	}
	return parts.join(".");
}

String.prototype.toURI/*E*/= function(){
	try{
	return encodeURIComponent(this);
	}
	catch(e) {
	return this;
	}
}
String.prototype.printf/*E*/ = function () {
	var args = Array.from (arguments);
	if(isArray (arguments[0])) args = arguments[0];
	return this.replace(/\{{1}\d+\}{1}/ig,function(p){
		var s =p.toString(); 
		var i = parseInt(s.substr(1,s.length - 2));
		var v = args[i] || "" ;
		return v;
	});	
}
String.prototype.dup/*E*/=function (times){ //duplicate
	var i = 0; var s = ""; while (++i <= times) {s += this};return s;
}
String.prototype.fromURI/*E*/= function(){
	if(this==null||this=='') return '';
	return decodeURIComponent(this);
}

String.prototype.surround/*E*/ = function (sBefore,sEnd){
	return sBefore + this + sEnd;
}
String.prototype.isNumber/*E*/ = function() {
	if(this==null||this=='') return false;
	var re=new RegExp("^[\\d\\.\\-]+$");
	return re.test(this);
}
String.prototype.invariantCompare/*E*/ = function (strCompare){
	if (this.toLower()>strCompare.toLower()) return 1;
	else if (this.toLower()<strCompare.toLower()) return -1;
	else return 0;
}

String.prototype.inArray/*E*/ = function (array){
	return array.contains(this)
}

String.prototype.isDate/*E*/  = function () {   
    var patterns=[
        "^\\d{1,2}[\\s\\S]{1}\\d{1,2}[\\s\\S]{1}\\d{4}\\s*[\\d\\.\\:UTCGM\\s]*$",
        "^\\d{4}[\\s\\S]{1}\\d{1,2}[\\s\\S]{1}\\d{1,2}\\s*[\\d\\.\\:UTCGM\\s]*$"  
    ]
    var mFunc=new Function("pattern","var re=new RegExp (pattern);return re.test('"+ escape(this) +"');")
    return patterns.match(mFunc);
}

String.prototype.splitEx/*E*/=function (){    
//split che accetta piu' caratteri di separazione
    if(arguments.length>0){
    var temp=[this];
         for(var i=0; i<arguments.length;i++) {                
            var separator=arguments[i];
            var innerTemp=[];
            for(var n=0; n<temp.length;n++) {
                innerTemp.addRange(temp[n].split(separator));
            }
            temp=innerTemp;
         }
    }
    return temp;
}

String.prototype.splitPairs/*E*/=function(pairSeparator,innerSeparator){
    var pairs=this.split(pairSeparator);
    var result=new Object;
    for(var i=0; i<pairs.length;i++) {
        var kv=pairs[i].split(innerSeparator);
        if (kv.length!=0){
            var k= kv[0];
            var v= (kv.length>1)? kv[1] : null;
            result[k]=v;            
        }
    }        
    return  result;
}

String.prototype.toDateEx/*E*/ = function (dateSeparator,timeSeparator,format){
    var formatArray=format.splitEx(dateSeparator,timeSeparator," ");
    var valuesArray=this.splitEx(dateSeparator,timeSeparator," ");
    var formatFindPos=function(){
        for(var i=0;i<arguments.length;i++){
            var p = formatArray.indexOf(arguments[i]);
            if(p!=-1) return p
        }
        return  -1;
    }
    var positions = []
    positions["d"]=formatFindPos("d","dd");
    positions["M"]=formatFindPos("M","MM");
    positions["y"]=formatFindPos("y","yy","yyyy");
    positions["h"]=formatFindPos("h","hh");
    positions["m"]=formatFindPos("m","mm");
    positions["s"]=formatFindPos("s","ss");
    var valuesFind=function(token){
        var p=positions[token];
        if(p==-1) return  0;
        else return  valuesArray[p];
    }
    var d,m,y,h,M,s    
    d = valuesFind("d");
    M = valuesFind("M");
    y = valuesFind("y");
    h = valuesFind("h");
    m = valuesFind("m");    
    s = valuesFind("s");
    if([y,M,d].trueForAny(0)) return  null;
    else return  new Date(y,M-1,d,h,m,s);    
}

String.prototype.toDate/*E*/ = function (format){
    return this.toDateEx("/",":",format);
}
String.prototype.toLower/*E*/= function (){
    return this.toLowerCase();
}

String.prototype.toUpper/*E*/= function (){
    return this.toUpperCase();
}

String.prototype.equals/*E*/=function(s){
	if(isNull(s)) s="";
    return (this.toLower()==s.toString().toLower())
}


String.prototype.startsWith/*E*/=function(s){
	if(isNull(s)) s="";
    return  (this.substring(0,s.length).toLower()==s.toLower());
}

String.prototype.endsWith/*E*/=function(s){
	if(isNull(s)) s="";
    return  this.substr(this.length - s.length).toLower()==s.toLower();
}
String.prototype.contains/*E*/=function(s){
	if(isNull(s)) s="";
    return  (this.toLower().indexOf(s.toLower())!=-1);
}
String.prototype.trimEnd/*E*/=function (s) {
	if (this.length>0 && this.substr(this.length-1)==s) {		
		return this.substring(0,this.length-1)
	}
	return this;
}

String.prototype.Trim/*E*/=function () {
return this.replace(/\s+$|^\s+/g,"");
}

String.prototype.RTrim/*E*/=function () {
return this.replace(/^\s+/,"");
}

String.prototype.LTrim/*E*/=function () {
return this.replace(/\s+$/,"");
}
   
String.prototype.truncate/*E*/ = function (maxlength,paddingchar){
	var p = paddingchar || "...";
	if(this.length<=maxlength) return  this;
	else return  this.substring(0,maxlength) + p;
}

String.prototype.padLeft/*E*/ = function (maxlength,paddingchar){
	if(this.length>= maxlength) return this;
	return paddingchar.dup(maxlength-this.length) + this;
}
String.prototype.padRight/*E*/ = function (maxlength,paddingchar){
	if(this.length>= maxlength) return this;
	return this + paddingchar.dup(maxlength-this.length) ;
}

Number.prototype.round/*E*/ = function (precision) {
	var number = this;
    if (precision == undefined) precision = 2;
    var sign = (number < 0) ? -1 : 1;
    var multiplier = Math.pow(10, precision);
    var result = Math.abs(number);
    result = Math.floor((result * multiplier) + .5000001) / multiplier;
    if (sign < 0) result = result * -1;
    return result;
}

Number.prototype.formatBytes/*E*/ = function (precision) {
	var giga_limit = 2 << 29;
	var mega_limit = 2 << 19;
	var kilo_limit = 2 << 9;
    if (precision == undefined) precision = 2;
	var number = this;
    if (number < 0)
        throw new Error("formatBytes(precision): Negative this not allowed in format_bytes.");
    var suffix = "byte";
    if (number > giga_limit) {
        number /= giga_limit;
        suffix = "Gb";
    }
    else if (this > mega_limit) {
        number /= mega_limit;
        suffix = "Mb";
    }
    else if (this > kilo_limit) {
        number /= kilo_limit;
        suffix = "Kb";
    }
    return number.round(precision).toLocaleString() + " " + suffix;
}
/********	DATE ********/
var Now/*Fv*/ = function (){ return new Date();}
Date.prototype.shortDate/*E*/=function (){
   var s = new String();
   s += this.getDate() + "/";                   //Get day
   s += (this.getMonth() + 1) + "/";            //Get month
   s += this.getFullYear();                         //Get year.
   return s;
}
Date.prototype.format/*E*/ = function (dateFormat){
	var s = dateFormat,month =(this.getMonth() + 1).toString(),year = this.getFullYear().toString();
	s=s.replace(/y+/g,year);
	s=s.replace(/M{2,}/g,month.padLeft(2,'0'));
	s=s.replace(/M{1}/g,month);
	s=s.replace(/d{2,}/g,this.getDate().toString().padLeft(2,'0'));
	s=s.replace(/d{1}/g,this.getDate());
	s=s.replace(/h{2,}/g,this.getHours().toString().padLeft(2,'0'));
	s=s.replace(/h{1}/g,this.getHours());
	s=s.replace(/m{2,}/g,this.getMinutes().toString().padLeft(2,'0'));
	s=s.replace(/m{1}/g,this.getMinutes());
	s=s.replace(/s{2,}/g,this.getSeconds().toString().padLeft(2,'0'));
	s=s.replace(/s{1}/g,this.getSeconds());
	return s;
}

Function.prototype.bind/*E*/ = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener/*E*/ = function(object) {
  var __method = this, args = $A(arguments), object = args.shift();
  return function(event) {
    return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
  }
}
Function.prototype.getName/*E*/ = function(){	
	var cs = this.arguments.callee;
	if(isNullString(cs)) return 'undefined';
	cs = cs.substr('function '.length);       
    cs = cs.substr(0, cs.indexOf('('));    
    return cs.toString().Trim();
}

RegExp.escape/*Es*/ = function(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}

var Class/*Jo*/ = {
  create: function() {
    return function() { this.initialize.apply(this, arguments)}
  }
}
var ControlBase/*Jo*/ = {
	element : null,
	bindToElement : function  (element){
		this.element = $(element);
		this.element.owner = this;
	},
	bindOptions : function  (options){
		for(prop in options) {
			if(!isNull(this[prop])) this.assignValue(prop,options[prop]);
		}
	},
	bindAttributes : function  (){
		if(isNull(this.element)) return ;
		var atts = this.element.attributes;
		for(var i=0, length = atts.length;i<length;i++){
			var a = atts[i];
			try{ this.setProperty(a.nodeName,a.nodeValue); }
			catch(e){}							
		}
	},
	inherits: function  (element,options){
		//tutti i bindings
		this.bindToElement(element);
		this.bindOptions(options);
		this.bindAttributes();
	}
}

function extend/*Fx*/ (destination, source) {
  for (var property in source) {
  	try{
	if(!destination[property]) destination[property] = source[property];}
	catch(e){}
  }
  return destination;
}
Object.prototype.extend/*E*/=function(base){return Object.extend(this,base)}
Object.extend/*Es*/ = function(destination, source) { 
	return extend(destination, source);
}
Object.prototype.keys/*E*/ = function  (){
	var keys = [];
    for (var prop in this)
      keys.push(prop);
    return keys;
}
Object.prototype.hasProperty/*E*/ = function (propName){
	var k = this.keys();	
	return (k.indexOfInvariant(propName)!=-1);
}
Object.prototype.setProperty/*E*/  = function (propName,value){
	for (var prop in this){
		if(prop.invariantCompare(propName)==0) this.assignValue(prop,value);
	}
}
Object.prototype.assignValue/*E*/  = function (propName,value){
	if(isNull(this[propName])) return;
	if(isBool(this[propName]) && isString(value)) {
		this[propName] = (value.toLower()=="true") ;
		}
	else this[propName] = value;
}
/********	SHORTCUTS ********/

var $/*A^2*/ = getObj/*Fv|2*/ = function (e){ /*Shortcut per getElementById*/
	if (arguments.length > 1) {
		for (var i = 0, elements = [], length = arguments.length; i < length; i++)
	    elements.push($(arguments[i]));
	    return elements;
	}
	if(typeof e =="string") return document.getElementById(e);
	else if(typeof e =="object") return e;
	else return null;
}

$.eval = function (s){
	eval("var obj=" + s);
	return obj;
}
var $V/*Fv*/ = function (e,def){ 
	var v = $(e).value;
	if(isNullString(v)) v=def||null;
	return v;
} //value input by id

function formatInt/*Fx*/(d){
	var s = new Number(d).toLocaleString();
	if (navigator.systemLanguage=="it") {
		var p = s.indexOf(",");
		if(p != -1) s = s.substring(0,p);
	}
	return s;
} 

function DOMElement/*Ot*/(e){
    this.base=getObj(e);
    extend(this,this.base); 
	this.private_getElementsOf=function (founds,current,matchFunction){
        if(current.nodeType==1){
            if(matchFunction==null) founds.add(current);
            else {
                if(matchFunction(current)) founds.add(current);
                }
            for(var i=0;i < current.childNodes.length;i++){
                this.private_getElementsOf(founds,current.childNodes[i],matchFunction);
            }
        }
    } 	 
	 //restituisce tutti gli elementi DOM di un oggetto
	this.getElements=function(){
        var founds=[];
        this.private_getElementsOf(founds,this,null);
        return  founds;    
    }
	//restituisce tutti gli elementi DOM di un oggetto con una data classe
	this.getElementsByClassName=function(classname){
	        var founds=[];    
	                classname=classname.toLower();
	                var matchFunction=function(e){        
	                    if(typeof(e.className)!='undefined'){                    
	                         return  (e.className.toLower()==classname);
	                    }
	                    return  false;
	                }  // end matchFunction   
	            this.private_getElementsOf(founds,this.base,matchFunction); 
	        return  founds;    
	} 
	//restituisce tutti gli elementi DOM di un oggetto con un dato attributo
	this.getElementsByAttribute=function(attributeName,attributeValue){
        var founds=[];
                var matchFunction=function(e){					
                    var attrValue = e.getAttribute(attributeName,0);
                    if(attrValue!=null){
						if(isNull(attributeValue)) return true;
                        if(typeof(attributeValue)=="string")
                            return  (attrValue.equals(attributeValue));
                        else return  attrValue=attributeValue;
                    }
                    return  false;
                }  // end matchFunction
            this.private_getElementsOf(founds,this.base,matchFunction);
        return  founds;
    }	
}
    
window.getElementsByClassName=
document.getElementsByClassName= function(classname,parentElement){
    var DOM = new DOMElement(getObj(parentElement) || document.body);
    return  DOM.getElementsByClassName(classname);
}

window.getElementsByAttribute=
document.getElementsByAttribute = function(attributeName,attributeValue,parentElement){
    var DOM = new DOMElement(getObj(parentElement) || document.body);
    return  DOM.getElementsByAttribute(attributeName,attributeValue);
}

if(!window.attachEvent) { //attachEvent enabled for non IE
Window.prototype.attachEvent =Document.prototype.attachEvent = HTMLElement.prototype.attachEvent = function($name, $handler) {this.addEventListener($name.slice(2), $handler, false)}
Window.prototype.detachEvent =	Document.prototype.detachEvent = HTMLElement.prototype.detachEvent = function($name, $handler) {this.removeEventListener($name.slice(2), $handler, false)}
}

function isObject/*Fx*/(obj){return obj instanceof Object}
function isArray/*Fx*/(obj){return obj instanceof Array}
function isFunction/*Fx*/(f){return  (typeof(f)=='function')}
function isString/*Fx*/(obj){return (typeof(obj)=='string')}
function isDate/*Fx*/(obj){return obj instanceof Date}
function isBool/*Fx*/(obj){return (typeof(obj)=='boolean')}
function isNull/*Fx*/(obj){ return (obj ==null)} // non funziona per undefined
function isNullString/*Fx*/(obj){return (isNull(obj) || obj.toString() =="")}

function purge/*Fx*/(d) {    
		var a = d.attributes, i, l, n;    
		if (a) {
			l = a.length;        
			while(--i>=0) {n = a[i].name; if (typeof d[n] === 'function') d[n] = null;}    
		}    
		a = d.childNodes;    
		if (a) {        
			l = a.length;        
			while(--i>=0) {purge(d.childNodes[i]);}    
		}
	}

var $E/*Jo*/ = {
      preventDefault : function (){
        try{window.event.preventDefault();}
        catch(ex){}
      },
	  getElements:function (parent) {
	  	var e = $(parent);
		var founds = [];
		for(var i=0;i<e.childNodes.length;i++){
			var child = e.childNodes[i];
			if(child.nodeType==1) founds.add(child);
		}
		return founds;
	  },
	  insertAfter : function (newElement,targetElement) {
		var parent = $(targetElement).parentNode;
		if(parent.lastChild == targetElement) {return parent.appendChild(newElement)}
		else return parent.insertBefore(newElement, targetElement.nextSibling)
	  },
	  getElementsByClassName:function (element,classname){
	  	  var e = $(element);
		  var founds = [];
		  for(var i=0;i<e.childNodes.length;i++){
		  	var child = e.childNodes[i];
			if(child.nodeType==1 && child.className && child.className.toLower()==classname.toLower()) {
				founds.add(child);
			}
		  }
		  return founds;
	  },
	  getChildElementsByClassName:function (element,classname){
	  	  var e = $(element);
		  var DOM = new DOMElement(e);
    	  return  DOM.getElementsByClassName(classname);
	  },
	  clearChilds : function  (element){
			 var e = $(element);
			 for(var i=(e.childNodes.length - 1);i>=0;i--){
			 	e.removeChild(e.childNodes[i]);
			}
	  },
	  appendContent : function  (element,content){
			 var e = $(element);
 	  		 this.clearChilds(e);
			 if(isString(content)) e.innerHTML=content;
			 else e.appendChild(content);
			 return e;
	  },
	  classover:function(element,normalClass,overClass) {
	  	var e = $(element);
		if(!overClass) overClass = normalClass + '_sel';
		e.className = normalClass;
		e.onmouseover=new Function("this.className='" + overClass + "'")
		e.onmouseout=new Function("this.className='" + normalClass + "'")
	  },
	  value:function (id){
	  	if(isNull($(id))) return;
		var isSetting = (arguments.length>1) ;
		if($(id).nodeName.invariantCompare("select")==0) {
			//select
			var options = $(id).options;			
			if(isSetting) {				
				for(var i=0;i<options.length;i++){
					if(options[i].value.invariantCompare(arguments[1])==0) {
						options[i].selected=true;
					}
				}
			}
			return options[$(id).selectedIndex].value;
		}
		else {
			//input, textarea
			if(isSetting) $(id).value=arguments[1];
			return $(id).value;
		}
	  },
      visible: function(element) {
	  	return this.getStyle(element,'display') != 'none';
      }, //visible
      hideContextmenu:function (){ 
        //$E.hideContextmenu() disabilita per l'intero documento
        //$E.hideContextmenu('element' | element) disabilita per l'elemento
        var obj=(arguments.length==0)? document : $(arguments[0]);
        var action=function(e){
            try{window.event.preventDefault();}
            catch(x){};
            return  false;
            }
        obj.oncontextmenu=action;
      }, 
	  hover: function(e,outStyle,overStyle){
	  		this.style($(e),outStyle);
			$(e).onmouseover = new Function("$E.style(this,'" + overStyle + "')");
			$(e).onmouseout = new Function("$E.style(this,'" + outStyle + "')");
	  },
	  elementContains:function(thisElement,targetElement){
	  	if(isNull(thisElement) || isNull(targetElement)) return false;
		while (!isNull(thisElement)){
			if(thisElement==targetElement) return true;
			thisElement=thisElement.parentNode;
		}
		return false;	
	  },
	  set:function (e,strProps){
		if(isArray(e)){var i = e.length; while(--i>=0){this.set(e[i],strProps)};return e;}
		var propsPairs = strProps.split(";");
		var e  = $(e);
		for(var i=0;i<propsPairs.length;i++){
			var propsPair = propsPairs[i].split(":");
			var propName = propsPair[0];
			var propValue = (propsPair[1])?propsPair[1]:"";
			e[propName]=propValue;
		}
		return e;
	  },
	  style:function(e,strStyle){
	  	if(isArray(e)){var i = e.length; while(--i>=0){this.style(e[i],strStyle)};return ;}
	  	//applica style all'oggetto
		var getStylePropName = function (name){
			//trasforma un nome di stile tipo border-color in camelCase borderColor
			var ss = name.split("-");var StylePropName="";
			for(var i=0;i<ss.length;i++){
				var chunk = ss[i].toLower();
				if (i>0){var firstChar = chunk.charAt(0);var restChars = chunk.substr(1);chunk=firstChar.toUpper() + restChars.toLower();}
				StylePropName+=chunk;
			}
			return StylePropName;
		}//getStylePropName
		var stylePairs = strStyle.split(";");
		for(var i=0;i<stylePairs.length;i++){
			var stylePair = stylePairs[i].split(":");
			var styleName = getStylePropName(stylePair[0])
			var styleValue = (stylePair[1])?stylePair[1]:"";
			try{
				$(e).style[styleName]=styleValue;
				}
			catch(exc){
			}
		}
	  },//style
	  getStyle:function (e,propName){
	  	if(isArray(e)){var i = e.length,a=[]; while(--i>=0){a.add(this.style(e[i],propName))};return a;}
		e = $(e);
		if(e.currentStyle) return(e.currentStyle[propName]);
		if(document.defaultView.getComputedStyle) return(document.defaultView.getComputedStyle(e,'')[propName]);
		return null;
	  },//getStyle
	  swap:function(){
	  	for(var i=0;i<arguments.length;i++){
			var a = arguments[i];			
			if(this.visible(a)) this.hide(a);
			else this.show(a);
		}
	  },//swap	
	  swapVis:function(){
	  	for(var i=0;i<arguments.length;i++){
			var a = arguments[i];
			if(this.getStyle(a,"visibility")=="hidden") {this.vShow(a)}
			else {this.vHide(a)}
		}
	  },//swap	
	  vShow :function(e){
	  	this.style(e,"visibility:visible");
	  },
	  vHide :function(e){
	  	this.style(e,"visibility:hidden");
	  },
      show:function(){
	  	var styleValue = "block";
        if(arguments.length>1){
            this.show(Array.from(arguments));
        }
        else if (arguments.length==1){
            var e = arguments[0];
            if(isArray(e)){
                for(var i=0;i<e.length;i++) { 
					var _e = e[i];
					if(_e=="block"||_e=="inline") styleValue = _e;
					else this.show(_e);
				}
            }
            else{
				try {
                	getObj(e).style.display=styleValue;
				}
				catch(ex) {
					//alert(e);
				}
            }
        }
      },//show
	  showOne : function (arrayIds,visibleId){
	  	for(var i=0;i<arrayIds.length;i++){
			var item = arrayIds[i];
			if(item==visibleId) $E.show(item); 
			else $E.hide(item);  
		}
	  },
	  showif : function (/*arguments[1...n],condition*/){
	  	var args = Array.from(arguments);
		if(args.length<2) return;
		var elements = args.slice(0,args.length - 1);
		if(args[args.length - 1]) this.show(elements);
		else this.hide(elements);
	  },
      hide:function(){
        if(arguments.length>1){
            this.hide(Array.from(arguments));
        }
        else if (arguments.length==1){
            var e = arguments[0];
            if(isArray(e)){
                for(var i=0;i<e.length;i++) { this.hide(e[i])}
            }
            else{
				try{
                	getObj(e).style.display='none';
					}
				catch(ex){
					//alert(e);
				}
            }
        }
      }, //hide  
	  showIf:function(e,test) {
	  	if(test) this.show(e);
		else this.hide(e);
	  },//showIf
      border:function (element,style){
        $(element).style.border=style;
      },//border
	  pointer:function (element){
	  	try{$(element).style.cursor='pointer';}
		catch(ex){
			try{$(element).style.cursor='hand';}
			catch(ex2){}
		}
      },//pointer
      setWidth:function (element,value){
        $(element).style.width=this.pixelValueOf(value);
      },
      setHeight:function (element,value){
        $(element).style.height=this.pixelValueOf(value);
      },
      create:function (name){
        return  document.createElement(name);
      },
      createDiv:function (){return  this.create("div")},
	  createSpan:function (){return  this.create("span")},
	  createInput:function (){var oInp = this.create("input");
	  if(arguments[0]) extend(oInp,arguments[0]);
	  return oInp},
	  createImg:function (){return  this.create("img")},
      createTable:function (){
	  	var oTable=this.create("table");
		oTable.addRow = function (){
			var oTr = this.insertRow(-1);
			if(arguments[0]) extend(oTr,arguments[0]);
			oTr.addCell = function (){
				var oTd = this.insertCell(-1);
				if(!isNull (arguments[0])) oTd.innerHTML=arguments[0];
				//if(arguments[0]) extend(oTd,arguments[0]);
				return oTd;
			}
			return oTr;
		}
        return  oTable;
      },
      addTr:function (table){
        return  table.insertRow(-1);
      },
      addTd:function (tr) {
        return  tr.insertCell(-1);
      },
	  addCells:function (tr,cellProperties,innerTextArray){
		for(var i=0;i<innerTextArray.length;i++){
			var c = tr.insertCell(-1);			
			extend(c,cellProperties);
			c.innerHTML=innerTextArray[i];
		}
	  },
	  unselectable:function (el){
	  	var e =$(el);
  		if(e.style.setProperty) e.style.setProperty ('-moz-user-select', 'none', '');	
		else {
				e.unselectable="on";
				e.setAttribute("UNSELECTABLE","On");
			}
	  },
	 setOpacity : function (e,value){
	 	var e = $(e);
		try{e.style.filter = "Alpha(Opacity=" + value * 100 + ")"}catch(ex){}
		try{e.style.MozOpacity = value}catch(ex){}
		try{e.style.KhtmlOpacity = value}catch(ex){}
	 },
	 fadeOut : function  (e,delay,opacity){
		var e = $(e); var delay= delay || 200; if(delay<50)delay==50;
		var opacity = opacity || 1; if(opacity>1) opacity = 1;
		this.setOpacity(e,opacity);
		if(opacity==0) {
			this.hide(e)
		}
		else {
			var fx = function (){$E.fadeOut(e,delay,opacity - 0.1)}
			window.setTimeout(fx,delay);
		}
	 }
}

location.getNameWithoutExtension = function (){
	var n = this.getName ();
	var lastDot = n.lastIndexOf(".");
	return n.substring(0 , lastDot);
}

location.getExtension = function (){
	var n = this.getName ();
	var lastDot = n.lastIndexOf(".") + 1;
	if(lastDot!=0)
	return n.substring(lastDot);
}

location.extractName = function (uri){
	var lastSlash = uri.lastIndexOf("/")	+ 1
	var hasPath = (uri.indexOf("?")!=-1);
	uri = uri.substring(lastSlash)
	if (hasPath) 
		uri = uri.substring(0,uri.indexOf("?"));
	return uri;
}

location.getName = function (){
	return this.extractName(this.href);
}
location.directoryName = function (){
	var cDir = this.currentDirectory();
	if(cDir.endsWith("/")) {
		cDir = cDir.substring(0, cDir.lastIndexOf("/"))
	}
	cDir = cDir.substr(cDir.lastIndexOf("/") + 1)
	return cDir
}

location.currentDirectory = function (){
	h = this.href;
	var lastSlash = h.lastIndexOf("/")	+ 1
	return h.substring(0,lastSlash);
}
location.baseDirectory = function (rootDirectories){
	//metodo per trovare la root path basato sulle root dirs
	var rDirs = rootDirectories||["scripts","css","public","admin"];
	var cd = this.currentDirectory().trimEnd("/");
	var parts = cd.split("/");
	if(isArray(rDirs)) {
		var i=-1;
		while(++i<rDirs.length){
			var j= parts.indexOfInvariant(rDirs[i]);
			if(j!=-1) return parts.copy(0,j).join("/");
		}
	}	
	return cd;
}
location.query = location.search;

location.path = function (){
	var h = this.href;
	var q = h.indexOf("?");
	if (q!=-1) {
		return  h.substring(0,q);
	}
	return h;
}
location.changeQuery = function (newQuery){
	return this.path() + "?" + newQuery;
}

location.redirect = function (uri){
	window.location=uri;
}
location.redirectQuery = function (newQuery){
	this.redirect(this.changeQuery(newQuery));
}
location.getRequestDict = function (){
	var d = new Dictionary();
	if(location.search.length!=0) d.fill(location.search.substr(1),"&","=");
	return d;
}
/*
location.redir
ridirige la pagina a se stessa cambiando la queryString
i nuovi valori vanno messi negli argomenti come in location.set
*/
location.redir = function (){
	this.redirect(this.changeQuery(this.set(arguments)));
}
location.redirOut = function (uri,args){
	this.redirect(uri + "?" + this.set(args));
}
/*
location.setUrl
come location.redir soltanto che 
restituisce l'url senza reindirizzare la pagina
*/
location.setUrl = function (){
	return this.changeQuery(this.set(arguments));
}
/*
location.set
restituisce una nuova queryString 
le chiavi e i valori si impostano come argomenti della funzione
alternando chiave/valore:
location.set("id",1,"name","xz"); = id=1&name=xz
per rimuovere un valore settarlo a null o stringa vuota:
location.set("id",1,"name",""); = id=1
*/
location.set = function (){
	var d = this.getRequestDict();
	var c = 0
	var kvList = [];
	var args = (arguments.length==1)?arguments[0]:arguments;	
	while (c<args.length){
		var k = args[c].toString();
		c += 1 ;
		if (c<args.length) {
			var v = args[c].toString();
			c += 1 ;
		}
		else {break}
		kvList.add({"key":k,"value":v});
	}
	kvList.foreach (function (kv){
		if(!isNullString(kv.value)) {
			if(d.item(kv.key)!=null) d.setItem(kv.key,kv.value);
			else d.add(kv.key,kv.value);
			}
		else d.remove(kv.key)
	})
	return d.join("&","=");
}
location._request=null;
location.request = function () {
	if(!isNull(location._request)) return location._request;
	location._request= {};
	if(location.search.length!=0) {		
		q = location.search.substr(1);
		location._request = q.splitPairs("&","=");
	}
	return location._request;
}

location.refresh = function (){
	if('reload' in location) location.reload();
	else window.location=this;
}
var $L = window.location;
var $GET = function  (name,def){
	var v = $L.request()[name];
	if(isNullString(v)) v = def;
	return v;
}
function Dictionary(){
	this.keys = [];
	this.values = [];
	this.add =function (key,value){
		this.keys.add(key.toString());
		this.values.add(value.toString());
	}
	this.item = function (key){
		var i = this.indexOf(key);
		if(i>-1) return this.values[i];
		return null;
	}
	this.setItem = function (key,value){
		var i = this.indexOf(key);
		if(i>-1) this.values[i] = value;
	}
	this.foreach = function (callback){
		for(var i=0;i<this.keys.length;i++){
			callback(this.keys[i],this.values[i]);
		}
	}
	this.indexOf = function (key){
		return this.keys.indexOfInvariant(key);
	}
	this.remove = function (key){
		var i = this.indexOf(key);
		if(i>-1) {this.keys.splice(i,1);this.values.splice(i,1);}
	}
	this.join = function (pairSeparator,keyValueSeparator){
		var pairs = [];
		this.foreach(function (k,v){
			pairs.add(k.toString() + keyValueSeparator + v.toString());
		})
		return pairs.join(pairSeparator);
	}
	this.fill = function (s,pairSeparator,keyValueSeparator){
		var pairs = s.split(pairSeparator);
		for(var i=0;i<pairs.length;i++){
			var pair = pairs[i]
			var kv = pair.split(keyValueSeparator);
			if(!isNullString(kv[1])) this.add(kv[0],kv[1]);
		}
	}
}
var Cookies = new Object();
Cookies.get = function (name,defaultValue) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
			var ckValue=c.substring(nameEQ.length,c.length);
			if(ckValue!='')	return ckValue;
			}
	}
	return defaultValue;
}

Cookies.set = function (name,value) {
	var expires = "";
	var days = arguments[2]; // 3° param expire
	var path = (arguments[3])?arguments[3]:"/"; // 4° param path
	if (days) {
		if(!isNaN(new Number(days))) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = "; expires="+date.toGMTString();
		}
	}
	var setValue = name+"="+value+expires+"; path=" + path;
	document.cookie = setValue;
}

Cookies.remove =  function (name){
	Cookies.set(name,"",-1);
}

var $C = Cookies;

var KeyWatch = new Object();
KeyWatch.keyPress = function (e,action){
		try{
			evt = (window.event && window.event.keyCode)? window.event : e;
  			var keyPressed = evt.which || evt.keyCode;
			var sender = evt.target || evt.srcElement;
			for(var i=2;i<arguments.length;i++){
				if(keyPressed==arguments[i] && isFunction(action)) {
					action(sender,keyPressed);
					//window.status = "keypress" + action;
					}
				
			}
		}
		catch (ex) {alert("")}
	}
KeyWatch.keyReturn = function (e,action){
		this.keyPress(e,action,13);
	}
	
KeyWatch.setWatcher = function (target,actionCallbackName,keycode){
	var listener = new Function ("e","KeyWatch.keyPress(e," + actionCallbackName + "," + keycode + ")");	
	try {$(target).addEventListener("keypress", listener,true)}
	catch(e) {$(target).attachEvent("onkeypress",listener)}
}
KeyWatch.removeWatcher = function (target,actionCallbackName,keycode){
	var listener = new Function ("e","KeyWatch.keyPress(e," + actionCallbackName + "," + keycode + ")");	
	try {$(target).removeEventListener("keypress", listener,true)}
	catch(e) {$(target).detachEvent("onkeypress",listener)}
}
KeyWatch.keyCodes = {"RETURN":13,"ESC":27}
var $K = KeyWatch;
/*
KeyWatch USAGE:
	KeyWatch.setWatcher (myelement,"myfunctionName",keyNum)
KeyWatch SAMPLE:
	KeyWatch.setWatcher (document,"closeWindow",27); //close window on ESC
*/
/*StringBuilder*/
function StringBuilder (){
	this.list=[];
	this.append = function (s) {this.list.add(s);return this};
	this.appendLine = function (s) {if (!isNullString(s)) return this.append(s).append('\r\n');else return this.append('\r\n')};
	this.appendFormat = function (f) { var args=Array.from(arguments); return this.append(f.printf(args.slice(1)))};
	this.appendLiteral = function (s){return this.appendFormat("'{0}'",s.replace("'",(arguments[1]||"''")))};
	this.toString = function () {return this.list.join((arguments[0]||""))}
}
