﻿// JScript File
var ie =(((navigator.userAgent.indexOf("MSIE")>-1)||(navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var ns =(navigator.userAgent.indexOf("Netscape")>-1&&navigator.userAgent.indexOf("Opera")==-1?true:false);

// AJUSTAR CEP
function ajustar_cep(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 5) {
            input.value += "-";
        }
    }
    return true;
}

function transform_cep(input) {
	valor = input.value.replace(/[^\d]*/g,'');
	novovalor = "";
	for (i = 0; i < valor.length; i++) {
		novovalor += valor.substr(i, 1);
		if (i == 4)
			novovalor += "-";
	}
	input.value = novovalor;
}

// AJUSTAR CPF
function ajustar_cpf(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 3 || input.value.length == 7) {
            input.value += ".";
        }
        if (input.value.length == 11) {
            input.value += "-";
        }
    }
    return true;
}

function transform_cpf(input) {
	valor = input.value.replace(/[^\d]*/g,'');
	novovalor = "";
	for (i = 0; i < valor.length; i++) {
		novovalor += valor.substr(i, 1);
		if (i == 2 || i == 5)
			novovalor += ".";
		if (i == 8)
			novovalor += "-";
	}
	input.value = novovalor;
}

// AJUSTAR CNPJ
function ajustar_cnpj(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 2 || input.value.length == 6) {
            input.value += ".";
        }
        if (input.value.length == 10) {
            input.value += "/";
        }
        if (input.value.length == 15) {
            input.value += "-";
        }
    }
    return true;
}

function transform_cnpj(input) {
	valor = input.value.replace(/[^\d]*/g,'');
	novovalor = "";
	for (i = 0; i < valor.length; i++) {
		novovalor += valor.substr(i, 1);
		if (i == 1 || i == 4)
			novovalor += ".";
		if (i == 7)
			novovalor += "/";
		if (i == 11)
			novovalor += "-";
	}
	input.value = novovalor;
}

// AJUSTAR DATA
function ajustar_data(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 2 || input.value.length == 5) {
            input.value += "/";
        }
    }
    return true;
}

function transform_data(input) {
	valor = input.value.replace(/[^\d]*/g,'');
	novovalor = "";
	for (i = 0; i < valor.length; i++) {
		novovalor += valor.substr(i, 1);
		if (i == 1 || i == 3)
			novovalor += "/";
	}
	input.value = novovalor;
}

// ENVIAR FORM
function sendIt(input, evento, target) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla == 13) {
        evento.returnValue = false;
        __doPostBack(target, '');
    }
}