﻿// JavaScript File

// Open a new window

function newWindow(url)
{
   if(url.substring(0,4) != 'http')
      url = 'http://' + url;
   window.open(url,'_blank','width=800,height=620,resizable=yes,status=yes,scrollbars=yes,toolbar=yes,menubar=yes');
} 


// Body Mass Index Calculator
// copyright 28th April 2006, by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
function valButton(btn) {
    var cnt = -1;for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {
            cnt = i; i = -1;
        }
    }
    if (cnt > -1) 
        return btn[cnt].value;
    else return null;
}

function numerizeOrZero(fld) {
    var n = stripBlanks(fld);
    
    if ( !Number(n) ) 
        return 0; 
    else 
        return n;
}
    
        
function stripBlanks(fld) {
    var result = "";
    var c = 0;
    for (i=0; i < fld.length; i++) {
        if (fld.charAt(i) != " " || c > 0) {
            result += fld.charAt(i);
            if (fld.charAt(i) != " ") 
                c = result.length;
        }
    }
    return result.substr(0,c);
}

function calc(thisform) {
    var d = valButton(thisform.d);
    if (d == null) {
        alert("You must choose metric or standard!");
        thisform.d.focus();
        return false;
    }
    cv = d.split(',');
    var h1 = stripBlanks(thisform.h1.value);
    var h2 = stripBlanks(thisform.h2.value);

    if (cv[0] != 1) { //standard, so ensure inches is a number or 0
        h2 = numerizeOrZero(h2);
    }

    
    if (h1 == '' || h2 == '' ) { 
        alert("You must enter your height");
        thisform.h.focus();
        return false;
    }
    if (h1 != Number(h1) || (h1 = Number(h1*cv[2]/100)) < 1 || h1 > 2.5) {
        alert("Invalid height entered");
        thisform.h.focus();
        return false;
    }
    h2 = Number(h2*cv[0]/100);
    var h = h1 + h2;
    
    var w = stripBlanks(thisform.w.value);
    if (w == '') {
        alert("You must enter your weight");
        thisform.w.focus();
        return false;
    }
    if (w != Number(w) || (w = Number(w/cv[1])) < 25 || w > 250) {
        alert("Invalid weight entered");
        thisform.w.focus();
        return false;
    } 

    thisform.f.value = Math.round(w / (h*h)*100)/100;

}


/* PUT AT END OF JS FILE */
if(Sys && Sys.Application) {     
    Sys.Application.notifyScriptLoaded();
}