<?xml version="1.0" encoding="utf-8"?>
<Module>
  <ModulePrefs title="IMC / IMG Calculator"
  			   height="200" 
  			   directory_title="IMC / IMG Calculator"
			   description="Calculez votre indice de masse corporelle ainsi que votre indice de masse grasse très simplement. La surveillant régulière de ces deux paramètres vous permet de mieux gérer votre régime alimentaire et de vous sentir bien mieux dans vos baskettes."
			   thumbnail="http://www.strangeblackhole.com/igg/imc/th-imc.png"
			   screenshot="http://www.strangeblackhole.com/igg/imc/scr-imc.png"
			   title_url="http://www.strangeblackhole.com"
			   author="StrangeBlackHole"
			   author_email="contact@strangeblackhole.com"
			   author_location="Massy, France"
			   author_link="http://www.strangeblackhole.com">
	<Require feature="opensocial-0.7"/>
	<Require feature="tabs"/>
	<Require feature="dynamic-height"/>
	<Require feature="analytics"/>
	<Locale messages="http://www.strangeblackhole.com/igg/imc/ALL_ALL.xml"/>
	<Locale lang="es" messages="http://www.strangeblackhole.com/igg/imc/es_ALL.xml"/>
	<Locale lang="pt" messages="http://www.strangeblackhole.com/igg/imc/pt_ALL.xml"/>	 
        <Locale lang="pt-pt" messages="http://www.strangeblackhole.com/igg/imc/pt_pt_ALL.xml"/>
        <Locale lang="pt-br" messages="http://www.strangeblackhole.com/igg/imc/pt_br_ALL.xml"/>
  </ModulePrefs> 
  <Content type="html">
     <![CDATA[ 
		<style type="text/css">
			* {
				margin:0;padding:0;
				font-size:12px;
			}
			p {
				margin:10px 0;
			}
			form {
				padding:10px;
				text-align:right;
				background:url(http://www.strangeblackhole.com/igg/imc/fond.jpg) no-repeat;
			}
			label {
				margin:5px;
				text-align:right;
				display:block;
			}
			.val {
				padding-right:10px;
				text-align:right;
			}
		</style>
		<script type="text/javascript">
		
			var prefs = new gadgets.Prefs();	
			var tabs  = new gadgets.TabSet(__MODULE_ID__,prefs.getMsg("calculer"));
			
			function init()
			{
				var prefs = new gadgets.Prefs();
								
				tabs.addTab(prefs.getMsg("calculer"), {
		           contentContainer: document.getElementById("one_id"),
				   callback: callback
		        	});
				
				tabs.addTab(prefs.getMsg("imc"), {
		           contentContainer: document.getElementById("two_id"),
				   callback: callback
		        	});
				
				tabs.addTab(prefs.getMsg("img"), {
		           contentContainer: document.getElementById("three_id"),
				   callback: callback
		        	});
			}
			
			function callback(a)
			{
				if ( a == "one_id" )
				{
	       			gadgets.window.adjustHeight(230);
				}
				else
				{
	       			gadgets.window.adjustHeight();				
				}
			}
			
			/**
 			* initialisation des onglets
 			*/
			gadgets.util.registerOnLoadHandler(init);
			
			var sbh = {
			
				calculer : function()
				{
					var prefs = new gadgets.Prefs();
								
					var form = document.forms["formCalc"] ;
				
					var sex;
					(form.elements['sex'][0].checked) ? sex=1 : sex=0 ;
												
					var age    = form.elements["age"].value ;
					var taille = form.elements["taille"].value;
					var poids  = form.elements["poids"].value;
					var IMC    = Math.round(eval(eval(poids)/(eval(taille/100)*eval(taille/100))));
					var IMG    = Math.round(eval(eval(1.2*IMC)+eval(0.23*age)-eval(10.8*sex)-5.4));
								
					var imcLabel;
					if (IMC <= 16.5) {
						imcLabel = prefs.getMsg("denutrition");
					}
					if (IMC > 16.5 && IMC <= 18.5) {
						imcLabel = prefs.getMsg("maigreur");
					}
					if (IMC > 18.5 && IMC <= 25) {
						imcLabel = prefs.getMsg("corpulence-normale");
					}
					if (IMC > 25 && IMC <= 30) {
						imcLabel = prefs.getMsg("surpoids");
					}
					if (IMC > 30 && IMC <= 35) {
						imcLabel = prefs.getMsg("obesite-moderee");
					}
					if (IMC > 35 && IMC <= 40) {
						imcLabel = prefs.getMsg("obesite-severe");
					}												
					if (IMC > 40) {
						imcLabel = prefs.getMsg("obesite-morbide");
					}
								
					document.getElementById("imc").innerHTML = IMC ;
					document.getElementById("imcLabel").innerHTML = imcLabel ;
				
					var imgLabel;
					switch (sex) {
						case 1:
							if (IMG < 15){
								imgLabel = prefs.getMsg("trop-maigre");
							}
							if (IMG >= 15 && IMG <= 20){
								imgLabel = prefs.getMsg("normal");
							}
							if (IMG > 20){
								imgLabel = prefs.getMsg("trop-de-graisse");
							}
							break;
						case 0:
							if (IMG < 25){
								imgLabel = prefs.getMsg("trop-maigre");
							}
							if (IMG >= 25 && IMG <= 30){
								imgLabel = prefs.getMsg("normal");
							}
							if (IMG > 30){
								imgLabel = prefs.getMsg("trop-de-graisse");
							}					
							break;						
					}
					
					document.getElementById("img").innerHTML = IMG ;
					document.getElementById("imgLabel").innerHTML = imgLabel ;
					
					return false;
				}
			}			
			
		</script>
		
		<div id="one_id" style="display:none;">
			<form name="formCalc" onsubmit="return sbh.calculer()">
				<label for="sex"><input type="radio" name="sex" value="H" checked="checked" />__MSG_homme__ <input type="radio" name="sex" value="F"/>__MSG_femme__</label>			
				<label for="age">__MSG_age__ : <input name="age" value="" size="4" /></label>
				<label for="taille">__MSG_taille__ (cm) : <input name="taille" value="" size="4" /></label>
				<label for="poids">__MSG_poids__ (kg) : <input name="poids" value="" size="4" /></label>
				<input type="submit" value="__MSG_calculer__" />			
			</form>
			<h3>__MSG_imc__ : <span id="imc">00</span> kg.m<sup>-2</sup> <span id="imcLabel"></span></h3>
			<h3>__MSG_img__ : <span id="img">00</span> % <span id="imgLabel"></span></h3>
		</div>
		
		<div id="two_id" style="display:none;">
			<p>__MSG_imc-desc__</p>
			<table width="100%">
			<caption><b>__MSG_imc-interpretation__</b></caption>
			<tbody>
				<tr bgcolor="#cccccc">
					<th>__MSG_imc__ (kg·m<sup>-2</sup>)</th>
					<th>__MSG_interpretation__</th>
				</tr>
				<tr>
					<td class="val">< 16,5</td>
					<td>__MSG_denutrition__</td>
				</tr>
				<tr bgcolor="#f5f5f5">
					<td class="val">16,5 - 18,5</td>
					<td>__MSG_maigreur__</td>
				</tr>
				<tr>
					<td class="val">18,5 - 25</td>
					<td>__MSG_corpulence-normale__</td>
				</tr>
				<tr bgcolor="#f5f5f5">
					<td class="val">25 - 30</td>
					<td>__MSG_surpoids__</td>
				</tr>
				<tr>
					<td class="val">30 - 35</td>
					<td>__MSG_obesite-moderee__</td>
				</tr>
				<tr bgcolor="#f5f5f5">
					<td class="val">35 - 40</td>
					<td>__MSG_obesite-severe__</td>
				</tr>
				<tr>
					<td class="val">> 40</td>
					<td>__MSG_obesite-morbide-ou-massive__</td>
				</tr>
			</tbody>
			</table>
		</div>
		
		<div id="three_id" style="display:none;">
			<p>__MSG_img-desc__</p>
			<table width="100%">
			<caption><b>__MSG_img-interpretation__</b></caption>
			<tbody>
				<tr bgcolor="#cccccc">
					<th>__MSG_femme__</th>
					<th>__MSG_homme__</th>
					<th>__MSG_interpretation__</th>
				</tr>
	    		<tr>
					<td class="val">< 25 %</td>
					<td class="val">< 15 %</td>
					<td>__MSG_trop-maigre__</td>
				</tr>
	   			<tr bgcolor="#f5f5f5">
					<td class="val">25-30 %</td>
					<td class="val">15-20 %</td>
					<td>__MSG_normal__</td>
				</tr>
	    		<tr>
					<td class="val">> 30 %</td>
					<td class="val">> 20 %</td>
					<td>__MSG_trop-de-graisse__</td>
				</tr>
			</tbody>
			</table>
		</div>
		<p style="text-align:right;"><a href="http://blog.strangeblackhole.com" target="_blank">by StrangeBlackHole</a></p>
		<script>_IG_Analytics("UA-2419625-17", "/imc-img-calculator");</script> 
     ]]>
  </Content> 
</Module>
