function OpenUrlSelect(Obj){
	var value = Obj.options[Obj.selectedIndex].value;
	var array = value.split(";");
	window.open(array[1], array[0]);
}

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;
	}
}

function displayOff( id ){
	document.body.style.cursor = '';
	//document.getElementById(id).style.display = 'none';
	document.getElementById(id).style.visibility = 'hidden';
}
function displayOn( id ){
	document.body.style.cursor = 'wait';
	//document.getElementById(id).style.display = 'block';
	document.getElementById(id).style.visibility = 'visible';
}

Util = {
    DebugObj : function(obj){
        var temp = "";
        for(x in obj)
            temp += x + ": " + obj[x] + "\n";
        alert(temp);
    },
    Formatar : function(valor){
        var valores = new String(valor).split('.');
        if(valores != valor){
            if(valores[1].length > 2){
                var outrosValores = valores[1].split('');
                return (valores[0] + "," + outrosValores[0] + outrosValores[1]);
            }
            else if(valores[1].length==1)
                return valor + "0";
            else
                return valor;
        }
        else{
            return valor + ",00";
        }
    },
    Popup : function(url){
		window.open(url,"", 'width=720, height=450, scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
    },
    Favorito : function(url_site, titulo_site){
		if (document.all){
			window.external.AddFavorite(url_site,titulo_site);
		}
    },
	moveRelogio : function(componente)
	{ 
		momentoAtual = new Date() 
	
		horaImprimivel = this.doisDigitos(momentoAtual.getHours()+"")  + ":" + this.doisDigitos(momentoAtual.getMinutes()+"") + ":" + this.doisDigitos(momentoAtual.getSeconds()+"") + 
		"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ 
		momentoAtual.getDate() + "/" + (momentoAtual.getMonth() + 1) + "/" + momentoAtual.getFullYear()
		document.getElementById(componente).innerHTML = horaImprimivel;
	},
	doisDigitos : function(valor)
	{
		return ((valor.length == 1) ? "0"+valor : valor );
	}
}

Page = {
    DisplayIn : function(obj, str){
		if(obj.value == str){
			obj.value = "";
		}
    },
    DisplayOut : function(obj, str){
		if(obj.value == ""){
			obj.value = str;
		}
    },
    DisplayValidate : function(objId, str, msg){
		var obj = document.getElementById(objId);
		if( (obj.value == str) || (obj.value == "") || (obj.value == null) ){
			alert(msg);
			obj.focus();
			return false;
		}
		return true;
    },
	Abrir : function(url, width, height){
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=no,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height);");
    }
}