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();
}

function fScreen()
{
	top.window.moveTo(0,0);
	if( document.all )
	{
		top.window.resizeTo( screen.availWidth, screen.availHeight );
	}
	else if( document.layers || document.getElementById )
	{
		if( top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth )
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}


function GetCookie( name )
{
	var arg = name + '=';
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while( i < clen )
	{
		var j = i + alen;
		if( document.cookie.substring( i, j ) == arg ) return getCookieVal( j );
		i = document.cookie.indexOf( ' ', i ) + 1;
		if( i == 0 ) break;
	}
	return null;
}

function SetCookie( name, value )
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = ( argc > 2 ) ? argv[ 2 ] : null;
	var path = ( argc > 3 ) ? argv[ 3 ] : null;
	var domain = ( argc > 4 ) ? argv[ 4 ] : null;
	var secure = ( argc > 5 ) ? argv[ 5 ] : false;
	document.cookie = name + '=' + escape( value ) + ( ( expires == null ) ? '' : ('; expires=' + expires.toGMTString() ) ) + ( ( path == null ) ? '' : ( '; path=' + path ) ) + ( ( domain == null ) ? '' : ('; domain=' + domain ) ) + ( ( secure == true ) ? '; secure' : '');
}

function DeleteCookie( name )
{
	var exp = new Date();
	exp.setTime( exp.getTime() - 1 );
	var cval = GetCookie( name );
	document.cookie = name + '=' + cval + '; expires=' + exp.toGMTString();
}

function getCookieVal( offset )
{
	var endstr = document.cookie.indexOf( ';', offset );
	if( endstr == -1 ) endstr = document.cookie.length;
	return unescape( document.cookie.substring( offset, endstr ) );
}

function amt()
{
	var count = GetCookie( 'count' );
	if( count == null )
	{
		SetCookie( 'count', '1' );
		return 1;
	}
	else
	{
		var newcount = parseInt( count ) + 1;
		DeleteCookie( 'count' );
		SetCookie( 'count', newcount, exp );
		return count;
	}
}

function checkCount()
{
	var count = GetCookie( 'count' );
	if(count == null)
	{
		count = 1;
		SetCookie( 'count', count, exp );
		popUp( '/sitio/popup/popup2.php', 'fixNoScroll', 330, 307 );
		return false;
	}
	else
	{
		SetCookie( 'count', count++, exp );
   }
}


function setActiveStyleSheet( title )
{
	var i, a, main;
	for( i=0; ( a = document.getElementsByTagName('link')[ i ] ); i++ )
	{
		if( a.getAttribute( 'rel' ).indexOf( 'style' ) != -1 && a.getAttribute( 'title' ) )
		{
			a.disabled = true;
			if( a.getAttribute( 'title' ) == title ) a.disabled = false;
		}
	}
}
