/*  
ABRIR NOVA JANELA (POP UP)
*/
function novajanela(endereco,w,h) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += 'toolbar=no,location=no,status=no,scrollbars=no,resizable=no';
  win = window.open(endereco,'sub100',settings);
}

/*  
ABRIR NOVA JANELA (POP UP) COM BARRA DE ROLAGEM
*/
function novajanelarolagem(endereco,w,h) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=no';
  win = window.open(endereco,'sub100',settings);
}

/*  
ABRIR NOVA JANELA EM TELA CHEIA
*/
function telacheia(endereco){
  var w = screen.width;
  var h = screen.height;  
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=0,';
  settings += 'left=0,';
  settings += 'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes';
  win = window.open(endereco, 'sub100', settings);
}

/*  
FUNCAO PARA INSERCAO DE FLASH
*/
function mostraflash(nome,largura,altura){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'+ 
	' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'+
	' width="'+largura+'" height="'+altura+'" id="'+nome+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+nome+'.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+nome+'.swf" quality="high"'+
	' width="'+largura+'" height="'+altura+'" name="'+nome+'" align="middle"'+
	' allowScriptAccess="sameDomain" type="application/x-shockwave-flash" wmode="transparent"'+
	' pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

/*
FUNÇAO QUE VALIDA ACEITA APENAS NUMEROS NOS FORMULÁRIOS
Como usar: onKeyPress="return soNumero(this, event)"
*/
function isNum( caractere ){
	var strValidos = "0123456789"
	
	if ( strValidos.indexOf( caractere ) == -1 ){
		return false;
	}	
	return true;
}

function soNumero(campo, event){
	var key;
	var tecla;
	
	var teclasPermitidas = new Array(8,9,0);
	
	CheckTAB=true;
	
	if(navigator.appName.indexOf("Netscape")!= -1)
		tecla= event.which;
	else
		tecla= event.keyCode;
	
	key = String.fromCharCode( tecla);
	
	if ( tecla == 13 )
		return false;
	
	var i;
	
	for(i=0;i<teclasPermitidas.length;i++)
		if (tecla == teclasPermitidas[i])
			return true;
	
	return (isNum(key));
}


/*
FUNÇAO QUE HABILITA A NAVEGACAO DE LIGHTBOX QUANDO CARREGADA POR XAJAX
*/
function GroupDelegate(id) {
	var objLink = document.getElementById(id);
	Lightbox.prototype.start(objLink);
}


/*
FUNÇÃO PARA REDIRECIONAR LINKS DE ANÚNCIOS
*/
function PublicidadeClique(url,anuncio, canal, origem){
		window.open(url+'publicidade.php?id='+anuncio+'&idcanal='+canal+'&origem='+origem, "_blank");
}


/* 
FUNÇÃO QUE FORMATA VALOR EM REAIS 
*/
function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}



function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
} 

}
