﻿// Função de incremento do Spinner
function __Inc(txt,valor)
{
	var obj = document.forms[0].elements[txt]				
	if (isNaN(parseInt(obj.value)))
		{obj.value = 0;}				
	obj.value = parseInt(obj.value) + valor;				
	if(parseInt(obj.value) < 0)
		{obj.value = 0;}
}

// Ativa calendario

function __GetDate(CtrlName)
{
	if( ! document.getElementById(CtrlName).disabled)
	ChildWindow = window.open('MYCalendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, 'PopUpCalendar', 'width=220,height=200,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no');    
}

// formata Data 	
function FData(ConteudoCampo)
{  
	if (ConteudoCampo.value.length < 10)
	{
		if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
		{
			NumDig = ConteudoCampo.value;
			TamDig = NumDig.length;
			if (TamDig == 2)
			{
				NumDig +=   '/'  ;
			}
			if (TamDig == 5)
			{
				NumDig +=   '/'  ;
			}
			ConteudoCampo.value = NumDig;
			return(true);
		}
	}
	else
	{
		return(false);
	}
}

//formata valor com 0 casas decimais
function FValor0(ConteudoCampo)
{  
if (ConteudoCampo.value.length < 20) {
if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
{ NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
Contador = 0;
if (TamDig > 1) { 
numer = '';
for (i = TamDig; (i >= 0); i--){
if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) 
{
Contador++;
if (Contador == 3)
{numer = '.'+numer;
Contador = 0;
}
numer = NumDig.substr(i, 1)+numer;
	} 
}
ConteudoCampo.value = numer;
}
return(true);
}
else {return(false);}}}

//formata valor com 1 casas decimais
function FValor1(ConteudoCampo)
{  
if (ConteudoCampo.value.length < 20) {
if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
{ NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
Contador = 0;
if (TamDig > 1) { 
numer = '';
for (i = TamDig; (i >= 0); i--){
if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) 
{
Contador++;
	if ((Contador == 1) && ((TamDig -i) < 2))
{numer = ','+numer;
	Contador = 0;
	}
else if (Contador == 3)
{numer = '.'+numer;
Contador = 0;
}
numer = NumDig.substr(i, 1)+numer;
	} 
}
ConteudoCampo.value = numer;
}
return(true);
}
else {return(false);}}}

//formata valor com 2 casas decimais
function FValor2(ConteudoCampo)
{  
if (ConteudoCampo.value.length < 20) {
if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
{ NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
Contador = 0;
if (TamDig > 1) { 
numer = '';
for (i = TamDig; (i >= 0); i--){
if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) 
{
Contador++;
	if ((Contador == 2) && ((TamDig -i) < 4))
{numer = ','+numer;
	Contador = 0;
	}
else if (Contador == 3)
{numer = '.'+numer;
Contador = 0;
}
numer = NumDig.substr(i, 1)+numer;
	} 
}
ConteudoCampo.value = numer;
}
return(true);
}
else {return(false);}}}

//formata valor com 3 casas decimais
function FValor3(ConteudoCampo)
{  
if (ConteudoCampo.value.length < 20) {
if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
{ NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
Contador = 0;
if (TamDig > 1) { 
numer = '';
for (i = TamDig; (i >= 0); i--){
if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) 
{
Contador++;
	if ((Contador == 3) && ((TamDig -i) < 4))
{numer = ','+numer;
	Contador = 0;
	}
else if (Contador == 3)
{numer = '.'+numer;
Contador = 0;
}
numer = NumDig.substr(i, 1)+numer;
	} 
}
ConteudoCampo.value = numer;
}
return(true);
}
else {return(false);}}}

//formata valor com 4 casas decimais
function FValor4(ConteudoCampo)
{  
if (ConteudoCampo.value.length < 20) {
if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
{ NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
Contador = 0;
if (TamDig > 1) { 
numer = '';
for (i = TamDig; (i >= 0); i--){
if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) 
{
Contador++;
	if ((Contador == 4) && ((TamDig -i) < 5))
{numer = ','+numer;
	Contador = 0;
	}
else if (Contador == 3 && ((TamDig -i) > 4))
{numer = '.'+numer;
Contador = 0;
}
numer = NumDig.substr(i, 1)+numer;
	} 
}
ConteudoCampo.value = numer;
}
return(true);
}
else {return(false);}}}



//// muda cor do text no foco
function FocoMudaCor(obj,oque)
{
	if (oque == "0")
	{
		obj.style.backgroundColor = "ffffe0";

	}
	else
	{
		obj.style.backgroundColor = "f0f8ff";
	}
}

function ApenasNumeros(ConteudoCampo)
{  
    if (((event.keyCode) > 47) && ((event.keyCode) < 58)) 
    {
        return(true);
    }
    else 
    {
        return(false);
    }
}

function JsHttp(url ){
var urladress=url;
var is_protocol_ok=urladress.indexOf('http://');
var is_dot_ok=urladress.indexOf('.');
if ((is_protocol_ok==-1) || (is_dot_ok==-1))
 { 
  alert('A URL deve começar com o http://');
 }
else
	window.open(''+urladress+'','New','type=fullWindow,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=800,height=600,top=0,left=0,screenY=0,screenX=0');
}

//Abrir Janela Centralizada SEM Rolagem
function cria_janela_cent(horizontal,vertical,nome,pagina) 
{

var res_ver = screen.height
var res_hor = screen.width

var pos_ver_fin = (res_ver - vertical)/2
var pos_hor_fin = (res_hor - horizontal)/2

window.open(pagina,nome,"width="+horizontal+",height="+vertical+",top="+pos_ver_fin+",left="+pos_hor_fin+",status=yes,scrollbars=no,resizable=yes");

}

//Abrir Janela Centralizada COM Rolagem
function cria_janela_cent_rolagem(horizontal,vertical,nome,pagina) 
{

var res_ver = screen.height
var res_hor = screen.width

var pos_ver_fin = (res_ver - vertical)/2
var pos_hor_fin = (res_hor - horizontal)/2

window.open(pagina,nome,"width="+horizontal+",height="+vertical+",top="+pos_ver_fin+",left="+pos_hor_fin+",status=yes,scrollbars=yes,resizable=yes");

}


