function CaracteresValidos(teclapres) // Permite simbolos e alfanumericos
{
	if(window.event)
	{ // Internet Explorer
		var tecla = teclapres.keyCode;
	}
	else if(teclapres.which)
	{ // Nestcape / firefox
		var tecla = teclapres.which;
	}

	//alert(tecla);
    if ((tecla >= 32 && tecla <= 47) || (tecla >= 58 && tecla <= 64) || (tecla >= 91 && tecla <= 96) || (tecla >= 123))
    {
    	//alert('false');
    	return false;
    }
    else
    {
    	//alert('true');
    	return true;
    }
}

function CaracteresValidos2(teclapres) // Permite simbolos e alfanumericos
{
	if(window.event)
	{ // Internet Explorer
		var tecla = teclapres.keyCode;
	} 
	else if(teclapres.which) 
	{ // Nestcape / firefox
		var tecla = teclapres.which;
	}

	//alert(tecla);
	if ((tecla >= 32 && tecla <= 47) || (tecla >= 58 && tecla <= 64) || (tecla >= 91 && tecla <= 94) || (tecla == 96) || (tecla >= 123))
	{
		//alert('false');
		return false;
	}
	else
	{
		//alert('true');
		return true;
	}
}

function CaracteresValidosNumeros(teclapres) // Permite apenas numeros
{
	if(window.event)
	{ // Internet Explorer
		var tecla = teclapres.keyCode;
	} 
	else if(teclapres.which) 
	{ // Nestcape / firefox
		var tecla = teclapres.which;
	}

	//alert(tecla);
	if ((tecla >= 32 && tecla <= 47) || (tecla >= 58))
	{
		//alert('false');
		return false;
	}
	else
	{
		//alert('true');
		return true;
	}
}

function LoadDiv(url, layer, metodo) // carrega arquivo em determinado div
{
		ajax_loadContent(layer,url, metodo);
}

function formatar(src, mask, teclapres)
{
        if(window.event)
        { // Internet Explorer
                var tecla = teclapres.keyCode;
        } else if(teclapres.which) { // Nestcape / firefox
                var tecla = teclapres.which;
        }

        var i = src.value.length;
        var saida = mask.substring(0,1);
        var texto = mask.substring(i);
        var srcvalue = src.value;

        if ((tecla >= 48 && tecla <= 57) || tecla == 8)
        {
                if (texto.substring(0,1) != saida && tecla != 8)
                {
                        src.value += texto.substring(0,1);
                }
                return true;
        } else if ((tecla >= 32 && tecla <= 47) || tecla >=58) {
                return false;
        } else {
                return true;
        }
}

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;
}

//Formata número tipo moeda usando o evento onKeyDown

function FormataC(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 ) ;}
} 

}

function DoConfirmlo(message, url)
{
	if (confirm(message))
		location.href = url;
}

function MsgAlerta(message, javascript)
{
	window.alert(message);
	if (javascript) eval(javascript);
}

function atualizar() 
{
	window.close();
	self.opener.document.location.reload();// sem ser maiusculo
}

function redireciona(url)
{
	location.href=url;
}

