<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs
    title="Valor por Extenso"
    title_url="http://www.zoqui.com"
    author="Marco Aurelio Zoqui"
    author_email="marco@zoqui.com"
    height="200"
    width="320"
    description="Retorna Valor Por Extenso"
    scaling="false"
    thumbnail="http://lh5.ggpht.com/_yHJZ4Txl7xs/SujaQCP0jLI/AAAAAAAAAf4/bw-6GrtTmCk/s144/gadget_extenso.png"
    screenshot="http://lh5.ggpht.com/_yHJZ4Txl7xs/SujaQCP0jLI/AAAAAAAAAf4/bw-6GrtTmCk/s800/gadget_extenso.png" />
  <UserPref name="currency" default_value="true" display_name="Reais? " datatype="bool" required="true"/>
  <Content type="html">
    <![CDATA[
<script type="text/javascript">
	var prefs = new gadgets.Prefs();
  	var currency = prefs.getBool("currency");
	function getExtenso(vlr,c ){

                var value = new String;
		value = vlr;
		var ex = [
			["ZERO", "UM", "DOIS", "TRÊS", "QUATRO", "CINCO", "SEIS", "SETE", "OITO", "NOVE", "DEZ", "ONZE", "DOZE", "TREZE", "QUATORZE", "QUINZE", "DEZESSEIS", "DEZESSETE", "DEZOITO", "DEZENOVE"],
			["DEZ", "VINTE", "TRINTA", "QUARENTA", "CINQÜENTA", "SESSENTA", "SETENTA", "OITENTA", "NOVENTA"],
			["CEM", "CENTO", "DUZENTOS", "TREZENTOS", "QUATROCENTOS", "QUINHENTOS", "SEISCENTOS", "SETECENTOS", "OITOCENTOS", "NOVECENTOS"],
			["MIL", "MILHÃO", "BILHÃO", "TRILHÃO", "QUADRILHÃO", "QUINTILHÃO", "SEXTILHÃO", "SETILHÃO", "OCTILHÃO", "NONILHÃO", "DECILHÃO", "UNDECILHÃO", "DODECILHÃO", "TREDECILHÃO", "QUATRODECILHÃO", "QUINDECILHÃO", "SEDECILHÃO", "SEPTENDECILHÃO", "OCTENCILHÃO", "NONENCILHÃO"]
		];
		var a, n, v, i, n = value.replace(c ? /[^,\d]/g : /\D/g, "").split(","), e = " E ", $ = "REAL", d = "CENTAVO", sl;
		for(var f = n.length - 1, l, j = -1, r = [], s = [], t = ""; ++j <= f; s = []){
			j && (n[j] = (("." + n[j]) * 1).toFixed(2).slice(2));
			if(!(a = (v = n[j]).slice((l = v.length) % 3).match(/\d{3}/g), v = l % 3 ? [v.slice(0, l % 3)] : [], v = a ? v.concat(a) : v).length) continue;
			for(a = -1, l = v.length; ++a < l; t = ""){
				if(!(i = v[a] * 1)) continue;
				i % 100 < 20 && (t += ex[0][i % 100]) ||
				i % 100 + 1 && (t += ex[1][(i % 100 / 10 >> 0) - 1] + (i % 10 ? e + ex[0][i % 10] : ""));
				s.push((i < 100 ? t : !(i % 100) ? ex[2][i == 100 ? 0 : i / 100 >> 0] : (ex[2][i / 100 >> 0] + e + t)) +
				((t = l - a - 2) > -1 ? " " + (i > 1 && t > 0 ? ex[3][t].replace("ÃO", "ÕES") : ex[3][t]) : ""));
			}
			a = ((sl = s.length) > 1 ? (a = s.pop(), s.join(" ") + e + a) : s.join("") || ((!j && (n[j + 1] * 1 > 0) || r.length) ? "" : ex[0][0]));
			a && r.push(a + (c ? (" " + (v.join("") * 1 > 1 ? j ? d + "S" : (/0{6,}$/.test(n[0]) ? "DE " : "") + $.replace("L", "IS") : j ? d : $)) : ""));
		}
		return r.join(e);
	};
	function valuechanged(){
		formtrans.text.value = getExtenso(formtrans.num.value, currency);
		var content = document.getElementById("extenso_text");
		content.innerHTML = formtrans.text.value;
	};
        function init(){
            var element = document.getElementById('num');  
        };
        gadgets.util.registerOnLoadHandler(init);
</script>
<div id="content_div" 
style="
font-size:10pt; 
padding:2px; 
margin-left: 0px;
text-align:left;
font-family: Arial Narrow; 
width: 320px; 
height: 200px;
background: transparent url(http://sites.google.com/a/zoqui.com/www/gadgetbg.jpg) no-repeat;
">
<form action="http://translate.google.com/translate_t" id="text_form" name="formtrans" enctype="application/x-www-form-urlencoded" autocomplete="off">
	<input type="text" id="num" name="num" onkeyup="valuechanged();" size="20" 
               style="position:absolute; left:16px; top:13px; border:0; text-align: right;background-color: transparent;">
	<input type="hidden" name="text" id="text" value=""/>
	<input type=hidden name="js" value="n" id=js>
	<input type=hidden name="prev" value="_t" id=prev>
	<input type=hidden name="hl" value="en" id=hl>
	<input type=hidden name="ie" value="UTF-8">
	<input type=hidden name="sl" id=old_tl value="pt">
	<input type=hidden name="tl" id=old_tl value="en">
	<input type=hidden id="old_submit" value="Translate">
</form>
<div id="eng_btn" onclick="formtrans.submit();" 
     style="position:absolute; left:259px; top:13px; background-color: transparent; border-color: #FC6; width: 35px; height:25px;" ></div>
<div id="extenso_text" style="position:absolute; left:25px; top:70px; background-color: transparent;width:250px;"></div>
</div>
    ]]>
  </Content>
</Module>
