function formataMoeda(obj,e) {
    var strCheck = '0123456789';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 0) return true;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
    if (obj.value.length == 0) {
    	obj.value = '0.0';
    } else {
    	valor = parseFloat(obj.value);
    	if (valor < 1) {
    		obj.value = obj.value.substr(2,1) + "." + obj.value.substr(3,1);
    	} else {
    		var partes = obj.value.split(".");
    		if (partes.length != 2) obj.value = '0.0';
    		else obj.value = partes[0] + partes[1].substr(0,1) + "." + partes[1].substr(1,1);
    	}
    }
   	return true;
}

function formataPeriodo(obj,e) {
    var strCheck = '0123456789';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
    if (obj.value.length == 2) obj.value += '/';
   	return true;
}


function formataAgencia(obj,e) {
    var strCheck = '0123456789-';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 0) return true;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
   	return true;
}

function formataConta(obj,e) {
    var strCheck = '0123456789Xx-';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 0) return true;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
   	return true;
}

function formataBanco(obj,e) {
    var strCheck = 'BCXbcx';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 0) return true;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
   	return true;
}

function formataConta(obj,e) {
    var strCheck = '0123456789Xx-';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 0) return true;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
   	return true;
}

function soNumero(obj,e) {
    var strCheck = '0123456789';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 0) return true;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
   	return true;
}

function resetaNumeros(obj,e) {
    var strCheck = '0123456789';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    switch (whichCode) {
    	case 8:	case 37: case 46: case 39:
    		obj.value = '';
    	break;
    }
}

function pular(obj, prox, tam, action, handler) {
	if (obj.value.length == tam) {
		if (prox != null) document.getElementById(prox).focus();
		ajaxOpen('http1', action, handler ,null);
	}

}

function formataData(obj,e) {
    var strCheck = '0123456789';
    var tam = obj.length;
    
    var whichCode = (window.Event) ? e.which : e.keyCode;
    var key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1) return false;
    if (obj.value.length == 2) obj.value += '/';
    if (obj.value.length == 5) obj.value += '/';
    
    if (tam == 10) alert('teste');
    
   	return true;

}

// funcao auxiliar - cadastro de menu principal
function showHide(valor) {
	switch (valor) {
		case "C":
			document.getElementById('divtexto').style.display = 'block';
			document.getElementById('divlink').style.display = 'none';
		break;
		case "L":
			document.getElementById('divtexto').style.display = 'none';
			document.getElementById('divlink').style.display = 'block';
		break;
	}
}

function pular2(obj, prox, tam) {
	if (obj.value.length == tam) {
		if (prox != null) document.getElementById(prox).focus();		
	}

}

function showHide2(valor) {
	switch (valor) {
		case "0":
			document.getElementById('divTexto').style.display = 'none';
			//document.getElementById('divArquivo').style.display = 'block';
		break;
		case "1":
			document.getElementById('divTexto').style.display = 'block';
			//document.getElementById('divArquivo').style.display = 'none';
		break;		
	}
}

function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function txtBoxFormat(objeto, sMask, evtKeyPress) {
	//chamada da função: onkeypress="return txtBoxFormat(this, '(99) 9999-9999', event);"
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	} else {
		nTecla = evtKeyPress.which;
		if (nTecla == 8) {
			return true;
		}
	}

	sValue = objeto.value;

	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;

	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;

	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++; }
			else {
				sCod += sValue.charAt(nCount);
				nCount++;
			}

			i++;
	}

	objeto.value = sCod;

	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58)); }
			else { // qualquer caracter...
				return true;
			}
	}
	else {
		return true;
	}
}