//Focus first field
function fieldFocus() 
{
   // var textElements = 0;
	var focusField = -1;
	
	if(document.forms[0])
	{
		for (i = 0; i < document.forms[0].elements.length; i++)
		{
			if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "password") 
			{
				if (focusField < 0) 
				{
						focusField = i;
				}
			}
		}
		//put focus in first text or password field
		if(focusField > -1)
		{
			document.forms[0].elements[focusField].focus();
		}
	}

}


var activeMenu = null;

function showNotDropDown(id)
{
	setBackground(id, "#919efc");	
}

function hideNotDropDown(id)
{
	setBackground(id, "");	
}

function showDropDown(id)
{
	if(activeMenu == null)
	{	
		changeZindex(id, 1);
		var menu_id = id + "_menu";
		getObj(menu_id).style.visibility = "visible";
		fadeIn(menu_id, 0);
		activeMenu = id;
		setBackground(id, "#919efc");
	}
}

function hideDropDown(id)
{
	activeMenu = null;
	window.setTimeout("shutMenu('"+id+"')", 100);
}

function shutMenu(id)
{
	if(activeMenu != id)
	{
		var menu_id = id + "_menu";
		fadeOut(menu_id, 90);
		setBackground(id, "");
		changeZindex(id, 0);
	}
}

function setBackground(id, color)
{
	getObj(id).style.background = color;
}

function setActiveMenu(state)
{
	activeMenu = state;
}

function fadeIn(objId,opacity)
{
	if (document.getElementById) 
	{
		obj = document.getElementById(objId);
		if (opacity <= 90) 
		{
			if(opacity > 78 && opacity < 95)
			{
				opacity = 93;
			}
			
			setOpacity(obj, opacity);
			opacity += 20;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}
	}
}

function fadeOut(objId,opacity)
{
	//alert(opacity);
	if (document.getElementById) 
	{
		obj = document.getElementById(objId);
		if (1==1) 
		{
			setOpacity(obj, opacity);
			opacity -= 20;
			if(opacity > -10)
			{
				window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
			}else
			{
				getObj(objId).style.visibility = "hidden";
			}
		}
	}
}

function setOpacity(obj, opacity)
{
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function getObj(elementID)
{
	if (typeof elementID == "string") 
	{
		return document.getElementById(elementID);
	}
	else
	{
		return elementID;
	}
}

function changeZindex(id,z)
{ 
	getObj(id).style.zIndex = z; 
}


function popup(URL, width, height) 
{
	width = parseInt(width);
	
	if(width < 349)
		width = 349;
	
	heigth = parseInt(height) + 85;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+ width +",height=" + heigth + ",left = 100,top = 100');");
}
