/*
function formatarValor(valor,tammax,teclapres){

	var tecla = teclapres.keyCode;
																				
	valorSemFormato = valor.value;
	
	valorSemFormato = valorSemFormato.replace( ",", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	tamanho = valorSemFormato.length;
	
	if (tecla == 46) { // Tecla .
		valor.value = valor.value;
	alert('.');		
	}
	if (tamanho < tammax && tecla != 8) {
		tamanho = valorSemFormato.length + 1;
	}
	
	if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
		if (tecla == 8) { // BackSpace
			tamanho = tamanho - 1;
		}
		
		if (tamanho <= 2) {
			valor.value = valorSemFormato;
		}else if ((tamanho > 2) && (tamanho <= 5)) {
			valor.value = valorSemFormato.substr(0, tamanho - 2) + ',' +
			valorSemFormato.substr(tamanho - 2, tamanho);
		}else if ((tamanho >= 6) && (tamanho <= 8)) {
			valor.value = valorSemFormato.substr(0, tamanho - 5) + '.' +
			valorSemFormato.substr(tamanho - 5, 3) + ',' +
			valorSemFormato.substr(tamanho - 2, tamanho);
		}else if ((tamanho >= 9) && (tamanho <= 11)) {
			valor.value = valorSemFormato.substr(0, tamanho - 8) + '.' +
			valorSemFormato.substr(tamanho - 8, 3) + '.' +
			valorSemFormato.substr(tamanho - 5, 3) + ',' +
			valorSemFormato.substr(tamanho - 2, tamanho);
		}else if ((tamanho >= 12) && (tamanho <= 14)) {
			valor.value = valorSemFormato.substr(0, tamanho - 11) + '.' +
			valorSemFormato.substr(tamanho - 11, 3) + '.' +
			valorSemFormato.substr(tamanho - 8, 3)  + '.' +
			valorSemFormato.substr(tamanho - 5, 3)  + ',' +
			valorSemFormato.substr(tamanho - 2, tamanho);
		}else if ((tamanho >= 15) && (tamanho <= 17)) {
			valor.value = valorSemFormato.substr(0, tamanho - 14) + '.' +
			valorSemFormato.substr(tamanho - 14, 3) + '.' +
			valorSemFormato.substr(tamanho - 11, 3) + '.' +
			valorSemFormato.substr(tamanho - 8, 3)  + '.' +
			valorSemFormato.substr(tamanho - 5, 3)  + ',' +
			valorSemFormato.substr(tamanho - 2, tamanho);
		}
	}
}
*/
//  Função criada para calcular e retornar a posição do ponteiro do mouse
function calcPos(obj){
    var curleft = curtop = 0;
    curleft = event.clientX + document.body.scrollLeft -3;
    curtop = event.clientY + document.body.scrollTop - 3;
    return [curleft,curtop]
    //alert(curleft + ', ' + curtop)
}

function Adicionar_Elemento(pai, tipo) {
    var el = document.createElement(tipo);
    pai.appendChild(el);
    return el;
}

//  Função que cria e posiciona o box de opções dos Responsáveis
function criaDivResp(ema_pres_prj,tit_prj,termo,im_pes_per,im_app_pes_per,strAlert) {
    var posXY = calcPos(this);
    objStyle = document.getElementById('divResp')
    showDiv(true);
    objStyle.onmouseover = function() { showDiv(true); }
    objStyle.onmouseout = function() { showDiv(false); }
    objStyle.style.left = posXY[0];
    objStyle.style.top = posXY[1];

    /*  Objetos para a tabela */
    objStyle.innerHTML = ""
    
    var objTab, objTabBody, objTr, objTd

    objTab = Adicionar_Elemento(objStyle, 'table')
    objTabBody = Adicionar_Elemento(objTab, 'tbody')
    objTr = Adicionar_Elemento(objTabBody, 'tr')
    objTd = Adicionar_Elemento(objTr,'td')

    /**************************/
    objTd.align = 'center'
    objTd.innerHTML = "<a href=\"mailto:" + ema_pres_prj + "?Subject=" + termo + ":" + tit_prj + "\"><img border=0 src=\"../imagens/gpa_user_email.gif\"></a>"

    objTr = Adicionar_Elemento(objTabBody, 'tr')
    objTd = Adicionar_Elemento(objTr, 'td')

    objTd.align = 'center'

    switch(im_app_pes_per){
        case "SK":
            objTd.innerHTML = "<a href=\"skype:" + im_pes_per + "?chat\" onclick=\"alert('" + strAlert + "');return skypeCheck();\" ><img border=0 src=\"../imagens/gpa_user_skype.gif\"></a>"
            break;
        case "GT":
            objTd.innerHTML = "<a onclick=\"alert('" + strAlert + "');chamarApp('gtalk:chat?jid=" + im_pes_per + "')\" style=\"cursor:hand\" target=\"_blank\" ><img border=0 src=\"../imagens/gpa_user_gtalk.gif\"></a>"
            break;
        case "MS":
            objTd.innerHTML = "<a onclick=\"alert('" + strAlert + "');chamarApp('msnim:chat?contact=" + im_pes_per + "')\" style=\"cursor:hand\" target=\"_blank\" ><img border=0 src=\"../imagens/gpa_user_msn.gif\"></a>"
            break;
    }
}

function chamarApp(url) {
    var http = window.open(url)
    if(http)
        http.close()   
}

function showDiv(show) {
    objStyle = document.getElementById('divResp')
    if(show)
        objStyle.style.display = "block";
    else
        objStyle.style.display = "none";
        
}
////////////////////////////////////////////////////////////////////////////////////////

function FormatarValorStatico(flt){
	var str = "" + flt;
	var n = str.indexOf(".");
	var int1 = "";
	if( n == -1 ){
		int1 = str;
		str = ",00";
	}else{
		int1 = str.substr(0,n);
		str = "," + str.substr(n+1, 2);
		while( str.length < 3 )
			str += "0";
	}
	
	while( int1.length > 3 ){
		str = "." + int1.substr(int1.length-3, 3) + str;
		int1 = int1.substr(0, int1.length-3);
	}
	
	str = int1 + str;
	return str;	
}

////////////////////////////////////////////////////////////////////////////////////////

function Somente_Numero(tipo){
// tipo = N = Numeros
// tipo = H = Hora
// tipo = M = Moeda
// tipo = P = Aceita Ponto
// tipo = T = Aceita Traço

var ch; 

if (tipo=='P'){
	ch=46; // Ponto
} else {
	if (tipo=='N'){
		ch=9; // Nada
	} else {
		if (tipo =='H'){
			ch=58; // Dois-Pontos
		} else {
			if (tipo =='M'){
				ch=44; // Vírgula
			} else {
				if (tipo =='T'){
					ch=45; // Traço
				}
			}
		}
	}
}

	if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != ch) {
			event.keyCode = 0; // Trava
	}	
}

////////////////////////////////////////////////////////////////////////////////////////

function LimitaCampo(strCampo,intLimite){ // Nome do Campo e o Limite de Caracteres
	if ((strCampo).value.length > intLimite){
  		(strCampo).value = (strCampo).value.substring(0,intLimite);
	}
}

////////////////////////////////////////////////////////////////////////////////////////

function Formatar_Campo(obj,tipo){
	
// tipo = 'M' (Moeda)
// tipo ='H' (Hora)
	
	if (tipo == 'H') {obj.value = obj.value.replace(":",",");}	
	
	var j = document.getElementById(obj);
	
	var num = new NumberFormat();

	num.setInputDecimal(',');
	num.setSeparators(true, '.', ',');
	num.setNumber(obj.value);
	num.setPlaces('2');
	num.setCurrencyValue('$');
	num.setCurrency(false);
	num.setCurrencyPosition(num.LEFT_OUTSIDE);
	num.setNegativeFormat(num.LEFT_DASH);
	num.setNegativeRed(false);
	
	obj.value = num.toFormatted();
	
	if (tipo == 'H') {
		obj.value = obj.value.replace(",",":");
		obj.value = obj.value.replace(".","");
	}
	
}

////////////////////////////////////////////////////////////////////////////////////////

function Formatar_Float(float, tipo){ //Transforma Float em Hora ou Moeda


// tipo = 'M' (Moeda)
// tipo ='H' (Hora)
var string;

	if (tipo=='M'){	
		float += 0.005; // Arredonda na segunda casa
		string = float + "";
		
		if(string.indexOf(".") == -1) {string += ".0";}
		
		string += "0";
		string = string.substr(0,string.indexOf(".")+3);
		string = string.replace(".",",");
		
	} else {
		
		var horas = parseInt(float);
		var minutos = ((float-horas)*60)+0.005;

		if(minutos >= 60) {horas += 1; minutos -= 60;}
		
		string = horas + ":" + parseInt(minutos) + "00";
		string = string.substr(0,string.indexOf(":")+3);
	}

return string;

}

////////////////////////////////////////////////////////////////////////////////////////

function Float(string, tipo){ // Transforma Hora ou Moeda em Float


// tipo = 'M' (Moeda)
// tipo ='H' (Hora)

	if (tipo=='M'){
		
		string = string.replace(".","");
		string = string.replace(".","");
		string = string.replace(",",".");
		return parseFloat(string);
	
	} else {
		var pos2pts = string.indexOf(':'); // Posição dos 2 pontos
		if (pos2pts != -1){
			var hora = string.substr(0,pos2pts); // Valores antes dos 2 pontos
			var minutos = string.substr(pos2pts+1,string.lenght); // Valores depois dos 2 pontos
			var res = parseInt(hora) + parseFloat(minutos/60);
		} else {
			res = 0;
		}
		return res;
	}
	
}

////////////////////////////////////////////////////////////////////////////////////////

function ShowHide(id, visibility){
    obj = document.getElementsByTagName("div");
	if (obj != null)
		if (obj.length > 0)
			obj[id].style.visibility = visibility;
}


////////////////////////////////////////////////////////////////////////////////////////


function CentralizaLayer(nome, largura, altura, posicao) {

	Hor = ((document.body.clientWidth) / 2) - (largura/2); 

	if (posicao == 'topo')
		Ver = 3; 
	else
		Ver = (((document.body.clientHeight) / 2) - (altura/2)) + document.body.scrollTop; 
	
	document.all[nome].style.pixelLeft = Hor;
	document.all[nome].style.pixelTop = Ver;
}

