
/* função chamada pelo MaskInput */
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;
					    }
};

/* função chamada pelo MaskInput */
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;
};
MaskInput = function(f, m){ //v1.0
	function mask(e){
	var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/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);
};


function init_htmlarea()
{
	document.write('<style type="text/css">@import url(/includes/htmlarea_3/htmlarea.css);</style>');
	document.write('<script type="text/javascript" src="/includes/htmlarea_3/htmlarea.js"></script>');
	document.write('<script type="text/javascript" src="/includes/htmlarea_3/lang/pt_br.js"></script>');
	document.write('<script type="text/javascript" src="/includes/htmlarea_3/dialog.js"></script>');
}

/*
	Limita o numero máximo de caracteres a ser digitado em um Campo TEXTAREA
	show_text_len = eh para mostrar o valor num campo text
	Para Usar: onKeyUp="textAreaLimit('form1','mensagem','125')"
*/
function textAreaLimit(form_name,campo,maxlimit,show_text_len) { // v0.1
	if (eval("document." +form_name+ "." +campo+ ".value.length") >= maxlimit) {
		alert ("O Limite de Caracteres Foi Excedido: Permitido=" + maxlimit);
	}
	if (eval("document." +form_name+ "." +campo+ ".value.length") > maxlimit)
		eval("document." +form_name+ "." +campo+ ".value = document." +form_name+"." +campo+ ".value.substring(0, " +maxlimit+ ");");
	else
		status = eval("document." +form_name+ "." +campo+ ".value.length;") + " de " + maxlimit;

	// Insira um campo chamado <input type="text" name="len">
	if (show_text_len) {
		eval("document."+ form_name + ".len.value = document." + form_name + "." +campo+ ".value.length;");
	}
}


/*
Check all checkbox
	formName	= Form Name
	boxName		= Name of input type=checkbox
Usage:
	Put :
	<input type="checkbox" name="sellall" onClick="CheckAll('formName')">

formName = name of form

*/
function CheckAll(formName,boxName) { //v0.2
	if (!boxName) boxName = "selall";
	if (!formName) formName = "form";

	for (var i=0 ; i < eval("document." + formName + ".elements.length") ; i++)
	{
		var x = eval("document." + formName + ".elements["+ i + "]");
		status=x.name;
		if (x.name != boxName)
		      x.checked = eval("document."+ formName + "." + boxName + ".checked");
	}
}

/*
Check all especific checkbox
	formName	= Form Name
	inputName	= Checkbox will be checked
	boxName		= Name of input type=checkbox
Usage:
	Put :
	<input type="checkbox" name="sellall" onClick="CheckAll('formName')">

formName = name of form

*/
function checkBoxEsp(formName,inputName, boxName) { //v0.2
	//dumpObj(obj,inputName);
	//boxName = formName.name;

	for (var i=0 ; i < eval("document." + formName + ".elements.length") ; i++)
	{
		var x = eval("document." + formName + ".elements["+ i + "]");
		status=x.name;

		if (x.name != boxName && x.name == inputName)
		      x.checked = eval("document."+ formName + "." + boxName + ".checked");
	}
}

/*
	Setar Valor em um FORM>SELECT
	Modo de usar:
	setSelectValue(formName, formField, value2sel)
		formName = Nome do Formulario
		formField = Nome do Campo
		value2sel = Valor selecionado, pode ser multiplos quando form for multiple
			'PR|SC|SP'
		targ = Alvo (parent ...)
	ex.: setSelectValue('formulario','uf','PR|SC')

	obs.: Se o "<select" nao tiver multiple, e quando o valor
	value2sel = "A|B|C" ou multiplos, será marcado apenas o ultimo valor
*/
function setSelectValue(formName, formField, value2sel, targ) // 17.07.2003
{
	if(targ && targ != "undefined") targ = targ + "."
	else targ="";

	if('' == value2sel) return;
	objSelect = eval(targ + "document." + formName + "." + formField);
	//objSelect = eval("document." + formName + ".elements['" + formField + "']");

	if(!value2sel) return;
	_values = value2sel.split("|");

	for (var i=0; i < objSelect.options.length; i++)
	{
		objSelect.options[i].selected = false; // Limpa campos
		// Setar os valores
		for(j=0; j < _values.length; j++)
		{
			if (objSelect[i].value == _values[j] || objSelect[i].text == _values[j])
				objSelect.options[i].selected = true;
		}
	}
}

/*
	Pega o(s) valores de um FORM > SELECT
*/
function getSelectValue(formName,formField) // 17.07.2003
{
	obj = eval("document." + formName + "." + formField);
	if(obj.selectedIndex == -1) {return false};
	return obj.options[obj.selectedIndex].value;
}
/*
	Retorna o texto Selecionado ou o TEXTO textSel de um FORM > SELECT
*/
function getSelectText(formName,formField,textSel) // 17.07.2003
{
	obj = eval("document." + formName + "." + formField);
	if(textSel)
	{
		for(i=0; i < obj.length; i++){ return obj[i].text; }
	}
	if(obj.selectedIndex == -1) {return false};
	return obj.options[obj.selectedIndex].text;
}

/*
	Pega TODOS os valores Selecionado ou NAO selecionados(all_v=(text|value))
	de um select e retorna uma lista
*/
function getSelectArray(formName, fieldName, sep, all_v)
{
	if(!sep) sep="|"
	objSel = eval("document." + formName + "." + fieldName);
	s="";
	for(i=0 ; i < objSel.length; i++)
	{
		if (all_v)
		{
			if(i > 0) s += sep;
			if(all_v == "text") s += objSel[i].text;
			else s += objSel[i].value;
		}
		else
		{
			if(objSel[i].selected == true)
			{
				if(i > 0) if(s) s += sep;
				s += objSel[i].value;
			}
		}
	}
	return s;
}

/*
	Verifica se existe algum valor no select
	retorna true se encontrar
*/
function HaveInFormSelect(formName,formField,v) // 17.07.2003
{
	obj = eval("document." + formName + "." + formField);
	for(i=0; i < obj.length; i++)
	{
		if(obj[i].value == v) return true;
	}
	return false;
}

/*
	Setar valor em um FORM > INPUT RADIO
	setRadioValue(formName, formField, value2sel)
		formName = Nome do formulario
		formField = Nome do campo
		value2sel = valor para selecionar
*/

function setRadioValue(formName, formField, value2sel) // 01.07.2003
{
	if('' == value2sel) return;
	objRadio = eval("document." + formName + "." + formField);
	for(i=0; i < objRadio.length; i++)
	{
		if(objRadio[i].value == value2sel)
		{
			objRadio[i].checked = true;
		}
	}
}


/*
	Pega o valor de um FORM >INPUT RADIO
*/
function getRadioValue(formName,formField) // 01.07.2003
{
	objRadio = eval("document." + formName + "." + formField);
	for(i=0; i < objRadio.length; i++)
	{
		if(objRadio[i].checked == true)
		{
			return objRadio[i].value;
		}
	}
	return;
}

/*
	Setar valor para um FORM > INPUT CHECKBOX
	setCheckboxValue(formName,formField,value2sel)
		formName = Nome do formulario
		formField = Nome do Campo
		value2sel = Valor(es) para ser(em) setados
			ex.: 'mae|pai|avó' ou 'mae'

	Use: setCheckboxValue('formulario','cbox','mae|pai|avó')
*/
function setCheckboxValue(formName,formField,value2sel,php) // 28.11.2003, 08.07.03
{
	if('' == value2sel) return;
	//objCheckbox = eval("document." + formName + "." + formField)
	//alert(document.forms["entryform"].elements["select02[]"])
	// objCheckbox = eval("document.forms[\"" + formName + "\"].elements[\"" + formField + "\"]")
	if(php) objCheckbox = eval("document.forms[\"" + formName + "\"].elements[\"" + formField + "\"]");
	else objCheckbox = eval("document." + formName + "[\"" + formField + "\"]")
	_values = value2sel.split("|");

	// Se houver 1 checkbox
	if(objCheckbox.length == 'undefined' && objCheckbox.value == value2sel)
	{
		objCheckbox.checked = true;
	}
	for(i=0; i < objCheckbox.length ; i++)
	{
		objCheckbox[i].checked = false; // Limpando todos
		for(j=0; j < _values.length; j++)
		{
			if (objCheckbox[i].value == _values[j])
			{
				objCheckbox[i].checked = true;
			}
		}
	}
}


/*
	Setar valor para um FORM > INPUT CHECKBOX
	getCheckboxValue(formName,formField,value2sel)
		formName = Nome do formulario
		formField = Nome do Campo
		value2sel = Valor(es) para ser(em) setados
			ex.: 'mae|pai|avó' ou 'mae'

	Use: setCheckboxValue('formulario','cbox','mae|pai|avó')
*/
function getCheckboxValue(formName,formField,sep,php) // 08.07.03
{
	if(php) objCheckbox = eval("document.forms[\"" + formName + "\"].elements[\"" + formField + "\"]");
	else objCheckbox = eval("document." + formName + "[\"" + formField + "\"]");


	if(!sep) sep="|";
	s ="";
	if(objCheckbox.length == "undefined")
	{
		s = objCheckbox.checked;
	}
	else
	{
		for(i=0; i < objCheckbox.length ; i++)
		{
			//alert(objCheckbox[i].checked);
			if(objCheckbox[i].checked == true)
			{
				s += objCheckbox[i].value + sep;
			}
		}
	}
	return s;
}





/*
	Construidor de FORM > SELECT a partir de um array do typo
	array (["1","X"],["2","Y"])
	makeSelect(_array,formName, formField)
	parent

	obs.: esta funcao deve ser chamada apos o objeto form, ou seja,
	depois do form>select que esta criando.
*/
function makeSelect(_array, formName, formField, pai) // 02.07.2003
{
	objSel = eval((pai ? pai + "." : "") + "document." + formName + "." + formField);
	objSel.options.length = 0;
	for (k in _array)
	{
		objSel.options[objSel.options.length] = new Option(_array[k],k);
	}
}

/*
	Constroi um array assoc
	lista = "PR|Parana,SC|Santa Catarina" ou "PR|SC|AC.."
	sepOption = Separador de Array/Options ex.: /
	sepValue = Separador de valores ex.: ||
*/
function makeAssocArray(lista,sepOption,sepValue) // 18.07.2003
{
	if(!sepOption) sepOption = ",";
	if(!sepValue) sepValue = "|";
	_a = new Array();
	if(!lista) { _a[""]="" ; return _a; }
	lista = lista.split(sepOption);
	for(k=0; k < lista.length; k++)
	{
		kv = lista[k].split(sepValue);
		if(!kv[1]) _a[kv[0]] = kv[0];
		else _a[kv[0]] = kv[1];
	}
	return _a;
}

/*
	Cria um array associativo de um FORM > SELECT
*/
function makeAssocArraySelect(formName,formField)
{
	_s = new Array();
	obj = eval("document." + formName + "." + formField);
	for(i=0; i < obj.length; i++){ _s[obj[i].value] = obj[i].text; }
	return _s;
}

/*
	habilita e dasabilita campos do formulario.
	formName = Nome do formulario
	fieldName = Nome do campo
	targ = Alvo (parent ...)
	flag = (true|false) habilita,desabilita) padrao=false
*/
function DisEnable(formName,fieldName,flag,targ) // 15.07.2003
{
	flag = flag ? true : false;
	if(targ) targ = targ + ".";
	else targ="";
	obj = eval(targ + "document." + formName + "." + fieldName);
	obj.disabled = flag;
}

/* Carrega link dentro do iframe */
function iframeSrc(iframeName,src) {document.getElementById(iframeName).src = src; }
/* Escreve um iframe sem SRC H=0 W=0 B=0 M=0 FB=0*/
function writeIframe(nome,W,H,FB){
	if(!W) W=0; if(!H) L=0; if(!FB) FB=0;
	document.write('<iframe id="' +nome+ '" name="'+nome+'" src="" height="'+H+'" width="'+W+'" marginwidth="0" marginheight="0" frameborder="'+FB+'" border="' +FB+ '"> </iframe>');return nome;}

function getLocation(src)
{
	iframeSrc(iframeName, src);
}
/*

PS: form name should be "form"

Date Format in Brazilian
Usage into tag INPUT TEXT:
onKeyDown=DateFormatBr("fieldName_name",event)
*/
function DateFormatBr(fieldName,keyPressed) { // v0.1
	var KeyPress = keyPressed.keyCode;
	vr = document.form[fieldName].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	size = vr.length + 1;

	if ( KeyPress != 9 && KeyPress != 8 ){
		if ( size > 2 && size < 5 )
			document.form[fieldName].value = vr.substr( 0, size - 2  ) + '/' + vr.substr( size - 2, size );
		if ( size >= 5 && size <= 10 )
			document.form[fieldName].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

/*
Formata data no padrao Brasil (ex.: 30/12/2003)
onKeyDown=DateFormatBr_v2('formulario','fieldName_name',event)
*/
function DateFormatBr_v2(formName, fieldName, keyPressed) { // 08.07.2003
	var KeyPress = keyPressed.keyCode;
	objDate = eval("document." + formName + "." + fieldName);
	vr = objDate.value
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	size = vr.length + 1;

	if ( KeyPress != 9 && KeyPress != 8 ){
		if ( size > 2 && size < 5 )
			objDate.value = vr.substr( 0, size - 2  ) + '/' + vr.substr( size - 2, size );
		if ( size >= 5 && size <= 10 )
			objDate.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}




/*
PS: form name should be "form"

Description:	Value Format type Money in Brazilian

Usage on tag INPUT TEXT AND TEXTAREA
onKeyDown=ValueFormatBr("fieldName",<MaxSize>,event)
 - MaxSize can be a value of 0 until 17

*/

function ValueFormatBr(fieldName,maxSize,keyPressed) { //v0.1
	var tecla = keyPressed.keyCode;
	vr = document.form[fieldName].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	size = vr.length;
	if (size < maxSize && tecla != 8){ size = vr.length + 1 ; }

	if (tecla == 8 ){	size = size - 1 ; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		count = 0;
		if ( size <= 2 ){
			count=0;
	 		document.form[fieldName].value = vr ;
			}
	 	if ( (size > 2) && (size <= 5) ){
			count=1;
	 		document.form[fieldName].value = vr.substr( 0, size - 2 ) + ',' + vr.substr( size - 2, size ) ;
			}
	 	if ( (size >= 6) && (size <= 8) ){
			count=2;
	 		document.form[fieldName].value = vr.substr( 0, size - 5 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
			}
	 	if ( (size >= 9) && (size <= 11) ){
			count=3;
	 		document.form[fieldName].value = vr.substr( 0, size - 8 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
			}
	 	if ( (size >= 12) && (size <= 14) ){
			count=4;
	 		document.form[fieldName].value = vr.substr( 0, size - 11 ) + '.' + vr.substr( size - 11, 3 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
			}
	 	if ( (size >= 15) && (size <= 17) ){
			count=5;
	 		document.form[fieldName].value = vr.substr( 0, size - 14 ) + '.' + vr.substr( size - 14, 3 ) + '.' + vr.substr( size - 11, 3 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
			}
	}
	status = size;
	if (size >= maxSize)
	{
		document.form[fieldName].value = document.form[fieldName].value.substring(0, maxSize+count - 1);
	}
}



/*
	ex.: jumpMenu('parent',this,0)

	Usage:<select>
		<option value="URL">Valor
	</select>
*/

function jumpMenu(targ,selObj,restore){ // v0.1
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/*
	Abre janelas popup.

*/
function openWindow(theURL,winName,features) { //v2.0
  if(!features)
  {
      features="width=350,height=350,status=yes,scrollbars=1";
  }
  window.open(theURL,winName,features);
}

////////// SHOW HIDE ///////////////
function ShowHide(id1, id2) {
	  if (id1 != '') expMenu(id1);
	  if (id2 != '') expMenu(id2);
	}

	function expMenu(id) {
	  var itm = null;
	  if (document.getElementById)
    {
		itm = document.getElementById(id);
	  }
    else if (document.all)
    {
		  itm = document.all[id];
	  }
    else if (document.layers)
    {
		itm = document.layers[id];
	  }

	  if (!itm)
    {
	    // do nothing
      alert ("teste");
	  }
	  else if (itm.style)
    {
		  if (itm.style.display == "none")
      {
        itm.style.display = "";
      }
		  else
      {
        itm.style.display = "none";
      }
	  }
	  else
    {
      itm.visibility = "show";
    }
	}
////////// SHOW HIDE ///////////////


function showHideLayers() { //v6.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function 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;
}




/*
	dumpObj objects and contents
	Use: dumpObj(this,NomeDoCampo)
*/
function dumpObj (obj, str) { // v0.1
var s = new Array ();
var i;
var j = 0;
  for (i in obj) {   // get all objects, and contents
    s[j] = i + ": " + obj[i];
    j = j + 1;
  }
  s.sort ();         // sort them data down
  document.open ("text/html");  // open a new document
  document.write ("<html><head>");  //  with full XHTML style
  document.write ("<title>Dump page</title>");
  document.write ("</head><body>");
  document.write ("<p><b>");  // make it kosher
  document.write (str, " contents.<br />");
  document.write (navigator.appName, "<br />");
  document.write (navigator.userAgent, "</b><br /><br />");
  for (i=0; i<j; i++) {
    document.write (s[i], "<br />");
  }
  document.write ("</p>");
  document.write ("</body></html>");
  document.close ();  // close down output stream
}



/*
Mostra mensagem, quando for escolhido mais de (n QUANTIDADE} na caixa de selecao (multiple)

	Obj 	- Use (this)
	nome	- Nome do Campo
	quantidade - Numero máximo de selecoes pode ter
Use: onBlur="escolha_n(this, NomeDoCampo, 3)"
*/

function escolha_n(Obj, nome, quantidade) { // v0.1

	//isArray(Obj);

	//ListObj(Obj.elements[3]);

	total = Obj.length;
	if (!quantidade) quantidade=3;
	count=0;
	for (var i=0; i < total ;i++)
	{
		var x = Obj[i] //.options[i];
		if (x.type == "select-multiple" && x.name == nome)
		{
			for(j=0; j < x.length; j++)
			{
				if (x[j].selected == true) count = count + 1
			}
		}
	}
	if (count > quantidade)
	{
		alert("Você só pode selecionar no máximo " + quantidade)

		// Dermarcar todos
		for (var i=0; i < total ;i++)
		{
			var x = Obj[i] //.options[i];
			if (x.type == "select-multiple" && x.name == nome)
			{
				for(j=0; j < x.length; j++)
				{
					x[j].selected = false;
				}
			}
		}
	}
	//Obj.nome.focus();

}
function email(action)
{
   document.boletim.action.value=action;
   document.boletim.submit();

}

/*
Esconde ou mostra um Div ou outra TAG que tenha ID=****_div
divIDName = Lista de nome dos ID, nao pode ter espacos e separado por virgula
hide = true-esconde false=mostra
*/
function hideDiv(divIDName, hide)
{
	_divID = divIDName.split(",");
	for(i=0 ; i < _divID.length; i++)
	{
		var div = document.getElementById(_divID[i] + "_div");     // W3C DOM level 2
		if (hide == true)
		{
			div.style.display = "none";
			continue;
		}
		else
		{
			div.style.display = "";
		}
		//window.location.hash = _divID[i];
	}
}

/* confirmar */
function confirmar()
{
	if(confirm("Deseja realmente remover este registro?\n\nContinuar?")) return true;
	else return false;
}

function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}
