// JavaScript Document

function $(att){
obj = false;
if(typeof att == "string"){
	try
	{
		obj = document.getElementById(att);
	
	}
	catch(e){
	    obj = "error";	
	}
}
 else if(typeof att ==  "object"){
        obj = att;	
		//alert(obj)
}


 
 if(obj != 'error'){

 obj.css = obj.style;
 
/* getting CSS properties*/
 obj.getProperty = function(prop){
	  return eval('obj.css.' + prop);
 }
 
/*adding or modify CSS properties*/
 obj.setProperty = function(prop, val){
	   //alert(typeof prop);
	   if(typeof prop  == 'object'){
		 for(i = 0; i < prop.lenght; i++){
			eval('obj.css.' + prop[i] + '=\'' + (typeof val == "object"?val[i]:val) + '\'');
		 }
	   }
	   else {
		   eval('obj.css.' + prop + '=\'' + (typeof val  == "object"?val[0]:val)  + '\'');
	   }
 }
 
 
 }
 
 
 /*event listener*/
 
 
 obj.trigging = function(eve,fnct){
	 
	 obj.fnct = function(){
		fnct; 
	 }
	 
 if(document.addEventListener){obj.addEventListener(eve,obj.fnct,false);}
 if(document.attachEvent){obj.attachEvent("on" + eve,obj.fnct); /*alert(obj.attachEvent);*/}
 else{eval("obj.on" + eve + " = " + fnct);}
 
 
 }
 
 /* fine event listener*/
 
 
 return obj;
}



/* subfunction getElementByClassName*/
function getElementsByClassName(className, tag, elm){
        var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for(var i=0; i<length; i++){
                current = elements[i];
                if(testClass.test(current.className)){
                        returnElements.push(current);
                }
        }
        return returnElements;
}




/* oggeto XMLHttpRequest generico*/

function XHR(){
 xhr = false;
 
             if(window.XMLHttpRequest){ 
                   xhr = new window.XMLHttpRequest();
                  }
			     else if(window.ActiveXObject){
			       try{
				      xhr  =  new window.ActiveXObject('Msxml2.XMLHTTP');
				    }
				    catch(e){
				      try{
				        xhr = new window.ActiveXObject('Microsoft.XMLHTTP');
				       }
				      catch(e){
				        xhr = false;
				        msg = e;
				       }
				    }
			       }
 return xhr;
 
	
}


/* utilità di posizionamento*/


  function intelligentPositioning(el){
	    
		dimensione = new Array();
		  
	    t = el.t; l = el.l; eloffh =  parseInt($(el.id).offsetHeight); eloffw =  parseInt($(el.id).getProperty('width'));
		b = document.documentElement || document.body;
		inWidth = window.innerWidth || b.clientWidth; inWidth = parseInt(inWidth);
		inHeight = window.innerHeight || b.clientHeight; inHeight = parseInt(inHeight);
		//alert(inHeight + "\n" + inWidth);
		dimensione["t"] = t + ((t + eloffh) > inHeight?( inHeight - (t + eloffh)):0);
		dimensione["l"] = l + ((l + eloffw) > inWidth?( inWidth - (l + eloffw)):0);
		
		//alert(inHeight +  "\n" + (t + eloffh));
		
		return dimensione;
	  
	  }
	  

