function SetBrowserOptions()
{
	if(navigator.preference)
	{
		navigator.preference("browser.enable_style_sheets", true);
		navigator.preference("network.cookie.cookieBehavior", 0);
		navigator.preference("network.cookie.warnAboutCookies", false);
	}
}

function FillZero(ANumber, AWidth)
{
	var Result = new String(ANumber);
	for (; Result.length < AWidth;)
	{
		Result = '0' + Result;
	}
	return Result;
}
function IsBlank(str)
{	
	var s = new String(str);
	for(var i = 0; i < s.length; i++)
	{
			var c = s.charAt(i);
			if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function SetElementValue(Name, Value)
{
	var e = document.all[Name];
	if (e)
	{
		if ((e.type == "text") || (e.type == "textarea"))
			e.value = Value;
		else if (e.type == "select-one")
		{
			for (var i = 0; i < e.length; i++)
			{
				if (e[i].value == Value)
				{
					e[i].selected = true;
				}
			}
			if(e.onchange)
				e.onchange();
		}
		else if (e.length)
		{
			if (e.length > 0)
				if (e[0].type == "radio")
				{
					for (var i = 0; i < e.length; i++)
						if (e[i].value == Value)
						{
							e[i].checked = true;
						}
					if(e.onchange)
						e.onchange();
				}
		}
	}
}

function IsValidEMail(EMail)
{
	var S = new String(EMail);
	var AtsignPos = S.indexOf('@');
	if (AtsignPos < 0)
		return false;
	var DotPos = S.lastIndexOf('.')
	if (DotPos < 0)
		return false;
	if (DotPos < AtsignPos)
		return false;
	return true;
}

//A value of 0 or NULL for Width or Hieght means to automatically detect them
function PreviewImage(ImagePath, Width, Height)
{
	var TaskbarHeight = 30;
	if (!Width || !Height || (Width * Height == 0))
	{
		var Img = new Image;
		Img.src=ImagePath;
		Width = Img.width;
		Height = Img.height;
	}
	Width = Math.min(screen.availWidth, Width);
	var Left = (screen.availWidth - Width) / 2;
	Left = Math.max(0, Left);
	var Top = (screen.availHeight - TaskbarHeight - Height) / 2;
	Top = Math.max(0, Top);
	if (Height > screen.availHeight - TaskbarHeight)
	{
		Height = screen.availHeight - TaskbarHeight;
		Width += 12; //for vertical scrollbar
	}
	window.open('imagepreview.php?item=' + ImagePath, '', 
		'left=' + Left + ', top=' + Top + ', width=' + (Width) + ', height=' + (Height));
}

function ToggleElement(e)
{
	if (!e) return;
	e.style.display = (e.style.display == "none") ? "inline" : "none";
}

function ToggleContents(ElementName)
{
	ToggleElement(document.all['sp' + ElementName])
	ToggleElement(document.all['spPlusSign' + ElementName])
	ToggleElement(document.all['spMinusSign' + ElementName])
}

function SetAmbientLight(ObjectName, Strength, Clear)
{
	var Obj = document.getElementById(ObjectName);
	if (!Obj) return;
	if (Obj.filters.length == 0) return;
	if (!Obj.filters("light")) return;
  Obj.filters("light").enabled=true;
	if (Clear)
	  Obj.filters("light").clear();
  Obj.filters("light").addAmbient(255, 255, 255, Strength);
}

function PreloadImage(imgPath)
{
	var img = new Image();
	img.src = imgPath;
}
