var d = document;
var dLoad = false;

/// mouse over /// PRELOAD //
function preloadImages( arr )
{
	var naA = eval( 'name' + arr );
	var onA = eval( 'on' + arr );
	var ofA = eval( 'off' + arr );
	var baA = eval( 'base' + arr );
	var clA = eval( 'click' + arr );

	if (document.images)
	{
		for ( i = 0; i < naA.length; i++ )
		{
			ofA[ i ] = new Image;
			ofA[ i ].src = baA + naA[ i ] + "_off.gif"
			onA[ i ] = new Image;
			onA[ i ].src = baA + naA[ i ] + "_on.gif";
			clA[ i ] = false;
		}
	}
}

/// mouse over /// OVER //
function mouseOver( arr, no, id )
{
	if ( !dLoad ) return;
	var naA = eval( 'name' + arr );
	var onA = eval( 'on' + arr );

	if ( document.layers && id )
	{
		document.layers[ id ].document.images[ naA[ no ] ].src = onA[ no ].src
	}
	else if ( document.images )
	{
		document.images[ naA[ no ] ].src = onA[ no ].src
	}
}

/// mouse over /// OUT //
function mouseOut( arr, no, id )
{
	if ( !dLoad ) return;
	var naA = eval( 'name' + arr );
	var ofA = eval( 'off' + arr );
	var clA = eval( 'click' + arr );

	if ( !clA[ no ] )
	{
		if ( document.layers && id )
		{
			document.layers[ id ].document.images[ naA[ no ] ].src = ofA[ no ].src
		}
		else if ( document.images )
		{
			document.images[ naA[ no ] ].src = ofA[ no ].src
		}
	}
}

/// mouse click /// CLICK //
function mouseClick( arr, no, id )
{
	if ( !dLoad ) return;
	var naA = eval( 'name' + arr );
	var clA = eval( 'click' + arr );
	var onA = eval( 'on' + arr );
	var ofA = eval( 'off' + arr );

	for ( i = 0; i < naA.length; i++ )
	{
		clA[ i ] = false;
		mouseOut( arr, i, id );
	}
	mouseOver( arr, no, id );
	clA[ no ] = true;
}

/// Controla o menu
function divControle( nome, acao )
{
	var divX = getObj( nome );
	if( acao )
	{
//		WCH_HideWndCtrl( divX );
		divX.style.visibility = 'visible';
	}
	else
	{
//		WCH_ShowWndCtrl( divX );
		divX.style.visibility = 'hidden';
	}
}

///
function getObj( nome )
{
	if( document.getElementById )
	{
		return document.getElementById( nome );
	}
	else if( document.all )
	{
		return document.all[ nome ];
	}
	else if( document.layers )
	{
		return document.layers[ nome ];
	}
	else return false;
}


function nova_jan( newwindow )
{
	var desktop = window.open( newwindow, '_blank', 'toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes' );
}


function selNavegacao( obj )
{
	var lnk = trim( obj.options[ obj.selectedIndex ].value );
	if( lnk )
	{
		if( ( lnk.substr( ( lnk.length - 3 ), lnk.length ) == "pdf" ) || ( lnk.substr( ( lnk.length - 3 ), lnk.length ) == "doc" ) || ( lnk.substr( ( lnk.length - 3 ), lnk.length ) == "xls" ) )
		{
			window.open( lnk, '_blank' );
		}
		else
		{
			window.location.href = lnk;
		}
	}
}


/// check mail ///
function checkMail( email )
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if ( filter.test( email ) )
	{
		return true;
	}
	return false;
}


/// trim ///
function trim( str )
{
	return str.replace( /^(\s)+|(\s)+$/g, '' );
}


/// pop-up ///
function popUp(strURL,strType,strWidth,strHeight) {
var strOptions="";
if (strType=="redScroll") strOptions="status,resizable,scrollbars,height="+strHeight+",width="+strWidth;
if (strType=="redNoScroll") strOptions="status,resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixNoScroll") strOptions="status,height="+strHeight+",width="+strWidth;
if (strType=="fixScroll") strOptions="status,scrollbars,height="+strHeight+",width="+strWidth;
if (strType=="padrao") strOptions="status,toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
newWin = window.open(strURL, strType, strOptions);
newWin.focus();
}

// NoSpan //
// USO <a href="javascript: noSpam('contato', 'dominio.com.br')">email para contato</a> //
/*function noSpam(user, domain)
{
  lString = "mailto: " + user + "@" + domain;
  window.location = lString;
}*/

// toggle visibility
function toggle( targetId ){
  if (document.getElementById){
        target = document.getElementById( targetId );
           if (target.style.display == "none" || target.style.display == ""){
              target.style.display = "block";
           } else {
              target.style.display = "none";
           }
     }
}

// Foco //
function focusme(obj)
{
  if(obj)
    obj.focus();
  else
    window.focus();
}

// retorna objeto do html pelo nome //
function getObj(nome)
{
  if(document.getElementById)
    return document.getElementById(nome);
  else if(document.all)
    return document.all[nome];
  else if(document.layers)
    return document.layers[nome];
  else return false;
}

// apresenta objeto html escondido //
function mostra(obj)
{
  obj.style.display = '';
}

// esconde objeto html //
function esconde(obj)
{
  obj.style.display = 'none';
}

// controla a apresentação de objeto html //
function controla(obj)
{
  var dx = getObj(obj);
  if(dx.style.display != 'none')
    esconde(dx);
  else
    mostra(dx);
}

// maximiza a janela //
function fullScreen()
{
  window.moveTo(0, 0);
  if(document.all)
    window.resizeTo(screen.availWidth, screen.availHeight);
  else if(document.layers || document.getElementById)
  {
    if(window.outerHeight < screen.availHeight || window.outerWidth < screen.availWidth)
    {
      window.outerHeight = screen.availHeight;
      window.outerWidth = screen.availWidth;
    }
  }
}
