/*-------------------------------------------------------------------------------------------------
	ESCOLHE AÇÃO A EXECUTAR
-------------------------------------------------------------------------------------------------*/

function escolheAcao(acao)
{
	with(document.formulario)
	{
		if (selecionados.value != "")
		{
			action = acao;
			submit();	
		}
	}
}

/*-------------------------------------------------------------------------------------------------
	ALERT
-------------------------------------------------------------------------------------------------*/

function alertSobre(msg)
{
	alert(msg);
}

/*-------------------------------------------------------------------------------------------------
	EXCLUIR
-------------------------------------------------------------------------------------------------*/

function execAct(acao)
{
	with(document.formulario)
	{
		if (confirm("Tem certeza que deseja excluir este registro?"))
		{
			action = acao;
			submit();
		}
	}
}

/*------------------------------------------------------
	CONFIRMA ENVIO
------------------------------------------------------*/

function confirmaAcao(frm,msg,act)
{
	if (confirm(msg))
	{
		document[frm].action = act;
		document[frm].submit();	
	}
}

/*------------------------------------------------------
	ENVIA FORM
------------------------------------------------------*/

function enviaForm(frm,act)
{
	if (act == "" || act == null)
	{
		document[frm].submit();	
	}
	else
	{
		document[frm].action = act;
		document[frm].submit();	
	}
}

/*---------------------------------------------------------------------------------
	FILTRO GERAL DE BUSCA
---------------------------------------------------------------------------------*/

function montaURL(tipo_de_retorno)
{
	var query = "";
	var tipo_de_retorno;
	
	if (tipo_de_retorno == null) 
	{
		//Irá pegar o valor do select pagina
		$('#formulario #pagina').removeAttr("alt");
	} 
	else 
	{ 
		//Não irá pegar o valor do select pagina
		$('#formulario #pagina').attr("alt","NAO_PEGA");
	}
	
	$('#formulario input,select,textarea').not(":checkbox,:button,:reset,:image,:submit,:file").each(function(){
		
		 if (!$(this).attr('alt') || $(this).attr('alt') != "NAO_PEGA")
		 {
			 if (this.value != "") 
			 {
				 query += this.name+"="+this.value+"&";
			 }
		 }
		 
	});	
	
	return query.replace(/&$/, "");  //Retira o ultimo & da query
}

function retornaURL(arquivo, tipo_de_retorno, elemento, evento)
{
	$(elemento).bind(evento, function(){
		var querystring = montaURL(tipo_de_retorno);
		location.href   = arquivo+"?"+querystring;
	});
}

/*-------------------------------------------------------------------------------------------------
	CHECK ALL CHECKBOX
---------------------------------------------------------------------------------------------------*/

function iniciaCheckBoxes(id)
{
	$(id).click(function() 
	{
		this.checked = !(this.checked == true);
		
		$("#formulario input:checkbox").attr("checked",function()
        {
            this.checked = !(this.checked == true);
        });
	});	
}


/*-------------------------------------------------------------------------------------------------
	RETORNA A POSIÇÃO DO SCROLLBAR DO NAVEGADOR
-------------------------------------------------------------------------------------------------*/

function getPageScroll()
{

	var xScroll, yScroll;

	if (self.pageYOffset) 
	{
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} 
	else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict
	{	 
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} 
	else if (document.body) // all other Explorers
	{
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}


/*-------------------------------------------------------------------------------------------------
	RETORNA O TAMANHO DA JANELA
-------------------------------------------------------------------------------------------------*/

function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
	{ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{ 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) // all except Explorer
	{	
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth; 
		} 
		else 
		{
			windowWidth = self.innerWidth;
		}
		
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{ 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body)  // other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else 
	{ 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth)
	{	
		pageWidth = xScroll;		
	} 
	else 
	{
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


/*-------------------------------------------------------------------------------------------------
	RESIZE IFRAME
-------------------------------------------------------------------------------------------------*/

function resizeIframe(iframe) 
{
	var arrayPageSize = getPageSize();
	var largura = arrayPageSize[0];
	var altura  = arrayPageSize[1];
	
	try {
	
	 frame    = document.getElementById(iframe);
	 innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	
	 objToResize = (frame.style) ? frame.style : frame;
	
	if(innerDoc=="[object]")
	{
		tamanho = innerDoc.body.scrollHeight; //IE
		auxilio = 20;
	}
	else
	{
		tamanho = innerDoc.body.offsetHeight; //Mozilla
		auxilio = 50;
	}
		objToResize.height = Number(tamanho+auxilio);
		document.getElementById('topo').focus();
	}
	
	catch (e) 
	{
		window.status = '';
	}
}

/*-------------------------------------------------------------------------------------------------
	REDIRECT IFRAME
-------------------------------------------------------------------------------------------------*/

function redirectIframe(frame,pagina)
{
	this[frame].location = pagina;
}

/*-------------------------------------------------------------------------------------------------
	MUDA PÁGINA
-------------------------------------------------------------------------------------------------*/

function mudaPagina(url)
{
	location.href = url;
}

/*-------------------------------------------------------------------------------------------------
	POPUP CENTRALIZADO
-------------------------------------------------------------------------------------------------*/

function abrePopup(pagina,largura,altura,rolagem)
{
	var posX;
	var posY;
	posX = (window.screen.width - largura) / 2;
	posY = (window.screen.height - altura) / 2;
	window.open(pagina,"_blank","width="+largura+",height="+altura+",top="+posY+",left="+posX+",scrollbars="+rolagem+",toolbar=no,location=no,directories=no,menubar=no,resizable=no,menubar=no");
}

/*-------------------------------------------------------------------------------------------------
	POPUP POSIÇÃO PADRÃO
---------------------------------------------------------------------------------------------------*/

function abrePopupMenor(pagina,largura,altura,rolagem)
{
	window.open(pagina,"_blank","width="+largura+",height="+altura+",top=80,left=80,scrollbars="+rolagem+",toolbar=no,location=no,directories=no,menubar=no");
}

/*-------------------------------------------------------------------------------------------------
	REMOVE ACENTOS DE UMA STRING
---------------------------------------------------------------------------------------------------*/

function removeAcentos(texto) 
{
	str = texto.toUpperCase();
	str = str.replace(new RegExp('[ÁÀÂÃ]','gi'), 'A');
	str = str.replace(new RegExp('[ÉÈÊ]','gi'), 'E');
	str = str.replace(new RegExp('[ÍÌÎ]','gi'), 'I');
	str = str.replace(new RegExp('[ÓÒÔÕ]','gi'), 'O');
	str = str.replace(new RegExp('[ÚÙÛÜ]','gi'), 'U');
	str = str.replace(new RegExp('[Ç]','gi'), 'C');
	str = str.replace(new RegExp('[Ñ]','gi'), 'N');
	
	return str;
} 

