function onlyThisChars(numbers,letters,others,e){
    var key;
    var event = e;

    if (!e) var e = window.event;
    if (e.keyCode) key = e.keyCode;       
    else if (e.which) key = event.which; // Netscape 4.?               //
    else if (e.charCode) key = e.charCode; // Mozilla                  //
    else 
         return true
	
    S=(others)?others:''
    if(numbers)
	S+='0123456789'
    if(letters)
	S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    if(key==null||key==0||key==8||key==9||key==13||key==27)
	return true
    else if(S.indexOf(String.fromCharCode(key))!=-1)
		return true
	else 
		return false
}


function checkForRequiredFields( ahFields, asMsgs, sFormName )
{
 var hField;

 for( var i=0; i< ahFields.length; i++)
 {hField = eval("document." + sFormName + "." + ahFields[i]);
  if( (hField.value=="") || (hField.value==null) )
  {
   Warn(hField, asMsgs[i]);
	return false;
  }
 }
 return true;
}
function Warn( hField, sMsg )
{
 alert( sMsg );
 hField.focus();
/* hField.select();*/
}

hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getYear()
ano += (ano < 1900) ? 1900 : 0
if (dia < 10)
dia = "0" + dia
if (ano < 2000)
ano = "19" + ano
function CriaArray (n) {
this.length = n }
NomeDia = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Terça-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "Sábado"
//
NomeMes = new CriaArray(12)
NomeMes[0] = "Janeiro"
NomeMes[1] = "Fevereiro"
NomeMes[2] = "Março"
NomeMes[3] = "Abril"
NomeMes[4] = "Maio"
NomeMes[5] = "Junho"
NomeMes[6] = "Julho"
NomeMes[7] = "Agosto"
NomeMes[8] = "Setembro"
NomeMes[9] = "Outubro"
NomeMes[10] = "Novembro"
NomeMes[11] = "Dezembro"
function WriteDate() {
}

day = new Date()
d = day.getDate()
m = day.getMonth()
hr = day.getHours()
mi = day.getMinutes()
se = day.getSeconds()

// A validaçao abaixo diz respeito aos campos de data das paginas. As funçoes sao usadas p/ validaçao das entradas do usuario
nome_mes = new Array();
nome_mes[1]="Jan";
nome_mes[2]="Feb";
nome_mes[3]="Mar";
nome_mes[4]="Apr";
nome_mes[5]="May";
nome_mes[6]="Jun";
nome_mes[7]="Jul";
nome_mes[8]="Aug";
nome_mes[9]="Sep";
nome_mes[10]="Oct";
nome_mes[11]="Nov";
nome_mes[12]="Dec";

function qtdeCarac(chc, campo)
{
	var intRetorno = 0;
	var strValor = campo.value;
	var x = 0;
	
	while( x < strValor.length)
	{
		if(strValor.indexOf(chc,x) > x)
		{
			x = strValor.indexOf(chc,x);
			intRetorno++;
		}
		else
		{
			x++;
		}
	}
	return intRetorno;
}

function setaCampo(dat1,dat2,radio1,radio2){
	var hoje = new Date();
	di2 = hoje.getDate() +"/"+ parseInt(hoje.getMonth()+ 1)  + "/"+ hoje.getFullYear();
	
	a = Calcula_Dias(di2,dat1.value);
	if (( dat1.value == "" ) || ( dat2.value == "") && (a >=0))
	{
	
	//ativo
	radio1.checked = true;
	radio2.checked = false;
	}
	else if (a < 0)
	{
		radio1.checked = false;
		radio2.checked = true;
	}
	else
	{
	
	di2 = hoje.getDate() +"/"+ parseInt(hoje.getMonth()+ 1)  + "/"+ hoje.getFullYear();
	
	a = Calcula_Dias(di2,dat1.value);
	b = Calcula_Dias(di2,dat2.value);

	if ((a >= 0) && (b <= 0))
	    {
	    //ativo
		radio1.checked = true;
		radio2.checked = false;
		}
	else
	   {
	   //inativo
		radio2.checked = true;
		radio1.checked = false;
		}
	}
}

function checkDate( campo ){
	var data = campo.value;
	objVarFocus=campo;
	if (data == ""){	
		return true;		
	} else {	
		if( qtdeCarac("/", campo) != 2 || !(checkField( data, "<|>@#$%&*!+- ()?[]{}~^´`,.\"_=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáéíóúãõàüäëöïñçÁÉÍÓÚÃÕÀÜÄËÖÏÑÇ\\" )))
		{
		alert('Data Inválida \nFormato Correto:"dd/mm/aaaa".');
		setTimeout('objVarFocus.focus()',50);
		return false;
		}
		if (data.length > 1 && data.length < 10) {
		alert('Data Inválida \nFormato Correto:"dd/mm/aaaa".');
		setTimeout('objVarFocus.focus()',50);
		return false;
		} 
		var myDayStr = data.substr(0,2);
		var myMonthStr = nome_mes[Math.abs(data.substr(3,2))];
		var myYearStr = data.substr(6,4);
		var myDateStr = myDayStr + " " + myMonthStr + " " + myYearStr;
		var myDate = new Date( myDateStr );
		var myDate_string = myDate.toUTCString();
		var myDate_array = myDate_string.split(" ");

		// Array myDate_array:
		// Indices:
		// 0 - Dia da semana
		// 1 - Dia do mes (numero)
		// 2 - Nome do mes (Jan, Fev, etc)
		// 3 - Ano
		// 4 - Hora
		// 5 - Constante "UTC"

		if( ( myDate_array[2] != myMonthStr ) || Math.abs(data.substr(3,2)) < 1 || Math.abs(data.substr(3,2)) > 12 )
		{
			alert('Data Inválida \nFormato Correto:"dd/mm/aaaa".');
			setTimeout('objVarFocus.focus()',50);			
			return false;
		}
		else
		{
		return true;
		}
	}	
}

function checkField( sStr, sChars )
{
 var j=0;
 var bRetVal = true;
 while( j < sChars.length )
 {
	if( sStr.indexOf( sChars.substr(j,1) ) >= 0 )
	{
	 bRetVal = false;
	 break;
	}
	j++
 }
 
 return bRetVal;
}

  function mascaraDATA(campo, e){
    var key;
    var event = e;

    if (!e) var e = window.event;
    if (e.keyCode) key = e.keyCode;       
    else if (e.which) key = event.which;   // Netscape 4.?               //
    else if (e.charCode) key = e.charCode; // Mozilla                  //
    else 
         return true

    if (key != 8 && key != 46 && key != 9)
    {
		if (campo.value.length == 2 && key != 39 && key != 37 && key != 38 && key !=40) {
			campo.value = campo.value + "/";
		}
		else if (campo.value.length == 5 && key != 39 && key != 37 && key != 38 && key !=40){
			campo.value = campo.value + "/";
       }	
    }
}   


function mascaraHora(campo, e)
{
 var key;
 var event = e;

 if (!e) var e = window.event;
 if (e.keyCode) key = e.keyCode;       
 else if (e.which) key = event.which;   // Netscape 4.?               //
 else if (e.charCode) key = e.charCode; // Mozilla                  //
 else 
      return true

 if (key != 8 && key != 46 && key != 9)
 {
	if (campo.value.length == 2)
	{
           campo.value = campo.value + ":"; 
    }
	//numero eh de 48 a 57
	else if (key < 48 || key > 57)
    {
                key = 0;
    }
 }
}


function validaHORA(campo)
{
	var Hora = campo.value.substr(0,2);
	var Minuto = campo.value.substr(3,2);
	objVarFocus = campo;
		
	if (campo.value != null && campo.value != '')
	{
		if (Hora < '00' || Hora > '23')
		{
			alert('Campo Hora inválido!');
			setTimeout('objVarFocus.focus()',50);		
			return true;
		}
		if (Minuto < '00' || Minuto > '59')
		{
			alert('Campo Hora inválido!');
			setTimeout('objVarFocus.focus()',50);		
			return true;
		}	
	}
	else
	{
		return true;
		//alert('Campo Hora em branco!');
	}
}

function expanddiv(div){
	div.style.visibility = 'visible';
	div.style.display = '';
}

function closediv(div){
	div.style.visibility = 'hidden';
	div.style.display = 'none';
}

//Função para checar todos
var checkflag = false;
function check(valor) {
	var tb = document.getElementById(valor);
	var fields = tb.getElementsByTagName("input");
    for (i = 0; i < fields.length; i++) {
		if(fields[i].type.toUpperCase() == "CHECKBOX" && fields[i].name != "cbTodos"){
			fields[i].checked = !checkflag;
		}
    }
    checkflag = !checkflag;
    return checkflag;
}

//Função para verificar se houve alteração na tela
function setChange(){
	document.forms[0].txtAlterado.value = 'U';
}

//Função para redirecionar para a tela anterior após alteração na tela
function ckChange(tela){
	if( window.document.getElementById("txtAlterado") != null ){
		if( window.document.getElementById("txtAlterado").value == 'U' ){
			if(confirm("As alterações feitas para o registro serão perdidas. Deseja continuar?")){
				//window.location.href = "UIUsuario_lst.aspx";
				window.location.href = tela;
			}
		} else {
			window.location.href = tela;
		}
	}
}

//Função para verificar se deseja realmente excluir
function ckDelete(){
	
	if (confirm("Deseja realmente excluir esse registro?")){
		//window.document.forms[0].ImageButton2.click();
		window.document.form.btnExcluir.OnClick();
	}
}

//Função para colocar vírgula em campos decimais
function CurMask(sValue,p, e)
{
 //Ex de chamada: onkeyup = "CurMask(this,2);"
 var key;
 var event = e;

 if (!e) var e = window.event;
 if (e.keyCode) key = e.keyCode;       
 else if (e.which) key = event.which;   // Netscape 4.?               //
 else if (e.charCode) key = e.charCode; // Mozilla                  //
 else 
      return true

 if (key != 9)
    {
     CurMask01(sValue,p);			
    }
}

//Currency mask with comma as decimal separator (0.000.000,00)	
function CurMask01(v,p){	
	var a = "";
	var i = 0		
	var x = "";	
	var y = -1;	
	
	a = v.value.replace(",","");	
	while (a.indexOf(".") > 0)
	{
		a = a.replace(".","");	
	}
	if (p==0) y=0;	
	i = a.length - 1;
	if (i >= p)
	{
	//	alert(a);
		while (i >= 0)
		{
		//alert(x + " a(" + i + "):" + a.substr(i,1).toString());	
			if (x.length == p && p != 0)
			{
				x = "," + x;
				y = 0
			}	
			
				
			x = a.substr(i,1).toString() + x;
			if (y>=0) y++;
			i--;
		}
		v.value = PontoMilhar(x);				
	}			
	return;	  	
}

function CurMask2(sValue, p, e)
{ 
 //Ex de chamada: onkeyup = "CurMask2(this, 2, event);"
 var key;
 var event = e;

 if (!e) var e = window.event;
 if (e.keyCode) key = e.keyCode;       
 else if (e.which) key = event.which;   // Netscape 4.?               //
 else if (e.charCode) key = e.charCode; // Mozilla                  //
 else 
      return true

 if (key != 9)
    {
     CurMask02(sValue, p);			
    }
}


//Currency mask with comma as decimal separator (0.000.000,00)	
function CurMask02(v,p){	
	var a = "";
	var i = 0		
	var x = "";	
	var y = -1;	
	
	a = v.value.replace(",","");	
	while (a.indexOf(".") > 0){
		a = a.replace(".","");	
	}
	if (p==0) y=0;	
	i = a.length - 1;
	if (i >= p){
	//	alert(a);
		while (i >= 0){
		//alert(x + " a(" + i + "):" + a.substr(i,1).toString());	
			if (x.length == p && p != 0){
				x = "," + x;
				y = 0
			}			
				
			x = a.substr(i,1).toString() + x;
			if (y>=0) y++;
			i--;
		}
		v.value = x;				
	}			
	return;	  	
}


function PontoMilhar(strValor)
{
	var strDecimais = strValor.substring(strValor.lastIndexOf(","),strValor.length);
	var strSemDecimais = strValor.substring(0,strValor.lastIndexOf(","));
	var strRetorno = "";
	var counter = 0;
	
	for(ipm=strSemDecimais.length-1;ipm >= 0;ipm--)
	{		
		if(counter == 3)
		{
			strRetorno = '.' + strRetorno;
			counter=0;
		}
		strRetorno = strSemDecimais.substr(ipm,1) + strRetorno;	
		counter++;
	}
	
	return (strRetorno + strDecimais);
}

//Função para retirar caracteres que não devem está no campo
function replaceCaracter(aux,Txtin,Txtout){
	    aux = aux.split(Txtin);
	    StringT = aux.join(Txtout);
}

//Função para retirar letras de campos númericos, colocadas através do ctrl+c/ctrl+v
function retiraLetras(campo){
	letras = 'ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvxywz'
	StringT = campo.value;
	for (x=0;x < letras.length; x++){
		replaceCaracter(StringT,letras.charAt(x),'');
	}
	campo.value = StringT;
}

//Função para colocar vírgula


/******* Funcoes para nao inserir caracteres invalidos *******/
/* 34 " 35 # 36 $ 37 % 38 & 39 ' 42 * 43 + 47 / 58 : 59 ; 60 < 61 = 62 > 91 [ 92 \ 93 ]*/
function digitacaoAspas(campo,e){//onkeypress="return digitacaoAspas(this, event);"
	    var keycode;
	    if (window.event) keycode = window.event.keyCode;
	    else if (e) keycode = e.which;
	    else return true;
	    if ((keycode==34) || (keycode==35) || (keycode==36) || (keycode==37) 
			|| (keycode==38) || (keycode==39) || (keycode==42) || (keycode==43) 
			|| (keycode==47) || (keycode==58) || (keycode==59) || (keycode==60) 
			|| (keycode==61) || (keycode==62) || (keycode==91) || (keycode==92)
			|| (keycode==93)) {
			return false; 
		}else{ 
			return true;
		}
}

function validaAspas(campo){//onblur="validaAspas(this.id);"
	    doc = document.getElementById(campo);
	    StringT=doc.value;
	    replaceCaracter(StringT,'\"',' '); //34
	    replaceCaracter(StringT,'#',' ');  //35
	    replaceCaracter(StringT,'$',' ');  //36
	    replaceCaracter(StringT,'%',' ');  //37
	    replaceCaracter(StringT,'&',' ');  //38
	    replaceCaracter(StringT,'\'',' '); //39
	    replaceCaracter(StringT,'*',' ');  //42
	    replaceCaracter(StringT,'+',' ');  //43
	    //replaceCaracter(StringT,'/',' ');  //47
	    replaceCaracter(StringT,':',' ');  //58
	    replaceCaracter(StringT,';',' ');  //59
	    replaceCaracter(StringT,'<',' ');  //60
	    replaceCaracter(StringT,'=',' ');  //61
	    replaceCaracter(StringT,'>',' ');  //62
	    replaceCaracter(StringT,'[',' ');  //91			
	    replaceCaracter(StringT,'\\',' ');  //92			
	    replaceCaracter(StringT,']',' ');  //93			
	    doc.value = StringT;
}

//Funções para exibir ou não botões no relatório
	function alteraDivBotoes(div){
        d = document.getElementById(div);
        d.style.visibility='hidden';
	}
	function showDivBotoes(div){
        d = document.getElementById(div);
        if (d.style.visibility=='hidden' || d.style.visibility == ""){
        	d.style.visibility='visible';
    	}
    }
//Colocar no js     
function maxLengthy(campo, tamanho, e)
{
 var key;
 var event = e;

 if (!e) var e = window.event;
 if (e.keyCode) key = e.keyCode;       
 else if (e.which) key = event.which;   // Netscape 4.?               //
 else if (e.charCode) key = e.charCode; // Mozilla                  //
 else 
      return true

 if (campo.value.length >= tamanho && key != 8 && key != 40 && key != 38 && key != 37 && key != 39 && key != 46)
    {
     campo.value = campo.value.substring(0,tamanho); 
     return false;	  
    }
 return true;
}


function max(campo,tamanho){
campo.value = campo.value.substring(0,tamanho);
}


function Foco(campo){
objVarFocus=campo;
setTimeout('objVarFocus.focus()',50);
}
function Muda(obj)
		{	
				var strIDBasis = document.form.InfoBASIS.value ;   
				var arrLinha = strIDBasis.split('|');
				var objDesc = document.getElementById("repProdutoRel__ctl"+ obj.name.substring(18,obj.name.lastIndexOf(":")) + "_lblTbdesc");
				objDesc.innerHTML = ""
			
				for(x=0; x < arrLinha.length -1;x++)
			    {
					if(obj.selectedIndex + 1  == x && (arrLinha[x] != null || arrLinha[x] != "" || arrLinha[x] != " "))
					{
						arrColuna  = arrLinha[x].split('/');
						
						var strKey = arrColuna[0];
						var str    = arrColuna[1];

						objDesc.innerHTML = str;
						
					}
				}
		}
function calcula(){
		//if (document.getElementById("tbReducao").value == "")
	//	{
	//	document.getElementById("tbReducao").value = "1,00";
	//	}
		if ( document.getElementById("tbBaseCalculo").value != "" && document.getElementById("tbReducao").value != "" )
		{
			if (parseFloat(document.getElementById("tbReducao").value.replace(",",".")) > 1.00) {
				document.getElementById("tbReducao").value = "1,00";
				document.getElementById("tbBaseReduzida").value = (parseFloat(document.getElementById("tbBaseCalculo").value.replace(",",".")) * parseFloat(document.getElementById("tbReducao").value.replace(",",".")));
			document.getElementById("tbBaseReduzida").value = document.getElementById("tbBaseReduzida").value.replace(".",",");
			}
			else
			{
			document.getElementById("tbBaseReduzida").value = (parseFloat(document.getElementById("tbBaseCalculo").value.replace(",",".")) * parseFloat(document.getElementById("tbReducao").value.replace(",",".")));
			document.getElementById("tbBaseReduzida").value = document.getElementById("tbBaseReduzida").value.replace(".",",");
			
			//document.getElementById("tbBaseReduzida").value = 
			}
		}	
}

function submita(){
	form.submit();
}

function chama(){
		document.getElementById("filUpload").click();
}
function chama2(){
		document.getElementById("butUpload").click();
}

//CtrlC CtrlV
function veri(campo) 
{
var ctrl= window.event.ctrlKey;
var tecla=window.event.keyCode;
	
if (ctrl || tecla==17 ){
	return false;
}

}

//trabalhando com Datas




function Dia(Data_DDMMYYYY)
{

string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1)
{
dia = string_data.substring(0,posicao_barra);
return dia;
}
else
{
return false;
}
}

function Mes(Data_DDMMYYYY)
{

string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1)
{
dia = string_data.substring(0,posicao_barra);
string_mes = string_data.substring(posicao_barra+1,string_data.length);
posicao_barra = string_mes.indexOf("/");
if (posicao_barra!= -1)
{
mes = string_mes.substring(0,posicao_barra);
mes = Math.floor(mes);
return mes;
}
else
{
return false;
}

}
else
{
return false;
}
}

function Ano(Data_DDMMYYYY)
{

string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1)
{
dia = string_data.substring(0,posicao_barra);
string_mes = string_data.substring(posicao_barra+1,string_data.length);
posicao_barra = string_mes.indexOf("/");
if (posicao_barra!= -1)
{
mes = string_mes.substring(0,posicao_barra);
mes = Math.floor(mes);
ano = string_mes.substring(posicao_barra+1,string_mes.length);
return ano;
}
else
{
return false;
}

}
else
{
return false;
}
}

function Calcula_Dias(data1_DDMMYYYY,data2_DDMMYYYY){
	Var_Dia1=Dia(data1_DDMMYYYY);
	Var_Mes1=Mes(data1_DDMMYYYY);
	Var_Mes1=Math.floor(Var_Mes1)-1;
	Var_Ano1=Ano(data1_DDMMYYYY);
	var data1 = new Date(Var_Ano1,Var_Mes1,Var_Dia1);

	Var_Dia2=Dia(data2_DDMMYYYY);
	Var_Mes2=Mes(data2_DDMMYYYY);
	Var_Mes2=Math.floor(Var_Mes2)-1;
	Var_Ano2=Ano(data2_DDMMYYYY);
	var data2 = new Date(Var_Ano2,Var_Mes2,Var_Dia2);
	
	var diferenca = data1.getTime() - data2.getTime();
	var diferenca = Math.floor(diferenca / (1000 * 60 * 60 * 24));
	
	return diferenca;
}

function colocaZeroAposVirgula(campo){
	valor = campo.value;
	if (valor.indexOf(',') >= 1){
		x = valor.substring(valor.indexOf(','),valor.lenght - 1);
		while (valor.length < 3){
			x = x + '0';
		}
		valor = valor + x;		
	}else{
		valor = valor + ',00';
	}
	campo.value = valor;
}

function Desbloquia(chk)
	{
	
		var objChka = document.getElementById("rpBTef__ctl0_chkAV");

		var i = 1;
		
		while(objChka != null)
		{
			objChka.checked = false;				
			
			objChka = document.getElementById("rpBTef__ctl" + i.toString() + "_chkAV");
			i++;
		}
		chk.checked=true;
}

function DesbloquiaUnico(chk)
	{
		var objChka = document.getElementById("dlPag__ctl0_chkAb");
		var objChk2 = document.getElementById("dlPag__ctl0_chk2b");
		var objChk3 = document.getElementById("dlPag__ctl0_chk3b");
		var i = 1;
		
		while(objChka != null)
		{
			
			objChka.checked = false;				
			objChka = document.getElementById("dlPag__ctl" + i.toString() + "_chkAb");
			i++;
		}
		i=0;
		while(objChk2 != null)
		{
			objChk2.checked = false;				
			
			objChk2 = document.getElementById("dlPag__ctl" + i.toString() + "_chk2b");
			i++;
		}
		i=0
		while(objChk3 != null)
		{
			objChk3.checked = false;				
			
			objChk3 = document.getElementById("dlPag__ctl" + i.toString() + "_chk3b");
			i++;
		}
		chk.checked=true;
}


function LimpaPag()
	{
	
		var objChka = document.getElementById("dlPag__ctl0_chkAb");
		var objChk2 = document.getElementById("dlPag__ctl0_chk2b");
		var objChk3 = document.getElementById("dlPag__ctl0_chk3b");
		var i = 1;
		

		while(objChka != null)
		{
			
			objChka.checked = false;				
			objChka = document.getElementById("dlPag__ctl" + i.toString() + "_chkAb");
			i++;
		}
		i=0;
		while(objChk2 != null)
		{
			objChk2.checked = false;				
			
			objChk2 = document.getElementById("dlPag__ctl" + i.toString() + "_chk2b");
			i++;
		}
		i=0
		while(objChk3 != null)
		{
			objChk3.checked = false;				
			
			objChk3 = document.getElementById("dlPag__ctl" + i.toString() + "_chk3b");
			i++;
		}
}

function LimpaPagBOF()
	{
	
		var objChka = document.getElementById("rpBTef__ctl0_chkAV");
		var i = 1;
						
		while(objChka != null)
		{
			objChka.checked = false;				
			objChka = document.getElementById("rpBTef__ctl" + i.toString() + "_chkAV");
					
			i++;
				
			
		}
		i=0;
}


function daAutoPostBack(){
	document.form.submit();
}

 function GetItem( strValue )
{
if( window.document.getElementById("txthfilter") != null )
{
window.document.getElementById("txthfilter").value = strValue;
window.document.forms[0].submit();
}
}

function ddLinha(intLinha)
{
	oFrame = document.getElementById("iframe");
	oFrame.src = "UIPedidoListaPrecoProdutos_lista.aspx?Linha=" + intLinha;
}


function NextField(field,qt,nxt)
{

if(field.value.length == qt)
{
objVarFocus=field;
setTimeout('objVarFocus.focus()',50);
}
}

function volumePontos()
{	

	var repItens = document.form.RpCodProdCount.value;

	objVP = document.form.tbVP;
	objVP.value = 0;

	for(x=0;x <= repItens;x++)
	{
		objVPItem = document.getElementById("RpLinhaProd1__ctl" + x + "_lblVP");
		objQTDEItem = document.getElementById("RpLinhaProd1__ctl" + x + "_tbQtd");
		if ((objVPItem != null) && (objQTDEItem != null)){
			if (objVPItem.innerHTML == undefined || objVPItem.innerHTML == null || objVPItem.innerHTML == "" ) objVPItem.innerHTML=0;
		
				if (!(isNaN(parseFloat(objQTDEItem.value))))
				{	
								
				QTDE = new Number(objQTDEItem.value);
				VP = new Number(objVPItem.innerHTML.replace(",","."));
				VPTOTAL = new Number(objVP.value.replace(",","."));
									
				numero = new Number(VPTOTAL + (QTDE * VP));
				objVP.value = numero.toFixed(2).replace(".",",");
			
				}	
			}
		}	
}

function volumePontosSKU()
{	
	
	var repItens = document.form.RpCodProdCount.value;

	objVP = document.form.tbVP;
	objVP.value = 0;
	
	for(x=0;x <= repItens;x++)
	{
		objVPItem = document.getElementById("RpLinhaProd1__ctl" + x + "_lblVP");
		objQTDEItem = document.getElementById("RpLinhaProd1__ctl" + x + "_tbQtd");

		if ((objVPItem != null) && (objQTDEItem != null)){
			if (objVPItem.innerHTML == undefined || objVPItem.innerHTML == null || objVPItem.innerHTML == "" ) objVPItem.innerHTML=0;
		
				if (!(isNaN(parseFloat(objQTDEItem.value))))
				{	
							
				QTDE = new Number(objQTDEItem.value);
				VP = new Number(objVPItem.innerHTML.replace(",","."));
				VPTOTAL = new Number(objVP.value.replace(",","."));
				
				numero = new Number(VPTOTAL + (QTDE * VP));
				
				objVP.value = numero.toFixed(2).replace(".",",");
				}	
			}
		}	
	}

function PromoBloqQTDE(obj)
{

	var strSKU = document.getElementById("RpLinhaProd1__ctl"+ obj.name.substring(17,obj.name.lastIndexOf(":")) + "_lblSku").innerHTML; 
	var strPromoBloq = document.form.promoINF.value;
	var arrLinha = strPromoBloq.split("|ROW|");

	if (obj.value.length <= 0 || obj.value == "0") return;

	for(idxPB=0;idxPB < arrLinha.length;idxPB++)
	{
		if(strSKU == arrLinha[idxPB].split("|COL|")[0] && (!(arrLinha[idxPB].split("|COL|")[0] == "" || arrLinha[idxPB].split("|COL|")[0] == null )) )
		{
			
			var arrColuna = arrLinha[idxPB].split("|COL|");
			var strMsg = "";
							
			if (arrColuna[1].length > 0) 
			{
				//Bloqueio
				strMsg += arrColuna[1];
				obj.value = "";
			}	
			
			if (arrColuna[2].length > 0) 
			{
				//Promoção
				strMsg += '\n' + arrColuna[2];
			}
						
			if(strMsg.length > 0)alert(strMsg);
			break;
		}
	}
	
}

function PromoBloqQTDESKU(obj){
	var strSKU = document.getElementById("RpLinhaProd1__ctl"+ obj.name.substring(17,obj.name.lastIndexOf(":")) + "_tbSku").value; 
	strSKU = strSKU.toUpperCase();
	var strPromoBloq = document.form.promoINF.value;
	var arrLinha = strPromoBloq.split("|ROW|");
	if (obj.value.length <= 0 || obj.value == "0") return;
	
	for(idxPB=0;idxPB < arrLinha.length;idxPB++)	{
		if(strSKU == arrLinha[idxPB].split("|COL|")[0] && (!(arrLinha[idxPB].split("|COL|")[0] == "" || arrLinha[idxPB].split("|COL|")[0] == null )) )	{
			
			var arrColuna = arrLinha[idxPB].split("|COL|");
			var strMsg = "";
							
			if (arrColuna[1].length > 0) {
				//Bloqueio
				strMsg += arrColuna[1];
				obj.value = "";
			}	
			
			if (arrColuna[2].length > 0) {
				//Promoção
				strMsg += '\n' + arrColuna[2];
			}
						
			if(strMsg.length > 0)alert(strMsg);
			break;
		}
	}
}

function MudaProd(obj)
{
alert("a");
	var objLink = document.getElementById("RpLinhaProd1__ctl"+ obj.name.substring(18,obj.name.lastIndexOf(":")) + "_linkPd");
	//objLink.innerHTML = arrColuna[2];
	
	objLink.href = '/HRBL/ui/UICatalogo_lista.aspx?id_pd=' + obj.text;					
}


function ValidConfirm()
{
	ErrorClear('lblErro');
	Page_ValidationActive = true;
	Page_ClientValidate();

}

function foco(campo)
{
	setTimeout('window.document.getElementById(campo).focus()',50);
}

function BloqEnter(e)
{
 var key;
 var event = e;

 if (!e) var e = window.event;
 if (e.keyCode) key = e.keyCode;       
 else if (e.which) key = event.which;   // Netscape 4.?               //
 else if (e.charCode) key = e.charCode; // Mozilla                  //
 else 
      return true

 if(key == 13)
   return false;
 else
   return true;				
}


function AbreJanela(arquivo, tamx, tamy){
	window.open(arquivo,"","resizable=no,toolbar=auto,status=no,menubar=no,scrollbars=no,width=" + tamx + ",height=" + tamy)
}

function AbreJanelaREP(obj){
	var a = obj.toString();
	arquivo = 'UICatalogo_lista.aspx?id_pd=' + a.toString();
	window.open(arquivo,"","resizable=no,toolbar=auto,status=no,menubar=no,scrollbars=no,width=" + 500 + ",height=" + 560)
}

function AbreJanelaREP2(sku){
	//objSKU = document.getElementById("RpLinhaProd1__ctl" + x + "_tbSku");
	//alert(obj);
	//var a = obj.toString();
	//alert(objSKU);
	//alert(sku);
	arquivo = 'UICatalogo_lista.aspx?id_pd=' + sku.name;
	//alert(arquivo);
	window.open(arquivo,"","resizable=no,toolbar=auto,status=no,menubar=no,scrollbars=no,width=" + 500 + ",height=" + 600)
}

function preventDoubleClick(){
	alert(submitted);
	if (submitted){
		alert("Sua requisição já está sendo processada.  Aguarde...");
		return false;
	}
	submitted=true;
    return true;
}