



function getWindowWidth()
{
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' )
		myWidth = window.innerWidth;
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		myWidth = document.documentElement.clientWidth;
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		myWidth = document.body.clientWidth;
	
	return(myWidth);
}




function getWindowHeight()
{
	myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
		myHeight = window.innerHeight;
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		myHeight = document.documentElement.clientHeight;
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		myHeight = document.body.clientHeight;
	
	return(myHeight);
}




function GetElement(div_id)
{
	var elem;
	
	if( document.getElementById ) 
		elem = document.getElementById( div_id );  
	else if( document.all ) 
		elem = document.all[div_id];  
	else if( document.layers ) 
		elem = document.layers[div_id];  
	
	return elem;
}




function MoveDiv(div_id, left, top)
{  
	var elem = GetElement(div_id);
	elem.style.left = left + "px";
	elem.style.top = top + "px";
}




function CenterDiv(div_id)
{
	var elem = GetElement(div_id);
	
	var win_w = getWindowWidth();
	var win_h = getWindowHeight();
	
	var img_div_w = parseInt(elem.style.width);
	var img_div_h = parseInt(elem.style.height);
	
	var img_div_left = (win_w - img_div_w) / 2;
	var img_div_top = (win_h - img_div_h) / 2;
	
	MoveDiv(div_id, img_div_left, img_div_top);
}





function jumpToAnchor(anchor) {
   window.location = window.location + "#" + anchor;
}



function enter_pressed(e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode; 
	else if (e) keycode = e.which; 
	else return false; 
	return (keycode == 13); 
}


function ToggleDiv(divpanel_id)
{  
	var elem, vis;  
	
	if( document.getElementById ) 
		elem = document.getElementById( divpanel_id );  
	else if( document.all ) 
		elem = document.all[divpanel_id];  
	else if( document.layers ) 
		elem = document.layers[divpanel_id];  
	vis = elem.style;  
	
	// if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}


function ShowHideDiv(divpanel_id, show)
{  
	var elem;  
	
	if( document.getElementById ) 
		elem = document.getElementById( divpanel_id );  
	else if( document.all ) 
		elem = document.all[divpanel_id];  
	else if( document.layers ) 
		elem = document.layers[divpanel_id];  
	
	if (show)
		elem.style.display = 'block';
	else
		elem.style.display = 'none';
}





// restituisce l'oggetto identificato dall'ID in input, null se non esiste
function ElementById( id ) {
 // caso stringa
 if (typeof(id)!="string") return id;
 // dom
 if (document.getElementById) { return document.getElementById(id);
 // IE
 } else if (element.all) { return element.all[id];
 // NN4
 } else if (element.layers) { return FindLayer(id, element); }
 return null;
}

// ricerca del layer (caso NN4)
function FindLayer(id, doc) {
 var i,layer;
 for (i=0; i<doc.layers.length; i++) {
   layer = doc.layers[i];
   if (layer.id==id) return layer;
   if (layer.document.layers.length > 0) {
     if ((layer=FindLayer(name, layer.document)) != null) return layer;
   }
 }
 return null;
}




function SelectAll( form_name, obj_id, val )
{
	f = document.forms[form_name] ;

	for (i=0 ; i<f.elements.length ; i++)
	{
		if(f.elements[i].id == obj_id)
			f.elements[i].checked = val ;
	}
}


function SelectAllNoForm(obj_id, main_obj)
{
	var inc=0;
	var alltags = document.all ? document.all : document.getElementsByTagName("*");
	for (i=0; i<alltags.length; i++)
	{
		if (alltags[i].id == obj_id)
			alltags[i].checked = main_obj.checked;
	}
}




function MM_popupMsg( msg )
{
    confirm(msg);
}



function LinkConfirm( link, msg )
{
    var confirmation = confirm( msg ) ;
    if (confirmation == true)
        window.location = link ;
}



function Link( link )
{
    window.location = link ;
}




function ChangeAndSubmit( form, field, val )
{
	ElementById( field ).value = val ;
   ElementById( form ).submit() ;
}



function ask_confirm( form, msg )
{
   var confirmation = confirm( msg );
	if (confirmation == true)
		ElementById( form ).submit() ;
}


function ask_change_confirm( form, field, val, msg )
{
    var confirmation = confirm( msg );
    if (confirmation == true)
    {
        ElementById( field ).value = val ;
        ElementById( form ).submit() ;
    }
}




function AskConfirm( msg, url )
{
	var confirmation = confirm( msg );
	if (confirmation == true)
		window.location = url ;
}


function AskFormConfirm( msg, form_name )
{
	var confirmation = confirm( msg );
	if (confirmation == true)
		document.forms[form_name].submit() ;
}

