function FormataData(campo,teclapres) {
	var tecla = teclapres.keyCode;
	var obj = document.getElementById(campo);
	vr = obj.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			obj.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			obj.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}

// url_encode version 1.0  
function UrlEncode(str) {  
    var hex_chars = "0123456789ABCDEF";  
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;  
    var n, strCode, hex1, hex2, strEncode = "";  

    for(n = 0; n < str.length; n++) {  
        if (noEncode.test(str.charAt(n))) {  
            strEncode += str.charAt(n);  
        } else {  
            strCode = str.charCodeAt(n);  
            hex1 = hex_chars.charAt(Math.floor(strCode / 16));  
            hex2 = hex_chars.charAt(strCode % 16);  
            strEncode += "%" + (hex1 + hex2);  
        }  
    }  
    return strEncode;  
}  

// url_decode version 1.0  
function UrlDecode(str) {  
    var n, strCode, strDecode = "";  

    for (n = 0; n < str.length; n++) {  
        if (str.charAt(n) == "%") {  
            strCode = str.charAt(n + 1) + str.charAt(n + 2);  
            strDecode += String.fromCharCode(parseInt(strCode, 16));  
            n += 2;  
        } else {  
            strDecode += str.charAt(n);  
        }  
    }  
    return strDecode;  
}  

function showLoading()
{
	document.body.style.cursor = 'wait';
	document.getElementById('loading').style.display = 'block';
}

function hideLoading()
{
	document.body.style.cursor = '';
	document.getElementById('loading').style.display = 'none';
}

function textCounter(campo, countcampo, maxlimit){ //Esta função que irá contar, mostrar e restringir o tamanho do campo
    if (campo.value.length > maxlimit) { //se passar do limite não deixará entrar o caracter
		campo.value = campo.value.substring(0, maxlimit);
	}
	else { //aqui, enquanto não se chegar ao limite, a cada caracter inserido ele reduzira -1 da contagem
        countcampo.value = maxlimit - campo.value.length;
	}
}



