var IE = false;

var MyLink;
var Clicked = 0;var Show = new Array();

function getRealElementById(ID)
{
	var el;

	if (document.getElementById)
	{
		el = document.getElementById(ID);
	}

	else
	{
		el = document.all[ID];
	}

	return el;
}

function getElementsByClassName(classname, node)
{
	if (!node) node = document.getElementsByTagName("body")[0];

	var a = [];

	var re = new RegExp('\\b' + classname + '\\b');

	var els = node.getElementsByTagName("*");

	for(var i = 0, j = els.length; i < j; i++)
		if (re.test(els[i].className)) a.push(els[i]);

	return a;
}

function ChangeClass(ID, NewClass)
{
	getRealElementById(ID).className = NewClass;
}

function ShowDiv(ID)
{
	getRealElementById(ID).style.display = 'block';
}

function ShowDivOpacity(ID, UpDownEffect)
{	if (!UpDownEffect)	{
		var Op = 0.0;
		getRealElementById(ID).style.opacity = Op;		getRealElementById(ID).style.display = 'block';
		var TimerOp = setInterval(function ()
		{
			Op = Op + 0.1;

			getRealElementById(ID).style.opacity = Op;

			if (Op >= 1)
			{
				clearInterval(TimerOp);
			}
		}, 50);	}	else	{
		var Margin = -100;
		var TimerOp = setInterval(function ()		{			Margin = Margin + 5;
			getRealElementById(ID).style.marginBottom = Margin + 'px';			if (Margin >= 0)			{				clearInterval(TimerOp);			}		}, 10);	}
}function HideDiv(ID){	getRealElementById(ID).style.display = 'none';}function HideDivOpacity(ID, UpDownEffect){	if (!UpDownEffect)	{
		var Op = 1;
		getRealElementById(ID).style.opacity = Op;		getRealElementById(ID).style.display = 'block';		var TimerOp = setInterval(function ()		{			Op = Op - 0.1;			getRealElementById(ID).style.opacity = Op;			if (Op <= 0.0)			{				clearInterval(TimerOp);			}		}, 50);	}	else	{
		var Margin = getRealElementById(ID).style.marginBottom.split("px");
		Margin = Margin[0];
		var TimerOp = setInterval(function ()		{			Margin = Margin - 5;
			getRealElementById(ID).style.marginBottom = Margin + 'px';			if (Margin <= -100)			{				clearInterval(TimerOp);			}		}, 10);	}}function ShowHideBox(ID){	if (typeof(Show[ID]) == 'undefined')	{		Show[ID] = (getRealElementById(ID).style.display == 'none') ? false : true;	}	if (Show[ID])	{		HideDivOpacity(ID, true);		Show[ID] = !Show[ID];	}	else	{		ShowDivOpacity(ID, true);		Show[ID] = !Show[ID];	}	var status = Show[ID] == true ? 'showed' : 'hidden';	OpenAjaxURL('utils/ajaxopt.php?opt=footbar&status=' + status, false);}function ShowBox(){	ShowHideBox('footer_box');
	ShowDiv('hide_box');
	HideDiv('show_box');}function HideBox(){	ShowHideBox('footer_box');
	ShowDiv('show_box');
	HideDiv('hide_box');}

function HideBox2()
{
	Show['footer_box'] = false;

	ShowDiv('show_box');
	HideDiv('hide_box');
}function ShowHideDiv(ID){	if (typeof(Show[ID]) == 'undefined')	{		Show[ID] = true;	}	if (Show[ID])	{		HideDiv(ID);		Show[ID] = !Show[ID];	}	else	{		ShowDiv(ID);		Show[ID] = !Show[ID];	}}

function SetDivWidth(ID, Width)
{
	getRealElementById(ID).style.width = Width + 'px';
}
function SetDivHeight(ID, Height){	getRealElementById(ID).style.height = Height + 'px';}

function SetDivMargin(ID, Margin)
{
	getRealElementById(ID).style.marginBottom = Margin + 'px';
}

function SetMyLink(Link)
{
	MyLink = Link;
}

function GetMyLink()
{
	return MyLink;
}

function GoTo(Link)
{
	document.location.href = Link;
}

function GoToWait(Link, Wait)
{
	window.setTimeout("GoTo('" + Link + "')", Wait);
}

function SetLoading(Theme, ID)
{
	getRealElementById(ID).innerHTML = '<img class=\"GeneralLinkImg\" src=\"themes/' + Theme + '/images/loading.gif\" alt=\"\"/>';
}

function OpenWndBox(URL, Width, Height)
{
	var Width2 = parseInt(Width) + 18;
	newWindow = window.open(URL, "newWindow", "width=" + Width2 + ", height=" + Height + ", resizable=yes, scrollbars=yes, toolbar=yes, status=yes");
	/*newWindow.document.open();
	newWindow.document.write('<html><body topmargin="0">'); 
	newWindow.document.write('<iframe src="' + URL + '" frameborder="0" width="100%" height="100%"></iframe>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();*/
	newWindow.focus();
}

function OpenImgBox(Image, Width, Height)
{
	var Width2 = parseInt(Width) + 18;
	newWindow = window.open("", "newWindow", 'width=' + Width2 + ', height=' + Height);
	newWindow.document.open();
	newWindow.document.write('<html><body topmargin="0">'); 
	newWindow.document.write('<center><a href="javascript:self.close();"><img width=\"' + Width + '\" height=\"' + Height + '\" src=\"'+ Image +'\" border=\"0\"></a></center>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function GetScrollPos()
{
	return document.getElementsByTagName("html")[0].scrollTop;
}

function SetScrollPos(Pos)
{
	document.getElementsByTagName("html")[0].scrollTop = Pos;
}

function SetScroll()
{
	var pos = GetScrollPos();

	OpenAjaxURL('utils/ajaxopt.php?opt=scroll&pos=' + pos, false);
}function SetClickScroll(){	var anchors = document.getElementsByTagName('a');	var buttons = getElementsByClassName('ButtonBox', false);	for (var i = 0; i < anchors.length; i++)	{		anchors[i].onmousedown = SetScroll;	}	for (var i = 0; i < buttons.length; i++)	{		buttons[i].onmousedown = SetScroll;	}}

function AnimateDiv(ID)
{
	var Moving = true;
	var Margin = getRealElementById(ID).style.marginLeft.split("px");
	Margin = Margin[0];

	setInterval(function ()
	{
		if (Moving)
		{
			Margin += 2;

			Moving = false;
		}

		else
		{
			Margin -= 2;

			Moving =true;
		}

		getRealElementById(ID).style.marginLeft = Margin + 'px';
	}, 200);
}

function ShowHideDivWidth(ID, MaxSize)
{
	var Stop = false;
	var Height;

	if (typeof(Show[ID]) == 'undefined')
	{
		Show[ID] = false;
	}

	else
	{
		Show[ID] = !Show[ID];
	}

	if (Show[ID])
	{
		Height = MaxSize;
	}

	else
	{
		Height = 0;
	}

	var TimerOp = setInterval(function ()
	{
		if (Show[ID])
		{
			Height -= 5;

			if (Height <= 0)
			{
				Stop = true;
			}
		}

		else
		{
			Height += 5;

			if (Height >= MaxSize)
			{
				Stop = true;
			}
		}

		getRealElementById(ID).style.height = Height + 'px';

		if (Stop)
		{
			clearInterval(TimerOp);
		}
	}, 10);
}

function ShowHideThemeBox(MaxSize)
{
	ShowHideDivWidth('showtheme_box', MaxSize);
}

function SwapStyle(ID, Src)
{
	var Head = document.getElementsByTagName('head')[0];
	var NewStyle = document.createElement('link');

	NewStyle.rel = 'stylesheet';
	NewStyle.href = Src;
	NewStyle.id = ID;

	Head.removeChild(getRealElementById(ID));
	Head.appendChild(NewStyle);
}

function SetMyTheme(Theme)
{
	//Bisogna trovare un nuovo metodo per controllare i Temi giusti
	if ((Theme == "Default") || (Theme == "Light"))
	{
		SwapStyle('css', "/themes/" + Theme + "/css/styles.css");

		if (IE)
		{
			SwapStyle('css_ie', "/themes/" + Theme + "/css/tweaks_ie.css");
		}

		OpenAjaxURL('utils/ajaxopt.php?opt=theme&what=' + Theme, false); //Qui il controllo lo fa già PHP
	}
}