// JavaScript Document

function ajaxInit() {
	var req;
	try {
		 req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		 try {
			  req = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch(ex) {
		 try {
		   req = new XMLHttpRequest();
	     } catch(exc) {
	 		  alert("Esse browser não tem recursos para uso do Ajax");
	  		 req = null;
	     }
	 }
}
return req;
}

function carregaCombo(url, codigo, id) {
	//alert(url + "?tipo=" + tipo)
	ajax = ajaxInit();
	if(ajax) {
		ajax.open("GET",url + "?codigo=" + codigo, true);
		
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById(id).innerHTML = ajax.responseText;
				}else{
					alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
	}
}

function carregaComboCategoria(url, codigo, codProd, id) {
	//alert(url + "?tipo=" + tipo)
	ajax = ajaxInit();
	if(ajax) {
		ajax.open("GET",url + "?codProd=" + codProd + "&codigo=" + codigo, true);
		
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById(id).innerHTML = ajax.responseText;
				}else{
					alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
	}
}



//funções para menu suspenso
function pegaDados(codigo,controle,submenu,menu){
	conter = document.getElementById(controle).value;
	if (conter=="1"){
		h=100;
		document.getElementById(controle).value="0";
		document.getElementById(submenu).padding="0px";
		document.getElementById(submenu).style.lineHeight="0px";
		document.getElementById(submenu).style.display="none";
		
	}else{
		h=0;
		document.getElementById(controle).value="1";
		document.getElementById(submenu).style.lineHeight="normal";
		document.getElementById(submenu).style.display="";
		document.getElementById(controle).value="1";
	}
}

function checadoTodos(qtd,name,namehidden)
{
	
	quantidade  = qtd;
	valor = 0;
	if (document.getElementById(name).checked == true)
	{
		document.getElementById(namehidden).value= "";
		for(i=1; i<=quantidade; i++)
		{
			document.getElementById("c_"+i).checked = true;
			valor = document.getElementById("c_"+i).value;
			document.getElementById(namehidden).value += valor+"|";
		}
	}
	else
	{
		for(i=1; i<=quantidade; i++)
		{
			document.getElementById("c_"+i).checked = false;
			document.getElementById(namehidden).value = "";
		}
	}
}

function checadoTodos2(qtd,name,id)
{
	quantidade  = qtd;
	valor = 0;
	if (document.getElementById(name).checked == true)
	{
		for(i=1; i<=quantidade; i++)
		{
			document.getElementById(id+i).checked = true;
		}
	}
	else
	{
		for(i=1; i<=quantidade; i++)
		{
			document.getElementById(id+i).checked = false;
		}
	}
}

function checado(name, cod, id)
{
	novoCod="";
	if(document.getElementById(name).checked){
		document.getElementById(id).value += cod+"|"; 
	}
	if(document.getElementById(name).checked==false){
		valores = document.getElementById(id).value;
		document.getElementById(id).value="";
		codigos = valores.split("|");
		
		for (i=0;i<=codigos.length-2;i++){
			
			if(codigos[i] != cod){
				novoCod = novoCod+codigos[i]+"|";
				document.getElementById(id).value=novoCod;
			}
		}
	}
}
function isInt(id)
{
   	element = document.getElementById(id)
	var str = /^\d+$/;
	return str.test(valor_text);
}


function formatar(id, mask)
{
	src = document.getElementById(id);
	var i = src.value.length;
  	var saida = mask.substring(0,1);
  	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida)
  	{
    	src.value += texto.substring(0,1);
  	}
}
function formatarFone(id)
{
	src = document.getElementById(id);
	var i = src.value.length;
	if(i==1)
	{
		src.value = "(" + src.value;
	}
	if(i==3)
	{
		src.value = src.value + ") " 
	}
	if(i==9)
	{
		src.value = src.value + "-" 
	}
	
	
}
function formatarValor(id)
{
	obj = document.getElementById(id)
	valor_aux = obj.value;
	if( valor_aux != "")
	{
		if(isFloat(valor_aux) == true)
		{
			pos = valor_aux.search(",");
			if(pos != -1)
			{
				vet_valor = valor_aux.split(",");
				valor = vet_valor[0];
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor = valor * 100;
				valor = valor / 100;
				valor = new String(valor);	
				if(valor != "")
				{
					if (vet_valor[1].length == 2)
					{
						valor = formataFloatPonto(valor) + "," + vet_valor[1];
						document.getElementById(id).value = valor;
					}
					else
					{
						if (vet_valor[1].length > 2)
						{
							vet_valor[1] = vet_valor[1].substring(0,2);	
							valor = formataFloatPonto(valor) + "," + vet_valor[1]
							document.getElementById(id).value = valor;
						}
						else
						{
							valor = formataFloatPonto(valor) + "," + vet_valor[1] + "0"	
							document.getElementById(id).value = valor;
						}
					}
				}
				else
				{
					valor = formataFloatPonto(valor) + ",00"; 
					document.getElementById(id).value = valor;
				}
			}
			else
			{
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				obj = document.getElementById(id);
				obj.value = formataFloatPonto(valor_aux) + ",00"
				
			}
		}
	}
	
}
function formataFloatPonto(valorParam)
{
	valor = valorParam;	
	tam_vet = parseInt(valor.length / 3)
	var vet_aux = new Array();				
	cont = 0;
	contVet = 0
	if (valor != "")
	{
		if (valor.length > 3)
		{
				
			for(i=valor.length;i>0;i--)
			{
				if( ( cont % 3 == 0)  && (cont > 0) )
				{
					vet_aux[contVet] = i;
					contVet = contVet + 1;
				}	
				cont = cont + 1
			}
			for(i=0;i<vet_aux.length;i++)
			{
				valor = valor.substring(0,vet_aux[i]) + "." + valor.substring(vet_aux[i],valor.length);				
			}
			
		}
	}
	else
	{
		valor = "0";
	}
	return valor
}

function insNumeric(obj,event)
{
	if(obj.id == "cep1")
	{
		maxLengh = 5
		if( $.browser.msie )
		{
			setTimeout(function(){
				if( obj.value.length == 5)
				{
					document.getElementById("cep2").focus();	
				}
			},300)
			
		}
		else
		{		
			if( obj.value.length == maxLengh)
			{
				document.getElementById("cep2").focus();	
			}
		}
	}
	
	var tecla = event.charCode;
    var ie = event.keyCode;
    if (!event) event = window.event;
    var code;
    if (event.keyCode) code = event.keyCode;
    else if (event.which) code = event.which; // Netscape 4.?
//se nao for número nem parentesis ou espaço
	if( code==13 )
	{
		event.returnValue = true;
		return true;	
	}
	else
	{
		if ((code < 48 || code > 59) && (code != 8 ) ){
		  event.returnValue = false;
		  if (event.which){
			event.preventDefault();
		  }
		  return false;
		}else{
		  event.returnValue = true;
		  return true;
		}
	}    
}
function insFloat(obj,event)
{
    var tecla = event.charCode;
    var ie = event.keyCode;
    if (!event) event = window.event;
    var code;
    if (event.keyCode) code = event.keyCode;
    else if (event.which) code = event.which; // Netscape 4.?
//se nao for número nem parentesis ou espaço
    if ((code < 48 || code > 59) && (code != 8 ) & (code != 44)){
      event.returnValue = false;
      if (event.which){
        event.preventDefault();
      }
      return false;
    }else{
      event.returnValue = true;
      return true;
    }
 } 

function isFloat(valor)
{
	var valor_text = valor;
	var str = /^[+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+)$/;
	return str.test(valor_text);
}

function pegarHora(campo){
	hora = new Date;
	wHora = hora.getHours();
	wMin = hora.getMinutes();
	if(wMin < 10){
		wMin = "0" + wMin;
	}
	wSec = hora.getSeconds();
	if(wSec < 10){
		wSec = "0" + wSec;
	}
	
	//wHoraF = wHora +":"+ wMin +":"+ wSec;
	wHoraF = wHora +":"+ wMin;
	
	document.getElementById(campo).innerHTML = wHoraF;
	
	setTimeout("pegarHora('"+campo+"')",1);
}
function pegarData(){
	var nomeDia;
	data = new Date;
	dia  = data.getDay();
	mes = data.getMonth();
	ano = data.getFullYear();
	
	switch(dia){
		case 0:
			nomeDia = "Domingo";
		case 1:
			nomeDia = "Segunda-feira";
		case 2:
			nomeDia = "Terça-feira";
		case 3:
			nomeDia = "Quarta-feira";
		case 4:
			nomeDia = "Quinta-feira";
		case 5:
			nomeDia = "Sexta-feira";
		case 6:
			nomeDia = "Sábado";
	}
	
	switch(mes){
		case 0:
			nomeMes = "janeiro";
		case 1:
			nomeMes = "fevereiro";
		case 2:
			nomeMes = "março";
		case 3:
			nomeMes = "abril";
		case 4:
			nomeMes = "maio";
		case 5:
			nomeMes = "junho";
		case 6:
			nomeMes = "julho";
		case 7:
			nomeMes = "agosto";
		case 8:
			nomeMes = "setembro";
		case 9:
			nomeMes = "outubro";
		case 10:
			nomeMes = "novembro";
		case 11:
			nomeMes = "dezembro";
	}
	
	campoData = document.getElementById("data_semana");
	campoData.innerHTML = nomeDia +", "+ dia +" de "+ nomeMes +" de "+ ano +".";	
}



function janelaForm(largura,altura,url)
{
	winDt = window.open(url,'','top=300,left=150,width='+ largura +',height='+ altura +',scrollbars=1,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1');
	winDt.focus();
}
function salvarForm()
{
	document.getElementById("form").submit();	
}

function excluirReg(url)
{
	urlRetornoAlert=url;
	confirm("Deseja realmente excluir o registro?")
}
function fechar()
{
	close();
}
function salvar(id)
{
	document.getElementById(id).submit();	
}

function abrirMenu(wcontrole)
{
	$("#"+wcontrole).slideToggle("normal")
}


function horaImpressao()
{
	data_aux = new Date;
	whora = data_aux.getHours()
	wminuto = data_aux.getMinutes()
	
	dia = data_aux.getDate();
	mes = data_aux.getMonth();
	mes = parseInt(mes) + 1;
	ano = data_aux.getFullYear();
	if (dia < 10)
	{
		dia = "0" + dia;
	}
	if (mes < 10)
	{
		mes = "0" + mes;
	}
	if (whora < 10)
	{
		whora = "0" + whora;
	}
	if (wminuto < 10)
	{
		wminuto = "0" +wminuto;
	}
	
	obj = document.getElementsByTagName("span");
	
	for (i=0;i<obj.length;i++)
	{
		
		if (obj[i])
		{
			if (obj[i].className == "hora")
			{
				obj[i].innerHTML = dia + "/" + mes + "/" + ano + " " + whora + ":" + wminuto;
			}
		}
	}		
	
}

function janelaExterna(url)
{
	winDt = window.open(url,'','width='+ window.width +',height='+ window.height +',scrollbars=1,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1');
	winDt.focus();
}

function calculaParcela(codigo)
{
	wvalor = $("#lente").val().split("|")[1]
	if( $("#lente").val() == "")
	{
		wvalor = "0"	
	}
	url = "carrega_parcelas.asp?tipo=c&codigo="+codigo+"&valorLente="+wvalor
	carregaParcela(url,'parcCartao')
	setTimeout(function(){
		url = "carrega_parcelas.asp?tipo=b&codigo="+codigo+"&valorLente="+wvalor
		carregaParcela(url,'parcBoleto')					
	},500)
	
	
}
function mostraFormaPag(id_div)
{
	if( $("#"+id_div).is(":hidden") )
	{
		$("#"+id_div).show("slow")	
	}
	else
	{
		$("#"+id_div).hide("slow")
	}
}


function mostraMenu(id)
{
	var idImg = id;
	var idMenu = id.replace("img", "menu");
	
	if( $("#"+idMenu).is(":hidden") )
	{
		$("#"+idMenu).show("slow")	
		$("#"+idImg).attr("src","imagens/seta_direita.gif")
	}
	else
	{
		$("#"+idMenu).hide("slow")
		$("#"+idImg).attr("src","imagens/seta_baixo.gif")
	}
}
function carregaParcela(url, id) {
	//alert(url + "?tipo=" + tipo)
	ajax = ajaxInit();
	if(ajax) {
		ajax.open("GET",url, true);
		
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById(id).innerHTML = ajax.responseText;
				}else{
					alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
	}
}

function selecionaFrete(tipo,valor_frete,valor_total){
	document.getElementById('totalmostra').value='R$ ' + valor_total;
	document.getElementById('totalenvia').value=valor_total;
	document.getElementById('freteenvia').value=valor_frete;
	document.getElementById('freteescolhido').value='R$ ' + valor_frete;
	document.getElementById('tipo_frete').value=tipo;

	if(document.getElementById('tipofretel')){
		document.getElementById('tipofretel').value=tipo;
		document.getElementById('valorfretel').value=valor_frete;
		document.getElementById('valortotall').value=valor_total;
	}
	document.getElementById("freteCalculado").value = "S"
}

function calculaFrete()
{
	
	if(document.getElementById("cep1").value != "" && document.getElementById("cep2").value != "")
	{
		document.getElementById('labelTotal').childNodes[0].nodeValue = "R$0,00"
		document.getElementById('valorTotal').value="";
		document.getElementById('valorFrete').value="";
		
		var  cep1 = document.getElementById("cep1").value
		var cep2 = document.getElementById("cep2").value
		var peso  = document.getElementById("peso").value
		var preco = document.getElementById("valor").value
		
		wurl = "calc_frete.asp?cep1=" + cep1 + "&cep2="+cep2 + "&peso="+ peso + "&valor=" + preco
		
		document.getElementById("calcFrete").innerHTML = "<img src='imagens/ajax-loader.gif'>"
		carregaCombo(wurl,"calcFrete")	
		
	}
	else
	{
		alert("Atenção, preencha o campo CEP")		
	}
}
function verSelecao()
{
  obj = document.getElementsByTagName("input")
  for(i=0;i<obj.length;i++)
  {
	  if( obj[i].type == "radio" && obj[i].checked == true)
	  {
		  obj[i].click();		
		  
	  }
  }
  
}
function janelaCorreios(wurl)
{
	
	winDt = window.open(wurl,'','left=100,width=800,scrollbars=1,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1');
	winDt.focus();
	
}

function mudaCateg(categoria, divId, divId2){
	wcat = categoria;
	wdiv = document.getElementById(divId);
	wdiv2 = document.getElementById(divId2);
	if(wcat == 1){
		wdiv.style.display = 'block';
	}else{
		wdiv.style.display = 'none';
	}
	
	if(wcat != 1){
		wdiv2.style.display = 'block';
	}else{
		wdiv2.style.display = 'none';
	}
}

function inserirLenteProd(idAtual,idProxima)
{
	obj = $("#"+idAtual+" input,#"+idAtual+" textarea")
	erro = false;
	//objFocus = $("#"+idAtual)
	for(i=0;i<obj.length;i++)
	{
		
		if( obj[i].value == "" )
		{
			alert("Preencha o campo " + obj[i].title)
			erro = true
			objFocus = obj[i]
			break
			
		}
	}
		
	
	if(erro == false && validaValorFloat() == true)
	{
		id = "#"+ idProxima
		$(id).css("display","block")
		
	}
	
}
function retirarLenteProd(idAtual)
{
	
	$("#"+idAtual).css("display","none")
	obj = $("#"+idAtual+" input,#"+idAtual+" textarea")
	
	for(i=0;i<obj.length;i++)
	{
		obj[i].value = "" 
	}
}
function iniciar()
{
	obj = $(".labelDet")
	for(i=0;i<=obj.length;i++)
	{
		$("#mostraAjuda_"+i).click(function () { 
			
			 if( $("#"+$(this).attr("id").replace("mostraAjuda","ajuda")).is(":hidden"))
			 {
				$("#"+$(this).attr("id").replace("mostraAjuda","ajuda")).show("normal");
			 }
			 else
			 {
				$("#"+$(this).attr("id").replace("mostraAjuda","ajuda")).hide("normal");	 
			 }
			
			
		});
		
		$("#fechar_"+i).click(function () { 
			$("#"+$(this).attr("id").replace("fechar","ajuda")).hide("normal");
		})
		
	}
	
	obj = $(".labelDet")
	for(i=0;i<=obj.length;i++)
	{
		$("#mostraFormas_"+i).click(function () { 
			 //alert("aki")
			 if( $("#"+$(this).attr("id").replace("mostraFormas","mostraFormasDiv")).is(":hidden"))
			 {
				$("#"+$(this).attr("id").replace("mostraFormas","mostraFormasDiv")).show("normal");
			 }
			 else
			 {
				$("#"+$(this).attr("id").replace("mostraFormas","mostraFormasDiv")).hide("normal");	 
			 }
		});
		
		$("#fecharFormasDiv_"+i).click(function () {
			$("#"+$(this).attr("id").replace("fecharFormasDiv","mostraFormasDiv")).hide("normal");
		})
		
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function carregaItensProd()
{
	$(".exibeItens").click(function(){
		idItem = $(this).attr("id")
		if( $("#"+idItem.replace("titCateg_","categ_")).is(":hidden") )
		{
			$("#"+idItem.replace("titCateg_","categ_")).slideDown()
			$("#"+idItem.replace("titCateg_","img_")).attr("src","imagens/seta_cima.jpg")
			$("#"+idItem.replace("titCateg_","img_")).attr("alt","Clique para ocultar")
			$("#"+idItem.replace("titCateg_","img_")).attr("title","Clique para ocultar")
		}
		else
		{
			$("#"+idItem.replace("titCateg_","categ_")).slideUp()
			$("#"+idItem.replace("titCateg_","img_")).attr("src","imagens/seta_baixo.jpg")
			$("#"+idItem.replace("titCateg_","img_")).attr("alt","Clique para exibir")
			$("#"+idItem.replace("titCateg_","img_")).attr("title","Clique para exibir")
		}
		
	})
}

function verifCheck(campo1, campo2){
	if(document.getElementById(campo1).checked == true){
		document.getElementById(campo2).style.display = "";
	}else{
		document.getElementById(campo2).style.display = "none";
	}
}

function carregaUrlExterna()
{
	$(".novaJanela").click(function(){
		wurl = $(this).attr("href")
		janelaExterna(wurl)
		return false
	})
		
}

function ver_parcelamento(valor, divId){
	wvalor = valor;
	wdiv = document.getElementById(divId);
	if(wvalor == "S"){
		wdiv.style.display = 'block';
	}else{
		wdiv.style.display = 'none';
	}
}
function check_orcamento(id, cod_item){
	codItem = cod_item
	location.href='cesta.asp?solicita=ok&add_receita='+codItem;
}

function mudaDivePag(valor, divId){
	wvalor = valor;
	wdiv = document.getElementById(divId);
	if(wvalor == "visa"){
		wdiv.style.display = 'block';
		document.getElementById('visa_1').checked = 'checked';
	}else{
		document.getElementById('div_visa').style.display = 'none';
	}
	if(wvalor == "master"){
		wdiv.style.display = 'block';
		document.getElementById('master_1').checked = 'checked';
	}else{
		document.getElementById('div_master').style.display = 'none';
	}
	if(wvalor == "diners"){
		wdiv.style.display = 'block';
		document.getElementById('diners_1').checked = 'checked';
	}else{
		document.getElementById('div_diners').style.display = 'none';
	}
	if(wvalor == "american"){
		wdiv.style.display = 'block';
		document.getElementById('american_1').checked = 'checked';
	}else{
		document.getElementById('div_american').style.display = 'none';
	}
	if(wvalor == "boleto"){
		wdiv.style.display = 'block';
		document.getElementById('boleto_1').checked = 'checked';
	}else{
		document.getElementById('div_boleto').style.display = 'none';
	}
}

function manipulaVariacao(tipo,posicao)
{
	if( tipo== "+" )
	{
		if( $("#variacao_descricao_"+posicao).val() != "" && $("#variacao_valor_"+posicao).val() != "")
		{
			$("#vari_"+(parseInt(posicao)+1)).show()
			$("#adic_"+posicao).hide()
		}
		else
		{
			var campo = ""
			if( $("#variacao_descricao_"+posicao).val() == "")
			{
				objFocus = $("#variacao_descricao_"+posicao)
				campo = "Descrição"
			}
			else
			{
				if( $("#variacao_valor_"+posicao).val() == "")
				{
					objFocus = $("#variacao_valor_"+posicao)	
					campo = "Valor"
				}
			}
			
			alert("Preencha o campo " + campo + " para adicionar.")
		}
	}
	else
	{
		$("#vari_"+posicao).hide()
		$("#adic_"+(parseInt(posicao)-1)).show()
		$("#vari_"+posicao + " input").val("")
		
	}
}
function funcoesClickFrete()
{
	$("#frete_gratis").click(function(){		
		if( $(this).is(":checked") )
		{
			$("input[name='regiao_frete']").attr("checked","checked")
		}
		else
		{
			$("input[name='regiao_frete']").attr("checked","")	
		}
	})
	$("input[name='regiao_frete']").click(function(){
		if( $("input[name='regiao_frete']:checked").length == $("input[name='regiao_frete']").length  )
		{
			$("#frete_gratis").attr("checked","checked")
		}
		else
		{
			$("#frete_gratis").attr("checked","")	
		}
	})
	if( $("input[name='regiao_frete']:checked").length == $("input[name='regiao_frete']").length  )
	{
		$("#frete_gratis").attr("checked","checked")
	}
	
	$("#linkRecalc").click(function(){
		if( $("input[name=tipo_frete]:checked").length > 0 )
		{
			
			location.href = $(this).attr("href") + "&tipo_frete="  + $("input[name=tipo_frete]:checked").val()
			return false
		}
		else
		{
			objFocus = $("input[name=tipo_frete]:eq(0)")
			alert("Selecione o tipo de envio")	
		}
		return false
	})
	
}
function recalculaFrete(url,tipo)
{
	wurl = url + "&tipo_frete=" + tipo;
	location.href = wurl;
}

function ocultarDiv(secao, contador, qtdMax, qtdMin, op){
	wcontador = document.getElementById(contador);
	if(op == '+'){
		wsecao = document.getElementById(secao+wcontador.value);
		wsecao.style.display = "block";
		wcontador.value = parseInt(wcontador.value) + 1
		
		if(wcontador.value > qtdMin){
			document.getElementById("bt_menos").style.display = "";
		}
		
		if(wcontador.value == qtdMax){
			document.getElementById("bt_mais").style.display = "none";
		}
	}else{
		wcontador.value = parseInt(wcontador.value) - 1
		wsecao = document.getElementById(secao+wcontador.value);
		wsecao.style.display = "none";
		
		if(wcontador.value == qtdMin){
			document.getElementById("bt_menos").style.display = "none";
		}
	}
}

function buscaCep()
{
	wcep = $("#cep").val();	
	wcep = wcep.replace("-","")
	ajax = ajaxInit();	
	if(ajax) {
		ajax.open("GET","busca_cep.asp?cep=" + wcep, true);
		
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					retorno = ajax.responseText;
					if( retorno != "erro" )
					{
						vetRet = retorno.split("|")	
						$("#endereco").val(vetRet[0])
						$("#bairro").val(vetRet[1])
						$("#cidade").val(vetRet[2])
						objSelect = document.getElementById("estado")
						for(i=1;i<objSelect.options.length;i++)
						{
							if(objSelect.options[i].value == vetRet[3])
							{
								objSelect.options[i].selected =  true
								break
							}
						}
						
					}
				}else{
					//alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
	}	
	
}
function dimensoesTela()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;


	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	
	if(yScroll <= windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
		
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
		
	dimensao = pageWidth + "x" + pageHeight
	return dimensao
}
function manipulaNews(tipo,posicao)
{
	if( tipo== "+" )
	{
		if( $("#variacao_nome_"+posicao).val() != "" && $("#variacao_email_"+posicao).val() != "")
		{
			$("#vari_"+(parseInt(posicao)+1)).show()
			$("#adic_"+posicao).hide()
		}
		else
		{
			var campo = ""
			if( $("#variacao_nome_"+posicao).val() == "")
			{
				objFocus = $("#variacao_nome_"+posicao)
				campo = "Nome"
			}
			else
			{
				if( $("#variacao_email_"+posicao).val() == "")
				{
					objFocus = $("#variacao_email_"+posicao)	
					campo = "E-mail"
				}
			}
			
			alert("Preencha o campo " + campo + " para adicionar.")
		}
	}
	else
	{
		$("#vari_"+posicao).hide()
		$("#adic_"+(parseInt(posicao)-1)).show()
		$("#vari_"+posicao + " input").val("")
		
	}
}
