function alteraquantidade(url,quantidade,idItem)
	{
		window.location.href=url+"?quantidade="+quantidade+"&id="+idItem;
	}
function excluir(url,id)
	{
		if(confirm("Você tem certeza que deseja excluir este item de seu carrinho?"))
			{
				window.location.href=url+"?id="+id;
				return true;
			}else
				{
					return false;	
				}
	}
	
//--------------------------------------------------INÍCIO FUNÇÕES DE MÁSCARA
function mask(cnpj,tMask,valor,evento)
	{
		if(tMask.length>14)
			{
				return MascaraCNPJ(cnpj,valor,evento);	
			}
			else
				{
					return MascaraCPF(cnpj,valor,evento);	
				}
	}
function vCNPJ_CPF(vl)
	{
		var objVl=vl.value.length;
		if(objVl>14)
			{
				return ValidarCNPJ(vl);
			}
			else
				{
					return ValidarCPF(vl);
				}
	}
function MascaraCNPJ(cnpj,valor,evento){
	if(mascaraInteiro(evento)==false){
        evento.returnValue = false;
    }
    return formataCampo(cnpj, '00.000.000/0000-00', evento);
}
//adiciona mascara ao CPF
function MascaraCPF(cpf,valor,evento){
    if(mascaraInteiro(evento)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', evento);
}
//adiciona mascara de cep
function MascaraCep(cep, evento){
        if(mascaraInteiro(cep)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cep, '00.000-000', evento);
}

//adiciona mascara de data
function MascaraData(data,evento){
    if(mascaraInteiro(data)==false){
        evento.returnValue = false;
    }    
    return formataCampo(data, '00/00/0000', evento);
}

//adiciona mascara ao telefone
function MascaraTelefone(tel, evento){    
    if(mascaraInteiro(tel)==false){
        evento.returnValue = false;
    }
	if(tel.value!="")
		{
    		return formataCampo(tel, '(00) 0000-0000', evento);
		}
		else
			{
				tel.value="";	
			}
}
//valida telefone
function ValidaTelefone(tel){
    if(tel.value!="")
		{
		exp = /\(\d{2}\)\ \d{4}\-\d{4}/
		if(!exp.test(tel.value))
			{
			return false;
			}
		}
		else
			{
				return true;	
			}
}

//valida CEP
function ValidaCep(cep){
    exp = /\d{2}\.\d{3}\-\d{3}/
    if(!exp.test(cep.value))
		{
        	return false;
		}
		else
			{
				return true;	
			}
}

//valida data
function ValidaData(data){
    exp = /\d{2}\/\d{2}\/\d{4}/
    if(!exp.test(data.value))
        alert('Data Invalida!');            
}
//valida o CPF digitado
function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" );
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
	if(cpf=="") 
		{
			alert("O campo CNPJ/CPF é obrigatório, por favor preencha-o!");
			Objcpf.focus();
			return false;
		}
	if((cpf=="00000000000") || (cpf=="11111111111") || (cpf=="22222222222") || (cpf=="33333333333") || (cpf=="44444444444") || (cpf=="55555555555") || (cpf=="66666666666") || (cpf=="77777777777") || (cpf=="88888888888") || (cpf=="99999999999"))
		{
			alert("CPF Inválido, tente novamente!");
			Objcpf.value="";
			Objcpf.focus();
			return false;
		}
	if(cpf.length!=11)
		{
			alert("CPF Inválido, tente novamente!");
			Objcpf.value="";
			Objcpf.focus();
			return false;
		}	
		  var a = [];
		  var b = new Number;
		  var c = 11;
		  for (i=0; i<11; i++)
			{
			   a[i] = cpf.charAt(i);
			   if (i < 9)
					{ 
						b += (a[i] * --c);
					}
			}
		  if ((x = b % 11) < 2)
			{ 
				a[9] = 0;
			} 
			else
				{ 
				a[9] = 11-x;
				}
			b = 0;
			c = 11;
		   for (y=0; y<10; y++)
				{ 
					b += (a[y] * c--);
				}
		  if ((x = b % 11) < 2)
				{ 
					a[10] = 0;
				}
				else
				{
					a[10] = 11-x;
				}
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]))
		{
        alert("CPF Inválido, tente novamente!");
			Objcpf.value="";
			Objcpf.focus();
			return false;       
		}
}

//valida numero inteiro com mascara
function mascaraInteiro(evento){
    if (evento.keyCode < 48 || evento.keyCode > 57){
        evento.returnValue = false;
        return false;
    }
    return true;
}

//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
    var cnpj = ObjCnpj.value;
    var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
    var dig1= new Number;
    var dig2= new Number;
    
    exp = /\.|\-|\//g
    cnpj = cnpj.toString().replace( exp, "" );
    var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
	if(cnpj=="") 
		{
			alert("O campo CNPJ/CPF é obrigatório, por favor preencha-o!");
			Objcpf.focus();
			return false;
		}
	if((cnpj=="00000000000000") || (cnpj=="11111111111111") || (cnpj=="22222222222222") || (cnpj=="33333333333333") || (cnpj=="44444444444444") || (cnpj=="55555555555555") || (cnpj=="66666666666666") || (cnpj=="77777777777777") || (cnpj=="88888888888888") || (cnpj=="99999999999999"))
		{
			alert("CNPJ Inválido, tente novamente!");
			ObjCnpj.value="";
			ObjCnpj.focus();
			return false;
		}
	if(cnpj.length!=14)
		{
			alert("CNPJ Inválido, tente novamente!");
			ObjCnpj.value="";
			ObjCnpj.focus();
			return false;
		}
    for(i = 0; i<valida.length; i++){
        dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);    
        dig2 += cnpj.charAt(i)*valida[i];    
    }
    dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
    dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
    
    if(((dig1*10)+dig2) != digito)
		{
			alert("CNPJ Inválido, tente novamente!");
			ObjCnpj.value="";
			ObjCnpj.focus();
			return false;
		}
        
}
function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, 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;    
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
    	return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
 
 
    if (strCheck.indexOf(key) == -1) 
    	return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
        	break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
        	aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) 
    	objTextBox.value = '';
    if (len == 1) 
    	objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
    	objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}
//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) {
    var boleanoMascara;
    
    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace( exp, "" );
  
    var posicaoCampo = 0;    
    var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;;
    
    if (Digitato != 8) { // backspace
        for(i=0; i<= TamanhoMascara; i++) {
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/"))
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(")
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
            if (boleanoMascara) {
                NovoValorCampo += Mascara.charAt(i);
                  TamanhoMascara++;
            }else {
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);
                posicaoCampo++;
              }          
          }    
        campo.value = NovoValorCampo;
          return true;
    }else {
        return true;
    }
}
//------------------------------------------------------FIM FUNÇÕES DE MÁSCARAS DE CAMPOS
function aparecetr(tr)
	{
		if(document.getElementById(tr).style.visibility == 'visible')
			{
				document.getElementById(tr).style.visibility = 'hidden';
			}else
				{
					document.getElementById(tr).style.display = 'visible';
				}
								 
	}
	
function vEntrega()
	{
		var d=document.endentrega;
		if(d.logradouroentrega.value=="")
			{
				alert("Preencha o Logradouro para entrega!");
				d.logradouroentrega.focus();
				return false;
			}
		if(d.numeroentrega.value=="")
			{
				alert("Preencha o número para entrega!");
				d.numeroentrega.focus();
				return false;
			}
		if(d.bairroentrega.value=="")
			{
				alert("Preencha o bairro para entrega!");
				d.bairroentrega.focus();
				return false;
			}	
	}