	function insereFlash(caminho,div,largura,altura,largura_min){
			var so = new SWFObject(caminho,"flash",largura,altura, '8');
			so.addParam('menu', 'false');
			so.addParam('scale', 'noscale');
			so.addParam('salign', 'lt'); 
			so.addParam('wmode', 'transparent');         
			/*if( so.write(div) )
			{
				var forcesize = new SWFForceSize(so,largura_min,altura);
			}*/
              so.write(div);			
	}
	
function number_format( number, decimals, dec_point, thousands_sep ) {
    var i, j, kw, kd, km;

    // input sanitation & defaults
    if( isNaN(decimals = Math.abs(decimals)) ){
        decimals = 2;
    }
    if( dec_point == undefined ){
        dec_point = ",";
    }
    if( thousands_sep == undefined ){
        thousands_sep = ".";
    }

    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";

    if( (j = i.length) > 3 ){
        j = j % 3;
    } else{
        j = 0;
    }

    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    //kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");


    return km + kw + kd;
}

function url_decode(str)
        {
         var n, strCode, strDecode = "";

         for (n = 0; n < str.length; n++)
             {
              if (str.charAt(n) == "%")
                 {
                  strCode = str.charAt(n + 1) + str.charAt(n + 2);
                  strDecode += String.fromCharCode(parseInt(strCode, 16));
                  n += 2;
                 } else {
                  strDecode += str.charAt(n);
                 }
             }

         return strDecode;
        }

function AddOpcao(combo, valor, strDescricao, defaultSelected, selected)
        {
         var novaOpcao=new Option(strDescricao, valor, defaultSelected, selected);
         combo.options[combo.length]=novaOpcao;
        }

function DelOpcao(combo)
        {
         for (i=combo.length - 1;i>=0;i--)
              combo.remove(i);
        }

function trata_campo(campo,digitos)
	     {
          var i;
	      i = 0;
	      while (i < campo.value.length)
		        {
		         if (digitos.indexOf(campo.value.substring(i,i+1)) == -1)
                    {
			         campo.value = campo.value.substring(0,i) + campo.value.substring(i+1);
                    } else {
			         i++;
                    }
		        }
	     }
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function cadastrarNewsletter(nomeVal, emailVal)
{
	var expreg=/([a-z0-9_\.\-])+\@(([a-z0-9])+\.)+((gov|com|org|net|biz|info)|([a-z]{2}))$/;
	if (emailVal && expreg.exec(emailVal))
	{
		$.post('ajax/gravaNewsletter.php',
		{
			nome:	nomeVal,
			email:	emailVal,
			opcao:	1					  
		}, function (retorno){
			switch (retorno) 
			{
				case "existe": 
					alert("Este E-Mail já existe em nossa base de dados!");
					break;
				case "erro":
					alert("Erro ao salvar email!\nTente Novamente!");
					break;
				case "incluido":
					alert("E-Mail salvo com sucesso!");
					break;
				case "excluido":
					alert("E-Mail deletado com sucesso!");
					break;	
				case "naoexiste":
					alert("Este E-Mail não existe em nossa base de dados!");
					break;							
			}
			
			if ($("#txtNovidadeNome"))
				$("#txtNovidadeNome").val("Digite seu Nome"); 
			if ($("#txtNovidadeEmail"))
				$("#txtNovidadeEmail").val("Digite seu E-mail"); 
		});
	} else {
		alert("E-mail inválido!");
	}
}

$(document).ready(function(){
	var expreg=/([a-z0-9_\.\-])+\@(([a-z0-9])+\.)+((gov|com|org|net|biz|info)|([a-z]{2}))$/;
	
	$('a[rel=external]').attr('target', '_blank');
	
	if ($(".val_data"))
		$(".val_data").mask("99/99/9999");
	
	if ($(".val_cep"))
		$(".val_cep").mask("99999-999");
	
	if ($(".val_telefone"))
		$(".val_telefone").mask("(99) 9999-9999");
	
	if ($("#txtNovidadeNome"))
	{
		$("#txtNovidadeNome").focus(function(){
			if (this.value == "Digite seu Nome")
				this.value = "";
		});
		
		$("#txtNovidadeNome").blur(function(){
			if (!Trim(this.value))
				this.value = "Digite seu Nome";
		});
	}
	
	if ($("#txtNovidadeEmail"))
	{
		$("#txtNovidadeEmail").focus(function(){
			if (this.value == "Digite seu E-mail")
				this.value = "";
		});
		
		$("#txtNovidadeEmail").blur(function(){
			if (!Trim(this.value))
				this.value = "Digite seu E-mail";
		});
	}
	
	if ($("#btoNovidadeCadastrar"))
	{
		$("#btoNovidadeCadastrar").click(function(){
			cadastrarNewsletter($("#txtNovidadeNome").val(), $("#txtNovidadeEmail").val());
		});
	}
});

 


