function imc(h,w,a,s) {
//alert("height="+h+" , weight="+w+" , age="+a+" , sex="+s);
	var h2 = h / 100;
	var imc = w  / (h2 * h2);
	return custRound(imc,2);
}

function checkImcData(h,w,a,s) {
	var msg = '';
	if (h == '') msg += "Completeaza inaltimea\n";
	if (w == '') msg += "Completeaza greutatea\n";
	if (a == '') msg += "Completeaza varsta\n";
	if (s == '') msg += "Completeaza sexul\n";
	if (msg != '') {
		alert(msg);
		return false;
	} else {
		return true;
	}
	return false;
}

function custRound(x,places) {
  return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places);
}

function perfectWeight(h,w,a,s) {
	var pw = 0;
	if (s == 'm') {
		pw = (h-100-((h-150)/4))+((a-20)/4); 
	} 
	if (s == 'f') {
		pw = (h-100-((h-150)/2.5))+((a-20)/6); 
	}
    return Math.round(pw);
}

function imcVerdict(imc) {
	var v = 'n/a';
    
    if (imc < 18.8) v = 'Subponderal';
    if (imc >= 18.8 && imc < 25) v = 'Greutate normala';	
    if (imc >= 25 && imc < 30) v = 'Supraponderal';	
    if (imc >= 30 && imc < 40) v = 'Obez I';	
    if (imc >= 40) v = 'Obez II';	
      
    return v;
	
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


