/**************
	
	© 2008 Natural Standard. All rights reserved.

**************/

function checkNumeric () {
	for(var i=0; i<arguments.length; ++i){
		if(isNaN(arguments[i])) return false;
	}
	return true;
}

function writeDiv(id, text) {
	document.getElementById(id).innerHTML = text
}

function clearDiv(id) {
	writeDiv(id,"");
}

function showElement(id, displayType){
	displayType = displayType || "block";
	document.getElementById(id).style.display = displayType;
}

function hideElement (id) {
	document.getElementById(id).style.display = "none";
}

function setInput(id,text) {
	document.getElementById(id).value = text

}

function setSelect (name, idx, frm) {
	frm = frm || document.forms[0];
	var sel = frm[name];
	
	if(sel) sel.selectedIndex = idx;
}

function getSelectValue (name, frm) {
	frm = frm || document.forms[0];
	var sel = frm[name];
	
	return sel ? sel.options[sel.selectedIndex].value : null;
}

function clearInput() {
	for(var i=0; i<arguments.length; ++i){
		setInput(arguments[i],"");
	}
}

function getInput(id) {
	var input = null;
	/*
	for(var i=1; i<document.forms.length; ++i){ // CMH - 4/10/08 - changed i=0 to i=1 so this function would ignore the search form in the header
		if(input = document.forms[i].elements[id].value){
			return input;
		}		
	}
	*/

	var input = document.getElementById(id);

	return input.value;
}

function doError(str){
	str = str || "Invalid input. Please try again.";
	alert(str);
	return false;
}

function toDate(str) {

      var dateArray = str.split('/');
      sdate = new Date(dateArray[2],dateArray[0]-1,dateArray[1]);

	return(sdate);

}

function formatDate(date) {
	return ((date.getMonth()+1)+"/" +(date.getDate())+"/" + date.getFullYear());

}

function makeDate(str) {
	var now = new Date();

	if (str.indexOf("/")<0) {
		doError ("Date is not in the right format");
	}
	else {
		return (toDate(str+"/" + now.getFullYear()));
	}

}

function addDays(sdate,days) {
	var msPerDay = 24 * 60 * 60 * 1000

  // add the number of days as milleseconds
        var odate = new Date(sdate.valueOf() + (days * msPerDay));

        return (odate);
 }
 
function getElapsedDays (startDate, endDate){
	var msPerDay = 24 * 60 * 60 * 1000;		
	var eDate = getBaseDate(endDate);
	var sDate = getBaseDate(startDate);
	
	var msDiff = eDate.valueOf() - sDate.valueOf();
	
	return Math.floor(msDiff/msPerDay);
	
}

function getBaseDate (d) {
	// strips time portion from d
	return new Date(d.getFullYear(), d.getMonth(), d.getDate());
}

function getRadioButtonValue (name, frm){
	frm = frm || document.forms[0];
	var radioButtons = frm[name];
	
	for(var i=0; radioButtons && i<radioButtons.length; ++i){
		if(radioButtons[i].checked) {
			return radioButtons[i].value;
		}
	}
}

function clearRadioButtons (name, frm) {
	frm = frm || document.forms[0];
		var radioButtons = frm[name];
		
		for(var i=0; radioButtons && i<radioButtons.length; ++i){			
				radioButtons[i].checked = false;			
		}
}

function getPounds (kg) {
	return kg * 2.2;
}

function getKilograms (lbs) {
	return lbs/2.2;
}

function getInches (cm){
	return cm/2.54;
}

function getCentimeters (inches) {
	return inches*2.54;
}

