//FUNCOES PARA JANELA
function AbreJanela(aURL,nomeJanela,features) { 
	window.open(aURL,nomeJanela,features); 
} 

function mudaCorTabela(theRow,acao){
	if(acao == "over"){
		if(theRow.style.backgroundColor==""){
			theRow.style.backgroundColor = "#f6f6f6";
		}
		
	}else if(acao == "out"){
		if(theRow.style.backgroundColor=="#f6f6f6"){
			theRow.style.backgroundColor = "";
		}
	}
}

function excluirRegistro(formulario){
	if(!confirm('Você realmente deseja excluir esse registro?\nClique em OK para confirmar!')){
		return false;
	}else{
		return true;
	}
}
function campoNumero(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var caract = new RegExp(/^[0-9 ]+$/i);
	var caract = caract.test(String.fromCharCode(keyCode));

	if(!caract){
		keyCode=0;
		return false;
	}
}
//FUNCOES PARA STRINGS


//FUNCOES PARA MASCARA
function campoMascara(string, mascara, saida) {
	var i = string.value.length;
	var str = mascara.substring(i)
	if (str.substring(0,1) != saida) {
		string.value += str.substring(0,1);
	}
}

function strMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, 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;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}
function verificaData(campo) {
	if(campo.value.length > 0){
		dia = (campo.value.substring(0,2)); 
		mes = (campo.value.substring(3,5));
		ano = (campo.value.substring(6,10));
	
		situacao = "";
		if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) {
			situacao = "falsa";
		}
		if (mes < 01 || mes > 12 ) {
			situacao = "falsa";
		}
		if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
			situacao = "falsa";
		}
		if (campo.value == "") {
			situacao = "falsa";
		}
		if (situacao == "falsa") {
			alert("Data inválida, preencha novamente!");
			campo.focus();
			if(campo.value.length==10){
				campo.value = "";
			}						
			return false;
		}
	}	
	return true;
}
