/* BlackClass 
      BlackClass  v1.0 
	  Last Updated: 13/06/2009 23:18
	  Craft by:     Gilson Silva 
	  Organization: Neocreative Studio
	  Mail:         suporte@neocreative.com.br
*/

// Função para localizar onde se encontra o cod raiz 
function REMOTE_PLACE(){$tags = document.getElementsByTagName('script'); for(var $i=0;$i<$tags.length;$i++){ if($tags[$i].src != ''){	var tmp = $tags[$i].src.indexOf('black_class.js'); if(tmp != -1){ var $pasta = $tags[$i].src.replace(/black_class.js/gi, ""); return $pasta;}}}}

// VARIÁVEIS GLOBAIS DE CONFIGURAÇÃO

$_CONFIG = new Array();
$_CONFIG[  'soms'   ]   = false;
$_CONFIG[  'cursor' ]   = false;
$_CONFIG[  'imgs'   ]   = false;
$_CONFIG[  'Pasta'  ]   = REMOTE_PLACE();




//// -------------------------------------------------------- início da classe -----------------------------------------------------
function Objeto($id){
	
	// Funções disponíveis	
	this.get              = get              // Carrega um objeto e retorna o mesmo
	this.css              = css;             // Seta um estilo css 
	this.GotoX            = GotoX;           // Espande o objeto a posição X
	this.GotoY            = GotoY;	         // Espande o objeto a posição Y
	this.mask_value       = mask_value;      // Mascara um valor de Imput ou Text area   
	this.mask_money       = mask_money;      // Mascara o valor do imput para valor monetario 
	this.MaskNum          = MaskNum          // Permite a digitação de apenas numeros no imput 
	this.mask_cep         = mask_cep         // Mascara de CEP
	this.opacit           = opacit;          // Seta Opacidade no objeto
	this.v_email          = v_email;         // Veirifica se o campo possui um e-mail válido
	this.criar_get_enviar = criar_get_enviar;// Criar um GET para url a partir de um objeto e seus filhos 
	this.get_values       = get_values;      // Varre o objeto atrás de valores 
    this.aleatorio        = aleatorio;       // Cria um número aleatório 
	this.RemoveAtributo   = RemoveAtributo;  // Remove Um atributo do objeto
    this.atributo         = atributo;        // Seta Um atributo para o objeto
	this.hide             = hide;	         // Esconde o objeto
	this.show             = show;		     // Mostra o objeto
	this.ShowFND          = ShowFND;         // função para mostrar o fundo lightbox
	this.HideFND          = HideFND;         // função para esconder o fundo lightbox
	this.Preload          = Preload;         // Função carrega a imagem
	this.Numerico         = Numerico         // Permite a digitação de apenas numeros
	this.isset            = isset;           // Função verifica se o objeto ou variável existe
	this.openajax         = openajax		 // Função resposável por criar a conecção ajax  	
	this.Ajax             = Ajax			 // Função responsável por enviar e receber dados via ajax 
	this.ExtraiScript     = ExtraiScript;    // Executa o javascript do ajax	
	this.novoJS           = novoJS;          // Função carraga novos Js 
	this.novoCSS          = novoCSS          // Função carregar novas folhas de estilos css
	this.addFlash         = addFlash         // Adiciona um arquivo flash onde quiser
	this.FLUpload         = FLUpload;        // Transforma o imput em uma area de upload
	this.LimpaNumero      = LimpaNumero;     // Função limpar as vigulas e pontos do número;
	this.Formata_moeda    = Formata_moeda;   // Função Formatar numero p/ Moeda
	this.txtPARAhmtl      = txtPARAhmtl;     // Converte o valor de um campo textarea \n para HTML <br>
	this.nPARAtxt         = nPARAtxt;        // Reverte o HTML <br> para \n no text area
	this.BuscaCep         = BuscaCep;        // retorna um array de cep
	this.Extend           = Extend           // Extende a class com novos JSs
	this.CarregaJS        = CarregaJS;       // 
	this.Replace          = Replace;         // Replace mais eficiente que o replace do JS
	this.Show_GATEWAY     = Show_GATEWAY;
	this.codUrl           = codUrl;          // Codifiva a ulr para acitar acentos no FF
	


	
	// Variáveis Diposníveis
    if($id != '' || undefined || null){ this.obj = get($id); }else{ this.obj = ''; }	
	this.w           = '';
	this.h           = '';
	this.maxX	     = '';
	this.maxY	     = '';	
	this.intervaloX  = '';
	this.intervaloY  = '';
	this.idd         = aleatorio(1,100000);
	this.Nocache     = true;	
	this.valor       = '';
	this.HTTP_persist= 0; // variável para tentar várias vezes caso o retorne 404 AJAX
	this.Memo_link   = '';
	this.Memo_Func   = '';
	this.HTTP        = 'GET';
	this.JSs         =  new Array(); // arrau de javascript para carregar
	this.JSi         =  0; // indice dos JSs
	this.Jsloaded    =  0;
	

	
	// variáveis para o uploads  
	this.pasta      = $_CONFIG['Pasta']+'tmp/';
	this.upload     = 'upload.php';
	this.extencao   = new Array();
	
/// Função retorna objeto ///////////////////////////////////////////////////////////////////////////////////////////////////////////
function get($id){ return document.getElementById($id); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função css //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function css($estilo,$valor){
	if($estilo == 'bg_cor')       { $estilo    = 'backgroundColor';                              }
	if($estilo == 'cor')          { $estilo    = 'color';                                        }
	if($estilo == 'bg')           { $estilo    = 'background';                                   }
	if($estilo == 'bg_img')       { $estilo    = 'backgroundImage';  $valor = 'url('+$valor+')'; }
	if($estilo == 'bg_img_pos')   { $estilo    = 'backgroundPosition';                           } 
	if($estilo == 'bg_img_repet') { $estilo    = 'backgroundRepeat';  							 } 
	if($estilo == 'borda_cor')    { $estilo    = 'borderColor';                                  } 
	if($estilo == 'borda')        { $estilo    = 'border';                                       }
	if($estilo == 'w')            { $estilo    = 'width';   this.w = $valor;  $valor +='px';     }
	if($estilo == 'h')            { $estilo    = 'height';  this.h = $valor;  $valor +='px';     }
	if($estilo == 'mouse')        { $estilo    = 'cursor';   								     }

	 
	$txt = 'this.obj.style.'+$estilo+'="'+$valor+'"';
	eval($txt);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função value objeto txt /////////////////////////////////////////////////////////////////////////////////////////////////////////
function mask_value($ini_txt){
 var $obj = this.obj;
 $obj.onfocus = function(){ if(this.value == $ini_txt){ this.value = '';} } 
 $obj.onblur  = function(){ if(this.value == ''){ this.value = $ini_txt;} } 
 if($obj.value.length == 0){
 $obj.value   = $ini_txt;
 } 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função GotoX //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GotoX($div,$max,$delay,$ac){
	//	Uso GotoX(Objeto_clas,tamanhoMaximo_minimo,tempo,se deseja almetar use '+' se não use '-')
	if($ac == '+'){ var $operador = '>='; }
	if($ac == '-'){ var $operador = '<='; }
	this.maxX = $max;
	this.intervaloX = window.setInterval(function(){
						 if(eval($div.w + $operador + $div.maxX)  || $div.w < 1){
							 clearInterval($div.intervaloX); $div.css('w',$div.maxX); $div.w = $div.maxX;
							 }else{ 
							 $div.w = (eval($div.w+$ac+10));	 $div.css('w',($div.w)); 
							 }
							 },$delay);	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função GotoY //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GotoY($div,$max,$delay,$ac){
	//	Uso GotoY(Objeto_clas,tamanhoMaximo_minimo,tempo,se deseja almetar use '+' se não use '-')
	if($ac == '+'){ var $operador = '>='; }
	if($ac == '-'){ var $operador = '<='; }
	
	this.maxY = $max;
	
	this.intervaloY = window.setInterval(function(){ 
		if(eval($div.h + $operador + $div.maxY)){
			clearInterval($div.intervaloY); $div.css('h',$div.maxY); $div.h = $div.maxY;
			}else{ 
			$div.h = (eval($div.h+$ac+10));	 $div.css('h',$div.h); 
			}
			},$delay);	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função ShowHide //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function opacit(){
//	alert('s');
	this.obj.style.opacity         = '0.50';
	this.obj.filters.alpha.opacity = '50'; 
} 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função Verifica E-mail //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function v_email(){
	//var $valor = this.obj.value;
    var $obj = this.obj;
      $obj.onblur  = function(){ if(this.value == ''){ 
	  $obj.style.border = '1px solid #FF9595';
	 }else{
		  var $erro = false;
		  if($obj.value.indexOf('@') == -1){ $erro = true;}
		  if($obj.value.indexOf('.') == -1){ $erro = true;}
	
	if($erro == true){
		$obj.style.border = '1px solid #FF9595';
	}else{
		$obj.style.border = '1px solid #009700';
		
	}
 }}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Função criar get e enviar //////////////////////////////////////////////////////////////////////////////////////////////////////
function criar_get_enviar($quem) {
	  $url_GET_ENVIAR = '';
	  var $tabela          = document.getElementById($quem);
	  var $todos_elementos = $tabela.getElementsByTagName('input');
	  var $type;
	  for($i=0;$i<$todos_elementos.length;$i++){
	  $type = $todos_elementos[$i].getAttribute('type');
	 
	  $name    = '&'+$todos_elementos[$i].getAttribute('name');
	  $value   = $todos_elementos[$i].value;
	  if($type == 'checkbox'){ if($todos_elementos[$i].checked != true){ $value = '';  }}
	  if($type == 'image'){    $value = ''; }
	  
	  $url_GET_ENVIAR += $name+'='+$value;
	  }
	  $todos_elementos = $tabela.getElementsByTagName('textarea');
	  for($i=0;$i<$todos_elementos.length;$i++){
	  $url_GET_ENVIAR += '&'+$todos_elementos[$i].name+'='+$todos_elementos[$i].innerHTML;
	  }
	  
	  $todos_elementos = $tabela.getElementsByTagName('select');
	  for($i=0;$i<$todos_elementos.length;$i++){
		  $indice = $todos_elementos[$i].selectedIndex;
		  $valor  = $todos_elementos[$i].options[$indice].value.replace(/&/g, "#");;
	      $url_GET_ENVIAR += '&'+$todos_elementos[$i].name+'='+$valor;
	  }
	  $url_GET_ENVIAR = this.Replace('?','!',$url_GET_ENVIAR);

	  return $url_GET_ENVIAR;
	  
} 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função ler valores ///////////////////////////////////////////////////////////////////////////////////////////////////////////
function get_values($quem) {
	  $url_GET_ENVIAR = '';
	  var $tabela          = document.getElementById($quem);
	  var $todos_elementos = $tabela.getElementsByTagName('input');
	  // alert($todos_elementos.length);
	  for($i=0;$i<$todos_elementos.length;$i++){
	  if($url_GET_ENVIAR != ''){
	  $url_GET_ENVIAR += '&'+$todos_elementos[$i].value.replace(/&/g, "#");
	  }else{
		$url_GET_ENVIAR += $todos_elementos[$i].value.replace(/&/g, "#");    
	  }
	  }
	  $todos_elementos = $tabela.getElementsByTagName('textarea');
	  // alert($todos_elementos.length);
	  for($i=0;$i<$todos_elementos.length;$i++){
	  $url_GET_ENVIAR += '&'+$todos_elementos[$i].innerHTML.replace(/&/g, "#");
	  }
	  return $url_GET_ENVIAR;
} 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função setar atributos ao campo /////////////////////////////////////////////////////////////////////////////////////////////////
function atributo($atr, $valor, $obj) {
    var newAttr = document.createAttribute($atr);
    newAttr.nodeValue = $valor;
	if($obj == undefined || $obj == ''){
    this.obj.setAttributeNode(newAttr);
	}else{
	$obj.setAttributeNode(newAttr);
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função remover atributos ao campo /////////////////////////////////////////////////////////////////////////////////////////////////
function RemoveAtributo($atr) {
    var m = this.obj.removeAttribute($atr);
        if (m != true) {
           // alert("Erro na remoção do atributo no objeto"+$obj+' atributo '+$atr);
        }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função gera numero aleatorio /////////////////////////////////////////////////////////////////////////////////////////////////
function aleatorio(i, f){
	if(arguments[0] == null){
			return Math.random();
	}else{
		if (i > f) {numInicial = f;numFinal = i+1;}else{numInicial = i;numFinal = f+1;}
		numRandom = Math.floor((Math.random()*(numFinal-numInicial))+numInicial);
		return numRandom;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função remover atributos ao campo /////////////////////////////////////////////////////////////////////////////////////////////////
function hide(){
this.obj.style.display = 'none';	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função remover atributos ao campo /////////////////////////////////////////////////////////////////////////////////////////////////
function show(){
this.obj.style.display = 'inline';	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Mostra o fundo LIGHT BOX /////////////////////////////////////////////////////////////////////////////////////////////////
function ShowFND(){
	this.get('Style_FND').style.display = 'inline';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Esconde o fundo LIGHT BOX /////////////////////////////////////////////////////////////////////////////////////////////////
function HideFND(){
	this.get('Style_FND').style.display = 'none';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Carrega a imagem quando quiser  /////////////////////////////////////////////////////////////////////////////////////////////////
function Preload() { 
	// uso $opcoes.Preload('img/aqui a 01','img/aqui a 02');
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Perminte apenas Números  /////////////////////////////////////////////////////////////////////////////////////////////////
function Numerico($txt){
	$aceitos  = '1234567890';
	$ok = true;
	$txt = $txt+'';
	$nums = $txt.split('');
	
	for($i = 0; $i<$nums.length;$i++){
		if($aceitos.indexOf($nums[$i]) == -1){ $nums[$i] = ''; }
	}
    $nums = $nums.join('');
	 return $nums;	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função verifica se o objeto ou variável existe  /////////////////////////////////////////////////////////////////////////////////
function isset(o) {   if (o != undefined && o != null){  return true; }else{  return false; }}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função Mascara o valor Monetário  ///////////////////////////////////////////////////////////////////////////////////////////////
this.mask_data = function ($obj){
	$obj.onkeyup = function (){   $B.Mk_data (this);}
	$obj.onblur = function (){    $B.Mk_data (this);}
	$obj.onmouseup = function (){ $B.Mk_data (this);}
	$obj.onkeypress= function (){ $B.Mk_data (this);}
	$obj.setAttribute('maxlength', '10');
}

function mask_money(){}

this.Mk_data = function ($obj){

	var $num       = $obj.value + '';
		var $numeros   = Numerico($num);
		$numeros       = $numeros.split('');
		var $total     = $numeros.length;
		var $resultado = '';
		
		for ($i = 0; $i<$total; $i ++){
				
			$resultado += $numeros[$i];
			
			if ($i == 1){
				$resultado += '/';
				}
			if ($i == 3){
				$resultado += '/';
				}
			
		}
		
		$obj.value = $resultado;

	
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função Mascara o valor Numérico  ///////////////////////////////////////////////////////////////////////////////////////////////
function MaskNum(){

this.obj.onkeyup = function (){  	
	$aceitos  = '1234567890';
	$ok = true;
	$txt = this.value+'';
	$nums = $txt.split('');
	
	for($i = 0; $i<$nums.length;$i++){
		if($aceitos.indexOf($nums[$i]) == -1){ $nums[$i] = ''; }
	}
    $nums = $nums.join('');
	this.value = $nums; 
	}
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função Mascara de cep ///////////////////////////////////////////////////////////////////////////////////////////////////////////

function mask_cep(){
	this.obj.onblur     = function(){ Cep_(this); if(this.value.length < 9){ this.value = '';}}
	this.obj.onmouseup  = function(){ Cep_(this);}
	this.obj.onkeyup    = function(){ Cep_(this);}
	this.atributo('maxlength', '9');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// função ajax para a classe  =D ///////////////////////////////////////////////////////////////////////////////////////////////////
function openajax(){
var ajax; /* Defini a Variável */
try{ ajax = new XMLHttpRequest(); /* Tenta Instanciar o Objeto */}
catch(ee){ try {
ajax = new ActiveXObject("Msxm12.XMLHTTP"); /* Se Nao Conseguiu o Anterior Tenta esse*/
}catch(e){
try{
ajax = new ActiveXObject("Microsoft.XMLHTTP"); /* E o mesmo se repete aqui*/
}catch(E){
ajax = false; /* Se nao conseguiu em Nenhum retorna False pois o Navegador Usado nao Suporta Ajax*/
}
}
}
return ajax; /* Retorna um Boleano*/
}
// segunda parte 
function Ajax($link,$func){ /*Recebe parâmetro o Link a Pagina Solicitada */

    this.Memo_link    = $link;
	this.$Memo_Func    = $func;
	var $Memo_link    = $link;
	var $Memo_Func    = $func;
	var $HTTP_persist = this.HTTP_persist;
	$blk = this;

var ajax = this.openajax(); /* Chama a Função que Instancia o AJAX */
// retito o cache ^^ 
if(this.Nocache == true){ $verif = $link.indexOf('?'); if($verif == -1){ $link+= '?NO_CACHE_sess='+Math.random();}else{ $link+= '&NO_CACHE_sess='+Math.random(); } } 
$link = this.codUrl($link);

ajax.open("GET",$link,true);
/* ajax.open = Abri uma Solicitação ao Navegador */
/* GET = Método Usado */
/* plink = pagina que tratara o solicitado */
/* true = Assicrono ou não = Dando o Refresh no Browser ou Nao*/
ajax.onreadystatechange = function(){/* ajax.onreadystatechange = O que ele fara de acordo com o tempo de execuação*/

if (ajax.readyState < 4){}/* ajax.readystate = Estado que se encontra a Requisição*/
if (ajax.readyState == 4){
if (ajax.status == 200){
/* Estado de Carregamento*/
var $resp = ajax.responseText;
$blk.ExtraiScript($resp); // executo os codigos javascript se ouver 
$func($resp);
}else{
	//alert($HTTP_persist);
if($HTTP_persist > 0){  // aqui se a variável está ativa se estiver executa novamente o pedido
    $HTTP_persist--;
    var tmp = new Objeto();
	tmp.HTTP_persist = $HTTP_persist;
	tmp.Ajax($Memo_link,$Memo_Func);
	
	//alert($Memo_Func);
	//alert($HTTP_persist);
}else{ $func('404'); } }

}
}
ajax.send(null);
/* Muito Importante Envia o Resultado para o Navegador */
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// função acentos no FF //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function codUrl($texto) {


$texto  = this.Replace('á', "%E1", $texto);
$texto  = this.Replace('â', "%E2", $texto); 
$texto  = this.Replace('ã', "%E3", $texto); 
$texto  = this.Replace('Á', "%C1", $texto); 
$texto  = this.Replace('Â', "%C2", $texto); 
$texto  = this.Replace('Ã', "%C3", $texto); 
$texto  = this.Replace('É', "%C9", $texto);
$texto  = this.Replace('é', "%E9", $texto);
$texto  = this.Replace('ê', "%EA", $texto);
$texto  = this.Replace('Í', "%CD", $texto);
$texto  = this.Replace('í', "%ED", $texto); 
$texto  = this.Replace('Ó', "%D3", $texto); 
$texto  = this.Replace('Ô', "%D4", $texto); 
$texto  = this.Replace('Õ', "%D5", $texto);
$texto  = this.Replace('ó', "%F3", $texto); 
$texto  = this.Replace('õ', "%F5", $texto); 
$texto  = this.Replace('ô', "%F4", $texto); 
$texto  = this.Replace('Ú', "%DA", $texto);
$texto  = this.Replace('Ü', "%DC", $texto);
$texto  = this.Replace('ú', "%FA", $texto); 
$texto  = this.Replace('ü', "%FC", $texto); 
$texto  = this.Replace('ç', "%E7", $texto);
$texto  = this.Replace('Ç', "%C7", $texto);

$texto  = this.Replace("\n", "", $texto);
$texto  = this.Replace("\r", "", $texto);

return $texto;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// função carrega js  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function novoJS($js,$cache){
	
this.JSs[this.JSi] = $js;
this.JSi++;
}
function CarregaJS($cache){
	$js = this.JSs[this.Jsloaded];
	if($cache == true){
		this.Nocache = false;
	}
	var $BL = this;	 // 0 
	console('Aguarde carregando <br>'+$js); ShowFND(); 
	this.Ajax($js,function($codigo){
	novo = document.createElement("script");
	novo.type         = 'text/javascript';
	novo.language     = 'javascript';
	novo.text = $codigo;
	document.body.appendChild(novo);
    $BL.Jsloaded++;
	if($BL.Jsloaded < $BL.JSi){ $BL.CarregaJS(); }else{  close_alert(); HideFND(); $BL.Nocache = true; }

	
	});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// função carrega css //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function novoCSS($css,$cache){
	
var novo = document.createElement("link");
novo.rel         = 'stylesheet';
novo.type        = 'text/css';
novo.href        = $css+'?sess='+Math.random();	

document.body.appendChild(novo);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// função carrega js  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ExtraiScript(texto){

    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            novo = document.createElement("script")
			novo.type         = 'text/javascript';
			novo.language     = 'javascript';
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// função novo flash  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function addFlash($swf,$div,$tamanhoX,$tamanhoY,$fundo){
	$idd  = 10;
	$swff = $swf;
	$divv = $div;
	$X    = $tamanhoX;
	$Y    = $tamanhoY;
	$BG   = $fundo;
	if($X == undefined){ $X = 200; } if($Y == undefined){ $Y = 100; } if($BG == undefined){ $BG = "#336699"; }
    this.novoJS($_CONFIG['Pasta']+'swfs/swfobject.js');
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// add Upload 1.0  //////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FLUpload($type,$div){
    var $extension   = '';
	var $description = '';
	var url = $_CONFIG['Pasta']+'swfs/upload.swf?$pasta='+this.pasta+'&$upload='+this.upload+'&$div='+$div+'&sess='+Math.random();
	this.addFlash(url,$div,450,110,'#fff');
	 // alert(url);

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função limpar as vigulas e pontos do número ///////////////////////////////////////////////////////////////////////////////////
function LimpaNumero($NUM){
// exemplo limpanumero('1.200,00');
// Retiro o ponto 
$NUM = $NUM+'';
var $LIMP  =  $NUM.split(".");
$count = $LIMP.length;
$TEXT  = '';
for($i = 0; $i < $count; $i++){
  if($TEXT == ""){
  $TEXT = $LIMP[$i];
  }else{
   $TEXT = $TEXT+$LIMP[$i];
  }
}
//  Retiro a virgula e substituo as variáveis 
$NUM   = $TEXT;
$LIMP  = $NUM.split(",");
$count = $LIMP.length;
$TEXT  = '';
for($i = 0; $i < $count; $i++){ // faço o for para juntar a array 
  if($TEXT == ""){
  $TEXT    = $LIMP[$i];
  }else{
   $TEXT   = $TEXT+=$LIMP[$i];
  }
}

return eval($TEXT);
}// fim da função de limpar números 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função Formatar numero p/ Moeda /////////////////////////////////////////////////////////////////////////////////////////////////
function Formata_moeda($NUM){


if($NUM == 0 || $NUM == '0'){ return '0,00';}

$NUM = $NUM.toString();
var $LIMP  =  $NUM.split('');
$count = $LIMP.length;
$count -= 2;
$TEXT  = '';
for($i=0;$i<$count;$i++){
//AQUI ELE ME DEVOLVE O NUMERO SEM A VIRGULA 
  if($TEXT == ""){
  $TEXT    = $LIMP[$i];
  }else{
   $TEXT   = $TEXT+=$LIMP[$i];
  }	
}
//AQUI ELE SOMA OS VALORES COM A VIRGULA
//$count += 2;
$TEXT += ',';
for($i=$count;$i<$LIMP.length;$i++){

		$TEXT   = $TEXT+=$LIMP[$i];
}

$NUM   = $TEXT.split('');
$count = $NUM.length;



if($count >= 7){
	
$count = ($count - 7); 
$NUM[$count]  = $NUM[$count]+'.';
$count = $NUM.length;

$TEXT = $NUM.join('');
}

return $TEXT;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função trocar \n por <br> /////////////////////////////////////////////////////////////////////////////////////////////////
function txtPARAhmtl($obj){
	if($obj == undefined || $obj == ''){ var $nome = this.obj.value; }else{
	var $nome = $obj.value;
	}
	$total = $nome.split("\n");
	
	for(var $i=0;$i<$total.length;$i++){
	try{$nome = $nome.replace("\n",'<br>') }catch(e){ $nome = $nome; };	
	}
	return $nome;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função trocar  <br> por '' /////////////////////////////////////////////////////////////////////////////////////////////////
function nPARAtxt($obj){
	
	if($obj == undefined || $obj == ''){ var $nome = this.obj.value; }else{
	var $nome = $obj.value;
	}
	$total = $nome.split("<br>");
	
	for(var $i=0;$i<$total.length;$i++){
	$nome = $nome.replace("<br>",'');	
	}
	return $nome;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função Buscar cep /////////////////////////////////////////////////////////////////////////////////////////////////
function BuscaCep($cep,$func){
//this.Nocache = false;	
if($cep != '' || $cep != undefined){
var $link = $_CONFIG[  'Pasta'  ]+'/php/Cep.php?cep='+$cep;	
$cep = $cep.replace(/-/g,'');
$cep = $cep.replace(/,/g,'');
$cep = $cep.replace(/ /g,'');
$cep = $cep.replace(/_/g,'');
//this.Ajax($url,function($rsp){ alert($rsp); });	

var ajax = this.openajax(); 
if(this.Nocache == true){ $verif = $link.indexOf('?'); if($verif == -1){ $link+= '?NO_CACHE_sess='+Math.random();}else{ $link+= '&NO_CACHE_sess='+Math.random(); } } 
ajax.open("GET",$link,true);
ajax.onreadystatechange = function(){
if (ajax.readyState == 4){
if (ajax.status == 200){
var $respo 	= ajax.responseText.split('&');
for(var $i=0;$i<$respo.length;$i++){
 $respo[$i] =  $respo[$i].split('=')[1];
 if($respo[$i] == undefined){ $respo[$i] = ''; } 
}
$func($respo);
}else{ $func('404'); }
}}
ajax.send(null);
}else{
	alerta('Defina um cep');
}

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Cria a tag para js /////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Extend($JS){
 document.writeln('<script type="text/javascript" src="'+$JS+'"></script>');
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função semelhante a do php str_replace///////////////////////////////////////////////////////////////////////////////////////////
function Replace($search,$replace,$txt){
					  $txt = $txt.split($search);
					  $txt = $txt.join($replace);
					  return  $txt;	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função mostra o frame para POST ////////////////////////////////////////////////////////////////////////////////////////////////
function Show_GATEWAY(){
get('GATEWAY').style.display = 'inline';
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}// fim da classe 

/// -----------------------------------------------------------------------------------------------------------------------------
function onload(func){

//by Micox - based in jquery bindReady and Diego Perini IEContentLoaded
    //flag global para indicar que já rodou e function que roda realmente
    done = false
    init = function(){ if(!done) { done=true; func() } }
    var d=document; //apelido para o document
    //pra quem tem o DOMContent (FF)
    if(document.addEventListener){ d.addEventListener("DOMContentLoaded", init, false );}
    
    if( /msie/i.test( navigator.userAgent ) ){ //IE
        (function () {
            try { // throws errors until after ondocumentready                
                d.documentElement.doScroll("left");
            } catch (e) {
                setTimeout(arguments.callee, 10); return;
            }
            // no errors, fire
            init();
        })();
    }
    if ( window.opera ){
        d.addEventListener( "DOMContentLoaded", function () {
            if (done) return;
            //no opera, os estilos só são habilitados no fim do DOMready
            for (var i = 0; i < d.styleSheets.length; i++){
                if (d.styleSheets[i].disabled)
                    setTimeout( arguments.callee, 10 ); return;
            }
            // fire
            init();
        }, false);
    }
    if (/webkit/i.test( navigator.userAgent )){ //safari's
        if(done) return;
        //testando o readyState igual a loaded ou complete
        if ( /loaded|complete/i.test(d.readyState)===false ) {
            setTimeout( arguments.callee, 10 );    return;
        }
        init();
    }
    //se nada funfou eu mando a velha window.onload lenta mesmo
    if(!done) window.onload = init
}
/// -----------------------------------------------------------------------------------------------------------------------------

/// aqui o fundo ligth 
FND_STYLE = new Array();
FND_STYLE['z-index'] = 999;
FND_STYLE['color']   = '#000';
FND_STYLE['opacity'] = 80;
function FND_LIGTH(){
	
document.writeln('<style>'
				+'#Style_FND {'
				+'	position:fixed;'
				+'	left:0;'
				+'	top:0;'
				+'	width:100%;'
				+'	height:100%;'
				+'	z-index:'+FND_STYLE['z-index']+';'
				+'	background-color: '+FND_STYLE['color']+';'
				+'	filter:alpha(opacity='+FND_STYLE['opacity']+');'
				+'  opacity:0.'+FND_STYLE['opacity']+';'
				+'  -moz-opacity: 0.'+FND_STYLE['opacity']+';'
				+'	display:none;'
				+'}'
				+'</style> '
				+'<div id="Style_FND"></div>');
}


// aqui conteudo do alert
function MAKE_ALERTA(){ 
	document.writeln('<div id="dialog_alerta" style="position:fixed; left: 50%; top: 50%; width: 370px; height: 140px;layer-background-color: #FF0000; border: 1px none #000000; display:none; z-index:1000; background:url('+$_CONFIG['Pasta']+'/img/alerta.png) left no-repeat;" > <table width="100%" height="135" border="0" cellpadding="0" cellspacing="0"><tr><td height="19" colspan="2" id="titulo_alerta">Console do sistema</td></tr><tr><td width="19%" height="76" align="center"><img id="IMG_display" src="'+$_CONFIG['Pasta']+'/img/38.gif" style="margin-left:20px;" /></td><td width="81%" align="left" valign="middle"><div id="txt_alerta"></div></td></tr><tr><td height="40" colspan="2" align="center" valign="top"><input type="submit" id="dialog_bot_ok" value="    Ok    " style="display:none;"/></td></tr></table></div>'+
		
		'<style type="text/css"><!-- #dalog_informativo{ font-family:Verdana, Geneva, sans-serif;font-size:12px;	color:#333;	font-weight:bold;	cursor:default; } #titulo_alerta{	font-family:Verdana, Geneva, sans-serif;	font-size:12px;	color:#333;	padding-left:30px; padding-top:3px;	cursor:default;}#txt_alerta{ max-height:100px; width:260px; overflow:hidden; margin-left:8px; font-family:Verdana, Geneva, sans-serif;	font-size:12px;color:#000;	padding-left:30px; padding-top:3px;	cursor:default; } --></style>');	
}
document.writeln('<div id="Janela_Vazia" style="display:none; z-index:1000">Aguarde...</div>');
document.writeln('<div id="HIDE_CONTENTS_CONFIG" style="display:none;"></div>');
document.writeln('<iframe style="display:none; position:fixed; z-index:10000" id="GATEWAY" name="GATEWAY"></iframe>');

document.writeln('<style>'
				+'#Janela_Vazia {'
				+'	position:fixed;'
				+'	left:0;'
				+'	top:0;'
				+'	width:100%;'
				+'	height:100%;'
				+'	display:none;left:50%; top:50%; z-index:30;'
				+'}'
				+'</style>');
function div_centro(){ }

// AQUI O SCONTROLE DO SOM APENAS PARA IE 
if(navigator.userAgent.indexOf("MSIE") != -1){
document.writeln ('<bgsound src="" id="PG_SOUND" loop="0" hidden="true" volume="100">');
}else{
//document.writeln ('<embed src="" id="PG_SOUND" loop=true autostart=true volume=100 hidden=true>');
}

FND_LIGTH();
MAKE_ALERTA();
//aqui o código para deichar o html 100% no browser 
document.writeln('<style>'
+' html, body {'
+'	height: 99%; '
+'  }'
+'</style>');

// função para carregar o objeto
function get($id){ return document.getElementById($id); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ShowFND(){
	get('Style_FND').style.display = 'inline';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Esconde o fundo LIGHT BOX /////////////////////////////////////////////////////////////////////////////////////////////////
function HideFND(){
	get('Style_FND').style.display = 'none';
}
// função para substituir o alert do javascript 
function alerta($txt){
	if(!$txt){ $txt = '';}
	var $obj = get('dialog_alerta');
	get('txt_alerta').innerHTML = $txt;
	var $x = $obj.style.width.replace('px','');
	var $y = $obj.style.height.replace('px','');
	$obj.style.marginLeft   = '-'+($x / 2)+'px';
	$obj.style.marginTop    = '-'+($y / 2)+'px';
	$obj.style.display = 'inline';
    ShowFND();
	
	
	//get('dialog_bot_ok').focus();
	get('dialog_bot_ok').onclick = function(){ 
    close_alert(); 
	}
	if($_CONFIG['soms']){	
	get('PG_SOUND').src = $_CONFIG['Pasta']+'/media/alerta.wav';
	}
}

function console($txt){
	if(!$txt){ $txt = '';}
	var $obj = get('dialog_alerta');
	try{ get('IMG_display').src= $_CONFIG['Pasta']+'/img/38.gif'; }catch(e){ }
	get('txt_alerta').innerHTML = $txt;
	var $x = $obj.style.width.replace('px','');
	var $y = $obj.style.height.replace('px','');
	$obj.style.marginLeft   = '-'+($x / 2)+'px';
	$obj.style.marginTop    = '-'+($y / 2)+'px';
	$obj.style.display = 'inline';
    ShowFND();
	
	
	//get('dialog_bot_ok').focus();
	//get('dialog_bot_ok').disabled = true;
}

// função para fechar o dialog de alerta 
function close_alert(){
	var $obj = get('dialog_alerta');
	$obj.style.display = 'none';
	
	HideFND();
	if($_CONFIG['soms']){	
	get('PG_SOUND').src = '';
}}


//// função validar numero /////
function monetario($obj){
$numeros = Numerico($obj.value);
$numeros = sem_zeros($numeros);


$txt2 = $numeros+'';
$txt2 = $txt2.split('');
var $final = $numeros;
var $total =  $txt2.length;

if($total == 1){
$final = '0,0'+$numeros;
}

if($total == 2){
$final = '0,'+$numeros;
}

if($total == 3){
 $final = '';
 for($i=0;$i < $total; $i++ ) {
 
 if($i == 0){
 $final += $txt2[$i]+',';
 }else{
 $final += $txt2[$i];
 }
 }

}
if($total == 4){
 $final = '';
 for($i=0;$i < $total; $i++ ) {
 
 if($i == 1){
 $final += $txt2[$i]+',';
 }else{
 $final += $txt2[$i];
 }
 }

}

if($total == 5){
$final = '';
 for($i=0;$i < $total; $i++ ) {
 
 if($i == 2){
 $final += $txt2[$i]+',';
 }else{
 $final += $txt2[$i];
 }
 }
}

if($total == 6){
$final = '';
var $conf  = ($total-2);
 for($i=0;$i < $total; $i++ ) {
 
 if($i == $conf){
 $final += ',';
 }
 if($i == 0){
 $final += $txt2[$i]+'.';
 }else{
 $final += $txt2[$i];
 }
 }
}

if($total == 7){
$final = '';
var $conf  = ($total-2);
 for($i=0;$i < $total; $i++ ) {
 
 if($i == $conf){
 $final += ',';
 }
 if($i == 1){
 $final += $txt2[$i]+'.';
 }else{
 $final += $txt2[$i];
 }
 }
}

if($total == 8){
$final = '';
var $conf  = ($total-2);
 for($i=0;$i < $total; $i++ ) {
 
 if($i == $conf){
 $final += ',';
 }
 if($i == 2){
 $final += $txt2[$i]+'.';
 }else{
 $final += $txt2[$i];
 }
 }
}

if($total == 9){
$final = '';
var $conf  = ($total-2);
 for($i=0;$i < $total; $i++ ) {
 
 if($i == $conf){
 $final += ',';
 }
 if($i == 3){
 $final += $txt2[$i]+'.';
 }else{
 $final += $txt2[$i];
 }
 }
}

if($total == 9){
$final = '';
var $conf  = ($total-2);
 for($i=0;$i < $total; $i++ ) {
 
 if($i == $conf){
 $final += ',';
 }
 if($i == 1){
 $final += '.';
 }
 if($i == 3){
 $final += $txt2[$i]+'.';
 }else{
 $final += $txt2[$i];
 }
 }
}

if($total > 9){
$final = '';
var $conf  = ($total-2);
 for($i=0;$i < $total; $i++ ) {
 
 if($i == $conf){
 $final += ',';
 }
  $final += $txt2[$i];
 }
}

$obj.value = 'R$ '+$final;
}
//////////////////////////////////////////////////////////////////////////////////////////

//função make cep
function Cep_($obj){
		var $num       = $obj.value + '';
		var $numeros   = Numerico($num);
		$numeros       = $numeros.split('');
		var $total     = $numeros.length;
		var $resultado = '';
		for ($i = 0; $i<$total; $i ++){
			
			$resultado += $numeros[$i];
			if ($i == 4){
				$resultado += '-';
				}	
		}
		
		$obj.value = $resultado;
}
//

///////////////////////////////////////////////////////////////////////////////////////////
function Numerico($txt){
	$aceitos  = '1234567890';
	$ok = true;
	$txt = $txt+'';
	$nums = $txt.split('');
	
	for($i = 0; $i<$nums.length;$i++){
		
		if($aceitos.indexOf($nums[$i]) == -1){ $nums[$i] = ''; }
		
		
	}
    $nums = $nums.join('');
	 return $nums;
	
}

///////////////////////////////////////////////////////////////////////////////////////////
function sem_zeros($caracteres){
var $found    = false;
var $caracter = $caracteres.split('');
//alert('Total = '+$caracter.length);
 for($i=0;$i < $caracter.length; $i++ ) {
	
	$caracter[$i] = eval($caracter[$i]);
	if($caracter[$i] != 0){
	  $found = true;	
	  
	}
	
	 //aqui se for zero antes do primeiro numero
	  if($found != true){
	  if($caracter[$i] == 0){
	    $caracter[$i] = '';
	  }
	}
	
}
$caracter = $caracter.join("");
return $caracter ;
}
/// 
function uploadOK($div,$nome){
	
	get($div).value = $nome;
	confere_arquivo($div);
	
	
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Função Mascara data  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Data_Masc($obj){
		
		var $num       = $obj.value + '';
		var $numeros   = this.limpar($num);
		$numeros       = $numeros.split('');
		var $total     = $numeros.length;
		var $resultado = '';
		
		for ($i = 0; $i<$total; $i ++){
				
			$resultado += $numeros[$i];
			
			if ($i == 1){
				$resultado += '/';
				}
			if ($i == 3){
				$resultado += '/';
				}
		}
		$obj.value = $resultado;
}
// captura os erros da página
//onerror=handleErr
function handleErr(msg,url,l){
	var txt="Um erro encontrado nesta página.\n\n";
	txt+="Erro: " + msg + "\n";
	txt+="Pagina: " + url + "\n";
	txt+="Linha: " + l + "\n\n";
	txt+="Click OK para continuar.\n\n";
	alert(txt);
	return true;
}

// captura os erros da página
function Barra1($local,$total1,$uso1){

	var $menoUSO = $uso1;
	var $menoTOTAL = $total1;
 	var $variavel = $uso1;	
    var $total = $total1;	

    $tenho = $variavel * 100 / $total;
    $uso1 = parseInt($tenho);
	
	var $ok = false;
	var $total = $total1;
	var $tmpid = Math.random()+''; $tmpid = $tmpid.replace('.','');
	var $div = 'b_'+$tmpid;
	var $HTML = '<div style="background: url(img/ecommerce/icones/barra_progresso1.png) no-repeat left; height:15px; width:173px; "><img id="'+$div+'" src="img/ecommerce/icones/barra_verde.png" width="1" height="12" style="margin-top:2px; margin-left:1px;" /></div>';
	var $total = $total1 / 100 * $uso1;
	var $uso = $uso1;
	
	try{ get($local).innerHTML = $HTML; $ok = true; }catch(e){ window.setTimeout(function(){ Barra1($local,$menoTOTAL,$menoUSO)},1000); }

	if($ok == true){
	get($local).innerHTML = $HTML;
	get($div).style.width = '1px';
	
    var $go = window.setInterval(function(){
	var $total = 173 / 100 * $uso;
	try{ var $barra  = get($div).style.width.replace('px',''); 
	if($barra < $total && $barra < 173){
		$barra++; $barra++; $barra++; $barra++;
	get($div).style.width = $barra+'px';	
	}else{
		window.clearInterval($go);
	}	
	}catch(e){ window.clearInterval($go); }
	
	},50);
}}

$B = new Objeto();
