//Allarga secondo dimensioni finestra
function get_wsize() {
	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;
	}
	var size;
	size = new Object();
	size.x=myWidth;
	size.y = myHeight;
	return size;
}


//allarga secondo dimensioni totali documento
function xDocSize() {
	var b=document.body, e=document.documentElement;
	var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
	if (e) {
		esw = e.scrollWidth;
		eow = e.offsetWidth;
		esh = e.scrollHeight;
		eoh = e.offsetHeight;
	}
	if (b) {
		bsw = b.scrollWidth;
		bow = b.offsetWidth;
		bsh = b.scrollHeight;
		boh = b.offsetHeight;
	}
	//  alert('compatMode: ' + document.compatMode + '\n\ndocumentElement.scrollHeight: ' + esh + '\ndocumentElement.offsetHeight: ' + eoh + '\nbody.scrollHeight: ' + bsh + '\nbody.offsetHeight: ' + boh + '\n\ndocumentElement.scrollWidth: ' + esw + '\ndocumentElement.offsetWidth: ' + eow + '\nbody.scrollWidth: ' + bsw + '\nbody.offsetWidth: ' + bow);
	return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}


function xDef() {
	for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
	return true;
}

function xNum(){
	for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
	return true;
}


function xScrollTop(e, bWin) {
	var offset=0;
	if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
		var w = window;
		if (bWin && e) w = e;
		if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
		else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
	} else {
		e = xGetElementById(e);
		if (e && xNum(e.scrollTop)) offset = e.scrollTop;
	}
	return offset;
}



function resize(this_div,centra_div) {
	var size = xDocSize();
	if (document.getElementById(this_div)) {
		document.getElementById(this_div).style.width = size.w+"px";
	/*	document.getElementById(this_div).style.height = size.h+"px";*/
		centra (centra_div);
	}
}




function centra(tdiv,dx,dy) {
//	dx = document.getElementById(tdiv).style.width;
//	dy = document.getElementById(tdiv).style.height;
	if (!dx) dx=700;
	if (!dy) dy=200;	


	var size = get_wsize();
	var scroll = xScrollTop();
	newx = ( (size.x-dx) /2);	
	newy = scroll+(size.y/2)-dy;
	
	document.getElementById(tdiv).style.top = newy+"px";
	document.getElementById(tdiv).style.left = newx+"px";
}

function close_generic(divn) {
	var root = document.getElementById(divn);
	if (root) {
		root.style.visibility="visible";

		var new1 = document.createElement("div");
		new1.id = "close_mark";
		new1.innerHTML="<a href='javascript:close_generic.close(\""+divn+"\")'>x</a>";
		root.appendChild(new1);
	//alert( document.getElementById("contenutore").id );
	//alert (root.id);	
	}
}
close_generic.close = function(divn) {
	if ( aaa = document.getElementById(divn) ) {
		aaa.parentNode.removeChild(aaa);
	}
}

function close_delayed(divn,tempo) {
	var root = document.getElementById(divn);
	if (root) {
		var aclose = setTimeout("close_generic.close('"+divn+"')",tempo);
	}
}


//esempio di chiamata ajax
/*
dettagli = {
	open: function(thismacro, pos){		
		if ((thismacro) && (pos)) {
			new Ajax.Request("_comp/_dettagli.php", {
				method: "post",
				parameters: { this_macro: thismacro, this_pos: pos},
				onSuccess: function (a) { 
					$("dettagli_div").innerHTML = a.responseText
					resize("dettagli");
					$("dettagli_div").style.visibility = "visible";
					centra("finestra");
				}
			});
		}

	},
	close: function(thismacro) {
		$("dettagli").style.width = "100%";
		$("dettagli").style.height = "100%";
		$("dettagli_div").style.visibility="hidden";
	}
}

*/


function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


//Cambia l'opacita' secondo i browser;
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

function shade(id,millisec,start) {
	setTimeout("opacity('"+id+"', 100, 10, "+millisec+")",start);
}

