function cad_voltar(passo) {
	document.getElementById('cadastrando').value='0';
	document.getElementById('passo_cadastro').value=passo;
	document.getElementById('zone').submit();
}

function doDestacaTexto(Texto, termoBusca){
	inicioTag = "<b>";
	fimTag = "</b>";
	var novoTexto = "";
	var i = -1;
	var lcTermoBusca = termoBusca.toLowerCase();
	var lcTexto = Texto.toLowerCase();
	while (Texto.length > 0){
		i = lcTexto.indexOf(lcTermoBusca, i+1);
		if (i < 0){
			novoTexto += Texto;
			Texto = "";
		}
		else{
			if (Texto.lastIndexOf(">", i) >= Texto.lastIndexOf("<", i)){
				if (lcTexto.lastIndexOf("/script>", i) >= lcTexto.lastIndexOf("<script", i)){
					novoTexto += Texto.substring(0, i) + inicioTag + Texto.substr(i, termoBusca.length) + fimTag;
	  				Texto = Texto.substr(i + termoBusca.length);
					lcTexto = Texto.toLowerCase();
	  				i = -1;
				}
			}
		}
	}
	return novoTexto;
}

function doDestacaTextoBusca(textoBusca, textoObj, ehFrase){
	var textoObj=document.getElementById(textoObj);
	if (ehFrase){arrayBusca=[textoBusca];}
	else{arrayBusca = textoBusca.split(" ");}
	var Texto = textoObj.innerHTML;
	for (var i = 0; i < arrayBusca.length; i++){Texto = doDestacaTexto(Texto, arrayBusca[i]);}
	textoObj.innerHTML = Texto;
	return true;
}



function hpmaisSiteCarregado() {
	document.body.removeChild(hpmaisDark);
	hpmaisHTML.style.overflow='auto';
}

var tamFonte=0;
function zoomfont(id,tipo) {
	var size=$(id).getStyle('fontSize').toUpperCase();
	size=parseFloat(size.replace('PX',''));
	if ((tipo=="+") && (tamFonte<=3)) {
		$(id).style.fontSize=(size+1)+'px';
		tamFonte++;
	}
	if ((tipo=="-") && (tamFonte>=-1)) {
		$(id).style.fontSize=(size-1)+'px';
		tamFonte--;
	}
}

function HPMAISconteudoProtegidoFF() {
	if ((document.getElementById || document.layers) && (!document.all)) {
	 document.oncontextmenu = function () { return false; }
	  document.onkeypress = function (evt) {
			return HPMAISconteudoProtegido(evt);
	  }
	}
}

function HPMAISconteudoProtegido(evt) {
	if ((document.getElementById || document.layers) && (!document.all)) {
		var r = '';
		var ctrl = 0;
		
		if (document.getElementById && (!document.all)) {
		  ctrl = evt.ctrlKey;
		}
		else if (document.layers) {
		  ctrl = Event.CONTROL_MASK;
		} 
		r = String.fromCharCode(evt.which).toUpperCase();    
		if (ctrl){
			if (r=='C'){
				alert('Não é permitido a cópia ou utilização deste conteúdo.\nPara obter mais informações entre em contato conosco!');
			}
		}
	} else 
		alert('Não é permitido a cópia ou utilização deste conteúdo.\nPara obter mais informações entre em contato conosco!');
	return false;
}

function abreLightbox(foto,id) {
	eval(myLightbox.start(document.getElementById(id+'_thumb_'+foto)));
}

function popupBlogImpressao(id) {
	var url = "impressao.php?id="+id;	
	window.open(url,'popupImpressao'+id , 'width=700, height=600,resizable=1,status=0,menubar=0,scrollbars=1');
}

function popupBlogEmail(id,url) {
	var url = "enviar_email.php?id="+id+'&url='+url;
	window.open(url,'popupEmail'+id , 'width=500, height=400,resizable=1,status=0,menubar=0,scrollbars=1');
}

function popupBlogComentar(id) {
	var url = "comentarios.php?id="+id;	
	window.open(url,'popupComentarios'+id , 'width=700, height=600,resizable=1,status=0,menubar=0,scrollbars=1');
}

var rottime;
var rotatual=0;
function notrotativo(opcao) {
	var ul=document.getElementById('noticias_ini_rotativo');
	ul=ul.childNodes[0];
	if (opcao=='iniciar') {
		ul.childNodes[rotatual].className='li_noticia'; 
		Element.hide(ul.childNodes[rotatual]); new Effect.Appear(ul.childNodes[rotatual]);
		rottime=window.setInterval('notrotativo("+1")',7000);
	}
	if (opcao=='-1') {
		if (rotatual==0) voltar=(ul.childNodes.length-1); else voltar=(rotatual-1);
		Element.hide(ul.childNodes[rotatual]);
		rotatual=voltar;		
		window.clearInterval(rottime);
		notrotativo('iniciar');
		document.getElementById('rot_bt_pause_play').innerHTML='<a href="javascript:notrotativo(\'pause\');"><img src="../imagens/rot_pause.jpg" alt="Pause" /></a>';
	}
	if (opcao=='+1') {
		if (rotatual==(ul.childNodes.length-1)) avanca=0; else avanca=(rotatual+1);
		Element.hide(ul.childNodes[rotatual]);
		rotatual=avanca;
		window.clearInterval(rottime);
		document.getElementById('rot_bt_pause_play').innerHTML='<a href="javascript:notrotativo(\'pause\');"><img src="../imagens/rot_pause.jpg" alt="Pause" /></a>';
		notrotativo('iniciar');
	}
	if (opcao=='pause') {
		document.getElementById('rot_bt_pause_play').innerHTML='<a href="javascript:notrotativo(\'play\');"><img src="../imagens/rot_play.jpg" alt="Play" /></a>';
		window.clearInterval(rottime);
	}
	if (opcao=='play') {
		notrotativo('+1');
	}
}

var confproduto_detalhe='pri';
function lvprodutos_sel_meiopgt(id) {
	id=document.getElementById(id);
	if (!id.checked)
		id.checked=true;
}

function LV_PopupBoleto(url) {
	window.open(url,'BOLETO_LOJAVIRTUAL','toolbar=no,resizable=yes,status=yes,location=no,menubar=yes,directories=no,scrollbars=yes,width=710,height=500');
}

function LV_PopupItauShopline() {
	window.open('','ITAUSHOPLINE_LOJAVIRTUAL','toolbar=no,resizable=yes,status=yes,location=no,menubar=yes,directories=no,scrollbars=yes,width=675,height=485');
}

function LV_PopupBBecommerce() {
	window.open('','BBECOMMERCE_LOJAVIRTUAL','toolbar=no,resizable=yes,status=yes,location=no,menubar=yes,directories=no,scrollbars=yes,width=675,height=485');
}

function confproduto_imgm(id) {
	document.getElementById('img_'+confproduto_detalhe).className='hide';
	document.getElementById('img_'+id).className='';
	confproduto_detalhe=id;
}

var produto_detalhe='pri';
function produto_imgm(id) {
	document.getElementById('img_'+produto_detalhe).className='hide';
	document.getElementById('img_'+id).className='';
	produto_detalhe=id;
}

function flipping_popup(id) {
	width=screen.width;
	height=screen.height;
	var url = "../flipping/flipping.php?id="+id;
	window.open(url,'popupFlipping'+id , 'width='+width+', height='+height+',resizable=0,status=0,menubar=0,scrollbars=1');
}

function flippingavancado_popup(id) {
	width=875;
	height=605;
	var url = "../flippingavancado/flipping.php?id="+id;
	window.open(url,'popupFlippingAvancado'+id , 'width='+width+', height='+height+',resizable=0,status=0,menubar=0,scrollbars=1');
}

function flipping_ampliar(url) {
	width=screen.width;
	height=screen.height;
	url=url.substr(0,url.length-6)+".jpg";
	newwindow=window.open(url,'popupFlippingAmpliar' , 'width='+width+', height='+height+',resizable=0,status=0,menubar=0,scrollbars=1');
	newwindow.focus();
	void(0);
}

function ttipo_pessoa(troca,cpf,cnpj) {
	if (troca==1) {
		if (document.getElementById('fisica').checked==true) {
			document.getElementById('dados_pessoais').style.display='';
			document.getElementById('dados_empresa').style.display='none';
			var texto=cpf;
		}
		if (document.getElementById('juridica').checked==true) {
			document.getElementById('dados_pessoais').style.display='none';
			document.getElementById('dados_empresa').style.display='';
			var texto=cnpj;
		}
	} else
		var texto=cpf;
	document.getElementById('zone').onsubmit=new Function(texto);
}

function popupGaleria(id,width) {
	width+=60;
	var url = "fotopopup.php?id="+id;
	window.open(url,'popupGaleria'+id , 'width='+width+', height=460,resizable=0,status=0,menubar=0,scrollbars=1');
}

function maxChar(obj,m) {
	obj=document.getElementById(obj);	
	if (obj.value.length>m) {
		obj.value=obj.value.substring(0,m);
	}
}

function createRss(title,url) {
	rss=document.createElement('link');
	rss.type='application/atom+xml';
	rss.rel='alternate';
	rss.href=url;
	rss.title='title';
	document.getElementsByTagName('head')[0].appendChild(rss);
}
function popupNoticiaImpressao(id) {
	var url = "impressao.php?id="+id;	
	window.open(url,'popupImpressao'+id , 'width=700, height=600,resizable=1,status=0,menubar=0,scrollbars=1');
}

function popupColunistaImpressao(id) {
	var url = "impressao.php?id="+id;	
	window.open(url,'popupImpressao'+id , 'width=700, height=600,resizable=1,status=0,menubar=0,scrollbars=1');
}

function popupColunistaEmail(id,url) {
	var url = "enviar_email.php?id="+id+'&url='+url;
	window.open(url,'popupEmail'+id , 'width=500, height=400,resizable=1,status=0,menubar=0,scrollbars=1');
}

function vcep(id) {
	vr=''
	if (id.value.length>5) {
		vr=id.value
		if (vr.substr(5,1)!='-')
			id.value=vr.substr(0,5)+'-'+vr.substr(5,vr.lenght);
	}
}

function popupNoticiaEmail(id,url) {
	var url = "enviar_email.php?id="+id+'&url='+url;
	window.open(url,'popupEmail'+id , 'width=500, height=400,resizable=1,status=0,menubar=0,scrollbars=1');
}

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_validateForm() { //v4.0 // modificado por hpmais
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
// alteracoes hpmais
    if (val) { nm=val.title; if ((val=val.value)!="") {
// cpf cnpj
	  if (test.indexOf('isCpfCnpj')!=-1) {
		if ((TESTA(val,'CPF')=='invalido') && (TESTA(val,'CNPJ')=='invalido')) errors+='- '+nm+' inválido.\n';
// 2 campos iguais
	  } else if (test.indexOf('isIgual')!=-1) {
		val2=MM_findObj(args[i+1]);
		nm2=val2.title;
		val2=val2.value;
		if (val!=val2) errors+='- '+nm+' e '+nm2+' não conferem.\n';
// fim alteracoes hpmais
	  } else if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' precisa ser um e-mail.\n';
      } else if ((test.indexOf('isNum')!=-1) || (test.indexOf('inRange')!=-1)) { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' precisa ser um número. (Ex.: 9.89)\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' precisa ser um número entre '+min+' e '+max+'.\n';
    } }
// alteracoes hpmais	
// minimo de caracteres	
	  if (test.indexOf('minChar')!=-1) {
  	    p=test.indexOf('minChar:')+8;
	    minchar=test.substring(p);
	    ttchar=val.length;
	    if (ttchar<minchar) errors+='- '+nm+' precisa conter no mínimo '+minchar+' caracteres.\n';
	  }
//	fim alteracoes hpmais
	} else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Erro(s):\n'+errors);
  document.MM_returnValue = (errors == '');
}

function TESTA(CNUMB,CTYPE)
{
  if(Verify(CNUMB, CTYPE))
  {
    return("valido")
  }
  else
  {
    return("invalido")
  }
}

function ClearStr(str, char)
{
  while((cx=str.indexOf(char))!=-1)
  {		
    str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}

function ParseNumb(c)
{
  c=ClearStr(c,'-');
  c=ClearStr(c,'/');
  c=ClearStr(c,',');
  c=ClearStr(c,'.');
  c=ClearStr(c,'(');
  c=ClearStr(c,')');
  c=ClearStr(c,' ');
  if((parseFloat(c) / c != 1))
  {
    if(parseFloat(c) * c == 0)
    {
      return(c);
    }
    else
    {
      return(0);
    }
  }
  else
  {
    return(c);
  }
}

function Verify(CNUMB,CTYPE)
{
  CNUMB=ParseNumb(CNUMB)
  if(CNUMB == 0)
  {
    return(false);
  }
  else
  {
    g=CNUMB.length-2;
    if(TestDigit(CNUMB,CTYPE,g))
    {
      g=CNUMB.length-1;
      if(TestDigit(CNUMB,CTYPE,g))
      {	
        return(true);
      }
      else
      {
        return(false);
      }
    }
    else
    {
      return(false);
    }
  }
}

function TestDigit(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
    dig+=parseInt(CNUMB.charAt(f-1))*ind;
    if (CTYPE=='CNPJ')
    { if(ind>8) {ind=2} else {ind++} }
    else
    { ind++ }
  }
  dig%=11;
  if(dig<2)
  {
    dig=0;
  }
  else
  {
    dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
    return(false);
  }
  else
  {
    return(true);
  }
}
