//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function Popin(obj, w, h)
{
	$.fn.colorbox(
	{
		overlayClose:true,
		inline:true,
		href:obj,
		width:w+'px',
		height:h+'px'
	});
}
function PopinIframe(url, w, h)
{
	$.fn.colorbox(
	{
		overlayClose:true,
		iframe:true,
		href:url,
		width:w+'px',
		height:h+'px'
	});
}
function PopinHtml(html, w, h, close, buttonclose)
{
	if( close == 'true' )
	{
		close = true;
	}
	else
	{
		close = false;
	}
	$.fn.colorbox(
	{
		overlayClose:close,
		html:html,
		width:w+'px',
		height:h+'px'
	});
	if( buttonclose == 1 )
	{
		$('#cboxClose').hide();
		$('#cboxLoadedContent').css({'margin-bottom':'0px', 'height':''});	
	}
}
function Carregando()
{
	$.fn.colorbox(
	{
		overlayClose:false,
		html:'<div style="font-family:Tahoma;font-size:12px;margin-top:15px;text-align:center;"><strong>Aguarde, Carregando...</strong></div><div class="imgCarregando" style="padding-top:10px;padding-bottom:15px;text-align:center;"><img src="/_img/barracarregando.gif" border="0"></div>',
		width:'320px',
		height:'120px'
	});
	$('#cboxClose').hide();
	$('#cboxLoadedContent').css({'margin-bottom':'0px', 'height':'120px'});
	setTimeout(function()
	{
		$('.imgCarregando').append('<div style="font-family:Tahoma;font-size:9px;margin-top:5px;color:#000;">Ocorreu algum erro na conexão, clique <a href="javascript:PopinClose();">aqui</a> para fechar,<br>e após, tente novamente.</div>')
	}, 30000);
}
function PopinClose()
{
	$.fn.colorbox.close();
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function indicacaoconteudo()
{
	Url = 'pg=indicacaoconteudo';
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 290, 300);
		}
	});
}
function enviaindicacao()
{
	var Url = 'pg=enviaindicacao&NomeRemetente='+$('#NomeRemetente').val()+'&EmailRemetente='+$('#EmailRemetente').val()+'&Emails='+$('#Emails').val()+'&Link='+window.location;
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 350, 110, false, 1);
		}
	});
}
function cadastranewsletter()
{
	var Filtro=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if( !$('.txtEmailNewsletter').val() )
	{
		alert ("Informe o campo 'e-Mail'");
		$('.txtEmailNewsletter').focus();
		return false;
	}
	else if ( !Filtro.test($('.txtEmailNewsletter').val()) )
	{
		alert ('Informe um "e-Mail" válido');
		$('.txtEmailNewsletter').focus();
		return false;
	}
	else
	{
		if ( $('.txtEmailNewsletter').val() != "email@dominio.com.br" )
		{
			Url = 'pg=cadastranewsletter&Acao='+$('.cboAcaoNewsletter').val()+'&Email='+$('.txtEmailNewsletter').val();
			$.ajax(
			{
				type: 'POST',
				url: '/ajax.php',
				dataType: 'json',
				data: Url,
				success: function(Retorno)
				{
					PopinHtml(Retorno.Html, 350, 110, false, 1);
					setTimeout('PopinClose()', 3000);
				}
			});
		}
		else
		{
			alert ("Informe o campo 'e-Mail'");
			$('.txtEmailNewsletter').focus();
			return false;
		}
	}
}
function adicionavotoenquete()
{
	Url = 'pg=adicionavotoenquete&id='+$('.optRespostaDaEnquete[type="radio"]:checked').val();
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		beforeSend: function()
		{
			Carregando();
		},
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 350, 110, false, 1);
			setTimeout('PopinClose()', 1000);
		}
	});
}
function resultadodaenquete()
{
	var Url = 'pg=resultadodaenquete';
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		beforeSend: function()
		{
			Carregando();
		},
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 500, 300, false);
		}
	});
}
function descricaoimagemgaleria(imagem)
{
	var Url = 'pg=descricaoimagemgaleria&imagem='+imagem;
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 350, 300);
		}
	});
}
function salvadescricaoimagemgaleria()
{
	var Url = 'pg=salvadescricaoimagemgaleria&txtDescricao='+escape($('#txtDescricao').val())+'&txtOrdem='+$('#txtOrdem').val()+'&idimagem='+$('#idimagem').val();
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			$('.salvadescricaoimagemgaleria').attr({'disabled':true});
			$('.MsgAjaxLocal').html(Retorno.Msg).show('slow');
			setTimeout(function()
			{
				$('.MsgAjaxLocal').hide('slow');
				$('.salvadescricaoimagemgaleria').attr({'disabled':false});
			}, 4000);
		}
	});
}
function dadoswidget(id)
{
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: 'pg=dadoswidget&id='+id,
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 500, 400);
		}
	});
}
function salvadadoswidget()
{
	var Url = 'pg=salvadadoswidget&'+$('#tabs input, select').serialize();
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			$('.salvadescricaoimagemgaleria').attr({'disabled':true});
			$('.MsgAjaxLocal').html(Retorno.Msg).show('slow');
			setTimeout(function()
			{
				$('.MsgAjaxLocal').hide('slow');
				$('.salvadescricaoimagemgaleria').attr({'disabled':false});
			}, 4000);
		}
	});
}
function cadastramentodalistadepresentes()
{
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: 'pg=cadastramentodalistadepresentes',
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 500, 500);
		}
	});
}
function salvacadastramentodalistadepresentes()
{
	var Url = 'pg=salvacadastramentodalistadepresentes&'+$('#cboxLoadedContent input,select,textarea').serialize();
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 350, 110, false, 1);
			setTimeout('PopinClose()', 1000);
		}
	});
}
function verlistadepresentes()
{
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: 'pg=verlistadepresentes',
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 500, 400);
		}
	});
}
function compralistadepresentes(id)
{
	Url = 'pg=compralistadepresentes&id='+id;
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 500, 400);
		}
	});
}
function salvacompralistadepresentes()
{
	Url = 'pg=salvacompralistadepresentes&'+$('#cboxLoadedContent input,select,textarea').serialize();
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		beforeSend: function()
		{
			Carregando();
		},
		success: function(Retorno)
		{
			PopinHtml(Retorno.Html, 350, 110, false, 1);
			setTimeout('PopinClose()', 1000);
		}
	});
}

function MostraNoticia(id)
{
	PopinIframe(escape('/noticiasinternas/'+id), 600, 500);
}
function AdicionaAosFavoritos()
{
	if (document.all) window.external.AddFavorite(UrlFavoritos, TituloFavoritos);
	else if (window.sidebar) window.sidebar.addPanel(TituloFavoritos, UrlFavoritos, "")
}
function StatusDoElementoDaGrid(acao)
{
	Url = 'pg=statusdoelementodagrid&'+acao;
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			$('.conteudo').html(Retorno.Html);
		}
	});
}
function StatusCadeadoDaGrid(url)
{
	Url = 'pg=statuscadeadodagrid&'+url;
	$.ajax(
	{
		type: 'POST',
		url: '/ajax.php',
		dataType: 'json',
		data: Url,
		success: function(Retorno)
		{
			$('.conteudo').html(Retorno.Html);
		}
	});
}
function AbreModelos(tipo)
{
	var pasta;
	if( tipo == 'topos' )
	{
		pasta = 'upload/modelos/topo';
	}
	else if( tipo == 'backgrounddosite' )
	{
		pasta = 'upload/modelos/fundo';
	}
	else if( tipo == 'backgrounddotopo' )
	{
		pasta = 'upload/modelos/fundo';
	}
	else if( tipo == 'backgrounddoconteudo' )
	{
		pasta = 'upload/modelos/fundo';
	}
	
	w = 400;
	h = 300;
	p = 10;
	
	PopinIframe('/?pg=modelos&tipo='+tipo+'&pasta='+base64_encode(pasta), 500, 400);
}
/*function AdicionaTemplate(id)
{
	if (confirm("ATENÇÃO:\n\nVocê já habilitou o (cadeado) nas opções: Páginas, Topos, Rodapé, Menus, BG do Topo, BG do Site (dentro), BG do Site (fora) e Topo-Conteúdo, que você deseja preservar?"))
	{
		if (confirm('Você realmente deseja adicionar este template ?             '))
		{
			Url = 'pg=adicionamodelos&id='+id;
			$.ajax(
			{
				type: 'POST',
				url: '/ajax.php',
				dataType: 'json',
				data: Url,
				success: function(Retorno)
				{
					PopinHtml(Retorno.Html, 350, 110, false, 1);
					setTimeout('PopinClose();window.location="/";', 1000);
				}
			});
		}
	}
}*/
function excluir(acao)
{
	var id = '';
	var contador = 0;
	$("input[type='checkbox']").each(function()
	{
		if( $(this).attr('checked') == true )
		{
			id += $(this).val()+',';
			contador++;
		}
	});
	if( contador == 0 )
	{
		alert('AVISO!\n\nSelecione pelo menos 1 registro para executar a ação.\n');
	}
	else
	{
		id = id.substring(0,id.length-1);
		if (confirm('Você realmente deseja excluir este(s) registro(s) ?             '))
		{
			Url = 'pg=excluir'+acao+'&id='+id;
			$.ajax(
			{
				type: 'POST',
				url: '/ajax.php',
				dataType: 'json',
				data: Url,
				beforeSend: function()
				{
					Carregando();
				},
				success: function(Retorno)
				{
					$('.conteudo').html(Retorno.Html);
					PopinHtml(Retorno.Msg, 350, 110, false, 1);
					setTimeout('PopinClose()', 1000);
				}
			});
		}
	}
}
function excluirindividualmente(id, acao)
{
		if (confirm('Você realmente deseja excluir este registro ?             '))
		{
			Url = 'pg=excluir'+acao+'&id='+id;
			$.ajax(
			{
				type: 'POST',
				url: '/ajax.php',
				dataType: 'json',
				data: Url,
				beforeSend: function()
				{
					Carregando();
				},
				success: function(Retorno)
				{
					$('.conteudo').html(Retorno.Html);
					PopinHtml(Retorno.Msg, 350, 110, false, 1);
					setTimeout('PopinClose()', 1000);
				}
			});
		}
}
function editar(acao)
{
	var id;
	var contador = 0;
	$("input[type='checkbox']").each(function()
	{
		if( $(this).attr('checked') == true )
		{
			id = $(this).val();
			contador++;
		}
	});

	if( contador == 0 )
	{
		alert('AVISO!\n\nSelecione pelo menos 1 registro para executar a ação.');
	}
	else if( contador > 1 )
	{
		alert('AVISO!\n\nVocê só pode editar apenas 1 registro por vez.');
	}
	else
	{
		window.location = '?pg='+acao+'&id='+id;
	}
}
function MostraBiblia()
{
	if( $('.BibliaLivro').val() != '-' )
	{
		Url = '/biblia/'+$('.BibliaLivro').val()+'/'+$('.BibliaCapitulos').val();
		if( $('.BibliaVersiculos').val() )
		{
			Url = Url+'/'+$('.BibliaVersiculos').val();
		}
		window.location = escape(Url);
		//alert(Url);
	}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
HexToRGB = function (hex)
{
	var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
	return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
}
function SomenteNumeros(e) // USO: <input type="text" onkeypress="javascript:return SomenteNumeros(event);">
{
	var tecla=new Number();
	
	if(window.event)
	{
		tecla = e.keyCode;
	}
	else if(e.which)
	{
		tecla = e.which;
	}
	else
	{
		return true;
	}
	
	if(((tecla < 48) || (tecla > 57)) && (tecla!=8) )
	{
		return false;
	}
}
function SomenteLetras(e) // USO: <input type="text" onkeypress="javascript:return SomenteLetras(event);">
{
	var tecla=new Number();
	
	if(window.event)
	{
		tecla = e.keyCode;
	}
	else if(e.which)
	{
		tecla = e.which;
	}
	else
	{
		return true;
	}
	
	if( ((tecla < 65) || (tecla > 90)) && ((tecla < 97) || (tecla > 122)) && (tecla!=8) )
	{
		return false;
	}
}
function SomenteEmail(e) // USO: <input type="text" onkeypress="javascript:return SomenteEmail(event);">
{
	var tecla=new Number();
	
	if(window.event)
	{
		tecla = e.keyCode;
	}
	else if(e.which)
	{
		tecla = e.which;
	}
	else
	{
		return true;
	}
	
	if( ((tecla < 65) || (tecla > 90)) && ((tecla < 97) || (tecla > 122)) && ((tecla < 48) || (tecla > 57)) && (tecla!=8) && (tecla!=45) && (tecla!=46) && (tecla!=95) )
	{
		return false;
	}
}


function AbrePopup(Pagina,Janela,Largura,Altura,Rolagem)
{
	var PosicaoLeft = ((screen.width) - (Largura)) / 2;
	var PosicaoTop = ((screen.height) - (Altura)) / 2;
	
	var PropriedadesDaJanela = "width="+Largura+",height="+Altura+",top="+PosicaoTop+",left="+PosicaoLeft+",fullscreen=no,resizable=no,scrollbars="+Rolagem+",toolbar=no,location=no,menubar=no,status=no";
	window.open(Pagina, Janela, PropriedadesDaJanela);
}
function AbrePopupTopLeft(Pagina,Janela,Largura,Altura,Rolagem,Top,Left)
{
	var PropriedadesDaJanela = "width="+Largura+",height="+Altura+",top="+Top+",left="+Left+",fullscreen=no,resizable=no,scrollbars="+Rolagem+",toolbar=no,location=no,menubar=no,status=no";
	window.open(Pagina, Janela, PropriedadesDaJanela);
}
var src;
function VerImagem()
{
	AbrePopupTopLeft('/?pg=verimagem&src='+src, 'IMAGEM', 100, 100, 0, 0, 0);
}
function SubtraiOrdem(obj)
{
	if( $('#'+obj).val() > 0 )
	{
		$('#'+obj).val($('#'+obj).val()-1);
	}
}
function SomaOrdem(obj)
{
	if( $('#'+obj).val() < 999 )
	{
		$('#'+obj).val(parseInt($('#'+obj).val())+1);
	}
}
function filemanagerKB(field_name, url, type, win)
{
	//alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
	
	/* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
	the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
	These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
	
	var cmsURL = '/?pg=filemanager&pasta='+base64_encode('upload');    // script URL - use an absolute path!
	if (cmsURL.indexOf("?") < 0)
	{
		//add the type as the only query parameter
		cmsURL = cmsURL+'&tipo='+base64_encode(type);
	}
	else
	{
		//add the type as an additional query parameter
		// (PHP session ID is now included if there is one at all)
		cmsURL = cmsURL+'&tipo='+base64_encode(type);
	}
	tinyMCE.activeEditor.windowManager.open(
	{
			file : cmsURL,
			title : '',
			width : 450,  // Your dimensions may differ - toy around with them!
			height : 400,
			resizable : "yes",
			inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
			close_previous : "yes"
		},
		{
			window : win,
			input : field_name,
			resizable : "yes",
			inline : "yes",
			type : type
		}
	);
	return false;
}
function URLencode( sStr )
{
	return escape( sStr ).replace( /\+/g, '%2C' ).replace( /\"/g,'%22' ).replace( /\'/g, '%27' );
}
function trim( str )
{
	return str.replace( /^\s*|\s*$/g,"" );
}
/**
* Clone da função do PHP number_format()
*
* @param		int/string		-> Numero ao qual se quer formatar
* @param		int				-> Numero de casas decimais
* @param		string			-> Separador decimal
* @param		string			-> Separador Milheiro
* @return 		string
*/
function number_format(number, decimals, dec_point, thousands_sep)
{
	var exponent  = "";
	var numberstr = number.toString ();
	var eindex    = numberstr.indexOf ("e");

	if(numberstr.match(',') && numberstr.match('.')) {
		return numberstr;
	}

	if (eindex > -1)
	{
		exponent = numberstr.substring (eindex);
		number = parseFloat (numberstr.substring (0, eindex));
	}

	if (decimals != null)
	{
		var temp = Math.pow (10, decimals);
		number   = Math.round (number * temp) / temp;
	}

	var sign       = number < 0 ? "-" : "";
	var integer    = (number > 0 ?	Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
	var fractional = number.toString().substring (integer.length + sign.length);

	dec_point  = dec_point != null ? dec_point : ".";
	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";

	if (decimals != null && decimals > 0)
	{
		for (i = fractional.length - 1, z = decimals; i < z; ++i)
		fractional += "0";
	}

	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;

	if (thousands_sep != null && thousands_sep != "")
	{
		for (i = integer.length - 3; i > 0; i -= 3)
		integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	}

	return sign + integer + fractional + exponent;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}
function checkPopupBlocker()
{
	 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
	 if(mine) {
	    var popUpsBlocked = false;
	 } else {
	    var popUpsBlocked = true;
	 }

	 mine.close();

	 return popUpsBlocked;
}
function escapeAll(string)
{
    var decHex = function(dec) {
        var chars = '0123456789ABCDEF';
        
        return chars.charAt(Math.floor(dec / 16)) + chars.charAt(dec % 16);
    };
    
    var out = '';
    
    for(var i = 0; i < string.length; i++) {
        var code = string.charCodeAt(i);
        
        if(code > 255)
            out += '%3F'; //coloca uma interrogacao caso o caractere seja desconhecido
        else
            out += '%' + decHex(code);
    }
    return out;
}
function Url2Array(query)
{
   var ArrayUrl = {};
   if ( ! query ) {return ArrayUrl;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      ArrayUrl[key] = val;
   }
   return ArrayUrl;
}
function PegaExtensao(Url)
{
   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
   var Url = Url.toLowerCase().match(urlString);
   return Url;
}
function removeHTMLTags(str)
{
	str = str.replace(/&(lt|gt);/g, function (strMatch, p1){ return (p1 == "lt")? "<" : ">";	});
	var str = str.replace(/<\/?[^>]+(>|$)/g, "");
	return str;
}
function Rnd(n)
{
	return ( Math.floor ( Math.random ( ) * n + 1 ) );
}
function ValidaEmail(sEmail)
{
	var regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,6}$/;
	return regex.test(sEmail);
}
function ValidaCep(CEP)
{
	var validos="0123456789-";
	var NumHifens=0;
	if (CEP.length<8)return false;
	for (var i=0;i<CEP.length;i++)
	{
	temp=""+CEP.substring(i,i+1);
	if(temp=="-") NumHifens++;
	if(validos.indexOf(temp)=="-1")return false;
	if(NumHifens>0 && ""+CEP.charAt(5)!="-")return false;
	}
	return true;
}
function str_replace(str, de, para)
{
	var pos = str.indexOf(de);
	while (pos > -1)
	{
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
	return (str);
}
function ValidaCnpj(str)
{
	CNPJ = str;
	CNPJ = str_replace(CNPJ, '.', '');
	CNPJ = str_replace(CNPJ, '/', '');
	CNPJ = str_replace(CNPJ, '-', '');
	
	erro = new String;
	if (CNPJ.length < 14)
	{
		erro = "O CNPJ deve conter 14 dígitos!";
		alert(erro);
		return false;
	}
	
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ))
	{
		erro = "A verificação de CNPJ suporta apenas números!";
		alert(erro);
		return false;
	}
	
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++)
	{
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
	for (y=0; y<13; y++)
	{
		b += (a[y] * c[y]); 
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
	{
		erro ="Dígito verificador com problema!";
		alert(erro);
		return false;
	}
	return true;
}
function ValidaCpf(str)
{
	str = str_replace(str, '.', '');
	str = str_replace(str, '-', '');
	
	if (VerificaCpf(str))
	{
		return true;
	}
	else
	{
		alert('CPF não é válido!');
		return false;
	}
	
	function VerificaCpf(cpf)
	{
		if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		return false;
		add = 0;
		for (i=0; i < 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
		rev = 0;
		if (rev != parseInt(cpf.charAt(9)))
		return false;
		add = 0;
		for (i = 0; i < 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
		rev = 0;
		if (rev != parseInt(cpf.charAt(10)))
		return false;
		//alert('O CPF INFORMADO É VÁLIDO.');
		return true;
	}
}
//##########################################
function base64_encode(str)
{
	return encode64(str);
}
function base64_decode(str)
{
	return decode64(str);
}
// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);

   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@