﻿    function ShowAlert(message) {
        msg = message;
        setTimeout("Alerta('"+message+"')", 20);
    }

    function Alerta() {
        alert(msg);
    }

 function validarEmail(objCampo) {
        if (objCampo.value.indexOf("@") == -1 || objCampo.value.indexOf(".") == -1) {
            alert("O campo email não está preenchido corretamente!");
            return false;
        }
    }


// Formata a data enquanto o usuário está digitando
function FormataData(objCampo,intKeyCode){
	if((parseInt(intKeyCode) < 48) || (parseInt(intKeyCode) > 57)){
		return false
	}
	else
	{
		strValor = objCampo.value
		intLengthValor = parseInt(strValor.length)
		if(intLengthValor == 2){
			objCampo.value = strValor + "/"
		}
		if(intLengthValor == 5){
			objCampo.value = strValor + "/"
		}

		return true
	}
}

// Formata a data enquanto o usuário está digitando
function FormataDataHora(objCampo, intKeyCode) {
    
    if (document.all) {
        
        if ((parseInt(intKeyCode.keyCode) < 48) || (parseInt(intKeyCode.keyCode) > 57)) {
            return false
        }
        else {
            strValor = objCampo.value
            intLengthValor = parseInt(strValor.length)
            if (intLengthValor == 2) {
                objCampo.value = strValor + "/"
            }
            if (intLengthValor == 5) {
                objCampo.value = strValor + "/"
            }

            if (intLengthValor == 10) {
                objCampo.value = strValor + " ";
            }

            if (intLengthValor == 13) {
                objCampo.value = strValor + ":"
            }
            if (intLengthValor == 16) {
                objCampo.value = strValor + ":"
            }
        }
    }
    else
    {
        if ((intKeyCode.which == 8))
            return true;
        else
        
            if ((intKeyCode.which < 48) || (intKeyCode.which > 57) ) {
                
            return false
        }
        else {
            strValor = objCampo.value
            intLengthValor = parseInt(strValor.length)
            if (intLengthValor == 2) {
                objCampo.value = strValor + "/"
            }
            if (intLengthValor == 5) {
                objCampo.value = strValor + "/"
            }

            if (intLengthValor == 10) {
                objCampo.value = strValor + " ";
            }

            if (intLengthValor == 13) {
                objCampo.value = strValor + ":"
            }
            if (intLengthValor == 16) {
                objCampo.value = strValor + ":"
            }
        }
        
    }
    return true
}


function validaNumero(evento) {
    var tecla = window.event ? evento.keyCode : evento.which;

    if (tecla != 8 && tecla != 0) {
        if (tecla < 48 || tecla > 57) {
            if (tecla != 44 && tecla != 46) {
                evento.preventDefault ? evento.preventDefault() : evento.returnValue = false;
                evento.keyCode = 0;
                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;
}


function FormataCPF(campo, evento) {
    var tecla = window.event ? evento.keyCode : evento.which;

    if (tecla != 8 && tecla != 0) {
        if (tecla < 48 || tecla > 57) {
            evento.preventDefault ? evento.preventDefault() : evento.returnValue = false;
            evento.keyCode = 0;
            return false;
        }
        else {
            if (campo.value.length == 3 || campo.value.length == 7) {
                campo.value += ".";
            }
            else {
                if (campo.value.length == 11) {
                    campo.value += "-";
                }
            }
        }
    }

    return true;
}


function FormataCEP(objCampo, intKeyCode) {
    //alert(intKeyCode);
    var tecla = document.all ? intKeyCode.keyCode : intKeyCode.which;

    if (tecla != 8 && tecla != 0) {
        if (tecla < 48 || tecla > 57) {
            intKeyCode.preventDefault ? intKeyCode.preventDefault() : intKeyCode.returnValue = false;
            intKeyCode.keyCode = 0;
            return false;
        }
        else {
            
            if (objCampo.value.length == 2) {
                objCampo.value += ".";
            }
            else {
                if (objCampo.value.length == 6) {
                    objCampo.value += "-";
                }
            }
        }
    }
    return true;
}


   function bloqueiaColar(evento) {
        var ctrl = window.event.ctrlKey;
        var tecla = event.keyCode;
        if ((ctrl && tecla == 86) || (ctrl && tecla == 118)) {
            event.keyCode = 0;
            event.returnValue = false;
        }
        else {
            return true;
        }
    }

    function desabilitaMenu(e) {
        if (window.Event) {
            if (e.which == 2 || e.which == 3)
                return false;
        }
        else {
            event.cancelBubble = true
            event.returnValue = false;
            return false;
        }
    }

    function BloqueiaClickDireito(controle) {
        if (navigator.appName == 'Microsoft Internet Explorer'
    && (event.button == 2 || event.button == 3)) {

            if (window.Event) document.captureEvents(Event.MOUSEUP);
            if (document.layers) document.captureEvents(Event.MOUSEDOWN);

            var ctrl = document.getElementById(controle);

            ctrl.oncontextmenu = desabilitaMenu;
            ctrl.onmousedown = desabilitaBotaoDireito;
            ctrl.onmouseup = desabilitaBotaoDireito;

            return false;
        }
        return true;
    }

    function desabilitaBotaoDireito() {
        if (window.Event) {
            if (event.which == 2 || event.which == 3)
                return false;
        }
        else if (event.button == 2 || event.button == 3) {
            event.cancelBubble = true
            event.returnValue = false;
            return false;
        }
    }


    function ShowDiv(divId) {
        var _theDiv = document.getElementById(divId);
        _theDiv.style.display = 'block';
    }

    function HideDiv(divId) {
        var _theDiv = document.getElementById(divId);
        _theDiv.style.display = 'none';
    }

