function jumptolink(what)
{
	var selectedopt=what.options[what.selectedIndex]
	if ( selectedopt.value != '' )
	{
		window.open(selectedopt.value);
		what.selectedIndex = 0;  
	}    
}

function formata_hora( tempo )
{
	if (event.keyCode<48 || event.keyCode>57 )
	{ event.returnValue=false; }
	if (tempo.value.length==2)
	{ tempo.value+=":"; }
}

function Verifica_CPF( CPF )
{
	// Verifica se o campo é nulo
	if (CPF == '')
	{ return true; }

// Aqui começa a checagem do CPF
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
	
	// Desemembra o número do CPF na array DIGITO
	for (I=0; I<=8; I++)
	{ DIGITO[I] = CPF.substr( I, 1); }
	
	// Calcula o valor do 10º dígito da verificação
	POSICAO = 10;
	SOMA = 0;
	for (I=0; I<=8; I++)
	{ 
		SOMA = SOMA + DIGITO[I] * POSICAO;
		POSICAO = POSICAO - 1;
	}
	DIGITO[9] = SOMA % 11;
	if (DIGITO[9] < 2)
	{ DIGITO[9] = 0; }
	else
	{ DIGITO[9] = 11 - DIGITO[9]; }
	
	// Calcula o valor do 11º dígito da verificação
	POSICAO = 11;
	SOMA = 0;
	for (I=0; I<=9; I++)
	{
		SOMA = SOMA + DIGITO[I] * POSICAO;
		POSICAO = POSICAO - 1;
	}
	DIGITO[10] = SOMA % 11;
	if (DIGITO[10] < 2 )
	{ DIGITO[10] = 0; }
	else
	{ DIGITO[10] = 11 - DIGITO[10]; }
	
	// Verifica se os valores dos dígitos verificadores conferem
	DV = DIGITO[9] * 10 + DIGITO[10];
	if (DV != DV_INFORMADO)
	{ 
		alert( 'CPF inválido.' );
		formulario.CPF.value = '';
		formulario.CPF.focus();
		return false;
	} 
}

function validaCNPJ( CNPJ )
{
  if ( CNPJ != '' )
	{ 
		if ( CNPJ.length < 18 )
		{
			return false;
		}
			
		if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
		{
			return false;
		}

    //substituir os caracteres que não são números
		if(document.layers && parseInt(navigator.appVersion) == 4)
		{
			x = CNPJ.substring(0,2);
			x += CNPJ. substring (3,6);
			x += CNPJ. substring (7,10);
			x += CNPJ. substring (11,15);
			x += CNPJ. substring (16,18);
			CNPJ = x; 
		}
		else
		{
			CNPJ = CNPJ. replace (".","");
			CNPJ = CNPJ. replace (".","");
			CNPJ = CNPJ. replace ("-","");
			CNPJ = CNPJ. replace ("/","");
		}
		var nonNumbers = /\D/;
		if (nonNumbers.test(CNPJ))
		{
			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]))
		{
			return false;
		}
	}
	return true;
}

function mascara(o,f)
{
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara()
{
  v_obj.value=v_fun(v_obj.value)
}

function leech(v)
{
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v)
{
  return v.replace(/\D/g,"")
}

function telefone(v)
{
    v=v.replace(/\D/g,"")                 //Remove tudo o que nÃ£o Ã© dÃ­gito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parÃªnteses em volta dos dois primeiros dÃ­gitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hÃ­fen entre o quarto e o quinto dÃ­gitos
    return v
}

function cpf(v)
{
    v=v.replace(/\D/g,"")                    //Remove tudo o que nÃ£o Ã© dÃ­gito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dÃ­gitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dÃ­gitos
                                             //de novo (para o segundo bloco de nÃºmeros)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hÃ­fen entre o terceiro e o quarto dÃ­gitos
    return v
}

function cep(v)
{
    v=v.replace(/D/g,"")                //Remove tudo o que nÃ£o Ã© dÃ­gito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse Ã© tÃ£o fÃ¡cil que nÃ£o merece explicaÃ§Ãµes
    return v
}

function cnpj(v)
{
    v=v.replace(/\D/g,"")                           //Remove tudo o que nÃ£o Ã© dÃ­gito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dÃ­gitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dÃ­gitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dÃ­gitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hÃ­fen depois do bloco de quatro dÃ­gitos
    return v
}

function site(v)
{
    //Esse sem comentarios para que vocÃª entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}


function formatar( src, mask )
{
  var i = src.value.length;
  var saida = mask.substring( 0, 1 );
  var texto = mask.substring( i )
  if ( texto.substring( 0, 1 ) != saida )
  {
    src.value += texto.substring(0,1);
  }
}

function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim)
{
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim)
{
	return stringToTrim.replace(/\s+$/,"");
}

function over(src)
{
  if (!src.contains(event.fromElement))
	{
		src.style.cursor = 'hand';
		corfundo( "#EEEEEE" );
	}
}

function out(src)
{
	if (!src.contains(event.toElement))
	{
		src.style.cursor = 'default';
		corfundo( "#FFFFFF" );
	}
}        

function corfundo(cor)
	{
	source=event.srcElement
	while(source.tagName!="TR")
		source=source.parentElement
	if (source.style.backgroundColor!=cor&&source.id!="ignore")
		{
		source.style.backgroundColor=cor;
		source.style.cursor="hand";
		}
	}   


function mouseXY()
{
  if (document.layers)
	  getMouseLoc;     //NS
  else if (document.all)
	  getMouseLoc(); //IE
}


function montaFlash(swf, width, height, wmode, cache)
{
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	monta_swf = "";
	monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
	monta_swf += "<param name=\"quality\" value=\"high\" />";
    monta_swf += "<param name=\"wmode\" value=\"transparent\" />";
	monta_swf += '<embed src="' + swf + noCache + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
	monta_swf += "</object>";
	document.write(monta_swf);
}

function jumptolink(what)
{
	var selectedopt=what.options[what.selectedIndex]
	if ( selectedopt.value != '' )
	{
		window.open(selectedopt.value);
		what.selectedIndex = 0;  
	}    
}

function seta_option( oCampo )
{
  alert( oCampo.value );	
}										 

function FormataValor(campo,tammax)
{
	var valorAuxiliar = "";
	digitosValidos = "0123456789" ;
	
	valor = campo.value;
		
	//retira digitos não numericos
	for (i=0;i<valor.length;i++){
		if(digitosValidos.indexOf(valor.charAt(i))>=0) {
			valorAuxiliar += valor.charAt(i);
		}
	}

	//verifica tamanho (tamanho máximo vindo do método)
	if(tammax > 0 && tammax < valorAuxiliar.length)
		valorAuxiliar = valorAuxiliar.substring(0,tammax);

	//retira zeros desnecessários ao início do número
	while (valorAuxiliar.length > 3 && valorAuxiliar.charAt(0) == "0")
		valorAuxiliar = valorAuxiliar.substring(1);

	valor = valorAuxiliar;
	digitosNumericos = valor.length;

	//insere pontos decimais
	for(i = 1;i<=(digitosNumericos/3);i++)
		valor = valor.substring(0,digitosNumericos + 1 - 3*i) +
			(i==1?',':'.') +
			valor.substring(digitosNumericos + 1 - 3*i);
				
	campo.value = valor;
}


function FormataValor1(campo,tammax)
{
	var valorAuxiliar = "";
	digitosValidos = "0123456789" ;
	
	valor = campo.value;
		
	//retira digitos não numericos
	for (i=0;i<valor.length;i++)
	{
		if(digitosValidos.indexOf(valor.charAt(i))>=0)
		{
			valorAuxiliar += valor.charAt(i);
		}
	}

	//verifica tamanho (tamanho máximo vindo do método)
	if(tammax > 0 && tammax < valorAuxiliar.length)
		valorAuxiliar = valorAuxiliar.substring(0,tammax);

	//retira zeros desnecessários ao início do número
	while (valorAuxiliar.length > 3 && valorAuxiliar.charAt(0) == "0")
		valorAuxiliar = valorAuxiliar.substring(1);

	valor = valorAuxiliar;

	//insere pontos decimais
	contador_decimal = 0;
	mi_formatado = '';

  for ( i = valor.length; i > 0; i-- )
	{
    if ( contador_decimal == 3 )
		{
		  mi_formatado = valor.charAt(i - 1) + '.' + mi_formatado;
			contador_decimal = 1;			
    }
		else
		{
			mi_formatado = valor.charAt(i - 1) + mi_formatado;
		  contador_decimal++;
		}		
  }
  campo.value = mi_formatado;
}


function muda_cursor()
{
  source=event.srcElement
  source.style.cursor="hand";
}				 

function str_FormataValor( valor )
{
	valor_retorno = valor.toString()
	valor_retorno = valor_retorno.replace( ".", "" );
	valor_retorno = valor_retorno.replace( ".", "" );
	valor_retorno = valor_retorno.replace( ".", "" );	
	valor_retorno = valor_retorno.replace( ".", "" );		
	valor_retorno = valor_retorno.replace( ",", "." );
	return( valor_retorno );
}

var ie=(((navigator.userAgent.indexOf("MSIE")>-1)||(navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);	

function formata_data( input, evento )
{
	var BACKSPACE=  8; 
	var DEL=  46; 
	var FRENTE=  39; 
	var TRAS=  37; 
	var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
	if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS))
	{
		 return true; 
	}
	if ( tecla == 13 )
	 return false;

	if ((tecla<48)||(tecla>57))
	{
		 evento.returnValue = false; 
		 return false;
	}
	else
	{ 
		 if ((input.value.length==2)||(input.value.length==5))
		 {
				input.value=input.value + "/" ;
		 }
	}
	return true;			
}	
	  
function valida_data( oData )
{ 
	dia = (oData.substring(0,2)); 
	mes = (oData.substring(3,5)); 
	ano = (oData.substring(6,10)); 
	situacao = true; 
	if ( (dia < 1 ) || ( dia < 1 || dia > 30 ) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31 )
	{ 
		 situacao = false; 
	} 
	if (mes < 01 || mes > 12 )
	{ 
		 situacao = false; 
	} 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4))))
	{ 
		 situacao = false; 
	} 
	return situacao;
} 	


function Nova_Action( cAction ) 
{ 
  document.formulario.action = cAction; 
  document.forms.formulario.submit(); 
} 


function Valida_Jpg( cArquivo, oOpcao )
{
  separacao = cArquivo.split( "." );
  extensao = separacao[separacao.length - 1];
	extensao = extensao.toLowerCase();
	if ( extensao != "" )
    if ( extensao != "jpg" )
	  { 
	    alert( "Arquivo inválido, " + cArquivo + " não é padrão .jpg!" );
		  return false;
    }		
	oOpcao.value = "2";	
	return true;
}

function randomiza( maximo, minimo )
{
  if (typeof(minimo)!="number")
	 { minimo=0; }
  return( Math.floor(Math.random()*(maximo-minimo))+minimo );
}
 
function redireciona( url_nome )
{ self.location.href=url_nome; }
   
//Verifica qual o browser do visitante e armazena na variável púbica clientNavigator,
//Caso Internet Explorer(IE) outros (Other)
if (navigator.appName.indexOf('Microsoft') != -1)
{ clientNavigator = "IE"; }
else
{ clientNavigator = "Other"; }


function Bloqueia_Caracteres(evnt)
{
 	if (clientNavigator == "IE")
	{
 		if (evnt.keyCode == 13 )
		  return true
		else if (evnt.keyCode < 48 || evnt.keyCode > 57)
		{
			alert( 'Favor preencher este campo somente com números.' );
 			return false
 		}
 	}
	else
	{
 		if ((evnt.charCode < 48 || evnt.charCode > 57) && evnt.keyCode == 0)
		{
			alert( 'Favor preencher este campo somente com números.' );
 			return false
 		}
 	}
}


function abre_janela( topo, esquerda, altura, largura, endereco )
{
	if (document.all)
	{
		var janela = window.open( "", "", "left=" + esquerda + ", top=" + topo + ", width=" + largura + ", height=" + altura + ",resizable=no,scrollbars=yes");
		janela.location = endereco;
	}
	else
		window.location = endereco;
}


function Checa_Email( campo )
{
	if (campo.value == "") {
		alert("Informe seu e-mail.");
		return false;
	} else {
		prim = campo.value.indexOf("@")
		if(prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
		if(campo.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			return false;
		}
	}
		return true;
}


function currencyFormat( fld, milSep, decSep, e )
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13)
	  return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1)
	  return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++)
	  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep))
		  break;
	aux = '';
	for(; i < len; i++)
	  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	    aux += key;
	len = aux.length;
	if (len == 0)
	  fld.value = '';
	if (len == 1)
	  fld.value = '0'+ decSep + '0' + aux;
	if (len == 2)
	  fld.value = '0'+ decSep + aux;
	if (len > 2)
	{
	  aux2 = '';
	  for (j = 0, i = len - 3; i >= 0; i--)
		{
	    if (j == 3)
		  {
	      aux2 += milSep;
			  j = 0;
	    }
	    aux2 += aux.charAt(i);
	    j++;
	  }
	  fld.value = '';
	  len2 = aux2.length;
	  for (i = len2 - 1; i >= 0; i--)
	    fld.value += aux2.charAt(i);
	    fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}