/* ======================================================================

     JavaScript Source File -- Created with NetObjects ScriptBuilder

NAME: Scripts.js


====================================================================== */

function On(imgName) {
	homeOn= new Image();
	homeOn.src="images/header4mid2d.gif";
	aboutOn= new Image();
	aboutOn.src="images/header4mid3d.gif";
	reflexologyOn= new Image();
	reflexologyOn.src="images/header4mid4d.gif";
	resourcesOn= new Image();
	resourcesOn.src="images/header4mid5d.gif";
	servicesOn= new Image();
	servicesOn.src="images/header4mid6d.gif";

	if(parseInt(navigator.appVersion) >=4) {
		if(document.images) {
			document[imgName].src = eval(imgName + "On.src");
		}
	}
}

function Off(imgName) {
	homeOff= new Image();
	homeOff.src="images/header4mid2.gif";
	aboutOff= new Image();
	aboutOff.src="images/header4mid3.gif";
	reflexologyOff= new Image();
	reflexologyOff.src="images/header4mid4.gif";
	resourcesOff= new Image();
	resourcesOff.src="images/header4mid5.gif";
	servicesOff= new Image();
	servicesOff.src="images/header4mid6.gif";

	if(parseInt(navigator.appVersion) >=4) {
		if(document.images) {
			document[imgName].src = eval(imgName + "Off.src");
		}
	}
}	


//Get current date.  
	function dates() {
        months = new Array(13);
        months[0] = 'January';
        months[1] = 'February';
        months[2] = 'March';
        months[3] = 'April';
        months[4] = 'May';
        months[5] = 'June';
        months[6] = 'July';
        months[7] = 'August';
        months[8] = 'September';
        months[9] = 'October';
        months[10] = 'November';
        months[11] = 'December';
        
        days = new Array(7);
        days[0] = 'Sunday';
        days[1] = 'Monday';
        days[2] = 'Tuesday';
        days[3] = 'Wednesday';
        days[4] = 'Thursday';
        days[5] = 'Friday';
        days[6] = 'Saturday';
                        
        today = new Date();
        tmonth = months[today.getMonth()];
        tdate = today.getDate();
        tyear = today.getFullYear();
        tday  = days[today.getDay()];
        document.write(tday + " " + " - " + "  " + tmonth +" "+ tdate +", "+tyear);
	}

//Show and hide drop down menus  
	var open = 0;
	function showmenu(menuname) {
		if(parseInt(navigator.appVersion) >=4) {
			if(navigator.appName =="Netscape") {
				if(open==0) {
	  				document.layers[menuname].visibility = 'visible';
					open = 1;
				} else {
	  				document.layers[menuname].visibility = 'hidden';
					open = 0;
				}
			}else{
				if(open==0) {
					document.all[menuname].style.visibility = 'visible';
					open = 1;
				} else {
         				document.all[menuname].style.visibility = 'hidden';
					open = 0;
				}
			}
		}
	}

//Check to ensure email address is valid
function checkEmail() {
   	var form = document.forms[0];
	if(trim(form.txtEmail.value).length==0 || !validEmailAdd(form.txtEmail.value)) {
		alert ("Email address is either empty or contains an invalid character");
		return false;
	}else {			
		return true;
	}
}
//Check for invalid characters in the email address
function validEmailAdd(str) {
	invalidEmailChar = "#$%^&*()<>~/:;"//variable that contains invalid characters

	if (str =="") {
		return false;
	}

	for ( var j=0; j < invalidEmailChar.length; j++) {//scan through the string
		badEmailChar=invalidEmailChar.charAt(j);
		if (str.indexOf(badEmailChar,0) != -1) {
			return false;
		}
	}
	
	atPos=str.indexOf("@", 1)
	if (atPos == -1) {
		return false;
	}

	if(str.indexOf("@", atPos+1) != -1) {
		return false;
	}

	periodPos = str.indexOf(".", atPos)
	if (periodPos+3 > str.length) {
		return false;
	}
	return true;//no bad character found
}

//Trim the leading and trailing spaces from the keyword string
//If string is all spaces, it returns and empty string.
function trim(str) {
   var i = str.length;
   var x = 0;

   while (str.substring(x,x+1) == ' ') x++;//get rid of the leading blank spaces
   while (str.substring(i-1,i) == ' ') i--;//get rid of the ending blank spaces

   if(x == str.length && i == 0)
      return '';//if the feild is all empty spaces return an empty string
   else
     	return str.substring(x,i);//return the stripped string
}		

//Check for invalid characters in the textboxes  
function validField(str) {
	invalidChar = "@#$%^&*()<>~/:;"//create a variable that contains invalid characters
	for ( var j=0; j < invalidChar.length; j++) {//start a loop that scans through the invlaidChar string
		badChar=invalidChar.charAt(j);//save the position of the invalidChar
		if (str.indexOf(badChar,0) != -1) {/*look for position of character in str, if position is -1,
the character isn't in the string*/
			return false;//return false if the string has a bad character
		}
	}
	return true;//no bad character found
}


//Validate questionaire data
function validateQuest() {
   	var form = document.forms[0];
   	var FirstName = "";
   	var LastName = "";
   	var EmailAdd = "";
	var valCat = ""
	var valFN = ""
	var valLN = ""
	var valEmail = ""
	var valid = 0

//Check to ensure that a catagory has been selected

		var catChoice=form.lstCategory.selectedIndex;
		if(form.lstCategory.options[catChoice].value=="") {
			alert("Please select a category.");
			return false;
		}

//Check to ensure field for First Name isn't empty or doesn't have invalid characters
		if(trim(form.txtFirst.value).length==0 || !validField(form.txtFirst.value)) {
			alert("First Name field is either empty or contains an invalid character.");
			return false;
		}

//Check to ensure field for Last Name isn't empty or doesn't have invalid characters
		if(trim(form.txtLast.value).length==0 || !validField(form.txtLast.value)) {
			alert("Last Name field is either empty or contains an invalid character.");
			return false;
		}

//Check to ensure email address is valid
		if(trim(form.txtEmail.value).length==0 || !validEmailAdd(form.txtEmail.value)) {
			alert("Email is invalid.");
			return false;
		}

//Is there invalid data
		if(valid==0) {
			return true;
		}
			
}	

//Clear Form
function blankQuestFields(){
	var form=document.forms[0];	

	//clear all the text fields
	form.txtFirst.value="";
	form.txtLast.value="";
	form.txtTitle.value="";
	form.txtTime.value="";
	form.txtEmail.value="";
	form.txtPhone.value="";
	form.txtZipCode.value="";

	//set list boxes back to first option in list
	form.lstCategory.options[0].selected=true;
	form.lstState.options[0].selected=true;

	//set radio button values to false
	form.quest1[1].checked=true;
	form.quest2[1].checked=true;
	form.quest3[1].checked=true;
	form.quest4[1].checked=true;
	form.quest5[1].checked=true;
	form.quest6[1].checked=true;
	form.quest7[1].checked=true;
	form.quest8[1].checked=true;
	form.quest9[1].checked=true;
	form.quest10[1].checked=true;
}

//Clear Form
function blankdonationFields(){
	var form=document.forms[0];	

	//clear all the text fields
	form.txtName.value="";
	form.txtAddress.value="";
	form.txtDayPhone.value="";
	form.txtEvePhone.value="";
	form.txtCity.value="";

	//set list boxes back to first option in list
	form.lstAttend.options[0].selected=true;
	form.lstDonation.options[0].selected=true;
	form.lstSponsor.options[0].selected=true;
	form.lstTraining.options[0].selected=true;
}

//Validate donation form data
function validateDonation() {
   	var form = document.forms[0];

//Check to ensure field for Name isn't empty or doesn't have invalid characters
		if(trim(form.txtName.value).length==0 || !validField(form.txtName.value)) {
			alert("Name field is either empty or contains an invalid character.");
			return false;
		}

//Check to ensure field for Address isn't empty or doesn't have invalid characters
		if(trim(form.txtAddress.value).length==0) {
			alert("Address field is empty.");
			return false;
		}

//Check to ensure email address is valid
		if(trim(form.txtDayPhone.value).length==0) {
			alert("Please provide a day time phone number.");
			return false;
		}

//Check to ensure field for City, State, and Zip Code isn't empty or doesn't have invalid characters
		if(trim(form.txtCity.value).length==0) {
			alert("Please provide the city state and zip code where you live.");
			return false;
		}
}	

//Set a cookie based on the Nutritional Evaluation Assessment
expireDate = new Date;
expireDate.setYear(expireDate.getYear()+1);

userName = "";
if (document.cookie !="") {
	userName = document.cookie.split ("=")[1];
}

function setCookie () {
	var selSex = document.geninfo.lstSex;
  	var selNationality = document.geninfo.lstNationality;
	var text = "cookieName=nutrition|expires="+expireDate.toGMTString()+"|name="+document.geninfo.txtName.value+"|email="+document.geninfo.txtEmail.value+"|phone="+document.geninfo.txtEvening.value+"|age="+document.geninfo.txtAge.value+"|sex="+selSex.options[selSex.selectedIndex].value+"|height="+document.geninfo.txtHeight.value+"|weight="+document.geninfo.txtWeight.value+"|nationality="+selNationality.options[selNationality.selectedIndex].value;
	document.cookie = text;
}


var message="No Right Click";
function click(e)
   {
   if (document.all) {
      if (event.button == 2) {
         alert(message);
         return false;
      }
   }
   if (document.layers) {
      if (e.which == 3) {
         alert(message);
         return false;
      }
   }
   }
   if (document.layers) {
      document.captureEvents(Event.MOUSEDOWN);
   }
   document.onmousedown=click;
   
   
function assessmentResults(CookieName) {
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var VitalSet = CookieSet[0].split ('|');
  var SetSize = CookieSet.length;
  var VitalSize = VitalSet.length;
  var CookiePieces
  var VitalPieces
  var ReturnValue = "";
  var VitalValue = "";
  var x = 0;
  var y = 0;
  var Field= new Array();
  var VField = new Array();
  var Value = new Array();
  var VValue = new Array();
  
  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
	CookiePieces = CookieSet[x].split ('=');
	if (CookiePieces[0].substring (0,1) == ' ') {
      		CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
      		CookiePieces[1] = CookiePieces[1].substring (0, CookiePieces[1].length);
      		Field[x] = CookiePieces[0];
      		Value[x] = CookiePieces[1];
    	}
   }
   for (y = 0; ((y < VitalSize) && (VitalValue == "")); y++) {
    	VitalPieces = VitalSet[y].split ('=');
    	VField[y] = VitalPieces[0];
    	VValue[y] = VitalPieces[1];
   }

   var sResults = " ";
   if (parseInt(Value[0]) >= 21) {
   	sResults = "<tr><td><b>Vitamin B Complex:</b></td><td>Vitamin B Complex provides a healthy                                        cardiovascular system and is food for the nervous system.</td></tr><tr><td><b><i>Recommendation:</i></b></td><td><A HREF='http://www.focusonhealing.com/Bodybalance.htm#min' TARGET='_parent'>MineralCheck</A></td></tr>";
   }
   if (parseInt(Value[1]) >= 12) {
   	sResults = sResults + "<tr><td><b>Hypoglycemia:</b></td><td>Hypoglycemia is the opposite of diabetes. It is low blood sugar. Reactive hypoglycemia occurs after consumption of a meal high in carbohydrates.</td></tr><tr><td><b><i>Recommendation:</i></b></td><td><A HREF='http://www.focusonhealing.com/Bodybalance.htm#min' TARGET='_parent'>MineralCheck</A></td></tr>";
   }

   
   newWindow = window.open('','newWin','resizable=yes,width=640,height=480');
   newWindow.document.write("<HTML><HEAD><TITLE>HealthCheck Nutrition Assessment Results</TITLE>");
   newWindow.document.write("<LINK rel=stylesheet href='http://www.focusonhealing.com/css/Foh.css' type='text/css'>");
   newWindow.document.write("</HEAD><BODY><TABLE BORDER='0x'ALIGN='CENTER' cellpadding=3px cellspacing=3px width=610px>");
   newWindow.document.write("<TR><TD class=heading colspan=2>HealthCheck Nutrition Assessment Results</TD></tr>");
   newWindow.document.write("<TR><TD class=subheading>Name:</TD><TD>" + VValue[1] + "</TD></tr>");
   newWindow.document.write("<TR><TD class=subheading>Email Address:</TD><TD>" + Vvalue[3] + "</TD></tr>");
   newWindow.document.write(sResults);
   newWindow.document.write("<TR><TD COLSPAN='2'><HR></TD></TR>");
   newWindow.document.write("<TR><TD ALIGN='CENTER'COLSPAN='2'><FORM><INPUT TYPE='button' VALUE='Click Here To Close Window' onClick='self.close()'></FORM></TD></TR>");
   newWindow.document.write("</TABLE></BODY></HTML>");
   return false;
   
}


function lastMod()
{
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730)
	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60)
	{
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14)
	{
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'This page was updated ';
	if (daysago == 0) towrite += 'today.';
	else if (daysago == 1) towrite += 'yesterday';
	else towrite += daysago + ' ' + unit + ' ago.';
	return towrite;
}


function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}



function checkHomeagain(){
	var form=document.subscription;

//Check to ensure name field isn't empty
		if(trim(form.txtName.value).length==0 || !validField(form.txtName.value)) {
			alert("Name field is either empty or contains an invalid character.");
			return false;
		}else {			
			form.txtName.value= trim(form.txtName.value);//passed validation
		} 
//Check to ensure email address is valid
		if(!validEmailAdd(form.txtEmail.value)) {
			alert("Email Address contains an invalid character.");
			return false;
		}else {			
			form.txtEmail.value= trim(form.txtEmail.value);//passed validation
			return true;
		}
}

