
/*
############################################
#
# Date: 5/12/2003
# Author: Justin B. Hankins
# Contact: hankins@meticulous.com
#
# Summary: This file contains all the javascript code for the main pages of LINKAGES
#
############################################	
*/

// This script is to kill any spambot in its tracks...
// Well, the dumb ones, anyways
// Call the following link: 
// <a href="javascript:returnEmail('username', 'domain');">Click to email</a>
function returnEmail(username, domain)	{
	var formattedEmail = username+"@"+domain;
	window.location.href = "mailto:"+formattedEmail;
}

// This script used to pop open a window
// This JavaScript pops open the photolog viewer window for users to 
// access larger versions of the photolog images
var browseWin = 0;
function openPopper(name,width,height) {
	browseWin = open('http://www.aedprofiles.org/media/photos/'+name, 'window_popper', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=yes,copyhistory=yes,width='+width+',height='+height);
	window.browseWin.focus();
}


function NORMINV(p, mu, sigma) {
//	p = form.prob.value // This value is supplied by the user
	t = (p > .5) ? (1 - p) : p
	s = Math.sqrt(-2.0 * Math.log(t))
	a = 2.515517 + (0.802853 * s) + (0.010328 * s * s)
	b = 1 + (1.432788 * s) + (0.189269 * s * s) + (0.001308 * s * s * s)
	u = s - (a / b)
	z = (p < .5) ? (- u) : u
	returned_data = sigma * z + mu;
	return roundNum(4, returned_data);
}

/* This function rounds the passed number */
function roundNum(places, data) {
	var returned_data = Math.round(data * Math.pow(10,places)) / Math.pow(10,places);
	return returned_data;
}


///////////////////////////////////////////////////
//
// IRON DEFICIENCY CALCULATOR FUNCTIONS ([x]IDForm)
//
//
///////////////////////////////////////////////////
/*
	This function is called when the form first loads and sets up any initial values that require calculations
*/
function setupIDForm() {
	// Setup initial data
	document.calc_form.b4.value  = 500;
	document.calc_form.b5.value  = 40;
	document.calc_form.b6.value  = 250000;
	document.calc_form.b7.value  = 0.5;
/*	document.calc_form.b8.value  = 0.8;
	document.calc_form.b10.value = 1;
	document.calc_form.b11.value = 1.2;
	document.calc_form.b12.value = 1.5;
	document.calc_form.b13.value = 11;
*/
	
	// Update the form with the data
	updateIDForm();
	
}

/*
	This function is called whenever data within one of the hot zones (yellow/editable) changes.
	It performs all necessary calculations and equating.
*/
function updateIDForm() {
	var b4  = document.calc_form.b4.value;
	var b5  = document.calc_form.b5.value;
	var b6  = document.calc_form.b6.value;
	var b7  = document.calc_form.b7.value;
/*	var b8  = document.calc_form.b8.value;
	var b10 = document.calc_form.b10.value;
	var b11 = document.calc_form.b11.value;
	var b12 = document.calc_form.b12.value;
	var b13 = document.calc_form.b13.value;
*/
	var b8  = 0.8;
	var b10 = 1;
	var b11 = 1.2;
	var b12 = 1.5;
	var b13 = 11;

	// Row 16 -- =IF(B5<15,B10,IF(B5<=30,B11,B12))
	if (b5 < 15) {
		b16 = b10;
	} else {
		if (b5 <= 30) {
			b16 = b11;
		} else {
			b16 = b12;
		}			
	}

	// Row 17 -- =IF(B5*(1-B7)<15,B10,IF(B5*(1-B7)<=30,B11,B12))
	if ((b5 * (1 - b7)) < 15) {
		b17 = b10;
	} else {
		if ((b5 * (1 - b7)) <=30) {
			b17 = b11;
		} else {
			b17 = b12;
		}
	}

	// Row 19 -- =B13-NORMINV(B5/100,0,B16)
	var b19 = b13 - NORMINV((b5 / 100), 0, b16);
	
	// Row 20 -- =B13-NORMINV(B5*(1-B7)/100,0,B17)
	var b20 = b13 - NORMINV((b5 * (1 - b7) / 100), 0, b17);
	
	// Row 21 -- =B20-B19
	var b21 = (b20 - b19);
	
	// Row 24 -- =1-B8^B21
	var b24 = (1 - (Math.pow(b8, b21)));
	document.calc_form.b24.value = roundNum(0, 100 * b24);
	
	// Row 25 -- =B6*(B4/100000)*B24
	var b25 = b6 * (b4 / 100000) * b24;
	document.calc_form.b25.value = roundNum(0, b25);
	
}

///////////////////////////////////////////////////
//
// UNDERWEIGHT CALCULATOR FUNCTIONS ([x]UWForm)
//
//
///////////////////////////////////////////////////

/*
	This function is called when the form first loads and sets up any initial values that require calculations
*/
function setupUWForm() {
	// Setup initial data
	document.calc_form.b4.value  = 100;
	document.calc_form.b5.value  = 25;
	document.calc_form.b6.value  = 15;
	document.calc_form.b8.value  = 10000;
	document.calc_form.b9.value  = 5;

	// Update the form with the data
	updateUWForm();
	
}

/*
	This function is called whenever data within one of the hot zones (yellow/editable) changes.
	It performs all necessary calculations and equating.
*/
function updateUWForm() {

	// Originally set in form data
	var b4 = document.calc_form.b4.value;
	var b5 = document.calc_form.b5.value;
	var b6 = document.calc_form.b6.value;
	var b7 = 0.025
	var b8 = document.calc_form.b8.value;
	var b9 = document.calc_form.b9.value;

	// B12 = b6 - b5
	// Was discarded prior to launch, but it's necessary to calculate B15, 
	// so substitute the var B12 as the value instead of using the form element
	var b12 = (b6 - b5);
	
	//  Row 15 - calculations -- =B4*EXP(B7*B12)
	var b15 = (b4 * Math.pow(Math.E,(b7 * b12)));
	document.calc_form.b15.value = roundNum(0, b15);
	
	// Row 16 - final calculations -- =(B8/1000)*(B4-B15)/B9
//	var b16 = roundNum(0, ((b8 / 1000) * (b4 - b15) / b9));
	var b16 = ((b8 / 1000) * (b4 - b15) / b9);
	document.calc_form.b16.value = roundNum(0, b16);
	
}