		function abs(num){
			return (num<0)?-num:+num;	
		}
		
		function url_load(url){
			window.location.href = url;	
		}

/////////////////////////////////////////////////////////////////////////////////

var jsDialog = document.getElementById('jsDialog');
var showDialog = false;

			function changeClass(object,_classname){
					object.className=_classname;
			}


		function select_url_load(that,address){
		//alert(that.options[1].value);
		for(i = 0; i<that.length;i++)			
			if(that.options[i].selected) {		
				str = address.replace('123id123',that.options[i].value);
				//alert(str);
				url_load(str);
			}
		}


///////////////////////////////////////////////////////////////////////////// Date




			// getDateElement č una funzione che prende un elemento (giorno(d), mese(M), anno(y) da una data(date) basandosi sul formato format. Per esempio: getDateElement("25/08/2006","dd/MM/yyyy") restituirā 08
			function getDateElement(date, format, type){
				var res="";
				for(i = 0; i < date.length && i < format.length; i++){
						if(format.charAt(i)==type)
							res+=date.charAt(i);
						//alert(res+"   "+date+"   "+format.charAt(i)+"   "+type);
				}
				return res;
			}
			
			function sortableDate(date, format){
				var stringDay = (getDateElement(date, format, 'd'));
				var day = parseInt(stringDay,10);
				var stringMonth = (getDateElement(date, format, 'M'));
				//alert("m,pi " + stringMonth + " " + parseInt("08"));
				var month = parseInt(stringMonth,10);
				//alert (day+"   !"+stringDay+"!   "+month+"   !"+stringMonth+"!");	
				var year = parseInt(getDateElement(date, format, 'y'));
				//alert(date+"   "+format+"   "+day+"  "+"   "+month+"   "+year);
				return year*10000+month*100+day;
			}
			
			function dateComp(start,end,format){
				//format = "MM/dd/yyyy";
				sortableStart = sortableDate(start,format);
				sortableEnd = sortableDate(end,format);	
				if(!sortableStart||!sortableEnd) return "+1"; // Se non passo un elemento mi considero nel caso standard in cui č la data end č maggiore della start
				//alert(sortableEnd-sortableStart);
				return sortableEnd-sortableStart;	
			}
			
			var InternetExplorer = document.all?true:false;
			
			// If NS -- that is, !IE -- then set up for mouse capture
			if (!InternetExplorer) document.captureEvents(Event.MOUSEMOVE);
			
			// Set-up to use getMouseXY function onMouseMove
			document.onmousemove = getMouseXY;

/////////////////////////////////////////////////////////////////////////////// Dimensioni, eccetera

function my_WH(obj){ return [obj.offsetWidth,obj.offsetHeight]; }

function my_win_XY(obj) {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return  [scrOfX, scrOfY];
}


function my_win_WH() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	return [myWidth,myHeight];
}

/////////////////////////////////////////////////////////////////////////////// Immagine Mouse
	
	var mouse_x ;
	var mouse_y ;
	function getMouseXY(e){
		if (InternetExplorer) { // grab the x-y pos.s if browser is IE
			mouse_x = event.clientX + document.body.scrollLeft;
			mouse_y = event.clientY + document.body.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			mouse_x = e.pageX + document.body.scrollLeft;
			mouse_y = e.pageY + document.body.scrollLeft;
		}  
		//document.getElementById("jsdialog").innerHTML = mouse_x+" - "+mouse_y;
	}
	
	function move_div_near_mouse(id,delta_x,delta_y){move_div_near_mouse(id,delta_x,delta_y,null)}
	

	var old_time;
	function move_div_near_mouse(id,delta_x,delta_y,direction){		


		div = document.getElementById(id);

		div.style.display='block';
		div.style.position='absolute';
		
		divWH = my_WH(div);
		div_width = divWH[0];
		div_height = divWH[1];

		winXY = my_win_XY(div);
		win_x = winXY[0];
		win_y = winXY[1];
		
		winWH = my_win_WH();
		win_width = winWH[0];
		win_height = winWH[1];		

		win_max_x = win_x+win_width;
		win_max_y = win_y+win_height;	

		
		pos_x=mouse_x+delta_x;
		if(direction=="left"){
			pos_x = mouse_x-delta_x-div_width;	
		}

		pos_y = mouse_y+delta_y;
		if(pos_y+div_height>win_max_y)
			pos_y = win_max_y - div_height ;
		if(pos_y<win_y)
			pos_y=win_y;
		

		
		div.style.left=""+(pos_x)+"px";
		div.style.top=""+(pos_y)+"px";
		
		
		if (showDialog) {
			jsDialog.style.display='block';
			jsDialog.style.left=""+win_x+"px";			
			jsDialog.style.top=""+win_y+"px";
			jsDialog.innerHTML = "mouse_x: "+mouse_x+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "mouse_y: "+mouse_y+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "width: "+div_width+"&nbsp;&nbsp;&nbsp;<br />"
			jsDialog.innerHTML += "height: "+div_height+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "win_x: "+win_x+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "win_y: "+win_y+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "win_width: "+win_width+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "win_height: "+win_height+"&nbsp;&nbsp;&nbsp;<br /></br>";			
			jsDialog.innerHTML += "pos_y+div_height: "+(mouse_y+delta_y+div_height)+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "win_max_y: "+win_max_y+"&nbsp;&nbsp;&nbsp;<br />";
			jsDialog.innerHTML += "win_max_y - div_height: "+(win_max_y - div_height)+"&nbsp;&nbsp;&nbsp;<br />";	
			jsDialog.innerHTML +=" <br />"
}
}
	
	function close_div_near_mouse(id){
		document.getElementById(id).style.display='none';
		if (showDialog) jsDialog.style.display='none';
	}
	
	var old_mouse_cursor;
	function set_mouse_cursor(cursor){
		old_mouse_cursor = document.getElementById('body').style.cursor;
		document.getElementById('body').style.cursor = cursor;
	}
	
	function reset_mouse_cursor(){
		document.getElementById('body').style.cursor = old_mouse_cursor;
	}
	
	function put_block_where_mouse(id,deltaX,deltaY){
			object = document.getElementById(id);
			object.style.position = "absolute";
			object.style.top=(mouse_y-deltaY)+"px";
			object.style.left=(mouse_x-deltaX)+"px";	
			object.style.display = 'block';
	}
	
//////////////////////////////////////////////////////////////////////////// messaggi e conferme
	
	function if_confirm_go(msg,url,same_window){
		if (confirm(msg)){
			if (same_window)
				document.location = url;
			else {
				var x = window.open(url);
				x.focus();
			}
		}
	}
//////////////////////////////////////////////////////////////////////////// Contestual Menu

	var stillInMenu = 0;
	var contestual_action=null;
	var contestual_id=null;

	function paste_url(address){
		address+="&recursive_action_id_son="+contestual_id+"&recursive_action="+contestual_action;
		url_load(address);
	}
	
	function contestual_menu(id, deltaX, deltaY){
		stillInMenu = 1;
		var object = document.getElementById(id);
		if(object==null) return;
		if(contestual_action!=null && document.getElementById("paste_"+id)) document.getElementById("paste_"+id).style.display="block";
		object.style.top=(mouse_y-deltaY)+"px";
		object.style.left=(mouse_x-deltaX)+"px";
		object.style.display="block";
	} 
	
	function keep_contestual_menu(id){
		stillInMenu = 1;				
	}
	
	function CloseContestualMenu(id){
		//alert(id)	;
		stillInMenu = 0;
		var object = document.getElementById(id);
		setTimeout("DelayedCloseContestualMenu('"+id+"')",100);
	}
	function DelayedCloseContestualMenu(id){
		var object = document.getElementById(id);
		if(!stillInMenu) object.style.display='none';
	} 
			

	
	
	