// JavaScript Document
// Felipe Gregorio - fgregorio@gmail.com

var 
		is_ie 	  = navigator.appName.toLowerCase().indexOf('explorer') != - 1,				
		site_nome = 'Marina Bella',
		site_url  = 'http://www.marinabella.com.br' ;
		
var config = {
	altura_ficha_impressao 	: 720,
	largura_ficha_impressao : 590,
	
	largura_item_ampliado	: 530,
	altura_item_ampliado	: 575,
	
	largura_materia_prima	: 370,
	altura_materia_prima	: 360,
	
	largura_projetos	: 420,
	altura_projetos		: 460,
	
	largura_gravacao	: 570, 
	altura_gravacao		: 400,
	
	largura_indique_site	: 370, 
	altura_indique_site		: 360,
	
	largura_envie_email	: 370, 
	altura_envie_email	: 430,
	
	largura_duvidas		: 370, 
	altura_duvidas		: 410,

	menu_drop_down		: true

	//	popup( './indique-site.php', 400, 330 );
};


//alert(config.altura_ficha_impressao);

function g(element_id){
	//alert(element_id);
	if (document.getElementById(element_id)){
		return document.getElementById(element_id);
	}	
	return element_id ;
}

function div_preenche(div_id,html_conteudo){
	document.getElementById(div_id).innerHTML = 'carregando...' ;
	document.getElementById(div_id).innerHTML = html_conteudo ;
}

function carrinho_add(form_obj){
	if ( ! ( form_obj.elements.qtd.value + 0 ) >= 1 ) {
		alert('informe uma quantidade') ;
		elements.qtd.focus();
	}
	else if ( form_obj.elements.qtd.value < form_obj.elements.qtd_minima.value ){
		alert('quantidade míima para esta peça = ' + form_obj.elements.qtd_minima.value ) ;	
	} 
	else 
		return true ;	
	return false ;
}

function carrinho_muda_qtd(input_obj, index ){	
	var form_obj = input_obj.form ;
	form_obj.acao.value  = 'altera' ;
	form_obj.index.value = index ;
	form_obj.qtd.value	 = input_obj.value ;
	form_obj.submit() ;
}

function carrinho_remove(input_obj, index ){
	if ( confirm('tem certeza que deseja remover?')){
		var form_obj = input_obj.form ;
		form_obj.acao.value  = 'remove' ;
		form_obj.index.value = index ;
		form_obj.submit() ;
	}
}

function carrinho_save_obs(textarea_obj){
	//  MANDA UMA REQUISICAO AJAX PARA SALVAR AS O
	var functionVolta = function(transport){} ;
	//alert(textarea_obj.value);
	//ajax_send_url( 'carrinho.php?acao=save_obs&obs='+url_encode(textarea_obj.value), { f: functionVolta } ) ;
	//var valor = url_encode(textarea_obj.value);
	var valor = escape(textarea_obj.value);
//	alert(valor);
	ajax_send_url( 'carrinho.php?acao=save_obs&obs='+valor, { f: functionVolta } ) ;
}

function favoritos_add(){
	document.all ? window.external.AddFavorite(site_url,site_nome) : sidebar.addPanel(site_nome, site_url, '');
}

function popup(p_url,p_largura,p_altura,extra){
	x = window.open(p_url,'p' + new Date().getSeconds(),'width='+p_largura+',height='+p_altura + ( extra ? ',' + extra : '' ) + ',resizable=no,scrollbars=1') ;
	try { x.focus() ; }
	catch(e) { 
		alert('por favor, desabilite o bloqueador de pop-ups para visualizar esta janela')  ;
	}
}

function popup_ficha_impressao(item_id){
	popup( 'item-ficha.php?item_id='+item_id, config.largura_ficha_impressao, config.altura_ficha_impressao );
}

function popup_imagem_ampliada(item_id, img){
	popup('item-ampliado.php?item_id='+item_id+'&img='+img, config.largura_item_ampliado, config.altura_item_ampliado);
}

function popup_indique() {

//open('./indique-site.php','NewWindow','top=0,left=0,width =450,height=350,status=yes,resizable=yes,scrollbar s=yes');
	popup( './indique-site.php', config.largura_indique_site, config.altura_indique_site );

}
/////////////////////////////////////////
function popup_envie_email(item_id){
	popup('indique.php?item_id=' + item_id, config.largura_envie_email, config.altura_envie_email ) ;
//	indique(item_id) ;
}
////////////////
function popup_materia_prima(item_materiaprima_id){
	popup( 'pop-up-materiaprima.php?item_materiaprima_id='+item_materiaprima_id, config.largura_materia_prima, config.altura_materia_prima );
}

function popup_duvidas(item_id){
	popup('duvida.php?item_id=' + item_id, config.largura_duvidas, config.altura_duvidas ) ;
}

function popup_projetos(item_projetos_id){
	popup( 'pop-up-projetos.php?item_projetos_id='+item_projetos_id, config.largura_projetos, config.altura_projetos );
}

function popup_garantia(garantia_id){
	popup( 'pop-garantia.php?garantia_id='+garantia_id, 500, 500 );
}

function popup_gravacao(gravacao_id){
	popup( 'pop-gravacao.php?gravacao_id='+gravacao_id, 500, 500 );
}

/**
 * Abre um pop-up da tela de gravacoes
 * @return void
*/

function popup_gravacoes(){
	popup( 'pop-up-gravacao.php', config.largura_gravacao, config.altura_gravacao );
}

function item_troca_imagem(img){
	document.getElementById('imagem').src = img ;
	var x = img.split('/') ;
	document.getElementById('imagem').setAttribute('nomeimagem', x[x.length-1]) ;
}

function ajax_send_form( obj_form, params ){
	document.getElementById('duvidas-loading').style.display = '' ;
	ajaxObject.open( 'GET', obj_form.action + '?' + get_form_elements_2_url(obj_form) ) ;
	ajaxObject.onreadystatechange = function(){
		if ( ajaxObject.readyState == 4 && ajaxObject.status == 200 ){
			//alert(params.f);
			params.f(ajaxObject.responseText) ;
		}
	}
	ajaxObject.send(null);
}

function ajax_send_url( url, params ){
	ajaxObject.open( 'GET', url ) ;
	ajaxObject.onreadystatechange = function(){
		if ( ajaxObject.readyState == 4 && ajaxObject.status == 200 ){
			//alert(params.f);
			params.f(ajaxObject.responseText) ;
		}
	}
	ajaxObject.send(null);
}

function ajax_get_string(url){
	ajaxObject.open( 'GET', url, false ) ;
	ajaxObject.onreadystatechange = function(){
		if ( ajaxObject.readyState == 4 && ajaxObject.status == 200 ){
			return ajaxObject.responseText ;
		}
	}
	ajaxObject.send(null);
}

function get_form_elements_2_url(obj_form){
	var retorno = [] ;	
	var p = ['input', 'select', 'textarea'] ;
	
	for ( var i = 0; i < p.length ; i ++ ){
		for ( var x = 0,	a = obj_form.getElementsByTagName(p[i]),m = obj_form.getElementsByTagName(p[i]).length ; x < m ; x ++ ){			
			condicao = false 	;
			element  = a[x] 	;
			switch( p[i] ){
				case 'input' :
					condicao = ( element.disabled == false && ! element.readOnly 
												&& ! ( element.getAttribute('type').toLowerCase() == 'button' || element.getAttribute('type').toLowerCase() == 'file' )
												|| ( element.getAttribute('type').toLowerCase() == 'radio' && element.checked )
												|| ( element.getAttribute('type').toLowerCase() == 'checkbox' && element.checked )) ;
				break ;
				case 'select' :
				case 'textarea' :
					condicao = ( element.disabled == false && ! element.readOnly ) ;				
				break ;
			}
			if ( condicao ){
				retorno[retorno.length] = element.getAttribute('name') + '=' + escape(element.value);		
			}
		}
	}
	return retorno.join('&');
}

function indique(id){
	frescura('indique',400,190);
	//popup('indique.php?item_id=' + id, config.altura_indique_site, config.largura_indique_site ) ;
}

function show_hide(obj_id){
	document.getElementById(obj_id).style.display = document.getElementById(obj_id).style.display == 'none' ? 'block' : 'none' ;
}

function apenas_numeros(obj){
	obj.value = obj.value.replace( /[a-z- ._]/ig , '' ) ;
}

function next_object(quantos_bytes,obj_atual,obj_next){
	if ( parseInt(obj_atual.value.length) == quantos_bytes ){
		obj_next.focus();		
	}
}

/*
COMECA VALIDACOES DE CADASTRO
*/

function indique_valida(form_obj)
{
	with ( form_obj )
	{
		if ( elements.usuario_nome.value == ""  )
		{
			alert('digite seu nome') ;
		}
		else if ( ! elements.usuario_email.value.isEmail() )
		{
			alert('digite seu email corretamente');
		}
		else if ( elements.amigo_nome.value == "" )
		{
			alert('digite o nome do seu amigo');
		}
		else if ( ! elements.amigo_email.value.isEmail() )
		{
			alert('digite o email do seu amigo corretamente');
		}
		else 
		{
			return true ;
		}
		return false ;
	}
}
function cadastro_valida(form_obj){

	quais_erros = '';

	with (form_obj){
		if ( ! elements.email.value.isEmail() ) {
			quais_erros += '<p>e-mail invalido</p>';
		}
		if ( elements.senha.value == '' ){
			quais_erros += '<p>senha em branco</p>';
		}
		if ( elements.senha1.value.length < 6 ){
			quais_erros += '<p>sua senha deve ter no minimo 6 caracteres</p>';
		}
		if ( elements.senha.value != elements.senha1.value ){
			quais_erros += '<p>a senha e a confirmacao nao conferem</p>';
		}
		if ( elements.tel1_telefone.value == '' ){
			quais_erros += '<p>telefone em branco</p>';
		}
		elements.nome.value = elements.responsavel.value ;
		elements.cnpj_cpf.value = elements.cnpj.value ;
		if ( elements.empresa.value == '' ){
			quais_erros += '<p>preencha a razao social</p>' ;
		}
		if ( ! elements.cnpj.value.isCNPJ() ){
			quais_erros += '<p>CNPJ invalido</p>' ;
		}
		if ( elements.responsavel.value == '' ){
			quais_erros += '<p>preencha o nome do responsavel</p>' ;
		}
		if ( elements.cep.value == '' ){
			quais_erros += '<p>preencha seu cep</p>' ;
		}
		if ( elements.endereco.value == '' ){
			quais_erros += '<p>preencha seu endereco</p>' ;
		}
		if ( elements.numero.value == '' ){
			quais_erros += '<p>preencha o nmero do seu endereco</p>' ;
		}
		if ( elements.bairro.value == '' ){
			quais_erros += '<p>preencha seu bairro</p>' ;
		}
		if ( elements.cidade.value == '' ){
			quais_erros += '<p>preencha sua cidade</p>' ;
		}
		if ( quais_erros.length > 0 ){
			document.getElementById('cadastro-msg').className = 'erro';
			document.getElementById('cadastro-msg').innerHTML = '<p><b>erros encontrados ...</b></p>' + quais_erros;
			return false ;
		}
		else {	
			elements.fone1.value = elements.tel1_telefone.value ; 
			elements.fone2.value = elements.tel2_telefone.value + ' ' + elements.tel2_ramal.value ;
			elements.fone3.value = elements.tel3_telefone.value ;
  
			return true ;
		}
	}	
	return false ;
}

function frete_calcula_valida(form_obj){
	if ( form_obj.elements.cep_calcular.value == '' ){
		alert('Digite o cep');
		form_obj.elements.cep_calcular.focus();
	}
	else if ( ! form_obj.elements.cep_calcular.value.length == 8 ){
		alert('Digite o cep com 8 posicoes') ;
		form_obj.elements.cep_calcular.focus();
	}
	else {
		return true ;
	}
	
	return false;
}

function contato_valida(obj_form){

	
	with ( obj_form ){
		if ( obj_form.elements.nome.value == "" ) {
			alert('digite seu nome corretamente') ;
			obj_form.elements.nome.focus() ;
			return false;
		}				
		else if ( obj_form.elements.telefone.value == "" ){
			alert('digite seu telefone corretamente');
			obj_form.elements.telefone.focus() ;
			return false;
		}
		else if ( obj_form.elements.mensagem.value == "" ){
			alert('digite sua mensagem') ;
			return false;
		}
		else if ( ! elements.email.value.isEmail() ){
			alert('digite seu e-mail corretamente');
			elements.email.focus() ;
			return false;
		}
		return true ;
	}
	
}

function indique_valida(form_obj){
	//return false ;
	with ( form_obj ){
		if ( elements.usuario_nome.value == ""  ){
			alert('digite seu nome') ;
		}
		else if ( ! elements.usuario_email.value.isEmail() ){
			alert('digite seu email corretamente');
		}
		else if ( elements.amigo_nome.value == "" ){
			alert('digite o nome do seu amigo');
		}
		else if ( ! elements.amigo_email.value.isEmail() ){
			alert('digite o email do seu amigo corretamente');
		}
		else {
			return true ;
		}
		return false ;
	}
}

function indique_site_valida(obj_form){
	with ( obj_form ){			
		if ( obj_form.elements.usuario_nome == "" ){
			alert('digite seu nome') ; 
			obj_form.elements.usuario_nome.focus() ;
		} 
		else if ( ! obj_form.elements.usuario_email.isEmail() ){
			alert('digite seu e-mail corretamente') ;
			obj_form.elements.usuario_email.focus();
		}
		else if ( obj_form.elements.amigo_nome == "" ){
			alert('digite o nome do seu amigo')	 ;
			obj_form.elements.amigo_nome.focus();
		}
		else if ( ! obj_form.elements.amigo_email.isEmail() ){
			alert('digite o e-mail do seu amigo corretamente')	 ;
			obj_form.elements.amigo_nome.focus();
		}
		else {
			return true ;	
		}
		return false ;
	}		
}
/*
TERMINA VALIDACOES DE CADASTRO
*/

/*
COMECA FUNCOES DO MENU
*/


/*
TERMINA FUNCOES DO MENU
*/


/*
**************************************
* String.isCPF Function v1.0         *
* Autor: Carlos R. L. Rodrigues      *
* BEGIN 							 *
**************************************
*/
String.prototype.isEmail = function(){
	return new RegExp(/[a-z0-9_\-.]{1,}@[a-z0-9_\-.]{1,}/ig).test(this) ;
};
String.prototype.isCPF = function(){
	var c = this;
	if((c = c.replace(/[^\d]/g,"").split("")).length != 11) return false;
	if(new RegExp("^" + c[0] + "{11}$").test(c.join(""))) return false;
	for(var s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);
	if(c[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
	for(var s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--);
	if(c[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
	return true;
};

String.prototype.isCNPJ = function(){
	var b = [6,5,4,3,2,9,8,7,6,5,4,3,2], c = this;
	if((c = c.replace(/[^\d]/g,"").split("")).length != 14) return false;
	for(var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
	if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
	for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
	if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
	return true;
};

function set_cor(_cor_id){
	obj_combo = document.getElementById('cor_id') ;
	for ( var i = 0 ; i < obj_combo.options.length ; i ++ ){
		if ( obj_combo.options[i].value == _cor_id ){
			obj_combo.options[i].selected = true ;
		}	
	}	
}

function swf(url, width, height, flashvars){
	var retorno = '' ;
	if( url.indexOf('.jpg') > -1 ){
		retorno = '<img src="'+url+'"/>' ;
	}
	else{
		retorno += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+ width +'" height="'+ height +'">' ;
		retorno += '<param name="movie" value="'+ url +'?m='+ new Date().getTime() +'">' ;
		retorno += '<param name="quality" value="high">' ;
		retorno += '<param name="wmode" value="transparent">' ;
		retorno += '<param name="flashvars" value="'+ flashvars +'">' ;
		retorno += '<embed wmode="opaque" src="'+ url +'?m='+ new Date().getTime() +'" flashvars="'+ flashvars +'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'"></embed>' ;
		retorno += '</object>' ;
	}
	document.write(retorno);
	//return retorno ;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
			curleft = obj.offsetLeft ;
			curtop = obj.offsetTop ;
			while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft
					curtop += obj.offsetTop
			}
	}
	return [curleft,curtop];
}



function init(){
	
	if ( config.menu_drop_down && document.getElementById('menu-produtos-geral') ){
		a = document.getElementById('menu-produtos-geral').childNodes[0];
		b = a.childNodes ;
		for ( var i = 0, c = b.length ; i < c ; i ++ ){
			if ( b[i].tagName == 'LI' ){
				// acertar posicao do primeiro ul dentro do li, se existir
				d = b[i].getElementsByTagName('ul') ;
				if (d.length > 0 ){
					d = d[0];
					t = findPos(b[i]) ;
					d.style.left = new String(t[0] ) + 'px';
					d.style.top  = new String(t[1] + 20)  + 'px';
					b[i].onmouseover = function(){ this.className+=" over"; }
					b[i].onmouseout  = function(){ this.className = this.className.replace(" over", "") }
				}
			}
		}
		window.onresize = init ;
	}

}

/*
PROTOTYPES ...
*/

function event_add(obj, evType, fn){
   if (obj.addEventListener){
       obj.addEventListener(evType, fn, true)
   }    
   if (obj.attachEvent){
       obj.attachEvent("on"+evType, fn)
   }
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/forms/masked-input [v1.0]

MaskInput = function(f, m){
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1}){
	    addEvent(f, i, mask);
	}
};

addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

addEvent( window, 'load', init );


// frescuras
function frescura(div_id,w,h) {	
	// display:none em tudo dentro de capa-img

	var dentro = frescura_dentro(div_id);

	for(var x = 0, o = dentro.childNodes, m = o.length ; x < m ; x ++ )
		if(o[x].tagName)
			o[x].style.display = 'none' ;

	pageSize	= getPageSize();
	pageScroll	= getPageScroll();  

	document.getElementById(div_id).style.height = new String(pageSize[1])+'px' ;
	dentro.style.top  = new String(y=(pageScroll[1]+(pageSize[3]-h-10)/2))+'px' ;
	dentro.style.left = new String(x=(document.body.clientWidth-w)/2)+'px' ;

	document.getElementById(div_id).style.display = '';
	dentro.style.display = '';
	frescura_abre1(div_id,w,h);
}

function frescura_dentro(div_id){
	return document.getElementById(div_id).getElementsByTagName('div')[0];
}

// abre width
function frescura_abre1(div_id,w,h) {
	var dentro = frescura_dentro(div_id);
	_w = int_val(dentro.style.width); 
	//alert(_w);
	if(_w<w) {
		dentro.style.width = new String(_w + 25)+'px' ;
		setTimeout('frescura_abre1(\''+div_id+'\','+w+','+h+');',15);
	}
	else{
		frescura_abre2(div_id,w,h);
	}
}

// abre height
function frescura_abre2(div_id,w,h) {
	var dentro = frescura_dentro(div_id);
	_h = int_val(dentro.style.height); 
	if(_h<h) {
		dentro.style.height = new String(_h + 25)+'px' ;
		setTimeout('frescura_abre2(\''+div_id+'\','+w+','+h+');',15);
	}
	else{
		frescura_abre3(dentro);
	}
}

// acende imagem, legenda e botao de fechar
function frescura_abre3(dentro) {
	for(var x = 0, o = dentro.childNodes, m = o.length ; x < m ; x ++ ){
		if(o[x].tagName)
			o[x].style.display = '' ;
	}
}

function frescura_fim(div_id) {
	document.getElementById(div_id).style.display='none' ;
	var dentro = frescura_dentro(div_id);
	dentro.style.width='20px';
	dentro.style.height='0px';
}

function int_val(x) {
	//alert('de'+x);
	x = new String(x);
	x = x.replace(/[a-z]/ig, '') ;
	x = new Number(x);
	//alert('para'+x);
	return x ;
}

function tab(tabn){
	var t = [];
	for ( var i = 0, m = document.getElementsByTagName('div'); i < m.length ; i ++ ){
		if(m[i].getAttribute("tab")=="1"){
			t[t.length] = m[i];
		}
	}
	for ( var i = 0, m = t.length; i < t.length ; i ++ ){
		t[i].style.display = 'none';
	}
	for ( var i = 0, m = t.length; i < t.length ; i ++ ){
		if(i == tabn)
			t[i].style.display = '';
	}
}

function formata(v) {
	var s = new String(v);
	if(s.indexOf('.')==-1) {
		return s+',00';
	}
	else {
		var x = s.split('.');
		if(x[1].length>=2){
			return x[0]+','+x[1].substr(0,2);
		}
		else{
			return x[0]+','+x[1]+'0';
		}
	}
}

function url_encode(str) { 
	var hex_chars = "0123456789ABCDEF"; 
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
	var n, strCode, hex1, hex2, strEncode = ""; 

	for(n = 0; n < str.length; n++) { 
		if (noEncode.test(str.charAt(n))) { 
			strEncode += str.charAt(n); 
		} else { 
			strCode = str.charCodeAt(n); 
			hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
			hex2 = hex_chars.charAt(strCode % 16); 
			strEncode += "%" + (hex1 + hex2); 
		} 
	} 
	return strEncode; 
}