function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}


/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getContent(formdate){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', '/dc_resources/dc_content.php?date='+formdate);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function addFoodItem(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	if(document.newFoodItemF.newFoodItem.value == "")
	{
	  alert("You need to type the name of the food!");
	}
	else if(isNaN(document.newFoodOzF.newFoodOz.value))
	{
	  alert("Your ounces needs to be a number!");
	}
	else if(isNaN(document.newFoodCalF.newFoodCal.value))
	{
	  alert("Your calories needs to be a number!");
	}
	else
	{
	var formItem = document.newFoodItemF.newFoodItem.value;
	var formOz = document.newFoodOzF.newFoodOz.value;
	var formCal = document.newFoodCalF.newFoodCal.value;
	var formCat = document.newFoodCatF.newFoodCat.value;
	var formMeal = document.newFoodMealF.newFoodMeal.value;
	http.open('get', '/dc_resources/dc_content.php?newFoodItem=' + formItem + '&newFoodOz=' + formOz + '&newFoodCal=' + formCal + '&newFoodCat=' + formCat + '&newFoodMeal=' + formMeal);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
	}
}

function removeFoodItem(rid){
	http.open('get', '/dc_resources/dc_content.php?removeFoodItem=' + rid);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function changeWeight(rid){
    if(document.start_weightF.start_weight.value == "") {
      alert("Please enter your surgery weight.");
    }
    else if(isNaN(document.start_weightF.start_weight.value)) {
      alert("Your weight at surgery needs to be a number.");   
    }
    else if(document.goal_weightF.goal_weight.value == "") {
      alert("Please enter your goal weight.");
    }
    else if(isNaN(document.goal_weightF.goal_weight.value)) {
      alert("Your goal weight needs to be a number.");   
    }
    else {
      var formSurg = document.start_weightF.start_weight.value;
      var formGoal = document.goal_weightF.goal_weight.value;
      if(rid) {
	    http.open('get', '/dc_resources/dc_content.php?changeWeight=' + rid + '&start_weight=' + formSurg + '&goal_weight=' + formGoal);
      }
      else {
        http.open('get', '/dc_resources/dc_content.php?newWeight=1&start_weight=' + formSurg + '&goal_weight=' + formGoal); 
      }
    }
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function addDayWeight(rid){
    if(!rid)
    {
      rid = 0;
    }
    if(document.newDayWeightF.newDayWeight.value == "") {
      alert("Please enter your weight for today.");
    }
    else if(isNaN(document.newDayWeightF.newDayWeight.value)) {
      alert("Your weight for today needs to be a number.");   
    }
    else {
      var formWeight = document.newDayWeightF.newDayWeight.value;
      http.open('get', '/dc_resources/dc_content.php?newDayWeight=' + formWeight +'&id=' + rid);
    }
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function saveJournal(rid){
    if(!rid)
    {
      rid = 0;
    }
    if(document.journalEntryF.journalEntry.value == "") {
      alert("Please enter your entry for today.");
    }
    else {
      var formEntry = document.journalEntryF.journalEntry.value;
      http.open('post', '/dc_resources/dc_content.php');
      http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      http.send('addJournalEntry=' + formEntry + '&id=' + rid);
    }
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	
}

function saveAnnouncement(rid){
    if(!rid)
    {
      rid = 0;
    }
    if(document.announceTitleF.announceTitle.value == "") {
      alert("Please enter a title.");
    }    
    else if(document.announcementF.announcement.value == "") {
      alert("Please enter your announcement.");
    }
    else {
      var formTitle = document.announceTitleF.announceTitle.value;
      var formAnnouncement = document.announcementF.announcement.value;
      http.open('post', '/dc_resources/dc_content.php');
      http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      http.send('addAnnouncement=' + formAnnouncement + '&title=' + formTitle + '&id=' + rid);
    }
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	
}

function editAnnounce(rid){
      http.open('post', '/dc_resources/dc_content.php');
      http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      http.send('editAnnounce=' + rid);
      http.onreadystatechange = handleProducts; 
}
function removeAnnounce(rid){
      http.open('post', '/dc_resources/dc_content.php');
      http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      http.send('removeAnnounce=' + rid);
      http.onreadystatechange = handleProducts; 
}


function addVitamin(){
    if(document.multiF.multi.checked) {
      var formMulti = 1;
    }
    if(document.calciumF.calcium.checked) {
	  var formCalcium = 1;
    }
    if(document.sublingualF.sublingual.checked) {
	  var formSublingual = 1;
    }
    if(document.ironF.iron.checked) {
	  var formIron = 1;
	}
	http.open('get', '/dc_resources/dc_content.php?newVitamin=true&multi=' + formMulti + '&calcium=' + formCalcium + '&sublingual=' + formSublingual + '&iron=' + formIron);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function editVitamin(rid){
    if(document.multiF.multi.checked) {
      var formMulti = 1;
    }
    if(document.calciumF.calcium.checked) {
	  var formCalcium = 1;
    }
    if(document.sublingualF.sublingual.checked) {
	  var formSublingual = 1;
    }
    if(document.ironF.iron.checked) {
	  var formIron = 1;
	}
	http.open('get', '/dc_resources/dc_content.php?editVitamin=true&multi=' + formMulti + '&calcium=' + formCalcium + '&sublingual=' + formSublingual + '&iron=' + formIron + '&id=' + rid);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function addExercise(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	if(document.newExerciseDurationF.newExerciseDuration.value == "")
	{
	  alert("You need to type how long you exercised!");
	}
	else if(isNaN(document.newExerciseDurationF.newExerciseDuration.value))
	{
	  alert("Your duration needs to be a number!");
	}
	else
	{
	var formItem = document.newExerciseF.activity.options[document.newExerciseF.activity.selectedIndex].text;
	var formDuration = document.newExerciseDurationF.newExerciseDuration.value;
	var formCalories = document.newExerciseCaloriesBurnedF.newExerciseCaloriesBurned.value;
	http.open('get', '/dc_resources/dc_content.php?newExerciseName=' + formItem + '&newExerciseDuration=' + formDuration + '&newExerciseCaloriesBurned=' + formCalories);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
	}
}

function removeExercise(rid){
	http.open('get', '/dc_resources/dc_content.php?removeExercise=' + rid);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function changeSection(rid){
	http.open('get', '/dc_resources/dc_content.php?section=' + rid);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
	}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
	    document.getElementById('dc_content').innerHTML = response;
		
	}
}

function generateReport()
{
  var my_user_id = document.report.my_user_id.value;
  var my_user_name = document.report.my_user_name.value;
  var foodLog = document.report.foodLog.checked;
  var vitaminLog = document.report.vitaminLog.checked;
  var exerciseLog = document.report.exerciseLog.checked;
  var weightLossLog = document.report.weightLossLog.checked;
  var weightLossGraph = document.report.weightLossGraph.checked;
  var weightLossJournal = document.report.weightLossJournal.checked;
  var startDate = document.report.start_year.value + "-" + document.report.start_month.value + "-" + document.report.start_day.value;
  var endDate = document.report.end_year.value + "-" + document.report.end_month.value + "-" + document.report.end_day.value;
  var size = "width=" + screen.width + ", height=" + screen.height;
  window.open("/dc_resources/reportviewer.php?my_user_id=" + my_user_id + "&foodLog=" + foodLog + "&vitaminLog=" + vitaminLog + "&exerciseLog=" + exerciseLog + "&weightLossLog=" + weightLossLog + "&weightLossGraph=" + weightLossGraph + "&weightLossJournal=" + weightLossJournal + "&startDate=" + startDate + "&endDate=" + endDate + "&my_user_name=" + my_user_name, "REPORT", size, "directories=0", "location=0", "menubar=0", "resizeable=0", "scrollbars=0", "status=0", "toolbar=0"); 
}


	var inReset=0;
	var globalWhat = '';
	
	function setIn() {
		inReset=1;
	}
	function setOut() {
		inReset=0;
		setTimeout(("deleteTab('"+globalWhat+"')"),7000);
	}
	
	function deleteAll() {
	    document.getElementById('Home').style.display='none';
		document.getElementById('MemInfo').style.display='none';
		document.getElementById('ToolsRes').style.display='none';
		document.getElementById('SurgInfo').style.display='none';
		document.getElementById('Community').style.display='none';
		document.getElementById('Company').style.display='none';
	}
	
	function deleteTab(what) {
		if(inReset==0 && what) document.getElementById(what).style.display='none';
	}
	
	function on(what, that) {
		inReset=1;
		that.style.cursor = 'hand';  //fixes ie bug
		
		deleteAll();
		document.getElementById(what).style.display='block';
	}
	function off(what) {
		inReset=0;
		globalWhat=what;
		setTimeout(("deleteTab('"+what+"')"),15000);
	}
	function compute(obj) {
        baseNum = 220;
        tarform = obj.form;
        secondsSelected = tarform.seconds.selectedIndex;
        if (tarform.gender[1].checked) baseNum = 222;
          age = tarform.age.value;
        maxHR = (baseNum - age);
        tarform.max_thr.value = Math.round(((maxHR * 0.60)/60) * (tarform.seconds.options[secondsSelected].value));
        tarform.min_thr.value = Math.round(((maxHR * 0.80)/60) * (tarform.seconds.options[secondsSelected].value));
        tarform.hrmax.value = Math.round((maxHR/60) * (tarform.seconds.options[secondsSelected].value));
        if (obj.name == "change_focus" ) {tarform.max_thr.focus()}
	}
	function searchSite() {
     document.searchForm.submit();
	}
function delete_news(nid)
{
    var nDelete = confirm("Are you sure you want to delete this newsletter?");
    if(nDelete == true)
    {
      window.location = "?do=delete&id=" + nid;
    }
    
}


function HowMany() {
var activity=new Array();
var weight;
var minutes;
var burn;
var kilograms;
var weight_entered;
var minutes_entered;

burn_value=document.newExerciseF.activity.options[document.newExerciseF.activity.selectedIndex].value;
weight_entered = document.newExerciseF.weightF.value;
minutes_entered=document.newExerciseDurationF.newExerciseDuration.value;
//alert();
kilograms=weight_entered/2.2;
hours=minutes_entered/60.0;
burn=Math.round(burn_value*kilograms*hours);


document.newExerciseCaloriesBurnedF.newExerciseCaloriesBurned.value = burn;
}
