function closePopup() {
	if ($chk($('falso_popup'))==true) {
		$('falso_popup').dispose();
		$('falso_popup_container').dispose();
	}
}

function ativaPopup() {
	$('falso_popup').setStyle('display','block');
	$('falso_popup_container').setStyle('visibility','visible');
}

var hpmaisGaleria = new Class({
	Implements: [Options,Events],
	options: {
		'id':null,
		'width':null,
		'thumb_height':0,
		'thumb_width':0,
		'start_index':0
	},
	posicao_atual:0,
	div_legenda:null,
	design_base: function() {
		//
		if (this.options.width!=null && this.options.width>0)
			this.options.id.setStyle('width',this.options.width);

		// thumbs
		this.div_thumbs = new Element('div').inject(this.options.id).setStyles({'overflow':'hidden'});
		this.ul_thumbs = this.options.id.getElements('ul')[0];
		this.images = this.ul_thumbs.getElements('.imageElement').hide();
		this.ul_thumbs.setStyles({
			'width':((this.options.thumb_width*this.images.length)+(this.images.length*3))+'px',
			'height':(this.options.thumb_height+2)+'px'
		});
		this.options.id.adopt(this.ul_thumbs);
		this.ul_thumbs.getElements('li').setStyles({
			'background':'url(../imagens/loading-black-p.gif) no-repeat center',
			'width':this.options.thumb_width+'px',
			'height':this.options.thumb_height+'px'

		});

		// imagem g
		this.div_imagem = new Element('div',{'class':'imagefull'}).inject(this.options.id);
		this.imagem = new Element('img').inject(this.div_imagem).hide().addEvents({
			'load': function(){
				this.imagem.show();
				this.div_imagem.setStyle('background','none');
				this.imagem.setStyle('visibility','visible');
				this.configure_positions();
			}.bind(this),
			'mouseover': function(){
				if (this.div_legenda!=null) {
					this.div_legenda.show().position({'relativeTo':this.div_imagem,'position':'bottom','edge':'bottom'});
				}
			}.bind(this),
			'mouseout': function(){
				if (this.div_legenda!=null) {
					this.div_legenda.hide();
				}
			}.bind(this)
		});

	},

	configure_thumbs: function() {
		// img thumbs
		this.images.each(function(img,i){
			img.setStyles({'width':this.options.thumb_width+'px','height':this.options.thumb_height+'px','cursor':'pointer'});
			img.addEvents({
				'load': function() {
					img.show();
				},
				'click': this.setImage.pass(i,this)
			});
			img.set('src',img.get('img_p'));
			new Element('a',{'href':'javascript:;'}).inject(img,'before').adopt(img);
		},this);
	},
	
	configure_arrows: function() {
		// setas thumbs

		this.div_thumb_anterior = new Element('div')
			.inject(this.options.id)
			.setStyles({
				'position':'absolute',
				'cursor':'pointer',
				'margin-top':'5px',
				'background':'url(../imagens/leftDisabled.png) no-repeat left',
				'width':Math.ceil(this.options.thumb_width/2.5)+'px',
				'height':Math.ceil(this.options.thumb_height)+'px',
				'z-index':9999999999
			})
			.addEvents({
				'mouseover': function(){
					this.div_thumb_anterior.setStyle('background','url(../imagens/left.png) no-repeat left #333333');
					this.thumb_move('left');
				}.bind(this),
				'mouseout': function() {
					this.div_thumb_anterior.setStyle('background','url(../imagens/leftDisabled.png) no-repeat left');
					this.thumb_move_pause();
				}.bind(this)
			})
			.set('opacity',0.6);
			
		this.div_thumb_proximo = new Element('div')
			.inject(this.options.id)
			.setStyles({
				'position':'absolute',
				'cursor':'pointer',
				'margin-top':'5px',
				'background':'url(../imagens/rightDisabled.png) no-repeat right',
				'width':Math.ceil(this.options.thumb_width/2.5)+'px',
				'height':Math.ceil(this.options.thumb_height)+'px',
				'z-index':9999999999
			})
			.addEvents({
				'mouseover': function(){
					this.div_thumb_proximo.setStyle('background','url(../imagens/right.png) no-repeat right #333333');
					this.thumb_move('right');
				}.bind(this),
				'mouseout': function() {
					this.div_thumb_proximo.setStyle('background','url(../imagens/rightDisabled.png) no-repeat right');
					this.thumb_move_pause();
				}.bind(this)
			})
			.set('opacity',0.6);
			
		// setas imagem g
		this.div_anterior = new Element('div')
			.inject(this.options.id)
			.setStyles({'background':'url(../imagens/transparent.png)','cursor':'pointer','position':'absolute','padding-left':'15px','z-index':9999999999,'width':'38px'})
			.addEvents({
				'mouseover': function(){ this.setStyle('background','url(../imagens/fleche1.png)  no-repeat center #333333'); },
				'mouseout': function(){ this.setStyle('background','url(../imagens/transparent.png)');	},
				'click':this.change.pass('previous',this)
			})
			.set('opacity',0.7);
		
		this.div_proximo = new Element('div')
			.inject(this.options.id)
			.setStyles({'background':'url(../imagens/transparent.png)','cursor':'pointer','position':'absolute','padding-left':'15px','z-index':9999999999,'width':'38px'})
			.addEvents({
				'mouseover': function(){ this.setStyle('background','url(../imagens/fleche2.png) no-repeat center #333333'); },
				'mouseout': function(){	this.setStyle('background','url(../imagens/transparent.png)');	},
				'click':this.change.pass('next',this)
			})
			.set('opacity',0.7);
	},
	configure_positions: function() {
		var coords_img = this.div_imagem.getCoordinates();
		this.div_thumbs.setStyles({'width':coords_img.width+'px'});
		
		this.div_thumb_anterior.position({'relativeTo':this.div_thumbs,'position':'topleft','edge':'topleft'});
		this.div_thumb_proximo.position({'relativeTo':this.div_thumbs,'position':'topright','edge':'topright'});

		this.div_anterior.position({'relativeTo':this.div_imagem,'position':'topleft','edge':'topleft'}).setStyle('height',(coords_img.height)+'px');
		this.div_proximo.position({'relativeTo':this.div_imagem,'position':'topright','edge':'topright'}).setStyle('height',(coords_img.height)+'px');
		
		if (this.div_legenda!=null) {
			this.div_legenda.setStyle('width',(coords_img.width-16)+'px');
		}
		
	},
	initialize: function(options) {
		this.setOptions(options);
		this.design_base();
		this.configure_arrows();
		this.configure_positions();
		this.div_thumbs.adopt(this.ul_thumbs.show());
		this.configure_thumbs();
		this.configure_positions();
		this.moving=false;
		this.setImage(0);
	},
	thumb_move: function(tipo) {
		if (this.moving==false) {
			var coords1 = this.div_thumbs.getCoordinates();
			var coords2 = this.ul_thumbs.getCoordinates();
			var margin = 0;
			if (tipo=='right') {
				var diff = coords2.right-coords1.right;
				if (diff>0) 
					margin = (coords2.width-coords1.width)*-1;
			} else {
				var diff = coords1.left-coords2.left;
			}
			if (diff>0) {
				var vel = diff*5;
				this.fx = new Fx.Tween(this.ul_thumbs,{
					'duration':vel					   
				})
				.addEvent('complete',function(){
					this.moving=false;
				}.bind(this))
				.start('margin-left',this.ul_thumbs.getStyle('margin-left'),margin+'px');
				this.moving=true;
			}
		}
	},
	thumb_move_pause: function() {
		if (this.moving==true) {
			this.fx.pause();
			this.moving=false;
		}
	},
	change: function(tipo) {
		if (tipo=='next')
			var changed = this.posicao_atual+1;
		else
			var changed = this.posicao_atual-1;
		if (changed>=0 && changed<this.images.length) {
			this.setImage(changed);
		} 
	},
	setImage: function(i) {
		var el = this.images[i];
		var src = el.get('img_g');
		if (src!=this.imagem.get('src')) {
			if (this.div_legenda!=null) {
				this.div_legenda.dispose();
			}
			var legenda = el.get('title');
			if (legenda!=null) {
				this.div_legenda=new Element('div',{'class':'legenda','html':legenda}).inject(this.div_imagem).set('opacity',0.6).hide();
			} else  {
				if (this.div_legenda!=null) {
					this.div_legenda.dispose();
					this.div_legenda=null;
				}
			}
			this.div_imagem.setStyle('background','url(../imagens/loading-bar-black.gif) no-repeat center');
			this.imagem.set('src',src);
			this.imagem.setStyle('visibility','hidden');
			
			this.posicao_atual=i;
			
		}
	}
});

function addFav(obj,url,titulo) {
	$(obj).addEvent('click',function() {
		if (window.sidebar)
			window.sidebar.addPanel(titulo,url,'');
		else if (navigator.appName == 'Microsoft Internet Explorer')
			window.external.addFavorite(url,titulo);
	});
}

function embedswf(arquivo, id, width, height, flashvars, params, attributes) {
	swfobject.embedSWF(arquivo, id, width, height, '9.0.0', '../flash/expressInstall.swf', flashvars, params, attributes);
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

var ajax_loader = new Class({
	online:false,
	initialize: function() {
		this.online=false;
	},
	showURL: function(url,div_id) {
		if ($chk($(div_id))) {
			if (this.online==false) {
				var ajaxReq = new Request.HTML({
					'url' : url,
					initialize: function() {
						if ($(div_id).getStyle('display')=='none')
							$(div_id).setStyles({'display':'block'});
						this.addLoading($(div_id));
						this.online=true;
					}.bind(this),
					onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
						$(div_id).empty();
						$(div_id).set('html',responseHTML);
						$exec(responseJavaScript);
						if (responseHTML=='')
							$(div_id).setStyles({'display':'none'});
						this.online=false;
					}.bind(this),
					evalScripts: false,
					evalResponse: false
				}).send();
			}
		}
	},
	addLoading: function(div) {
		div.empty();
		var div_img=Element('div',{'align':'center'});
		var img=Element('img',{'src':'../imagens/loading_p.gif'});
		div_img.appendChild(img);
		div.appendChild(div_img);
	}
});
var div_loader={};
window.addEvent('load', function() {
	div_loader=new ajax_loader();
});

function getHTTPObject() {
	var req;
	try {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			if (req.readyState == null) {
				req.readyState = 1;
				req.addEventListener("load", function () { req.readyState = 4; if (typeof req.onReadyStateChange == "function") req.onReadyStateChange();   }, false);
			}
			return req;
		}
		if (window.ActiveXObject) {
			var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
			for (var i = 0; i < prefixes.length; i++) {
				try {
					req = new ActiveXObject(prefixes[i] + ".XmlHttp");
					return req;
				}
				catch (ex) {};
			}
		}
	}
	catch (ex) {}
	alert("XmlHttp Objects not supported by client browser");
}

function detalhe_evento(id,href) {
	objid = 'eventos_texto'+id;
	hrefid = 'hrefevento'+id;
	if ($(objid).getStyle('display').toLowerCase()=='none') {
		div_loader.showURL('../eventos/texto.php?id='+id,'eventos_texto'+id);		

		$(objid).setStyle('display','block');
		$(hrefid).innerHTML='&lt;&lt; menos';
	} else {
		$(objid).setStyle('display','none');
		$(hrefid).innerHTML='mais &gt;&gt;';
	}
}

function detalhe_faq(id,href) {
	objid = 'faq_texto'+id;
	hrefid = 'hrefevento'+id;
	if ($(objid).getStyle('display').toLowerCase()=='none') {
		div_loader.showURL('../faq/texto.php?id='+id,'faq_texto'+id);		

		$(objid).setStyle('display','block');
		$(hrefid).innerHTML='<img src="../imagens/img_menos_faq.jpg" class="img_faq">';
	} else {
		$(objid).setStyle('display','none');
		$(hrefid).innerHTML='<img src="../imagens/img_mais_faq.jpg" class="img_faq">';
	}
}

function detalhe_download(id,href) {
	objid = 'download_texto'+id;
	hrefid = 'hrefevento'+id;
	if ($(objid).getStyle('display').toLowerCase()=='none') {
		div_loader.showURL('../downloads/texto.php?id='+id,'download_texto'+id);		

		$(objid).setStyle('display','block');
		$(hrefid).innerHTML='<img src="../imagens/img_menos_dl.jpg" alt="Ocultar detalhes" title="Ocultar detalhes" border="0" class="img_dl">';
	} else {
		$(objid).setStyle('display','none');
		$(hrefid).innerHTML='<img src="../imagens/img_mais_dl.jpg" alt="Exibir detalhes" title="Exibir detalhes" border="0" class="img_dl">';
	}
}

var produto_detalhe='pri';
function produto_imgm(id) {
	document.getElementById('img_'+produto_detalhe).className='hide';
	document.getElementById('img_'+id).className='';
	produto_detalhe=id;
}

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--;
	}
}

//protector class
var dwProtector = new Class({
	//implements
	Implements: [Options],
	//options
	options: {
		image: 'blank.gif',
		elements: $$('img'),
		zIndex: 10
	},
	//initialization
	initialize: function(options) {
		//set options
		this.setOptions(options);
		//make it happen
		this.protect();
	},
	//a method that does whatever you want
	protect: function() {
		//for each image that needs be protected...
		this.options.elements.each(function(el) {
			//get the element's position, width, and height
			var size = el.getCoordinates();
			//create the protector
			var p = new Element('img', {
				src: this.options.image,
				width: size.width,
				height: size.height,
				styles: {
					'z-index': this.options.zIndex,
					'left': size.left + 'px',
					'top': size.top + 'px',
					'position': 'absolute'
				}
			}).inject($(document.body),'top');
		},this);
	}
});

Element.implement({  
	appendHTML: function(html,where){  
		return this.grab(new Element('text',{'html':html}),where);  
	}  
});

function input_limpar(id,text) {
	if ((id.value!=text) || ((id.value==text) && (document.activeElement==id))) {
		id.value=id.value.replace(text,'');
	}
	return;
}

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 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 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 maxChar(obj,m) {
	obj=document.getElementById(obj);	
	if (obj.value.length>m) {
		obj.value=obj.value.substring(0,m);
	}
}

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 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';
					// soh cpf
				} else if (test.indexOf('isCpf')!=-1) {
					if (TESTA(val,'CPF')=='invalido') errors+='- '+nm+' inválido.\n';
					// soh cnpj
				} else if (test.indexOf('isCnpj')!=-1) {
					if (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);
  }
}

