function checkEF( efname )
{
  var OK = true;
  var fe = document.forms[ efname ].elements;
  if( fe[ 'keywords' ].value == '' )
  {
	 OK = false;
  }
  return OK;
}

function browserCheck() {
	this.br = navigator.appName.toLowerCase();
	this.version = navigator.appVersion.toLowerCase();
	this.agent = navigator.userAgent.toLowerCase();
	this.platform = navigator.platform.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.is_opera = (this.agent.indexOf('opera') != -1);
	this.is_safari = (this.agent.indexOf('safari') != -1);
	this.is_ns = (this.br == 'netscape' && !this.is_opera);
	this.is_ie = (this.br == 'microsoft internet explorer' && !this.is_opera);
	this.is_ns4 = (this.is_ns && this.major == 4 && !this.is_opera);
	this.is_ns6 = (this.is_ns && this.major == 5 && !this.is_opera);
	this.is_ie4 = (this.version.indexOf('msie 4.0') != -1 && !this.is_opera);
	this.is_ie5 = (this.version.indexOf('msie 5.0') != -1 && !this.is_opera);
	this.is_ie6 = (this.version.indexOf('msie 6.0') != -1 && !this.is_opera);
	this.is_windows = (this.platform.indexOf('win') != -1);
	this.is_mac = (this.agent.indexOf('mac') != -1);
	this.is_linux = (this.platform.indexOf('linux') != -1 || this.platform.indexOf('x11') != -1) ? true:false;
	this.is_dom = (document.getElementById) ? true:false;
	this.is_firefox = (this.agent.indexOf('firefox') != -1 );
	this.is_mozilla = (this.agent.indexOf('gecko') != -1 && !this.is_firefox );
}

br = new browserCheck();

var t1 = null;
var t2 = null;
var t3 = null;

var maxMarginLeft = 300;

var curOpen = null;

function initSubmenu( area_id, opener_id )
{
	area = area_id;
	opener = opener_id;
	var leftMargin = 0;
	if( openerEl = document.getElementById( opener_id ) )
	{
		var oPos = getPos( openerEl );

		if( sM = document.getElementById( "sm" ) )
		{
			sMpos = getPos( sM );					
			leftMargin = ( oPos[0] -  sMpos[0] ) - 100;
			if( leftMargin > maxMarginLeft )
			{
				leftMargin = maxMarginLeft;
			}
			
			if(leftMargin == 172) {
				leftMargin = 72;	// Fixed for "Applications"
			}
		}		
	}
	openSubmenu( area_id, leftMargin ); 
}

function openSubmenu( area_id, leftMargin )
{
	var el = null;
	if( el = document.getElementById("submenu_" + area_id) )
	{
		if( leftMargin > 0 )
		{
			if( br.is_ie )
			{
				var child = el.childNodes[0];
			}
			else
			{
				var child = el.childNodes[1];
			}
	
			if( child )
			{
				child.style.marginLeft = leftMargin + "px";	
			}
		}		
		keepOpen( el );
		curOpen = el;
	}	
}

function setRootActive()
{
	var mEl = document.getElementById( "mmT" );		
	var els = mEl.getElementsByTagName( "TD" );	

	for ( i=0; i<els.length; i++ )
	{
		if( els[ i ].className == "mm_left_mouseover_back" || els[ i ].className == "mm_content_mouseover_back" || els[ i ].className == "mm_right_mouseover_back" )
		{
			els[ i ].className = ( els[ i ].className.substr( 0, els[ i ].className.length - 15 ) + "_act" );
		}
		else
		{
			if( els[ i ].className == "mm_left_mouseover" || els[ i ].className == "mm_content_mouseover" || els[ i ].className == "mm_right_mouseover" )
			{
				els[ i ].className = ( els[ i ].className.substr( 0, els[ i ].className.length - 10 ) );
			}
		}
	}		
}

function changeMMBg( dir, area_id )
{
	var mEl = document.getElementById( "mmT" );		
	var els = mEl.getElementsByTagName( "TD" );
	
	if( dir == "act" )
	{		
		for ( i=0; i<els.length; i++ )
		{
			if( els[ i ].className == "mm_left_act" || els[ i ].className == "mm_content_act" || els[ i ].className == "mm_right_act" )
			{
				els[ i ].className = ( els[ i ].className.substr( 0, els[ i ].className.length - 4 ) + "_mouseover_back" );
			}
			if( els[ i ].className == "mm_left_mouseover" || els[ i ].className == "mm_content_mouseover" || els[ i ].className == "mm_right_mouseover" )
			{
				els[ i ].className = ( els[ i ].className.substr( 0, els[ i ].className.length - 10 ) );
			}
		}		
		document.getElementById( "mm_left_" + area_id  ).className = "mm_left_mouseover";
		document.getElementById( "mm_" + area_id  ).className = "mm_content_mouseover";
		document.getElementById( "mm_right_" + area_id  ).className = "mm_right_mouseover";
	}
	else
	{			
		for ( i=0; i<els.length; i++ )
		{
			if( els[ i ].className == "mm_left_mouseover_back" || els[ i ].className == "mm_content_mouseover_back" || els[ i ].className == "mm_right_mouseover_back" )
			{
				els[ i ].className = ( els[ i ].className.substr( 0, els[ i ].className.length - 15 ) + "_act" );
			}			
		}
		document.getElementById( "mm_left_" + area_id  ).className = "mm_left";
		document.getElementById( "mm_" + area_id  ).className = "mm_content";
		document.getElementById( "mm_right_" + area_id  ).className = "mm_right";
	}	
}

function changeSubmenu( area_id, new_area_id, opener_id, timerset )
{    
	clearTimeout( t1 );
	clearTimeout( t2 );
	clearTimeout( t3 );

	if( area_id != new_area_id )
	{
		var leftMargin = 0;
		if( opener_id != false && typeof( opener_id ) != "undefined" )
		{	
			if( openerEl = document.getElementById( opener_id ) )
			{								
				var oPos = getPos( openerEl );
				if( sM = document.getElementById( "sm" ) )
				{
					sMpos = getPos( sM );					
					leftMargin = ( oPos[0] -  sMpos[0] ) - 100;
					if( leftMargin > maxMarginLeft )
					{
						leftMargin = maxMarginLeft;
					}
					
					if(leftMargin == 173) { // Fixed for "Applications"
						leftMargin = 73;
					}
				}			
			}
		}
		
		if( el = document.getElementById("submenu_" + area_id) )
		{   			
			if( curOpen != el )
			{
				curOpen.style.display = "none";					
			}
	
			if( timerset )
			{
				//t1 = setTimeout( "kill( el )", 1000 );
				kill( el );
				t3 = setTimeout( "changeMMBg( 'notact', " + area_id + " )", 1000 );
			}
			else
			{
				kill( el );				
			}

			if( new_area_id > 0 )
			{
				if( timerset )
				{
					t2 = setTimeout( "openSubmenu( " + new_area_id + ", " + leftMargin + " )", 1000 );
				}
				else
				{
					openSubmenu( new_area_id, leftMargin );
				}
			}			
		} 
		else
		{		
			if( timerset )
			{
				t2 = setTimeout( "openSubmenu( " + new_area_id + ", " + leftMargin + " )", 1000 );
			}
			else
			{
				openSubmenu( new_area_id, leftMargin );
			}
		}
	}
}

function keepOpen ( el )
{
	el.style.display = "block";
}

function keepOpenById()
{
	if( br.is_ie6 && event && event.srcElement )
	{
		var el = event.srcElement, s = 0;
		while( s < 20 )
		{
			if( el.tagName == 'DIV' && el.className == 'popupbox' )
			{
				break;
			}
			el = el.parentNode;
			s++;
		}
		if( el.getAttribute && el.getAttribute( 'keepopenid' ) && document.getElementById( el.getAttribute( 'keepopenid' ) ) )
		{
			keepOpen( document.getElementById( el.getAttribute( 'keepopenid' ) ) );
		}
	}
}

function kill ( el )
{
	el.style.display = "none";
}

function killById()
{
	if( br.is_ie6 && event && event.srcElement )
	{
		var el = event.srcElement, s = 0;
		while( s < 20 )
		{
			if( el.tagName == 'DIV' && el.className == 'popupbox' )
			{
				break;
			}
			el = el.parentNode;
			s++;
		}
		if( el.getAttribute && el.getAttribute( 'keepopenid' ) && document.getElementById( el.getAttribute( 'keepopenid' ) ) )
		{
			kill( document.getElementById( el.getAttribute( 'keepopenid' ) ) );
		}
	}
}

function showPopup( id, is_pop ) 
{
	var popel = null;
	var rootel = null;
	
	var mainpos = getPos( document.getElementById("wrapper") );
	var mainleft = mainpos[0];
	if( rootel = document.getElementById("poproot_" + id ) )
	{	
		if( popel = document.getElementById("popup_" + id ) )
		{
			if( is_pop )
			{
				keepOpen( popel.parentNode );
				if( br.is_ie6 )
				{
					popel.style.zIndex = 1000;
					rootel.style.zIndex = 999;
				}
				if( false && br.is_ie6 )
				{
					popel.style.display = 'none';
					var pos = getPos( event.srcElement ? event.srcElement : rootel );
//					var pos = getPos( event.srcElement );
//window.alert( event.srcElement.outerHTML + ': ' + pos[ 0 ] + ', ' + pos[ 1 ] );
					var nu = document.createDocumentFragment();
					nu.appendChild( popel.parentNode.removeChild( popel ) );
					document.body.appendChild( nu );
					var left = pos[ 0 ] - 116;
					var top = pos[ 1 ];
					if( rootel.parentNode && rootel.parentNode.parentNode && rootel.parentNode.parentNode.getAttribute && rootel.parentNode.parentNode.getAttribute( 'id' ) )
					{
						popel.setAttribute( 'keepopenid', rootel.parentNode.parentNode.getAttribute( 'id' ) );
						popel.attachEvent( 'onmouseover', keepOpenById );
						popel.attachEvent( 'onmouseout', killById );
					}
					popel.style.textAlign = 'left';
				}
				else
				{
					var left = -123;
					var top = 0;
				}
			}
			else
			{
				var pos = getPos( rootel );           
				if( false && br.is_ie6 )
				{
					popel.style.display = 'none';
					var nu = document.createDocumentFragment();
					nu.appendChild( popel.parentNode.removeChild( popel ) );
					document.body.appendChild( nu );
					popel.style.textAlign = 'left';
					var left = pos[0] + 108;
					var top  = pos[1] + 30;
				}
				else
				{
					var left = pos[0];
					var top  = pos[1];
				}
				if( br.is_ie || br.is_opera || br.is_safari )
				{
					top = top - 0;
				}
				
				if( br.is_ie6 )
				{
					left = left - 132;	
				}
				else{
					left = left - 132;
				}
			}
		}

		popel.style.left = String( left ) + "px";         
		popel.style.top = String( top ) + "px";

		popel.style.display = "block";
	}
}

function closePopup( id ) 
{	
	var popel = null;
	var rootel = null;
	if( rootel = document.getElementById("poproot_" + id ) )
	{					
		if( popel = document.getElementById("popup_" + id ) )
		{
			popel.style.display = "none";
		}
	}
}

function getPos( obj ) 
{
	var curleft = 0;
	var curtop = 0;
	var oo = obj;

	if ( obj.offsetParent ) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while ( obj = obj.offsetParent ) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	if( oo && oo.getAttribute && oo.getAttribute( 'id' ) && String( oo.getAttribute( 'id' ) ).indexOf( 'pop' ) != -1 )
	{
	//	window.alert( curleft + ', ' + curtop );
	}
	return [curleft,curtop];
}