if (navigator.appName.indexOf('Microsoft') != -1) {
	clientNavigator = "IE";
} else {
	clientNavigator = "Other";
}
function Bloqueia_Caracteres(evnt){
	/**
 	 * Função original de Diego Pires Plentz
 	 *
 	 */
	if (clientNavigator == "IE") {
		if (evnt.keyCode < 48 || evnt.keyCode > 57) {
			return false
		}
	} else {
		if ((evnt.charCode < 48 || evnt.charCode > 57) && (evnt.keyCode == 0 || evnt.keyCode == 13)) {
			return false
		}
	}
}

function Ajusta_Data(input, evnt){
	/**
 	 * Função original de Diego Pires Plentz
 	 *
 	 */
	if (input.value.length == 2 || input.value.length == 5) {
		if(clientNavigator == "IE") {
			input.value += "/";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "/";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

function Ajusta_DataHora(input, evnt){
	/**
 	 * Função original de Pedro Henrique Braga Moreira
 	 *
 	 */
	if (input.value.length == 2 || input.value.length == 5) {
		if(clientNavigator == "IE") {
			input.value += "/";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "/";
			}
		}
	}
	if (input.value.length == 10) {
		if(clientNavigator == "IE") {
			input.value += " ";
		} else {
			if(evnt.keyCode == 0) {
				input.value += " ";
			}
		}
	}
	if (input.value.length == 13) {
		if(clientNavigator == "IE") {
			input.value += ":";
		} else {
			if(evnt.keyCode == 0) {
				input.value += ":";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

function Ajusta_Telefone(input, evnt){
	/**
 	 * Função original de Pedro Henrique Braga Moreira
 	 *
 	 */
	if (input.value.length == 0) {
		if(clientNavigator == "IE") {
            if(evnt.keyCode != 48) {
                input.value += "(";
			}
		} else {
			if(evnt.keyCode == 0 && evnt.charCode != 48) {
				input.value += "(";
			}
		}
	}
	if (input.value.length == 3 && input.value.slice(0, 1) != '0') {
		if(clientNavigator == "IE") {
			input.value += ")";
		} else {
			if(evnt.keyCode == 0) {
				input.value += ")";
			}
		}
	}
	if (input.value.length == 8 && input.value.slice(0, 1) != '0') {
		if(clientNavigator == "IE") {
			input.value += "-";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "-";
			}
		}
	}
	if ((input.value.length == 4 || input.value.length == 8) && input.value.slice(0, 1) == '0') {
		if(clientNavigator == "IE") {
			input.value += " ";
		} else {
			if(evnt.keyCode == 0) {
				input.value += " ";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

function Ajusta_CEP(input, evnt){
	/**
 	 * Função original de Pedro Henrique Braga Moreira
 	 *
 	 */
	if (input.value.length == 5) {
		if(clientNavigator == "IE") {
			input.value += "-";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "-";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

function Ajusta_CPF(input, evnt){
	/**
 	 * Função original de Pedro Henrique Braga Moreira
 	 *
 	 */
	if (input.value.length == 3 || input.value.length == 7) {
		if(clientNavigator == "IE") {
			input.value += ".";
		} else {
			if(evnt.keyCode == 0) {
				input.value += ".";
			}
		}
	}
	if (input.value.length == 11) {
		if(clientNavigator == "IE") {
			input.value += "-";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "-";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

function Ajusta_CNPJ(input, evnt){
	/**
 	 * Função original de Pedro Henrique Braga Moreira
 	 *
 	 */
	if (input.value.length == 2 || input.value.length == 6) {
		if(clientNavigator == "IE") {
			input.value += ".";
		} else {
			if(evnt.keyCode == 0) {
				input.value += ".";
			}
		}
	}
	if (input.value.length == 10) {
		if(clientNavigator == "IE") {
			input.value += "/";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "/";
			}
		}
	}
	if (input.value.length == 15) {
		if(clientNavigator == "IE") {
			input.value += "-";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "-";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

function Ajusta_Moeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
	/**
 	 * Função original obtida em
     * http://blog.zuntto.com/javascript-formatando-moeda-com-mascara/
 	 *
 	 */
    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;
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
    	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;
}

