/* 
   Guide-to-Health 
   checkwplan.js   
   This is the validation script for the walking planner, as well as some feedback, and module 3
   
   Author: Chad Blake (cblake@pcr-inc.com)
   5/17/2007
*/


function validate(form)
{
	var checkday = new Array();
	var daycount = 0;
	
	for (var i=0; i < 7; i++)
	{
		checkday[i]= document.wp_form1.elements[i];
		if (checkday[i].checked)
		{
			daycount++;
		}
	}
	
	if (daycount < 3)
	{		
		alert ("You must have at least 3 days set for your walking plan.")
		return false;
	}
	
	if (checkday[0].checked)
	{		
		var mondaytime = document.wp_form1.elements[7].value;
		var mondaycompany = document.wp_form1.elements[14].value;
		
		if (mondaytime == 'none' || mondaytime == null)
		{
			alert ("If you plan to walk on monday, Please make sure you set a time.");
			return false;
		}
		if (mondaycompany == 'none' || mondaycompany == null)
		{
			alert ("If you plan to walk on monday, Please make sure you set what company will be joining you.");
			return false;
		}		
	}
	else
	{
		var mondaytime = document.wp_form1.elements[7].value;
		var mondaycompany = document.wp_form1.elements[14].value;
		if (mondaytime != "none")
		{
			alert ("If you plan to walk on monday, Please make sure the Monday Checkbox has been checked.");
			return false;
		}
		if (mondaycompany != "none")
		{
			alert ("If you plan to walk on monday, Please make sure the Monday Checkbox has been checked.");
			return false;
		}	
		
	}
	if (checkday[1].checked)
	{
		var tuesdaytime = document.wp_form1.elements[8].value;
		var tuesdaycompany = document.wp_form1.elements[15].value;
		
		if (tuesdaytime == 'none' || tuesdaytime == null)
		{
			alert ("If you plan to walk on tuesday, Please make sure you set a time.");
			return false;
		}
		if (tuesdaycompany == 'none' || tuesdaycompany == null)
		{
			alert ("If you plan to walk on tuesday, Please make sure you set what company will be joining you.");
			return false;
		}		
	}
	else
	{
		var tuesdaytime = document.wp_form1.elements[8].value;
		var tuesdaycompany = document.wp_form1.elements[15].value;
		if (tuesdaytime != 'none')
		{
			alert ("If you plan to walk on tuesday, Please make sure the Tuesday Checkbox has been checked.");
			return false;
		}
		if (tuesdaycompany != 'none')
		{
			alert ("If you plan to walk on tuesday, Please make sure the Tuesday Checkbox has been checked.");
			return false;
		}			
	}
	if (checkday[2].checked)
	{
		var wednesdaytime = document.wp_form1.elements[9].value;
		var wednesdaycompany = document.wp_form1.elements[16].value;
		
		if (wednesdaytime == 'none' || wednesdaytime == null)
		{
			alert ("If you plan to walk on wednesday, Please make sure you set a time.");
			return false;
		}
		if (wednesdaycompany == 'none' || wednesdaycompany == null)
		{
			alert ("If you plan to walk on wednesday, Please make sure you set what company will be joining you.");
			return false;
		}
	}
	else
	{
		var wednesdaytime = document.wp_form1.elements[9].value;
		var wednesdaycompany = document.wp_form1.elements[16].value;		
		if (wednesdaytime != 'none')
		{
			alert ("If you plan to walk on wednesday, Please make sure the Wednesday Checkbox has been checked.");
			return false;
		}
		if (wednesdaycompany != 'none')
		{
			alert ("If you plan to walk on wednesday, Please make sure the Wednesday Checkbox has been checked.");
			return false;
		}
	}
	if (checkday[3].checked)
	{
		var thursdaytime = document.wp_form1.elements[10].value;
		var thursdaycompany = document.wp_form1.elements[17].value;
		
		if (thursdaytime == 'none' || thursdaytime == null)
		{
			alert ("If you plan to walk on thursday, Please make sure you set a time.");
			return false;
		}
		if (thursdaycompany == 'none' || thursdaycompany == null)
		{
			alert ("If you plan to walk on thursday, Please make sure you set what company will be joining you.");
			return false;
		}
	}
	else
	{
		var thursdaytime = document.wp_form1.elements[10].value;
		var thursdaycompany = document.wp_form1.elements[17].value;		
		if (thursdaytime != 'none')
		{
			alert ("If you plan to walk on thursday, Please make sure the Thursday Checkbox has been checked.");
			return false;
		}
		if (thursdaycompany != 'none')
		{
			alert ("If you plan to walk on thursday, Please make sure the Thursday Checkbox has been checked.");
			return false;
		}
	}
	if (checkday[4].checked)
	{
		var fridaytime = document.wp_form1.elements[11].value;
		var fridaycompany = document.wp_form1.elements[18].value;
		
		if (fridaytime == 'none' || fridaytime == null)
		{
			alert ("If you plan to walk on friday, Please make sure you set a time.");
			return false;
		}
		if (fridaycompany == 'none' || fridaycompany == null)
		{
			alert ("If you plan to walk on friday, Please make sure you set what company will be joining you.");
			return false;
		}
	}
	else
	{
		var fridaytime = document.wp_form1.elements[11].value;
		var fridaycompany = document.wp_form1.elements[18].value;		
		if (fridaytime != 'none')
		{
			alert ("If you plan to walk on friday, Please make sure the Friday Checkbox has been checked.");
			return false;
		}
		if (fridaycompany != 'none')
		{
			alert ("If you plan to walk on friday, Please make sure the Friday Checkbox has been checked.");
			return false;
		}
	}
	if (checkday[5].checked)
	{
		var saturdaytime = document.wp_form1.elements[12].value;
		var saturdaycompany = document.wp_form1.elements[19].value;
		
		if (saturdaytime == 'none' || saturdaytime == null)
		{
			alert ("If you plan to walk on saturday, Please make sure you set a time.");
			return false;
		}
		if (saturdaycompany == 'none' || saturdaycompany == null)
		{
			alert ("If you plan to walk on saturday, Please make sure you set what company will be joining you.");
			return false;
		}
	}
	else
	{
		var saturdaytime = document.wp_form1.elements[12].value;
		var saturdaycompany = document.wp_form1.elements[19].value;		
		if (saturdaytime != 'none')
		{
			alert ("If you plan to walk on saturday, Please make sure the Saturday Checkbox has been checked.");
			return false;
		}
		if (saturdaycompany != 'none')
		{
			alert ("If you plan to walk on saturday, Please make sure the Saturday Checkbox has been checked.");
			return false;
		}
	}
	if (checkday[6].checked)
	{
		var sundaytime = document.wp_form1.elements[13].value;
		var sundaycompany = document.wp_form1.elements[20].value;
		
		if (sundaytime == 'none' || sundaytime == null)
		{
			alert ("If you plan to walk on sunday, Please make sure you set a time.");
			return false;
		}
		if (sundaycompany == 'none' || sundaycompany == null)
		{
			alert ("If you plan to walk on sunday, Please make sure you set what company will be joining you.");
			return false;
		}
	}
	else
	{
		var sundaytime = document.wp_form1.elements[13].value;
		var sundaycompany = document.wp_form1.elements[20].value;		
		if (sundaytime != 'none')
		{
			alert ("If you plan to walk on sunday, Please make sure the Sunday Checkbox has been checked.");
			return false;
		}
		if (sundaycompany != 'none')
		{
			alert ("If you plan to walk on sunday, Please make sure the Sunday Checkbox has been checked.");
			return false;
		}
	}
	
	return true;
	
}

function checkdays(day) // This sets the values of days that were checked into a hidden field
{
	if (day == "mon") 
	{
		if (document.wp_form1.wp_mon.checked) {
			document.wp_form1.mon_checked.value = "check";
		}
		else {
			document.wp_form1.mon_checked.value = "";
			document.wp_form1.wp_time_mon[0].selected = "1";
			document.wp_form1.wp_company_mon[0].selected = "1";
		}
	}
    else if (day == "tues") 
	{
		if (document.wp_form1.wp_tues.checked) {
			document.wp_form1.tues_checked.value = "check";
		}
		else {
			document.wp_form1.tues_checked.value = "";
			document.wp_form1.wp_time_tues[0].selected = "1";
			document.wp_form1.wp_company_tues[0].selected = "1";
		}
	}
    else if (day == "wed") 
	{
		if (document.wp_form1.wp_wed.checked) {
			document.wp_form1.wed_checked.value = "check";
		}
		else {
			document.wp_form1.wed_checked.value = "";
			document.wp_form1.wp_time_wed[0].selected = "1";
			document.wp_form1.wp_company_wed[0].selected = "1";
		}
	}
    else if (day == "thur") 
	{
		if (document.wp_form1.wp_thur.checked) {
			document.wp_form1.thur_checked.value = "check";
		}
		else {
			document.wp_form1.thur_checked.value = "";
			document.wp_form1.wp_time_thur[0].selected = "1";
			document.wp_form1.wp_company_thur[0].selected = "1";
		}
	}
    else if (day == "fri") 
	{
		if (document.wp_form1.wp_fri.checked) {
			document.wp_form1.fri_checked.value = "check";
		}
		else {
			document.wp_form1.fri_checked.value = "";
			document.wp_form1.wp_time_fri[0].selected = "1";
			document.wp_form1.wp_company_fri[0].selected = "1";
		}
	}
    else if (day == "sat") 
	{
		if (document.wp_form1.wp_sat.checked) {
			document.wp_form1.sat_checked.value = "check";
		}
		else {
			document.wp_form1.sat_checked.value = "";
			document.wp_form1.wp_time_sat[0].selected = "1";
			document.wp_form1.wp_company_sat[0].selected = "1";
		}
	}
    else if (day == "sun") 
	{
		if (document.wp_form1.wp_sun.checked) {
			document.wp_form1.sun_checked.value = "check";
		}
		else {
			document.wp_form1.sun_checked.value = "";
			document.wp_form1.wp_time_sun[0].selected = "1";
			document.wp_form1.wp_company_sun[0].selected = "1";
		}
	}  
}
function checkgoalsettings(form) {
	// This is validation for the goal setting of average daily steps, planned and fitness walks, and walk minutes
	
	var goalsetting1 = form.elements[0];
	var goalsetting2 = form.elements[1];
	var goalsetting3 = form.elements[2];
	var goalsetting4 = form.elements[3];
		
	if (!goalsetting1.checked) { 
		if (!goalsetting2.checked) {
			if (!goalsetting3.checked) {				
				if (!goalsetting4.checked) {
					alert ("Please select one of the goal settings you'd like to work towards this week.");
					return false;
				}
				else { return true; }				
			} else { return true; }			  
		} else { return true; }
	} else { return true; }   
}

function checkRestaurantChoice(form) {
	// This is validation for the Fast Food Module where the user chooses a fast food restaurant
	
	var restaurants = new Array();
	var ischecked = false;
	var r_num = document.r_form.elements.length;
		
	for (i=0; i<r_num; i++) {
		restaurants[i] = document.r_form.elements[i];
		if (restaurants[i].checked) {
			ischecked = true;
		}
	}	
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You have not made a selection. Please select one of the restaurants from the following list.");
		return false;
	}	
}

function addItemCheck() {
	
	var items = new Array();
	var ischecked = false;
	var item_num = document.itemform.elements.length;
	
	for (i=0; i<item_num; i++) {
		items[i] = document.itemform.elements[i];
		if (items[i].checked) {
			ischecked = true;
		}
	}
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You must first select an item from the list to add it to your order.");
		return false;		
	}
}

function confirmDelete() {
	var x = confirm("Are you sure you want to remove that item from your order?");
	if (x == 1) {
		return true;
	}
	else {
		return false;
	}	
}

function validateChallenges(form,num) {
	// This is validation for choosing challenges
	
	var strats = new Array();
	var ischecked = false;
	var r_num = num;
		
	for (i=0; i<r_num; i++) {
		strats[i] = document.challenges.elements[i];
		if (strats[i].checked) {
			ischecked = true;
		}
	}	
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You have not made a selection. Please select at least one of the challenges listed.");
		return false;
	}	
}

function validateStrategies(form,num) {
	// This is validation for choosing strategies
	
	var strats = new Array();
	var ischecked = false;
	var r_num = num;
		
	for (i=0; i<r_num; i++) {
		strats[i] = document.strategies.elements[i];
		if (strats[i].checked) {
			ischecked = true;
		}
	}	
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You have not made a selection. Please select one of the strategies from the following list.");
		return false;
	}	
}

function validateItems(form,num) {
	// This is validation for choosing selection items used in a variety of pages
	
	var strats = new Array();
	var ischecked = false;
	var r_num = num;
		
	for (i=0; i<r_num; i++) {
		strats[i] = document.items.elements[i];
		if (strats[i].checked) {
			ischecked = true;
		}
	}	
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You have not made a selection. Please select one of the items from the following list.");
		return false;
	}	
}

function validateCFFB(form) {
	// This is validation for choosing soda grams of sugar, and other caution food feedback goal settings
	
	var ischecked = false;
	var goalsetting = document.getElementByID("cf_newgoal");
				
	if (goalsetting.checked) {
		ischecked = true;
	}		
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You have not made a selection. Please select one of the items from the following list.");
		return false;
	}	
}

function validateCFwgt(form) {
	// This is validation for weight goal setting during the caution food feedback
	
	var ischecked = false;
	var goalsetting = document.getElementByID("wgt_newgoal");
				
	if (goalsetting.checked) {
		ischecked = true;
	}		
		
	if (ischecked == true) {
		return true;
	}
	else {
		alert ("You have not made a selection. Please select one of the weighing time options.");
		return false;
	}	
}

function validateServings() {
	// validates the servings field in the problem solving modules
	
	var servings = document.getElementById("servings");
		
	if (servings.value != "") {
		return true;
	}
	else {
		alert ("Please enter the number of servings you had for this week.");
		return false;
	}
}

function selectPlanStrategies(page) {
	
	if (page == 1) {
		// hide page 2 and 3, show page 1
		var id = document.getElementById("page1");
		id.style.visibility = "hidden";
	}
	else if (page == 2) {
		// hide page 1 and 3, show page 2
		var id = "page1";
	}
	else {
		// hide page 1 and 2, show page 3
		var id = "page1";
	}
	
}