/* -------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------REQUEST MOOTOOLS     */



function Call(url,elementOut){
	var urlencoded=encodeURL(url);
	var myRequest = new Request.HTML({
								method: 'get', 
								url: urlencoded["url"],
								onRequest: function(){ mini_comparsa() },
								onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) 
											{ 
												if ( elementOut == 'PopNotify') { Notify('open',responseHTML);  }
												else if ( elementOut == 'NoNotify') { }
												else if ( elementOut ) { e = document.getElementById(elementOut); e.innerHTML = responseHTML; };
												close_mini_comparsa();
											}
								});
	myRequest.send(urlencoded["params"]+'&sid='+sid+'&rand='+Math.round(9999999*Math.random()));
}

function CallForm(url,form,elementOut){
	var urlencoded=encodeURL(url);
	var myRequest = new Request.HTML({
								method: 'get', 
								url: urlencoded["url"],
								onRequest: function(){ mini_comparsa() },
								onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) 
											{ 
												if ( elementOut == 'PopNotify') { Notify('open',responseHTML);  }
												else if ( elementOut == 'NoNotify') { }
												else if ( elementOut ) { e = document.getElementById(elementOut); e.innerHTML = responseHTML; };
												close_mini_comparsa();
											}
								});
	myRequest.send(urlencoded["params"]+"&"+encodeFORM(form)+'&sid='+sid+'&rand='+Math.round(9999999*Math.random()));
}


function encodeURL(url)
	{
		var ArrayParam = new Array();
		var ArrayParams = new Array();
		var string = null;
		
		if (url.indexOf("?") == '-1') url = url+'?';
		
		var ArrayAllParams = url.split("?");
		var ArrayCV = ArrayAllParams[1].split("&");
		
		for (var i=0; i < ArrayCV.length; i++)
		{
			if (ArrayCV[i])
			{
				ArrayParam = ArrayCV[i].split("=");
				ArrayParams[i] = ArrayParam[0]+"="+encodeURIComponent(ArrayParam[1]);
			};
		};
		string = ArrayParams.join("&");
		
		var ReturnArray = new Array();
		ReturnArray["url"] = ArrayAllParams[0];
		ReturnArray["params"] = string;
		
		
		return ReturnArray;
	};

function encodeFORM(form)
	{
			var firstArray = new Array();
				
				for (var i=0; i < form.length; i++)
					{
						if (form[i].name)
						{
							firstArray[i] = "FORM"+form[i].name+"="+encodeURIComponent(form[i].value);
						};
					};
				
				var string = firstArray.join("&");
				
				return string;
	};


/* -------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------GESTIONE DELLE RISPOSTE     */

function Notify(Action,responseHTML)
{	
	if (Action == 'open')
	{
		var myFx = new Fx.Elements($('notify'), 
						{
						onStart: function()
						    {
								document.getElementById('notify').style.top = -100 + document.body.scrollTop + document.documentElement.scrollTop;
								document.getElementById('notify').innerHTML = responseHTML;
								Overlay('open');
							},
						onComplete: function()
							{
								//alert('apertura terminata');
								//alert('animazione terminata');
							}
						}).start({
									'0': 
									{
										'top': [-100 + document.body.scrollTop + document.documentElement.scrollTop, 30 + document.body.scrollTop + document.documentElement.scrollTop ],
										'opacity': [0,1],
										'display': ['none','block']
									}
								});
	} 
	else if ( Action == 'close' )
	{
		var myFx = new Fx.Elements($('notify'), 
						{
						onComplete: function()
							{
								document.getElementById('notify').style.display='none';
								Overlay('close');
								//alert('chiusura terminata');
							}
						}).start({
									'0': 
									{
										'top': [30 + document.body.scrollTop + document.documentElement.scrollTop, -100 + document.body.scrollTop + document.documentElement.scrollTop ],
										'opacity': [1,0]
									}
								}); //alert('chiusura chiamata');
		
	}
	else if ( Action == 'closeNOFX' )
	{
				document.getElementById('notify').style.top = -100 + document.body.scrollTop + document.documentElement.scrollTop;
				document.getElementById('notify').style.display='none';
				Overlay('close'); //alert('closeNOFX');
	}
	else if ( Action == '' )
	{
				document.getElementById('notify').style.top = -100 + document.body.scrollTop + document.documentElement.scrollTop;
				document.getElementById('notify').style.display='none';
				Overlay('close'); //alert('close action=0');
	};
	
}

function Notify2(Action,responseHTML)
{    
    if (Action == 'open')
    {
        var myFx = new Fx.Elements($('notify2'), 
                        {
                        onStart: function()
                            {
                                document.getElementById('notify2').style.top = -100 + document.body.scrollTop + document.documentElement.scrollTop;
                                document.getElementById('notify2').innerHTML = responseHTML;
                                Overlay('open');
                            },
                        onComplete: function()
                            {
                                //alert('apertura terminata');
                                //alert('animazione terminata');
                            }
                        }).start({
                                    '0': 
                                    {
                                        'top': [-100 + document.body.scrollTop + document.documentElement.scrollTop, 30 + document.body.scrollTop + document.documentElement.scrollTop ],
                                        'opacity': [0,1],
                                        'display': ['none','block']
                                    }
                                });
    } 
    else if ( Action == 'close' )
    {
        var myFx = new Fx.Elements($('notify'), 
                        {
                        onComplete: function()
                            {
                                document.getElementById('notify').style.display='none';
                                Overlay('close');
                                //alert('chiusura terminata');
                            }
                        }).start({
                                    '0': 
                                    {
                                        'top': [30 + document.body.scrollTop + document.documentElement.scrollTop, -100 + document.body.scrollTop + document.documentElement.scrollTop ],
                                        'opacity': [1,0]
                                    }
                                }); //alert('chiusura chiamata');
        
    }
    else if ( Action == 'closeNOFX' )
    {
                document.getElementById('notify').style.top = -100 + document.body.scrollTop + document.documentElement.scrollTop;
                document.getElementById('notify').style.display='none';
                Overlay('close'); //alert('closeNOFX');
    }
    else if ( Action == '' )
    {
                document.getElementById('notify').style.top = -100 + document.body.scrollTop + document.documentElement.scrollTop;
                document.getElementById('notify').style.display='none';
                Overlay('close'); //alert('close action=0');
    };
    
}


function Overlay(Action){
		if (Action=='open')
		{
			document.getElementById('overlay').style.display='block';
			document.getElementById('opacity').style.display='block';
		}
		else if (Action=='close')
		{
			document.getElementById('overlay').style.display='none';
			document.getElementById('opacity').style.display='none';
		};
}

/* -------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------GESTIONE DELLE ATTESE     */

function Test(e) {
	var posx;
	var posy;
	
	//if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	
	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	/*x = document.getElementById('x_cursor');
	y = document.getElementById('y_cursor');
	x.innerHTML = posx;
	y.innerHTML = posy;*/
	move_mini_comparsato(posy+15,posx+20);
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}

function move_mini_comparsato(y,x) {
	e=document.getElementById('mini_comparsa');
	e.style.top=y+"px";
	e.style.left=x+"px";
}

function mini_comparsa(){
	e=document.getElementById('mini_comparsa');
	e.style.display='block';
};

function close_mini_comparsa()
{
	e=document.getElementById('mini_comparsa');
	e.style.display='none';
};

function nonfareniente()
{
};