// JavaScript Document



<!--


// =========== make it so you can only type numbers or letters in a text box
var validNums = '0123456789';  // allows numbers, dash, paranthesis
var validInt = '0123456789';     // allows numbers only (no decimal - add decimal if allowed)
var validAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,- ';  // allows letters only
var validZip = '0123456789-';
var validPhone = '0123456789-()';
var validAlphaNum = '0123456789@.()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,- ';

function validateKeyPress(e, validSet) 
{ 
    var key; 
    var keychar; 
    if(window.event || !e.which)// IE 
		key = e.keyCode; // IE 
    	else if(e) 
		  	key = e.which;   // Netscape 
		    else 
        		return true;     // no validation 

    keychar = String.fromCharCode(key); 
    validSet += String.fromCharCode(8); 

    if (validSet.indexOf(keychar) < 0) 
      return false; 

    return true; 
} 


function checkForm()
{	var form = document.my_risk; // create short name for document.forms[0]
	var smokeChecked = "no";      // create var for smoke radio button check
	var blood_pressureChecked = "no";      // create var for blood_preesure radio button check
	var cholesterolChecked = "no";      // create var for cholesterol radio button check
	var family_historyChecked = "no";      // create var for family_history radio button check
	var diabeticChecked = "no";      // create var for diabetic radio button check
	var exerciseChecked = "no";      // create var for exercise radio button check
	var personal_historyChecked = "no";      // create var for personal_history radio button check
	
	//use this if you have text fields that are optional - looks only for fields with z as 1st char
	for (i=0; i<form.elements.length; i++) //loop through text fields looking for blanks
	{	
		if (form.elements[i].id.charAt(0)=="*" && form.elements[i].value=="")
		{
			alert(form.elements[i].id + " is blank");
			form.elements[i].focus();
			return false;
			break;
		}
	}
	
	for (i=0; i<form.smoke.length; i++)             // check 2 c if smoke radio btn was selected
	{	if (form.smoke[i].checked)
		{ 	var  smokeChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (smokeChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Do you smoke?");
		return false;
	}
	
	
	for (i=0; i<form.blood_pressure.length; i++)             // check 2 c if blood pressure radio btn was selected
	{	if (form.blood_pressure[i].checked)
		{ 	var  blood_pressureChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (blood_pressureChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Is your blood pressure high or over 140/90 mmHG or higher?");
		return false;
	}
	
	for (i=0; i<form.cholesterol.length; i++)             // check 2 c if cholesterol radio btn was selected
	{	if (form.cholesterol[i].checked)
		{ 	var  cholesterolChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (cholesterolChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Is your cholesterol level 200 mg/dl or higher, or is your HDL level lower than 40 mg/dl?");
		return false;
	}
	
	
	for (i=0; i<form.family_history.length; i++)             // check 2 c if family_history radio btn was selected
	{	if (form.family_history[i].checked)
		{ 	var  family_historyChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (family_historyChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Has your mother or sister had heart disease before age 65, or your father or brother before age 55?");
		return false;
	}
	
	
	
	for (i=0; i<form.diabetic.length; i++)             // check 2 c if diabetic radio btn was selected
	{	if (form.diabetic[i].checked)
		{ 	var  diabeticChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (diabeticChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Are you a diabetic?");
		return false;
	}
	
	
	for (i=0; i<form.exercise.length; i++)             // check 2 c if exercise radio btn was selected
	{	if (form.exercise[i].checked)
		{ 	var  exerciseChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (exerciseChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Is your physical activity less than 30 minutes a day?");
		return false;
	}
	
	for (i=0; i<form.personal_history.length; i++)             // check 2 c if personal_history radio btn was selected
	{	if (form.personal_history[i].checked)
		{ 	var  personal_historyChecked = "yes";
			break;				// if so, set var happyChecked to yes
		}
	}
	if (personal_historyChecked == "no")                       // if so radio btn was selected, alert
	{	alert("Please answer yes or not to Do you have a personal histroy of angina (chest pains) or heart disease");
		return false;
	}
	
	return true;
}

// -->




