function createWeights(theObj){
  var callerForm=theObj.form;

  if(!gIsNumber(callerForm.PWeight.value,70/2.2,400/2.2)){
    alert("Voce deve entrar com pesos entre 32 and 181 Kg");
    callerForm.PWeight.focus();
    callerForm.PWeight.select();
    return false;
  }
  if(!gIsNumber(callerForm.CWeight.value,70/2.2,400/2.2)){
    alert("Voce deve entrar com pesos entre 32 and 181 Kg");
    callerForm.CWeight.focus();
    callerForm.CWeight.select();
    return false;
  }
   
  var pWeight=parseInt( stripLeadingZeros( (callerForm.PWeight.value)*2.2 ) );
  var cWeight=parseInt( stripLeadingZeros( (callerForm.CWeight.value)*2.2 ) );
  var theWeek=0;

  for(i=0;i<callerForm.Week.options.length;i++){
    if(callerForm.Week.options[i].selected==true){
      theWeek=parseInt(callerForm.Week.options[i].value);
    }
  }

  if(theWeek<8){
	  var lowWeight=0+pWeight;
	  var upWeight=0+pWeight;
	} else if(theWeek>=8 && theWeek <= 15){
      var lowWeight=Math.round((-0.002604*Math.pow(theWeek,3))+(0.1517857*Math.pow(theWeek,2))-(1.81994*Math.pow(theWeek,1))+6.4178571 +pWeight);
      var upWeight=Math.round((0.0130208*Math.pow(theWeek,3))-(0.379464*Math.pow(theWeek,2))+(4.0550595*Math.pow(theWeek,1))-12.58214 +pWeight);
   } else if(theWeek>=16 && theWeek <= 31){
        var lowWeight=Math.round((0.000342*Math.pow(theWeek,3))-(0.041126*Math.pow(theWeek,2))+(2.3628096*Math.pow(theWeek,1))-23.16739 +pWeight);
        var upWeight=Math.round((-0.000789*Math.pow(theWeek,3))+(0.0324675*Math.pow(theWeek,2))+(1.1341089*Math.pow(theWeek,1))-14.778114 +pWeight);
   } else if(theWeek>=32){
        var lowWeight=Math.round((0.0052083*Math.pow(theWeek,3))-(0.616071*(Math.pow(theWeek,2)))+(24.33631*Math.pow(theWeek,1))-297.05 +pWeight);
        var upWeight=Math.round((-4.9*Math.pow(10,-16))*Math.pow(theWeek,3)-(0.040179*Math.pow(theWeek,2))+(3.3303571*Math.pow(theWeek,1))-36.45 +pWeight);
   }

   callerForm.Pound1.value=(lowWeight)/2.1948;
   callerForm.Pound2.value=(upWeight)/2.1938;
   callerForm.GWeight.value=(cWeight-pWeight)/2.2;
}


function stripLeadingZeros( number ) {

  // convert to string
  number = "" + number;

  // strip out any leading zeros that might be interpreted as octal
  if ( number.indexOf("0") != -1 ) { //if it includes a 0 test:
    while ( number.indexOf("0") == 0 ) {
      number = (number.substring( 1 ));
    }
  }

  return number;

}


