//REFRESH NA PAGINA
function refresh()
{
	window.location.reload();
}

//Determina o Focu
function FocarAlguem()
{
	document.all.loginTextBox.focus();
}

// CENTRALIZA TELA		
function Centralizar()
{
	var w = window.document.body.offsetWidth;
	var h = window.document.body.offsetHeight;
	var wt = Table1.width;
	var ht = Table1.height;	
	
	Table1.style.top = ((h-ht)/2);
	Table1.style.left = ((w-wt)/2);		
}

//Bloqueia Digitação de Texto
function BloquearDigitacaoDeTexto()
{
	if ((window.event.keyCode >= 48) && (window.event.keyCode <= 57) || (window.event.keyCode == 92) )
	{
		// retorna o * para identificar a posição de inserção
		// window.event.keyCode=0;
	} 
	else
	{
		window.event.returnValue = false;
	}   
}

// Função para Imprimir conteudo de uma DIV
function PrintElementID(id, pg) 
{
	var oPrint, oJan;
	oPrint = window.document.getElementById(id).innerHTML;
	oJan = window.open(pg);
	oJan.document.write(oPrint);
	oJan.history.go();
	oJan.window.print();
}

//Converte para Casas decimais
function ConvToCurr(strNumber)
{
	var vlrIni;
	var convValue;
	var intI;
		
	// converte para duas casas 
	strNumber = Math.round(strNumber*100) / 100;
	vlrIni = strNumber ;
	convValue = vlrIni.toString().replace(".",",");
	I = convValue.indexOf(",");
	if (I < 0)  convValue += ",00";
	if (I == convValue.length - 2) convValue += "0"; 
	return convValue;
}    	

//Calcula o Custo Total Registro de Inventário
function Calcular()
{
	q = window.document.getElementById('quantidadeTextBox').getAttribute("value");
	q = q.toString().replace(",",".")
	quant = parseFloat (q);
	v = window.document.getElementById('custoUnitarioTextBox').getAttribute("value");
	v = v.toString().replace( /\./g, "" );
	v = v.toString().replace( ",", "." );
	unit = parseFloat(v);
	window.document.getElementById('custoTotalTextBox').setAttribute ("value", float2moeda( quant * unit));

}	

//Valor formatado com separador de milhar e vírgula nos centavos.
function float2moeda(num) {

   x = 0;

   if(num<0) {
      //num = Math.abs(num);
      x = 1;
   }   if(isNaN(num)) num = "0";
      cents = Math.floor((num*100+0.5)%100);

   num = Math.floor((num*100+0.5)/100).toString();

   if(cents < 10) cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
         num = num.substring(0,num.length-(4*i+3))+'.'
               +num.substring(num.length-(4*i+3));   ret = num + ',' + cents;   if (x == 1) ret = ' - ' + ret;return ret;

}

	//Formata digitação de valor moeda
	function FormatarMoedaReais(fld, milSep, decSep, e) 
	{ 
		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; 
		if (whichCode == 13) return true; 
		key = String.fromCharCode(whichCode);// Valor para o código da Chave 
		if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
		len = fld.value.length; 
		for(i = 0; i < len; i++)
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 
		aux = ''; 
		for(; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 
		aux += key; 
		len = aux.length; 
		if (len == 0) fld.value = ''; 
		if (len == 1) fld.value = '0'+ decSep + '0' + aux; 
		if (len == 2) fld.value = '0'+ decSep + aux; 
		if (len > 2) 
		{ 
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) 
			{
				if (j == 3) 
				{ 
					aux2 += milSep; 
					j = 0; 
				} 
				aux2 += aux.charAt(i); 
				j++; 
			} 
			fld.value = ''; 
			len2 = aux2.length; 
			for (i = len2 - 1; i >= 0; i--)
				fld.value += aux2.charAt(i); 
			fld.value += decSep + aux.substr(len - 2, len);
		}
		return false;
		
	} 


function Formatar3CasasDecimais(fld, milSep, decSep, e) 
{ 
	//0,100    +2  
		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; 
		if (whichCode == 13) return true; 
		key = String.fromCharCode(whichCode);// Valor para o código da Chave 
		if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
		len = fld.value.length; 
		//len=5
		for(i = 0; i < len; i++)
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 
		//i=2	
		aux = ''; 
		for(; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 
		
		//aux=100
		aux += key; 
		//aux=1002		
		len = aux.length; 
		//len=4
		if (len == 0) fld.value = ''; 
		if (len == 1) fld.value = '0'+ decSep + '00' + aux; 
		if (len == 2) fld.value = '0'+ decSep + '0' + aux; 
		if (len == 3) fld.value = '0'+ decSep +  aux; 		
		if (len > 3) 
		{ 
			aux2 = '';
			for (j = 0, i = len - 4; i >= 0; i--) 
			{
				//Separador de milhar
				if (j == 3) 
				{ 
					aux2 += milSep; 
					j = 0; 
				} 
				aux2 += aux.charAt(i); 
				j++; 
			} 
			//aux2=1
			fld.value = ''; 
			len2 = aux2.length; 
			//len2=1
			//i=0
			for (i = len2 - 1; i >= 0; i--)
				fld.value += aux2.charAt(i); 
			//fld.value =  1
			fld.value += decSep + aux.substr(len - 3, len);
			//fld.value =  1,002			
		}
		return false;
} 

function FormatarValor()
{
	if ((window.event.keyCode >= 48) && (window.event.keyCode <= 57) || (window.event.keyCode == 44) )
	{
		// retorna o * para identificar a posição de inserção
		// window.event.keyCode=0;
	} 
	else
	{
		window.event.returnValue = false;
	} 
		
}

function refresh()
{
    //  This version of the refresh function will be invoked
    //  for browsers that support JavaScript version 1.2
    //
    
    //  The argument to the location.reload function determines 
    //  if the browser should retrieve the document from the
    //  web-server.  In our example all we need to do is cause
    //  the JavaScript block in the document body to be
    //  re-evaluated.  If we needed to pull the document from 
    //  the web-server again (such as where the document contents
    //  change dynamically) we would pass the argument as 'true'.
    //  
    window.location.reload( true );
}



