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=800;
	height=600;
	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 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() {
	if (document.getElementById('fisica').checked==true) {
		document.getElementById('dados_pessoais').style.display='';
		document.getElementById('dados_empresa').style.display='none';
		document.getElementById('zone').onsubmit=new Function("MM_validateForm('cep','','R','dia','','RisNum','mes','','RisNum','ano','','RisNum','nome','','R','endereco','','R','bairro','','R','cidade','','R','email','','RisEmail','cpf','','isCpfCnpj','senha','csenha','RisIgual-minChar:4','csenha','','RminChar:4','login','','Rminchar:4');return document.MM_returnValue;");
	}
	if (document.getElementById('juridica').checked==true) {
		document.getElementById('dados_pessoais').style.display='none';
		document.getElementById('dados_empresa').style.display='';
		document.getElementById('zone').onsubmit=new Function("MM_validateForm('inscr_estadual','','R','cep','','R','razao_social','','R','endereco','','R','bairro','','R','cidade','','R','email','','RisEmail','cnpj','','isCpfCnpj','senha','csenha','RisIgual-minChar:4','csenha','','RminChar:4','login','','Rminchar:4');return document.MM_returnValue;");
	}
}

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);
  }
}
