
jQuery( document ).ready( iniciar )

carregaMapa = false;

function testaMapa()
{
	if( carregaMapa )
	{
		carregaMapa();
	}
}
function iniciar()
{
	testaMapa()
	
	aumentaFonte = function()
	{
		tamanho = $( "div#container *" ).css( "font-size" );
		
		if( parseInt( tamanho ) < 20 )
		{
			$( "div#container *" ).css( "font-size", ( parseInt( tamanho ) + 1 ) + "px" )
		}
	}
	
	diminuiFonte = function()
	{
		tamanho = $( "div#container *" ).css( "font-size" );
		
		if( parseInt( tamanho ) > 9 )
		{
			$( "div#container *" ).css( "font-size", ( parseInt( tamanho ) - 1 ) + "px" )
		}
	}
	
	$( "a#aumentarFonte" ).click( aumentaFonte );
	$( "a#diminuirFonte" ).click( diminuiFonte );
	
	$( "ul li span.descricao" ).addClass( "fechado" );
	$( "ul li span.descricao" ).hide();
	$( "ul li span.tituloExpande" ).css( "cursor", "pointer" );
	
	$( "ul li ul.descricao" ).addClass( "fechado" );
	$( "ul li ul.descricao" ).hide();
	$( "ul li h4.tituloExpande" ).css( "cursor", "pointer" );
	
	onClickTitulo = function()
	{
		id = $( this ).attr( 'id' );
		
		$( this ).next().toggleClass( 'aberto' );
		$( this ).next().toggleClass( 'fechado' );

		if( $( this ).next().attr( 'class' ).indexOf( 'aberto' ) == -1 )
		{
			$( this ).next().animate( { height: 'hide', opacity: 'hide' }, 'quick' );
			$( "span[id^=status_" + id + "]" ).html( "[ + ]" );
		}
		else
		{
			$( this ).next().animate( { height: 'show', opacity: 'show' }, 'quick' );
			$( "span[id^=status_" + id + "]" ).html( "[ - ]" );
		}
	}
	
	$( "ul li span.tituloExpande" ).click( onClickTitulo );
	$( "ul li h4.tituloExpande" ).click( onClickTitulo );
	
}

// window.open

function openNewWindow(URLtopen, windowName, windowFeatures) {
newWindow=window.open(URLtopen, windowName, windowFeatures);}
  
 // função que gerencia a abertura do submenu
function toogleSub( area )
{
	$( "#" + area ).animate(
	{
   		height: 'toggle'
 	}
	, "slow" );
}

// funções genéricas
var numericExpression = /^[0-9]+$/;

function validaCPF( s )
{
	var c = s.substr(0,9);
 
	var dv = s.substr(9,2);
 
	var d1 = 0;
 
	for ( i = 0 ; i < 9 ; i++ )
	{
		d1 += c.charAt( i ) * ( 10 - i );
	}
 
	if ( d1 == 0 )
	{
	 
		alert("CPF Invalido")
	 
		return false;
	 
	}
 
	d1 = 11 - (d1 % 11);
 
	if (d1 > 9) d1 = 0;
 
	if (dv.charAt(0) != d1)
	{
	 
		alert("CPF Invalido")
	 
		return false;
	 
	}
 
 
	d1 *= 2;
	 
	for (i = 0; i < 9; i++)
	{
	 
		d1 += c.charAt(i)*(11-i);
	 
	}
	 
	d1 = 11 - (d1 % 11);
	 
	if (d1 > 9) d1 = 0;
	 
	if (dv.charAt(1) != d1)	 
	{
	 
		alert("CPF Invalido")
	 
		return false;
	 
	}
	 
	return true;
 
}

function validaEmail( texto )
{
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( texto ))) 
	{ 
		return (false) 
	}
	return true;
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0){ 
		offset = document.cookie.indexOf(search)
		if (offset != -1){ 
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length
				return unescape(document.cookie.substring(offset, end))
			} 
		} 
	}

function expira(){
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*365);
	return expires;
}

function checaCookie(name,nomim) {
	if (getCookie(name)=='on'){
		Elemento = document.getElementById(nomim);
		Elemento.style.display="block";
	}
}