// ############################################################################
// # Nome: funcoes.js
// # Sistema: Portal ODM
// # Criado por: Kleber Cioccari - 20/11/2008
// # Empresa: ORBIS
// # E-mail: kleber.cioccari@sesipr.org.br
// # Última alteração: - Função Aumentar ou Diminuir a Fonte do Parágrafo
// # Propósito: Funcoes gerais em javascript
// # Histórico: 
// #			. 20/11/08 - Kleber Cioccari - Criação da Página
// #			. 20/11/08 - Kleber Cioccari - FUNÇÂO IMPRIMIR TELA
// #			. 20/11/08 - Kleber Cioccari - FUNÇÂO ESCONDER DIV
// #			. 20/11/08 - Kleber Cioccari - FUNÇÂO ESCONDER DIV OBJETIVOS
// #			. 20/11/08 - Kleber Cioccari - FUNÇÂO VALIDAÇÃO DE FORMULÁRIO (AJAX - REQUERIDO)
// #        	. 20/11/08 - Kleber Cioccari - FUNÇÃO AUMENTAR OU DIMINUIR FONTE DA PÁGINA
// #        	. 02/12/08 - Kleber Cioccari - FUNÇÃO PNGFIX
// ############################################################################


//  PAGINA PARA UTILIZAR FUNCOES EM JAVASCRIPT / AJAX
	
function ajaxInicia() 
{
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		ajax = new XMLHttpRequest();
		if (ajax.overrideMimeType) {
			ajax.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) { // IE
	   
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	
	return ajax;
}
ajax_adm = ajaxInicia();




/* Impressão da Tela do usuário */
function ImprimeTela(caminho) 
{
  var mac = (navigator.userAgent.indexOf("Mac") != -1); 
  var doc = (document.all) ? 1 : 0;
  var ie_ns = (window.print) ? 1 : 0;

  if (ie_ns)     			// Se for netscape 4 ou ie5
    window.print();
  else if (doc && !mac)     // Se for ie4
    vbPrintPage()
  else     					// Outros
    alert("Opção não suportada pela navegador ");
    return false;
}

/* VALIDAÇÃO DE FORMULÁRIO */
	var filters = {
			requerido: function(el) {return ($(el).val() != '' && $(el).val() != -1);},
			email: function(el) {return /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test($(el).val());},
			telefone: function(el){return /^[0-9]*$/.test($(el).val());}
		};
/* FIM - VALIDAÇÃO DE FORMULÁRIO */
	
/* MOSTRA OU ESCONDE DIV */
function mostra_div(nome_div)
{
	//alert(nome_div);
	if (document.getElementById(nome_div).className == "hidden") 
	{
		document.getElementById(nome_div).className = "";
	} 
	/*
	else  
	{
		document.getElementById(nome_div).className = "hidden"
	}
	*/
}	

function esconde_div(nome_div)
{
	document.getElementById(nome_div).className = "hidden";
}	

function mostra_div_nome(nome_div)
{
	//alert(nome_div);
	if (document.getElementsByName(nome_div).className == "hidden") 
	{
		document.getElementgetsByName(nome_div).className = "lista_tabela_alt_pagination ";
	} 
	/*
	else  
	{
		document.getElementById(nome_div).className = "hidden"
	}
	*/
}	
function esconde_div_nome(nome_div)
{
	document.getElementsByName(nome_div).className = "hidden";
}	

function mostra_esconde(nome_div)
{
	if (document.getElementById(nome_div).className == "hidden") 
	{
		document.getElementById(nome_div).className = "";
	} 
	else
	{
		document.getElementById(nome_div).className = "hidden";
	}
}	

/* MOSTRA / ESCONDE Pagina TOPO.PHP (8 Objetivos) */
function mostra_odm(div_objetivo)
{
	if (document.getElementById(div_objetivo).className == "hidden_odm")
	{
		var qtd_divs = 8; // SETADO NA MÃO AS 8 DIVS COM O NOME ODMS PARA O IE FUNCIONAR CORRETAMENTE.
			//var qtd_divs = document.getElementsByName("odms").length;
		
		var div_sel =  document.getElementById(div_objetivo);			
		var todas_divs;
	
		for (var i = 1; i <= qtd_divs; i++)
		{
			todas_divs = document.getElementById("div_odm"+i);
			if (todas_divs.id != div_objetivo)
				todas_divs.className = "hidden_odm";
			else
				div_sel.className = "";
		}
		document.getElementById(div_objetivo).className == "";
	}
	else  
	{
		document.getElementById(div_objetivo).className = "hidden_odm";
	}
}


/* MOSTRA OU ESCONDE DIV */


	/* FUNÇÃO AUMENTA OU DIMINUI A FONTE */
	var tgs = new Array('p'); //pega todas as tags p//

	//Specify spectrum of different font sizes:
	var szs = new Array('xx-small','x-small','small','medium','large','x-large','xx-large');
	var startSz = 2;
	
	function ts(trgt,inc) 
	{
		if (!document.getElementById) return
		var d = document,cEl = null,sz = startSz,i,j,cTags;
		sz += inc;
		if (sz<2) sz = 2;
		if (sz>5) sz = 5;
		startSz = sz;
		if (!(cEl = d.getElementById(trgt))) cEl = d.getElementsByTagName(trgt)[0];
		
		cEl.style.fontSize = szs[sz];
		
		for (i = 0; i < tgs.length; i++) 
		{
			cTags = cEl.getElementsByTagName(tgs[i]);
			for (j = 0; j < cTags.length; j++) cTags[j].style.fontSize = szs[sz];
		}
	}
	/* FIM - FUNÇÃO AUMENTA OU DIMINUI A FONTE */

	/* FUNCAO PARA ADICIONAR UM ACESSO A MAIS NA CATEGORIA EM QUE A NOTICIA CLICADA PERTENCE */
	function adicionaAcessoCategoria(id_categoria,categoria)
	{
	 	//alert(id_categoria);
		//alert(categoria);
		
		function ajaxInit() 
		{

		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			ajax = new XMLHttpRequest();
			if (ajax.overrideMimeType) {
				ajax.overrideMimeType('text/xml');
			}
		}
		else if (window.ActiveXObject) { // IE
		   
			try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		}
	
		return ajax;
		}
		ajax = ajaxInit();
		if(ajax) {
			ajax.open("GET", "adiciona_acesso_categoria_bd.php?id_categoria=" + id_categoria + "&categoria=" + categoria, true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
			ajax.send(null);
			ajax.onreadystatechange = function() 
			{
				if(ajax.readyState == 4) 
				{
					if(ajax.status == 200) {
					   //alert(ajax.responseText);
					} else {
					   //alert(ajax.statusText);
					   //FOI COMENTADO PARA TESTES
					}
				}
			}
		}
	 }
 	/* FUNCAO PARA ADICIONAR UM ACESSO A MAIS NA CATEGORIA EM QUE A NOTICIA CLICADA PERTENCE */
	/* FUNCAO PARA ADICIONAR UM ACESSO A MAIS NA CATEGORIA EM QUE A NOTICIA CLICADA PERTENCE */
	function adicionaAcessoItem(id_item,categoria)
	{
	 	//alert(id_item);
		//alert(categoria);
		
		function ajaxInit() 
		{

		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			ajax = new XMLHttpRequest();
			if (ajax.overrideMimeType) {
				ajax.overrideMimeType('text/xml');
			}
		}
		else if (window.ActiveXObject) { // IE
		   
			try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		}
	
		return ajax;
		}
		ajax = ajaxInit();
		if(ajax) {
			ajax.open("GET", "adiciona_acesso_item_bd.php?id_item=" + id_item + "&categoria=" + categoria, true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");       
			ajax.send(null);
			ajax.onreadystatechange = function() 
			{
				if(ajax.readyState == 4) 
				{
					if(ajax.status == 200) {
					   //alert(ajax.responseText);
					} else {
					   //alert(ajax.statusText);
					   //FOI COMENTADO PARA TESTES
					}
				}
			}
		}
	 }
 	/* FUNCAO PARA ADICIONAR UM ACESSO A MAIS NA CATEGORIA EM QUE A NOTICIA CLICADA PERTENCE */
	
function objectSwf(swf,width,height)
{
	document.write('<object type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" data="' + swf + '">');
	document.write('<param name="movie" value="' + swf + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + swf + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent"></embed>');
	document.write('</object>');
}
/**
	PARA O PLAYER .FLV
	
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;


<!--  PNGFIX !--> 
/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[@src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[@src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);





	function SomenteNumero(e)
	{
		var tecla=(window.event)?event.keyCode:e.which;
		if((tecla > 47 && tecla < 58) || (tecla == 0 || tecla == 8)) return true;
		else{
			//if (tecla != 8) return false;
			//else 
			return false;
		}
	}

	function getMilhar(valor)
	{
		//Esta funcao formata campos numericos com pontos de milhar.
		var vetor = new Array();
		var retorno = "";
		while(valor.length>6)
		{
			vetor.push(valor.substr(valor.length-6,valor.length-1));
			valor=valor.substr(0,valor.length-6);
		}
		
		if(vetor.length>=2)
		{
			vetor.reverse();
			retorno=vetor.join(",");
			if(valor.length>0){
			retorno=valor+","+retorno;
			}
			}else if(vetor.length==1){
			retorno=vetor[0];
			if(valor.length>0){
			retorno=valor+","+retorno;
		}
		return retorno;
		}
		else 
		{
			return valor;
		}
		return retorno;
	}

	function commaVerify(valor_aux) 
	{	
		 var valor_aux = valor_aux.replace(",",".");
		 return valor_aux;	 
	}

	function real(num)
	{
		reais=Math.floor(num)
		cents=Math.round((num-reais)*100)
		texto=reais+","
		if(cents<10)
		{
			texto=texto+"0"
		}
		var teste = texto.length;	
		
		texto= getMilhar(commaVerify(texto+cents));
		return texto	
	} 
	
	function tiravirgula(valor)
	{
		var valor = valor.replace(",","");
		 return valor;	 
	}
