var quitCode = 98;

function killEnter(keyEvent) {
  var keyEvent = (keyEvent) ? keyEvent : ((event) ? event : null);
  var node = (keyEvent.target) ? keyEvent.target : ((keyEvent.srcElement) ? keyEvent.srcElement : null);
  if ((keyEvent.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeypress = killEnter;

///////////////////////////
//incProgressBar(q)
function incProgressBar(q){
	progress = Math.round(q/40*100)
	d = document.getElementById('progress_bar');
	progBarInc = q * 5
	d.style.width = progBarInc +"px"
	document.getElementById('percentage').innerHTML = '<span id="percentage">&nbsp;&nbsp;&nbsp;'+progress+'% Complete</span>'
}

///////////////////////////
//changeSection(hide, show)
function changeSection(hide, show){
	document.getElementById('warning').style.display='none';
	document.getElementById(hide).style.display='none';
	document.getElementById(show).style.display='block';	
}

///////////////////////////
//specialupdate(where)
function specialupdate(where){
	d = document.screener
	d3 = document.contactForm
	// caregiverInfo
	if(where == 'patientName'){
		if(d.caregiverInfoPatientFirst.value.length >= 1 && d.caregiverInfoPatientLast.value.length >= 1){
			checkmark(where)
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'caregiverName'){
		if(d.caregiverInfoFirst.value.length >= 1 && d.caregiverInfoLast.value.length >= 1){
			checkmark(where)
		} else {
			uncheckmark(where)
		}
	}
	// zip code self/someone else
	if(where == 'zipCodeSelf'){
		if(d.zipCodeSelf.value.length == 5){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'zipCodeSomeoneElse'){
		if(d.zipCodeSomeoneElse.value.length == 5){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}

	// number of head injuries self/someone else
	if(where == 'numberOfHeadInjuriesSelf'){
		if(d.numberOfHeadInjuriesSelf.value.length >= 1){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'numberOfHeadInjuriesSomeoneElse'){
		if(d.numberOfHeadInjuriesSomeoneElse.value.length >= 1){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	// date of last head injury self/someone else
	var validformat2=/^\d{1,2}\/\d{4}$/
	if(where == 'headInjuryDateSelf'){
		if(validformat2.test(d.headInjuryDateSelf.value)){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'headInjuryDateSomeoneElse'){
		if(validformat2.test(d.headInjuryDateSomeoneElse.value)){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	// vacation date self/someone else
	if(where == 'vacationDatesSelf'){
		if(d.vacationDatesSelf.value.length >= 5){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'vacationDatesSomeoneElse'){
		if(d.vacationDatesSomeoneElse.value.length >= 5){
			updateContinueButton(where)
		} else {
			uncheckmark(where)
		}
	}
	// contact info
	if(where == 'Pfname'){
		if(d3.Pfname.value.length >= 1){
			checkmark(where)
			updateContinueButton('contactInfo')
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'Plname'){
		if(d3.Pfname.value.length >= 1){
			checkmark(where)
			updateContinueButton('contactInfo')
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'phone'){
		if(d3.phone.value.length >= 10){
			checkmark(where)
		} else {
			uncheckmark(where)
		}
	}
	if(where == 'bestTime'){
		if(d3.bestTime.value.length >= 5 && d3.ampm.value != ''){
			checkmark(where)
		} else {
			uncheckmark(where)
		}
	}
}

function updateDays(who){
	var d = document.screener;
	var m = '';
	(who == 'Self') ? m = d.monthSelf.value : m = d.monthSomeoneElse.value;
	var days = '<option>Day</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option>';

	if (m == '01' || m == '03' || m == '05' || m == '07' || m == '08' || m == '10' || m == '12') {
		jQuery('#'+days+'who').html(days+'<option value="30">30</option><option value="31">31</option>');
	} else if (m == '09' || m == '04' || m == '06' || m == '11') { 
		jQuery('#'+days+'who').html(days+'<option value="30">30</option>');
	} else { 
		jQuery('#'+days+'who').html(days);
	}
}

///////////////////////////
//un/checkmark(where)
function checkmark(where){
	jQuery("."+where).html('');//<img src="images/checkmark.png"/>
}
function uncheckmark(where){
	jQuery("."+where).html('');	
}

function readCookie(name){
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

///////////////////////////
//displayError(msg)
function displayError(msg){
	if(msg){
		message = msg
	} else {
		message = 'An answer is required.'	
	}

	w = document.getElementById("warning")
	w.style.display = "block";	
	w.innerHTML = message;
}

///////////////////////////
//updateContinueButton()
function updateContinueButton(sect, x){
	f = document.screener
	g = document.getElementById(sect+"But")
	g.className = "continueButton button icon arrow"
	g.href = "javascript:checkAnswer('"+sect+"')"
}

///////////////////////////
// site return stuff
function sitesReturnRequest(url, params, HttpMethod){
	if (!HttpMethod){
		HttpMethod = "POST"
	}

	sitesReq = getXMLHttpRequest();

	if(sitesReq){
		sitesReq.onreadystatechange = sitesReturnReady
		sitesReq.open(HttpMethod, url, true)
		sitesReq.setRequestHeader("content-Type", "application/x-www-form-urlencoded")
		sitesReq.send(params)
	}
}
function sitesReturnReady(){
	var ready = sitesReq.readyState
	var data = null

	if(ready == 4){
		results = sitesReq.responseText;
		alert(sitesReq.readyState)
		document.getElementById("siteFinder").innerHTML = results;
		changeSection('zipCode', 'siteFinder');
	}	
}
function screenerDBReturnRequest(url, params, HttpMethod){
	if (!HttpMethod){
		HttpMethod = "POST"
	}
	
	screenerDBReq = getXMLHttpRequest();
	if(screenerDBReq){
		screenerDBReq.onreadystatechange = screenerDBReturnReady
		screenerDBReq.open(HttpMethod, url, true)
		screenerDBReq.setRequestHeader("content-Type", "application/x-www-form-urlencoded")
		screenerDBReq.send(params)
	}
}
function screenerDBReturnReady(){
	var ready = screenerDBReq.readyState
	var data = null

	if(ready == 4){
		results = screenerDBReq.responseText;
		//alert(results);
		//document.getElementById("siteFinder").innerHTML = results;
	}	
}

///////////////////////////
//update functions
function updateScreenerDB(field, value){
	screenerDBReturnRequest("scripts/updateScreenerDB.php", "field="+field+"&value="+value, "POST" )
}
function updateCustomerDB(field, value){
	screenerDBReturnRequest("scripts/updateCustomerDB.php", "field="+field+"&value="+value, "POST" )
}
function updateQuitCode(code){
	screenerDBReturnRequest("scripts/updateQuitCode.php", "code="+code, "POST" )
}

/// Head Injury Time Frame question removed
//function checkHeadInjuryDate(month, year, who){
//	new Ajax.Request('scripts/HeadInjuryCheck.php',
//	  {
//		method: "post",
//		parameters: {month: month, year: year},
//		onSuccess: function(results){ 
//			var r = results.responseText;
//			updateScreenerDB('HeadInjuryDateMonth', month);
//			updateScreenerDB('HeadInjuryDateYear', year);
//			if(r){
//				incProgressBar('10');
//				updateScreenerDB('LastPageVisited', 'Legal/Workmans Comp Case');
//				updateCustomerDB('LastPageVisited', 'Legal/Workmans Comp Case');
//				changeSection('headInjuryDate'+who, 'compCase'+who);
//			} else {
//				updateScreenerDB('LastPageVisited', 'Unqualified');
//				updateCustomerDB('LastPageVisited', 'Unqualified');
//				changeSection('headInjuryDate'+who, 'uq'+who);
//				updateQuitCode('112');
//			}
//		},
//			onFailure: function(){alert("Error") }
//		});	
//}

function checkbirthday(bday, gender, who){
	new Ajax.Request('scripts/ageCheck.php',
	  {
		method: "post",
		parameters: {birthDate: bday, gender: gender},
		onSuccess: function(results){ 
				var r = results.responseText;
				if(r!=""){
					 var today = new Date();
					 var expire = new Date();
					 expire.setTime(today.getTime() + 3600000*24*1);
					 document.cookie = "G="+escape(gender)
									 + ";expires="+expire.toGMTString();+"path=/"

					 document.cookie = "A="+escape(r)
									 + ";expires="+expire.toGMTString();+"path=/"
									 

					updateScreenerDB('DateOfBirth', bday);
					updateScreenerDB('Age', r);
					updateScreenerDB('Gender', gender);
					updateCustomerDB('DateOfBirth', bday);
					updateCustomerDB('Gender', gender);
					
					if(r >= 18 && r <= 65){
						updateScreenerDB('LastPageVisited', 'Experienced Head Injury');
						updateCustomerDB('LastPageVisited', 'Experienced Head Injury');						
						incProgressBar('8');
						changeSection('demographics'+who, 'experiencedHeadInjury'+who);
					} else {
						document.cookie = "close=age" + ";expires="+expire.toGMTString();+"path=/"
						updateQuitCode('101');
						incProgressBar('40');
						updateScreenerDB('LastPageVisited', 'Unqualified Age');
						updateCustomerDB('LastPageVisited', 'Unqualified Age');	
						changeSection('demographics'+who, 'uqAge'+who);
					}

				} else {
				  displayInfoError('The date of birth and age supplied do not match, please verify these values.');
				}
		},
		onFailure: function(){alert("error") }
		});	
}

function selectSite(siteNum, who, contact, phone, protocol){
	incProgressBar('7');
	if(siteNum != 'notInterested'){
		updateScreenerDB('LastPageVisited', 'Demographics');
		updateCustomerDB('LastPageVisited', 'Demographics');
		updateScreenerDB('SiteNum', siteNum);
		updateCustomerDB('SiteNum', siteNum);
		updateScreenerDB('Center_Phone', phone);
		updateScreenerDB('Center_Contact', contact);
		updateScreenerDB('protocol', protocol);
		updateCustomerDB('protocol', protocol);
		if(contact != '' && phone != ''){
		  jQuery(document).ready(function(){
  			  jQuery(".contactDetails").html('<p>In case you  would like to call the study center yourself, the person to call is '+contact+' at '+phone+'.</p>');
 		  });
		}
		changeSection('siteList', 'demographics'+who);
	} else {
		updateScreenerDB('LastPageVisited', 'Not Interested In Site');
		updateCustomerDB('LastPageVisited', 'Not Interested In Site');
		updateScreenerDB('SiteNum', '99999');
		changeSection('active', 'notInterestedInSite'+who);
		document.getElementById('siteList').style.display= 'none';
	}
}

function findSites(zip, who){
	new Ajax.Request('scripts/findSites.php',
	{ 
		method: "get",
		parameters: {zip: zip, who: who},
		onSuccess: function(results){ 
				var r = results.responseText;
				if(results.readyState==4){
					jQuery("#siteList").html(r);
					//document.getElementById('sitesList').innerHTML = r;
					changeSection('zipCode'+who, 'siteList');
				}
		},
		onFailure: function(){ alert("Error.") }
	});	
}

function CallBack(){
	new Ajax.Request('scripts/updateCallBackDB.php',
	{ 
		method: "get",
		parameters: {},
		onSuccess: function(results){ 

		},
		onFailure: function(){ alert("Errors.") }
	});	
}

///////////////////////////
//checkAnswer()
//

function checkAnswer(question){
	var d = document.screener;

	switch(question){
		case 'visitingFor':
			// myself
			var da = new Date();
			document.cookie = "close=;expires=" + da.toGMTString() + ";" + ";";
			document.cookie = "A=;expires=" + da.toGMTString() + ";" + ";";
			document.cookie = "G=;expires=" + da.toGMTString() + ";" + ";";
			document.cookie = "PatientName=;expires=" + da.toGMTString() + ";" + ";";
			document.cookie = "headinjuries=;expires=" + da.toGMTString() + ";" + ";";

			if(d.visitingFor[0].checked){
				updateScreenerDB('LastPageVisited', 'Patient Permission from Self');
				updateCustomerDB('LastPageVisited', 'Patient Permission from Self');
				updateScreenerDB('RespondingFor', 'Myself');
				incProgressBar('4');
				changeSection('visitingFor', 'permissionSelf');
			// someone else
			}else if(d.visitingFor[1].checked){
				updateScreenerDB('LastPageVisited', 'Patient Permission from Someone Else');
				updateCustomerDB('LastPageVisited', 'Patient Permission from Someone Else');
				updateScreenerDB('RespondingFor', 'Someone Else');
				incProgressBar('2');
				changeSection('visitingFor', 'permissionSomeoneElse');
			}
		break;

		case 'permissionSelf':
			// yes
			if(d.permissionSelf[0].checked){
				updateScreenerDB('LastPageVisited', 'Site Lookup');
				updateCustomerDB('LastPageVisited', 'Site Lookup');
				updateScreenerDB('SelfPermission', 'Yes');
				incProgressBar('5');
				changeSection('permissionSelf', 'zipCodeSelf');
			// no
			} else if(d.permissionSelf[1].checked){
				updateQuitCode('57');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				updateCustomerDB('LastPageVisited', 'Courtesy Close');
				updateScreenerDB('SelfPermission', 'No');
				incProgressBar('40');
				changeSection('permissionSelf', 'courtesyClose');
			}
		break;

		case 'permissionSomeoneElse':
			if(d.permissionSomeoneElse[0].checked){
				updateScreenerDB('LastPageVisited', 'Disclose Data Someone Else');
				updateCustomerDB('LastPageVisited', 'Disclose Data Someone Else');
				updateScreenerDB('SomeoneElsePermission', 'Yes');
				changeSection('permissionSomeoneElse', 'collectSomeoneElse');
				incProgressBar('3');
			}else{
				updateScreenerDB('LastPageVisited', 'Responding for Someone Else Close');
				updateCustomerDB('LastPageVisited', 'Responding for Someone Else Close');
				updateScreenerDB('SomeoneElsePermission', 'No');
				changeSection('permissionSomeoneElse', 'rfSomeoneElse');
				updateQuitCode('52');
				incProgressBar('40');
			}
		break;
		
		case 'collectSomeoneElse':
			if(d.collectSomeoneElse[0].checked){
				updateScreenerDB('LastPageVisited', 'Demographic/Caregiver Information');
				updateCustomerDB('LastPageVisited', 'Demographic/Caregiver Information');
				updateScreenerDB('SomeoneElsePermissionToCollect', 'Yes');
				incProgressBar('4');
				changeSection('collectSomeoneElse', 'caregiverInfo');
			}else{
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				updateCustomerDB('LastPageVisited', 'Courtesy Close');
				updateScreenerDB('SomeoneElsePermissionToCollect', 'No');
				updateQuitCode('57');
				incProgressBar('40');
				changeSection('collectSomeoneElse', 'courtesyClose');
			}
		break;

		case 'caregiverInfo':
			rad = false;
			for(i=0; i < d.caregiverInfoRelationship.length; i++){
				if (d.caregiverInfoRelationship[i].checked){
					rad = true;
					rad_value = d.caregiverInfoRelationship[i].value;
				}
			}
			if(!rad || d.caregiverInfoFirst.value == '' || d.caregiverInfoLast.value == '' || d.caregiverInfoPatientFirst.value == '' || d.caregiverInfoPatientLast.value == ''){
				displayError();
				if(!rad){
					document.getElementById("relationship").className = "red"
				}else {
					document.getElementById("relationship").className = ""
				}
				if(d.caregiverInfoFirst.value == ''){
					document.getElementById("fname").className = "red"
				} else {
					document.getElementById("fname").className = ""
				}
				if(d.caregiverInfoLast.value == ''){
					document.getElementById("lname").className = "red"
				} else {
					document.getElementById("lname").className = ""
				}
				if(d.caregiverInfoPatientFirst.value == ''){
					document.getElementById("PatientFirst").className = "red"
				} else {
					document.getElementById("PatientFirst").className = ""
				}
				if(d.caregiverInfoPatientLast.value == ''){
					document.getElementById("PatientLast").className = "red"
				} else {
					document.getElementById("PatientLast").className = ""
				}
			} else {
				incProgressBar('5');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);

				updateScreenerDB('LastPageVisited', 'Site Lookup');
				updateCustomerDB('LastPageVisited', 'Site Lookup');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', d.caregiverInfoPatientFirst.value);
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', d.caregiverInfoPatientLast.value);
				updateScreenerDB('SomeoneElseAskName_FirstName', d.caregiverInfoFirst.value);
				updateScreenerDB('SomeoneElseAskName_LastName', d.caregiverInfoLast.value);
				updateScreenerDB('SomeoneElse_Relationship', rad_value);
				
				sname = d.caregiverInfoPatientFirst.value+' ';
				pname = d.caregiverInfoPatientFirst.value+'\'s ';
				
				jQuery(".singular").html(sname);
				jQuery(".plural").html(pname);
				jQuery(".cfname").html('<input type="text" name="Cfname" value="'+d.caregiverInfoFirst.value+'"/>');
				jQuery(".clname").html('<input type="text" name="Clname" value="'+d.caregiverInfoLast.value+'"/>');
				changeSection('caregiverInfo', 'zipCodeSomeoneElse');
			}
		break;

		case 'zipCodeSelf':
			if(d.zipCodeSelf.value != ''){
				incProgressBar('6');
				updateScreenerDB('LastPageVisited', 'Site List');
				updateCustomerDB('LastPageVisited', 'Site List');
				updateScreenerDB('zip', d.zipCodeSelf.value);
				updateCustomerDB('zip', d.zipCodeSelf.value);
				findSites(d.zipCodeSelf.value, 'Self');
			} else {
				displayError('A zip/postal code is required.');
			}
		break;
		
		case 'zipCodeSomeoneElse':
			if(d.zipCodeSomeoneElse.value != ''){
				updateScreenerDB('LastPageVisited', 'Site List');
				updateCustomerDB('LastPageVisited', 'Site List');
				updateScreenerDB('zip', d.zipCodeSomeoneElse.value);
				updateCustomerDB('zip', d.zipCodeSomeoneElse.value);
				findSites(d.zipCodeSomeoneElse.value, 'SomeoneElse');
				incProgressBar('6');
			} else {
				displayError('A zip/postal code is required.');
			}
		break;

		case 'nositeavail':
			updateQuitCode('102');
			if(d.nositeavail[0].checked){
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=site" + ";expires="+expire.toGMTString();+"path=/"
				changeSection('nositeavail', 'contactInfo');
				updateScreenerDB('LastPageVisited', 'Contact Information');
				updateCustomerDB('LastPageVisited', 'Contact Information');
				document.getElementById('siteList').style.display= 'none';
				incProgressBar('34');
			} else {
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				updateCustomerDB('LastPageVisited', 'Courtesy Close');
				changeSection('nositeavail', 'courtesyClose');
				incProgressBar('40')
				document.getElementById('siteList').style.display= 'none';
			}
		break;

		case 'notactive':
		 	who = d.notactive[0].value
			
			if(d.notactive[0].checked){
				updateQuitCode('104');
				incProgressBar('7');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=site" + ";expires="+expire.toGMTString();+"path=/"
				updateScreenerDB('LastPageVisited', 'Demographics');
				updateCustomerDB('LastPageVisited', 'Demographics');
				changeSection('siteList', 'demographics'+who);
			} else if(d.notactive[1].checked) {
				updateQuitCode('104');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=site" + ";expires="+expire.toGMTString();+"path=/"
				updateScreenerDB('LastPageVisited', 'Contact Information');
				updateCustomerDB('LastPageVisited', 'Contact Information');
				document.getElementById('siteList').style.display= 'none';
				incProgressBar('39');
				changeSection('notactive', 'contactInfo');
			} else if(d.notactive[2].checked) {
				updateQuitCode('103');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				updateCustomerDB('LastPageVisited', 'Courtesy Close');
				incProgressBar('39');
				changeSection('notactive', 'courtesyClose');
				document.getElementById('siteList').style.display= 'none';
			}
		break;

		case 'notInterestedInSiteSelf':
			updateQuitCode('103');
			if(d.notInterestedInSiteSelf[0].checked){
				incProgressBar('39');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=site" + ";expires="+expire.toGMTString();+"path=/"
				updateScreenerDB('LastPageVisited', 'Contact Info');
				updateCustomerDB('LastPageVisited', 'Contact Info');
				changeSection('notInterestedInSiteSelf', 'contactInfo');
			} else {
				incProgressBar('40');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				updateCustomerDB('LastPageVisited', 'Courtesy Close');
				changeSection('notInterestedInSiteSelf', 'courtesyClose');
			}
		break;

		case 'notInterestedInSiteSomeoneElse':
			updateQuitCode('103');
			if(d.notInterestedInSiteSomeoneElse[0].checked){
				incProgressBar('39');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=site" + ";expires="+expire.toGMTString();+"path=/"
				changeSection('notInterestedInSiteSomeoneElse', 'contactInfo');
				updateScreenerDB('LastPageVisited', 'Contact Info');
				updateCustomerDB('LastPageVisited', 'Contact Info');
			} else {
				incProgressBar('40');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				updateCustomerDB('LastPageVisited', 'Courtesy Close');
				changeSection('notInterestedInSiteSomeoneElse', 'courtesyClose');
			}
		break;

		case 'demographicsSelf':
			var gender = d.genderSelf.value
			var month = d.monthSelf.value
			var day = d.daySelf.value
			var year = d.yearSelf.value
			var bday = month + '/' + day + '/' + year
			
			if(d.ageSelf.value != '' && !isNaN(d.ageSelf.value) && month != 'Month' && day != 'Day' && year != 'Year'){
				checkbirthday(bday, gender, 'Self')
			} else {
				displayError()
			}
		break;
		
		case 'demographicsSomeoneElse':
			var gender = d.genderSomeoneElse.value
			var month = d.monthSomeoneElse.value
			var day = d.daySomeoneElse.value
			var year = d.yearSomeoneElse.value
			var bday = month + '/' + day + '/' + year

			if(d.ageSomeoneElse.value != '' && !isNaN(d.ageSomeoneElse.value) && month != 'Month' && day != 'Day' && year != 'Year'){
				checkbirthday(bday, gender, 'SomeoneElse')
			} else {
				displayError()
			}
		break;

		case 'experiencedHeadInjurySelf':
			if(d.experiencedHeadInjurySelf[0].checked){
				updateScreenerDB('ExperiencedHeadInjury', 'Yes');
				incProgressBar('9');
				updateScreenerDB('LastPageVisited', 'Number of Head Injuries');
				updateCustomerDB('LastPageVisited', 'Number of Head Injuries');
				changeSection('experiencedHeadInjurySelf', 'numberOfHeadInjuriesSelf');
			} else { 
				updateScreenerDB('ExperiencedHeadInjury', 'No');
				updateQuitCode('112'); //previously 110
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				changeSection('experiencedHeadInjurySelf', 'uqSelf');
			}
		break;

		case 'experiencedHeadInjurySomeoneElse':	
			if(d.experiencedHeadInjurySomeoneElse[0].checked){
				updateScreenerDB('LastPageVisited', 'Number of Head Injuries');
				updateCustomerDB('LastPageVisited', 'Number of Head Injuries');
				updateScreenerDB('ExperiencedHeadInjury', 'Yes');
				incProgressBar('9');
				changeSection('experiencedHeadInjurySomeoneElse', 'numberOfHeadInjuriesSomeoneElse');
			} else { 
				updateScreenerDB('ExperiencedHeadInjury', 'No');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('112'); //previously 110
				incProgressBar('38');
				changeSection('experiencedHeadInjurySomeoneElse', 'uqSomeoneElse');
			}
		break;

		case 'numberOfHeadInjuriesSelf':
			if(isNaN(d.numberOfHeadInjuriesSelf.value) || d.numberOfHeadInjuriesSelf.value == ''){
				displayError('Please provide a number value.')
			} else {
				if(d.numberOfHeadInjuriesSelf.value == 0){
					updateScreenerDB('LastPageVisited', 'Unqualified');
					updateCustomerDB('LastPageVisited', 'Unqualified');
					updateScreenerDB('NumberHeadInjuries', d.numberOfHeadInjuriesSelf.value);
					incProgressBar('38');
					updateQuitCode('110');
					changeSection('numberOfHeadInjuriesSelf', 'uqSelf');
				} else {
					var today = expire = new Date();
					expire.setTime(today.getTime() + 3600000*24*1);
					document.cookie = "headinjuries=" + d.numberOfHeadInjuriesSelf.value + ";expires="+expire.toGMTString();+"path=/"
					updateScreenerDB('LastPageVisited', 'Experience any Head Injuries with');
					updateCustomerDB('LastPageVisited', 'Experience any Head Injuries with');
					updateScreenerDB('NumberHeadInjuries', d.numberOfHeadInjuriesSelf.value);
					incProgressBar('10');
					changeSection('numberOfHeadInjuriesSelf', 'experiencedHIWithSelf');
				}
			}
		break;

		case 'numberOfHeadInjuriesSomeoneElse':
			if(isNaN(d.numberOfHeadInjuriesSomeoneElse.value) || d.numberOfHeadInjuriesSomeoneElse.value == ''){
				displayError('Please provide a number value.')
			} else {
				if(d.numberOfHeadInjuriesSomeoneElse.value == 0){
					updateScreenerDB('LastPageVisited', 'Unqualified');
					updateCustomerDB('LastPageVisited', 'Unqualified');
					updateScreenerDB('NumberHeadInjuries', d.numberOfHeadInjuriesSomeoneElse.value);
					incProgressBar('38');
					updateQuitCode('110');
					changeSection('numberOfHeadInjuriesSomeoneElse', 'uqSomeoneElse');
				} else {
					var today = expire = new Date();
					expire.setTime(today.getTime() + 3600000*24*1);
					document.cookie = "headinjuries=" + d.numberOfHeadInjuriesSomeoneElse.value + ";expires="+expire.toGMTString();+"path=/"
					updateScreenerDB('LastPageVisited', 'Experience any Head Injuries with');
					updateCustomerDB('LastPageVisited', 'Experience any Head Injuries with');
					updateScreenerDB('NumberHeadInjuries', d.numberOfHeadInjuriesSomeoneElse.value);
					incProgressBar('10');
					changeSection('numberOfHeadInjuriesSomeoneElse', 'experiencedHIWithSomeoneElse');
				}
			}
		break;

		case 'experiencedHIWithSelf':
			if(d.experiencedHIWithSelf[0].checked){
				updateScreenerDB('Symptoms', 'Yes');
				incProgressBar('11');
				changeSection('experiencedHIWithSelf', 'headInjuryCauseSelf');
				updateScreenerDB('LastPageVisited', 'Cause for Head Injury');
				updateCustomerDB('LastPageVisited', 'Cause for Head Injury');
			} else { 
				updateScreenerDB('Symptoms', 'No');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('128');
				incProgressBar('38');
				changeSection('experiencedHIWithSelf', 'uqSelf');
			}
		break;

		case 'experiencedHIWithSomeoneElse':
			if(d.experiencedHIWithSomeoneElse[0].checked){
				updateScreenerDB('Symptoms', 'Yes');
				incProgressBar('11');
				changeSection('experiencedHIWithSomeoneElse', 'headInjuryCauseSomeoneElse');
				updateScreenerDB('LastPageVisited', 'Cause for Head Injury');
				updateCustomerDB('LastPageVisited', 'Cause for Head Injury');
			} else { 
				updateScreenerDB('Symptoms', 'No');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('128');
				incProgressBar('38');
				changeSection('experiencedHIWithSomeoneElse', 'uqSomeoneElse');
			}
		break;

		case 'headInjuryCauseSelf':
			var cause = new Array();
			var pcount = 0 

			for(i=0; i<=9; i++){	
				if(document.getElementById('cause_'+i).checked){
					cause[pcount] = document.getElementById('cause_'+i).value
					pcount++
				}
			}
			var causes = cause.join(', ')

			updateScreenerDB('HeadInjuryCause', causes);
			updateScreenerDB('LastPageVisited', 'Onset Sleepiness During the Day');
			updateCustomerDB('LastPageVisited', 'Onset Sleepiness During the Day');
			incProgressBar('12');
			changeSection('headInjuryCauseSelf', 'beginBeforeHISelf');	
		break;
		
		case 'headInjuryCauseSomeoneElse':
			var cause = new Array();
			var pcount = 0 

			for(i=0; i<=9; i++){	
				if(document.getElementById('SE_cause_'+i).checked){
					cause[pcount] = document.getElementById('SE_cause_'+i).value
					pcount++
				}
			}
			var causes = cause.join(', ')

			updateScreenerDB('HeadInjuryCause', causes);
			updateScreenerDB('LastPageVisited', 'Onset Sleepiness During the Day');
			updateCustomerDB('LastPageVisited', 'Onset Sleepiness During the Day');
			incProgressBar('12');
			changeSection('headInjuryCauseSomeoneElse', 'beginBeforeHISomeoneElse');	
		break;

		case 'beginBeforeHISelf':
			if(d.beginBeforeHISelf[0].checked){
				updateScreenerDB('OnsetSleepiness', 'Yes');
				if(readCookie('headinjuries') == '1'){
					incProgressBar('15');
					updateScreenerDB('LastPageVisited', 'Treated by a medical professional');
					updateCustomerDB('LastPageVisited', 'Treated by a medical professional');
					changeSection('beginBeforeHISelf', 'medProfTreatmentSelf');
				} else {
					incProgressBar('13');
					updateScreenerDB('LastPageVisited', 'Other Head Injury Symptoms');
					updateCustomerDB('LastPageVisited', 'Other Head Injury Symptoms');
					changeSection('beginBeforeHISelf', 'anotherHeadInjurySelf');
				}
			}else if (d.beginBeforeHISelf[1].checked){
				updateScreenerDB('OnsetSleepiness', 'No');
				updateQuitCode('132');
				incProgressBar('38');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('beginBeforeHISelf', 'uqSelf');
			} else {
				updateScreenerDB('OnsetSleepiness', 'Unsure');
				if(readCookie('headinjuries') == '1'){
					incProgressBar('15');
					updateScreenerDB('LastPageVisited', 'Treated by a medical professional');
					updateCustomerDB('LastPageVisited', 'Treated by a medical professional');
					changeSection('beginBeforeHISelf', 'medProfTreatmentSelf');
				} else {
					incProgressBar('13');
					updateScreenerDB('LastPageVisited', 'Other Head Injury Symptoms');
					updateCustomerDB('LastPageVisited', 'Other Head Injury Symptoms');
					changeSection('beginBeforeHISelf', 'anotherHeadInjurySelf');
				}
			}
		break;

		case 'beginBeforeHISomeoneElse':
			if(d.beginBeforeHISomeoneElse[0].checked){
				updateScreenerDB('OnsetSleepiness', 'Yes');
				if(readCookie('headinjuries') == '1'){
					incProgressBar('15');
					updateScreenerDB('LastPageVisited', 'Treated by a medical professional');
					updateCustomerDB('LastPageVisited', 'Treated by a medical professional');
					changeSection('beginBeforeHISomeoneElse', 'medProfTreatmentSomeoneElse');
				} else {
					incProgressBar('13');
					updateScreenerDB('LastPageVisited', 'Other Head Injury Symptoms');
					updateCustomerDB('LastPageVisited', 'Other Head Injury Symptoms');
					changeSection('beginBeforeHISomeoneElse', 'anotherHeadInjurySomeoneElse');
				}
			}else if (d.beginBeforeHISelf[1].checked){
				updateScreenerDB('OnsetSleepiness', 'No');
				incProgressBar('38');
				updateQuitCode('132');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('beginBeforeHISomeoneElse', 'uqSomeoneElse'); 
			} else {
				updateScreenerDB('OnsetSleepiness', 'Unsure');
				if(readCookie('headinjuries') == '1'){
					incProgressBar('15');
					updateScreenerDB('LastPageVisited', 'Treated by a medical professional');
					updateCustomerDB('LastPageVisited', 'Treated by a medical professional');
					changeSection('beginBeforeHISomeoneElse', 'medProfTreatmentSomeoneElse');
				} else {
					incProgressBar('13');
					updateScreenerDB('LastPageVisited', 'Other Head Injury Symptoms');
					updateCustomerDB('LastPageVisited', 'Other Head Injury Symptoms');
					changeSection('beginBeforeHISomeoneElse', 'anotherHeadInjurySomeoneElse');
				}
			}
		break;
		
		case 'anotherHeadInjurySelf':
			if(d.anotherHeadInjurySelf[0].checked){
				updateQuitCode('133');
				incProgressBar('38');
				updateScreenerDB('OtherHeadInjurySymptoms', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('anotherHeadInjurySelf', 'uqSelf');
			} else { 
				updateScreenerDB('OtherHeadInjurySymptoms', 'No');
				updateScreenerDB('LastPageVisited', 'Sleepiness worse during the day');
				updateCustomerDB('LastPageVisited', 'Sleepiness worse during the day');
				changeSection('anotherHeadInjurySelf', 'otherHIWorseSelf');
				incProgressBar('14');
			}
		break;

		case 'anotherHeadInjurySomeoneElse':
			if(d.anotherHeadInjurySomeoneElse[0].checked){
				updateQuitCode('133');
				incProgressBar('38');
				updateScreenerDB('OtherHeadInjurySymptoms', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('anotherHeadInjurySomeoneElse', 'uqSelf');
			} else { 
				updateScreenerDB('OtherHeadInjurySymptoms', 'No');
				updateScreenerDB('LastPageVisited', 'Sleepiness worse during the day');
				updateCustomerDB('LastPageVisited', 'Sleepiness worse during the day');
				changeSection('anotherHeadInjurySomeoneElse', 'otherHIWorseSomeoneElse');
				incProgressBar('14');
			}
		break;

		case 'otherHIWorseSelf':
			if(d.otherHIWorseSelf[0].checked){
				updateScreenerDB('OtherHeadInjuryWorse', 'Yes');
			} else if(d.otherHIWorseSelf[1].checked) { 
				updateScreenerDB('OtherHeadInjuryWorse', 'No');
			} else {
				updateScreenerDB('OtherHeadInjuryWorse', 'Unsure');
			}

			incProgressBar('15');
			updateScreenerDB('LastPageVisited', 'Treated by a medical professional');
			updateCustomerDB('LastPageVisited', 'Treated by a medical professional');
			changeSection('otherHIWorseSelf', 'medProfTreatmentSelf');
		break;

		case 'otherHIWorseSomeoneElse':
			if(d.otherHIWorseSomeoneElse[0].checked){
				updateScreenerDB('OtherHeadInjuryWorse', 'Yes');
			} else if(d.otherHIWorseSomeoneElse[1].checked) { 
				updateScreenerDB('OtherHeadInjuryWorse', 'No');
			} else {
				updateScreenerDB('OtherHeadInjuryWorse', 'Unsure');
			}

			incProgressBar('15');
			updateScreenerDB('LastPageVisited', 'Treated by a medical professional');
			updateCustomerDB('LastPageVisited', 'Treated by a medical professional');
			changeSection('otherHIWorseSomeoneElse', 'medProfTreatmentSomeoneElse');
		break;

		case 'medProfTreatmentSelf':
			if(d.medProfTreatmentSelf[0].checked){
				updateScreenerDB('SymptomsTreatments', 'Yes');
			} else if(d.medProfTreatmentSelf[1].checked) { 
				updateScreenerDB('SymptomsTreatments', 'No');
			} else {
				updateScreenerDB('SymptomsTreatments', 'Unsure');
			}
			
			updateScreenerDB('LastPageVisited', 'Legal/Workmans Comp Case');
			updateCustomerDB('LastPageVisited', 'Legal/Workmans Comp Case');
			incProgressBar('16');
			changeSection('medProfTreatmentSelf', 'compCaseSelf');
		break;

		case 'medProfTreatmentSomeoneElse':
			if(d.medProfTreatmentSomeoneElse[0].checked){
				updateScreenerDB('SymptomsTreatments', 'Yes');
			} else if(d.medProfTreatmentSomeoneElse[1].checked) { 
				updateScreenerDB('SymptomsTreatments', 'No');
			} else {
				updateScreenerDB('SymptomsTreatments', 'Unsure');
			}
			
			updateScreenerDB('LastPageVisited', 'Legal/Workmans Comp Case');
			updateCustomerDB('LastPageVisited', 'Legal/Workmans Comp Case');
			incProgressBar('16');
			changeSection('medProfTreatmentSomeoneElse', 'compCaseSomeoneElse');
		break;

		case 'compCaseSelf':
			if(d.compCaseSelf[0].checked){
				updateQuitCode('113');
				incProgressBar('38');
				updateScreenerDB('LegalWorkmansCompCase', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('compCaseSelf', 'uqSelf');
			} else { 
				updateScreenerDB('LegalWorkmansCompCase', 'No');
				updateScreenerDB('LastPageVisited', 'Epworth Sleepiness Scale');
				updateCustomerDB('LastPageVisited', 'Epworth Sleepiness Scale');
				changeSection('compCaseSelf', 'sleepScaleSelf');
				incProgressBar('17');
			}
		break;

		case 'compCaseSomeoneElse':
			if(d.compCaseSomeoneElse[0].checked){
				updateQuitCode('113');
				updateScreenerDB('LegalWorkmansCompCase', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				changeSection('compCaseSomeoneElse', 'uqSomeoneElse');
			} else { 
				updateScreenerDB('LastPageVisited', 'Epworth Sleepiness Scale');
				updateCustomerDB('LastPageVisited', 'Epworth Sleepiness Scale');
				updateScreenerDB('LegalWorkmansCompCase', 'No');
				incProgressBar('17');
				changeSection('compCaseSomeoneElse', 'sleepScaleSomeoneElse');
			}
		break;

		case 'sleepScaleSelf':
			checked = t = 0
			e = 1
			
			while (e <= 8){
				for(i=0; i<document.scaleSelf.elements['q'+e].length; i++){
					if(document.scaleSelf.elements['q'+e][i].checked == true){
						checked++	
						updateScreenerDB('ESS'+e, parseInt(document.scaleSelf.elements['q'+e][i].value));
						t = parseInt(t) + parseInt(document.scaleSelf.elements['q'+e][i].value)
					}
				}
				e++
			}

			if(checked != 8){
				displayError('Please select an answer for every situation.')
				return false;
			}

			updateScreenerDB('ESS_Score', t);
			if(t >= 10){
				updateScreenerDB('LastPageVisited', '9PM - 12AM Sleep Schedule');
				updateCustomerDB('LastPageVisited', '9PM - 12AM Sleep Schedule');
				incProgressBar('18');
				changeSection('sleepScaleSelf', 'BedtimeSelf');
			} else {
				updateQuitCode('114');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				changeSection('sleepScaleSelf', 'uqSelf');
			}
		break;

		case 'sleepScaleSomeoneElse':
			checked = t = 0
			e = 1
			
			while (e <= 8){
				for(i=0; i<document.scaleSomeoneElse.elements['q'+e].length; i++){
					if(document.scaleSomeoneElse.elements['q'+e][i].checked == true){
						checked++	
						updateScreenerDB('ESS'+e, parseInt(document.scaleSomeoneElse.elements['q'+e][i].value));
						t = parseInt(t) + parseInt(document.scaleSomeoneElse.elements['q'+e][i].value)
					}
				}
				e++
			}

			if(checked != 8){
				displayError('Please select an answer for every situation.')
				return false;
			}
			updateScreenerDB('ESS_Score', t);
			if(t >= 10){
				updateScreenerDB('LastPageVisited', '9PM - 12AM Sleep Schedule');
				updateCustomerDB('LastPageVisited', '9PM - 12AM Sleep Schedule');
				incProgressBar('18');
				changeSection('sleepScaleSomeoneElse', 'BedTimeSomeoneElse');
			} else {
				updateQuitCode('114');
				incProgressBar('38');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				changeSection('sleepScaleSomeoneElse', 'uqSomeoneElse');
			}
		break;
		
		case 'BedtimeSelf':
			if(d.BedtimeSelf[0].checked){
				updateScreenerDB('BedTime', 'Yes');
				incProgressBar('19');
				updateScreenerDB('LastPageVisited', 'CPAP Machine');
				updateCustomerDB('LastPageVisited', 'CPAP Machine');
				changeSection('BedtimeSelf', 'CPAPSelf');
			}else if (d.BedtimeSelf[1].checked){
				updateQuitCode('134');
				updateScreenerDB('BedTime', 'No');
				incProgressBar('38');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('BedtimeSelf', 'uqSelf');
			} else {
				updateScreenerDB('BedTime', 'Unsure');
				incProgressBar('19');
				updateScreenerDB('LastPageVisited', 'CPAP Machine');
				updateCustomerDB('LastPageVisited', 'CPAP Machine');
				changeSection('BedtimeSelf', 'CPAPSelf');
			}
		break;

		case 'BedtimeSomeoneElse':
			if(d.BedtimeSomeoneElse[0].checked){
				updateScreenerDB('BedTime', 'Yes');
				incProgressBar('19');
				updateScreenerDB('LastPageVisited', 'CPAP Machine');
				updateCustomerDB('LastPageVisited', 'CPAP Machine');
				changeSection('BedtimeSomeoneElse', 'CPAPSomeoneElse');
			}else if (d.BedtimeSomeoneElse[1].checked){
				updateQuitCode('134');
				updateScreenerDB('BedTime', 'No');
				incProgressBar('38');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('BedtimeSomeoneElse', 'CPAPSomeoneElse');
			} else {
				updateScreenerDB('BedTime', 'Unsure');
				incProgressBar('19');
				updateScreenerDB('LastPageVisited', 'CPAP Machine');
				updateCustomerDB('LastPageVisited', 'CPAP Machine');
				changeSection('BedtimeSomeoneElse', 'CPAPSomeoneElse');
			}
		break;

		case 'CPAPSelf':
			if(d.CPAPSelf[0].checked){
				updateScreenerDB('UsingCPAP', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('130');
				incProgressBar('38');
				changeSection('CPAPSelf', 'uqSelf');
			}else{
				updateScreenerDB('UsingCPAP', 'No');
				updateScreenerDB('LastPageVisited', 'Anti-Depressants or Anti-Anxiety');
				updateCustomerDB('LastPageVisited', 'Anti-Depressants or Anti-Anxiety');
				incProgressBar('20');
				changeSection('CPAPSelf', 'depAnxietyMedsSelf');
			}
		break;
		
		case 'CPAPSomeoneElse':
			if(d.CPAPSomeoneElse[0].checked){
				updateScreenerDB('UsingCPAP', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('130');
				incProgressBar('38');
				changeSection('CPAPSomeoneElse', 'uqSomeoneElse');
			}else{
				updateScreenerDB('UsingCPAP', 'No');
				updateScreenerDB('LastPageVisited', 'Anti-Depressants or Anti-Anxiety');
				updateCustomerDB('LastPageVisited', 'Anti-Depressants or Anti-Anxiety');
				incProgressBar('20');
				changeSection('CPAPSomeoneElse', 'depAnxietyMedsSomeoneElse');
			}
		break;

		case 'depAnxietyMedsSelf':
			if(d.depAnxietyMedsSelf[0].checked){
				updateScreenerDB('TakingDepAnxMedications', 'Yes');
				updateScreenerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Medication');
				updateCustomerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Medication');
				incProgressBar('21');
				changeSection('depAnxietyMedsSelf', 'medicationsSelf');
			}else if(d.depAnxietyMedsSelf[1].checked){
				updateScreenerDB('TakingDepAnxMedications', 'No');
				updateScreenerDB('LastPageVisited', 'Anticonvulsant Medications');
				updateCustomerDB('LastPageVisited', 'Anticonvulsant Medications');
				incProgressBar('23');
				changeSection('depAnxietyMedsSelf', 'antiConvulsantSelf');
			} else {
				updateScreenerDB('TakingDepAnxMedications', 'Unsure');
				updateScreenerDB('LastPageVisited', 'Anticonvulsant Medications');
				updateCustomerDB('LastPageVisited', 'Anticonvulsant Medications');
				incProgressBar('23');
				changeSection('depAnxietyMedsSelf', 'antiConvulsantSelf');
			}
		break;

		case 'depAnxietyMedsSomeoneElse':
			if(d.depAnxietyMedsSomeoneElse[0].checked){
				updateScreenerDB('TakingDepAnxMedications', 'Yes');
				updateScreenerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Medication');
				updateCustomerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Medication');
				incProgressBar('21');
				changeSection('depAnxietyMedsSomeoneElse', 'medicationsSomeoneElse');
			}else if(d.depAnxietyMedsSomeoneElse[1].checked){
				updateScreenerDB('TakingDepAnxMedications', 'No');
				updateScreenerDB('LastPageVisited', 'Anticonvulsant Medications');
				updateCustomerDB('LastPageVisited', 'Anticonvulsant Medications');
				incProgressBar('23');
				changeSection('depAnxietyMedsSomeoneElse', 'antiConvulsantSomeoneElse');
			} else {
				updateScreenerDB('TakingDepAnxMedications', 'Unsure');
				updateScreenerDB('LastPageVisited', 'Anticonvulsant Medications');
				updateCustomerDB('LastPageVisited', 'Anticonvulsant Medications');
				incProgressBar('23');
				changeSection('depAnxietyMedsSomeoneElse', 'antiConvulsantSomeoneElse');
			}
		break;

		case 'medicationsSelf':
			var med = new Array();
			var pcount = 0 
			var dq = false
			for(n=0; n<=22; n++){	
				if(document.getElementById(n).checked){
					med[pcount] = document.getElementById(n).value
					pcount++
					if(n > 6) { dq = true }
				}
			}
			var meds = med.join(', ')
			//alert(meds + dq)
			if(!dq) {
				updateScreenerDB('DepAnxMedications', meds);
				updateScreenerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Same-Dose');
				updateCustomerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Same-Dose');
				incProgressBar('22');
				changeSection('medicationsSelf', 'MedtimeSelf');	
			} else {
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('DepAnxMedications', meds);
				updateQuitCode('131');
				incProgressBar('38');
				changeSection('medicationsSelf', 'uqSelf');
			}
		break;

		case 'medicationsSomeoneElse':
			var med = new Array();
			var pcount = 0 
			var dq = false
			for(n=0; n<=22; n++){	
				if(document.getElementById('SomeoneElse_'+n).checked){
					med[pcount] = document.getElementById('SomeoneElse_'+n).value
					pcount++
					if(n > 6) { dq = true }
				}
			}
			var meds = med.join(', ')
			//alert(meds + dq)
			if(!dq) {
				updateScreenerDB('DepAnxMedications', meds);
				updateScreenerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Same-Dose');
				updateCustomerDB('LastPageVisited', 'Anti-Depressants/Anti-Anxiety Same-Dose');
				incProgressBar('22');
				changeSection('medicationsSomeoneElse', 'MedtimeSomeoneElse');		
			} else {
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('DepAnxMedications', meds);
				updateQuitCode('131');
				incProgressBar('38');
				changeSection('medicationsSomeoneElse', 'uqSomeoneElse');
			}
		break;

		case 'MedtimeSelf':
			if(d.MedtimeSelf[0].checked){
				updateQuitCode('135');
				updateScreenerDB('DepAnxMedicationsTime', '0-1 month');	
			}else if(d.MedtimeSelf[1].checked){
				updateScreenerDB('DepAnxMedicationsTime', '2-4 months');
			} else if(d.MedtimeSelf[2].checked){
				updateScreenerDB('DepAnxMedicationsTime', '5 months or longer');
			} else {
				updateScreenerDB('DepAnxMedicationsTime', 'Unsure');
			}

			if(d.MedtimeSelf[0].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				changeSection('MedtimeSelf', 'uqSelf');	
			} else {
				updateScreenerDB('LastPageVisited', 'Anticonvulsant Medications');
				updateCustomerDB('LastPageVisited', 'Anticonvulsant Medications');
				incProgressBar('23');
				changeSection('MedtimeSelf', 'antiConvulsantSelf');
			}
		break;

		case 'MedtimeSomeoneElse':
			if(d.MedtimeSomeoneElse[0].checked){
				updateQuitCode('135');
				updateScreenerDB('DepAnxMedicationsTime', '0-1 month');	
			}else if(d.MedtimeSomeoneElse[1].checked){
				updateScreenerDB('DepAnxMedicationsTime', '2-4 months');
			} else if(d.MedtimeSomeoneElse[2].checked){
				updateScreenerDB('DepAnxMedicationsTime', '5 months or longer');
			} else {
				updateScreenerDB('DepAnxMedicationsTime', 'Unsure');
			}

			if(d.MedtimeSomeoneElse[0].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				changeSection('MedtimeSomeoneElse', 'uqSelf');	
			} else {
				updateScreenerDB('LastPageVisited', 'Anticonvulsant Medications');
				updateCustomerDB('LastPageVisited', 'Anticonvulsant Medications');
				incProgressBar('23');
				changeSection('MedtimeSomeoneElse', 'antiConvulsantSelf');
			}
		break;

		case 'antiConvulsantSelf':
			if(d.antiConvulsantSelf[0].checked){
				updateScreenerDB('AntiConvulsantMeds', 'Yes');	
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('123');
				incProgressBar('38');
				changeSection('antiConvulsantSelf', 'uqSelf');
			}else{
				updateScreenerDB('AntiConvulsantMeds', 'No');
				updateScreenerDB('LastPageVisited', 'Stimulants');
				updateCustomerDB('LastPageVisited', 'Stimulants');
				incProgressBar('24');
				changeSection('antiConvulsantSelf', 'stimulantsSelf');
			}
		break;

		case 'antiConvulsantSomeoneElse':
			if(d.antiConvulsantSomeoneElse[0].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('AntiConvulsantMeds', 'Yes');	
				updateQuitCode('123');
				incProgressBar('38');
				changeSection('antiConvulsantSomeoneElse', 'uqSomeoneElse');
			}else{
				updateScreenerDB('AntiConvulsantMeds', 'No');
				updateScreenerDB('LastPageVisited', 'Stimulants');
				updateCustomerDB('LastPageVisited', 'Stimulants');
				incProgressBar('24');
				changeSection('antiConvulsantSomeoneElse', 'stimulantsSomeoneElse');
			}
		break;

		case 'stimulantsSelf':
			if(d.stimulantsSelf[0].checked){
				updateScreenerDB('UsingStimulants', 'Yes');	
				updateScreenerDB('LastPageVisited', 'Willingness to Stop');
				updateCustomerDB('LastPageVisited', 'Willingness to Stop');
				incProgressBar('26');
				changeSection('stimulantsSelf', 'willingnessToStopSelf');
			}else{
				updateScreenerDB('UsingStimulants', 'No');
				updateScreenerDB('LastPageVisited', 'Medical Conditions');
				updateCustomerDB('LastPageVisited', 'Medical Conditions');
				incProgressBar('27');
				changeSection('stimulantsSelf', 'medicalConditionsSelf');
			}
		break;

		case 'stimulantsSomeoneElse':
			if(d.stimulantsSomeoneElse[0].checked){
				updateScreenerDB('UsingStimulants', 'Yes');	
				updateScreenerDB('LastPageVisited', 'Willingness to Stop');
				updateCustomerDB('LastPageVisited', 'Willingness to Stop');
				incProgressBar('26');
				changeSection('stimulantsSomeoneElse', 'willingnessToStopSomeoneElse');
			}else{
				updateScreenerDB('UsingStimulants', 'No');
				updateScreenerDB('LastPageVisited', 'Medical Conditions');
				updateCustomerDB('LastPageVisited', 'Medical Conditions');
				incProgressBar('27');
				changeSection('stimulantsSomeoneElse', 'medicalConditionsSomeoneElse');
			}
		break;

		case 'willingnessToStopSelf':
			// no
			if(d.willingnessToStopSelf[1].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('WillingToDiscussStoppingMeds', 'No');
				updateQuitCode('124');
				incProgressBar('38');
				changeSection('willingnessToStopSelf', 'uqSelf');
			} else if(d.willingnessToStopSelf[0].checked) {
				incProgressBar('27');
				updateScreenerDB('WillingToDiscussStoppingMeds', 'Yes');
				updateScreenerDB('LastPageVisited', 'Medical Conditions');
				updateCustomerDB('LastPageVisited', 'Medical Conditions');
				changeSection('willingnessToStopSelf', 'medicalConditionsSelf');
			} else {
				incProgressBar('27');
				updateScreenerDB('WillingToDiscussStoppingMeds', 'Unsure');
				updateScreenerDB('LastPageVisited', 'Medical Conditions');
				updateCustomerDB('LastPageVisited', 'Medical Conditions');
				changeSection('willingnessToStopSelf', 'medicalConditionsSelf');
			}
		break;

		case 'willingnessToStopSomeoneElse':
			// no
			if(d.willingnessToStopSomeoneElse[1].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('WillingToDiscussStoppingMeds', 'No');
				updateQuitCode('124');
				incProgressBar('34');
				changeSection('willingnessToStopSomeoneElse', 'uqSomeoneElse');
			} else if(d.willingnessToStopSomeoneElse[0].checked) {
				incProgressBar('27');
				updateScreenerDB('WillingToDiscussStoppingMeds', 'Yes');
				updateScreenerDB('LastPageVisited', 'Medical Conditions');
				updateCustomerDB('LastPageVisited', 'Medical Conditions');
				changeSection('willingnessToStopSomeoneElse', 'medicalConditionsSomeoneElse');
			} else {
				incProgressBar('27');
				updateScreenerDB('WillingToDiscussStoppingMeds', 'Unsure');
				updateScreenerDB('LastPageVisited', 'Medical Conditions');
				updateCustomerDB('LastPageVisited', 'Medical Conditions');
				changeSection('willingnessToStopSomeoneElse', 'medicalConditionsSomeoneElse');
			}
		break;

		case 'medicalConditionsSelf':
			if(d.medicalConditionsSelf[0].checked){
				updateScreenerDB('MedicalConditions', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('119');
				incProgressBar('38');
				changeSection('medicalConditionsSelf', 'uqSelf');
			}else{
				updateScreenerDB('MedicalConditions', 'No');
				updateScreenerDB('LastPageVisited', 'Sleep Conditions');
				updateCustomerDB('LastPageVisited', 'Sleep Conditions');
				incProgressBar('28');
				changeSection('medicalConditionsSelf', 'sleepConditionsSelf');
			}
		break;

		case 'medicalConditionsSomeoneElse':
			if(d.medicalConditionsSomeoneElse[0].checked){
				updateScreenerDB('MedicalConditions', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('119');
				incProgressBar('38');
				changeSection('medicalConditionsSomeoneElse', 'uqSomeoneElse');
			}else{
				updateScreenerDB('MedicalConditions', 'No');
				updateScreenerDB('LastPageVisited', 'Sleep Conditions');
				updateCustomerDB('LastPageVisited', 'Sleep Conditions');
				incProgressBar('28');
				changeSection('medicalConditionsSomeoneElse', 'sleepConditionsSomeoneElse');
			}
		break;

		case 'sleepConditionsSelf':
			if(d.sleepConditionsSelf[0].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('SleepConditions', 'Yes');
				updateQuitCode('120');
				incProgressBar('38');
				changeSection('sleepConditionsSelf', 'uqSelf');
			}else{
				updateScreenerDB('SleepConditions', 'No');
				incProgressBar('29');
				updateScreenerDB('LastPageVisited', 'Brain Surgery');
				updateCustomerDB('LastPageVisited', 'Brain Surgery');
				changeSection('sleepConditionsSelf', 'brainSelf');
			}
		break;

		case 'sleepConditionsSomeoneElse':
			if(d.sleepConditionsSomeoneElse[0].checked){
				updateScreenerDB('SleepConditions', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('120');
				incProgressBar('38');
				changeSection('sleepConditionsSomeoneElse', 'uqSomeoneElse');
			}else{
				updateScreenerDB('SleepConditions', 'No');
				updateScreenerDB('LastPageVisited', 'Brain Surgery');
				updateCustomerDB('LastPageVisited', 'Brain Surgery');
				incProgressBar('29');
				changeSection('sleepConditionsSomeoneElse', 'brainSomeoneElse');
			}
		break;

		case 'brainSelf':
			if(d.brainSelf[0].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('BrainSurgery', 'Yes');
				incProgressBar('38');
				updateQuitCode('121');
				changeSection('brainSelf', 'uqSelf');
			}else{
				updateScreenerDB('BrainSurgery', 'No');
				updateScreenerDB('LastPageVisited', 'Swallow Pills');
				updateCustomerDB('LastPageVisited', 'Swallow Pills');
				changeSection('brainSelf', 'nightshiftSelf');
				incProgressBar('30');
			}
		break;

		case 'brainSomeoneElse':
			if(d.brainSomeoneElse[0].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('BrainSurgery', 'Yes');
				incProgressBar('38');
				updateQuitCode('121');
				changeSection('brainSomeoneElse', 'uqSomeoneElse');
			}else{
				updateScreenerDB('BrainSurgery', 'No');
				updateCustomerDB('LastPageVisited', 'Swallow Pills');
				updateScreenerDB('LastPageVisited', 'Swallow Pills');
				incProgressBar('30');
				changeSection('brainSomeoneElse', 'nightshiftSomeoneElse');
			}
		break;

		case 'nightshiftSelf':
			if(d.nightshiftSelf[0].checked){
				updateScreenerDB('NightShiftWork', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('116');
				incProgressBar('38');
				changeSection('nightshiftSelf', 'uqSelf');
			}else{
				updateScreenerDB('NightShiftWork', 'No');
				incProgressBar('31');
				updateScreenerDB('LastPageVisited', 'Meet Study Requirements');
				updateCustomerDB('LastPageVisited', 'Meet Study Requirements');
				changeSection('nightshiftSelf', 'studyRequirementsSelf');
			}		
		break;

		case 'nightshiftSomeoneElse':
			if(d.nightshiftSomeoneElse[0].checked){
				updateScreenerDB('NightShiftWork', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('116');
				incProgressBar('38');
				changeSection('nightshiftSomeoneElse', 'uqSomeoneElse');
			}else{
				updateScreenerDB('NightShiftWork', 'No');
				incProgressBar('31');
				updateScreenerDB('LastPageVisited', 'Meet Study Requirements');
				updateCustomerDB('LastPageVisited', 'Meet Study Requirements');
				changeSection('nightshiftSomeoneElse', 'studyRequirementsSomeoneElse');
			}
		break;

		case 'studyRequirementsSelf':
			if(d.studyRequirementsSelf[1].checked){
				updateScreenerDB('MeetStudyRequirements', 'No');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('117');
				incProgressBar('38');
				changeSection('studyRequirementsSelf', 'uqSelf');
			}else if(d.studyRequirementsSelf[0].checked){
				updateScreenerDB('MeetStudyRequirements', 'Yes');
				updateScreenerDB('LastPageVisited', 'Vacation Plans');
				updateCustomerDB('LastPageVisited', 'Vacation Plans');
				incProgressBar('32');
				changeSection('studyRequirementsSelf', 'vacationSelf');
			} else {
				updateScreenerDB('MeetStudyRequirements', 'Unsure');
				updateScreenerDB('LastPageVisited', 'Vacation Plans');
				updateCustomerDB('LastPageVisited', 'Vacation Plans');
				incProgressBar('32');
				changeSection('studyRequirementsSelf', 'vacationSelf');
			}
		break;

		case 'studyRequirementsSomeoneElse':
			if(d.studyRequirementsSomeoneElse[1].checked){
				updateScreenerDB('MeetStudyRequirements', 'No');
				updateQuitCode('117');
				incProgressBar('38');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				changeSection('studyRequirementsSomeoneElse', 'uqSomeoneElse');
			}else if(d.studyRequirementsSomeoneElse[0].checked){
				updateScreenerDB('MeetStudyRequirements', 'Yes');
				updateScreenerDB('LastPageVisited', 'Vacation Plans');
				updateCustomerDB('LastPageVisited', 'Vacation Plans');
				incProgressBar('32');
				changeSection('studyRequirementsSomeoneElse', 'vacationSomeoneElse');
			} else {
				updateScreenerDB('MeetStudyRequirements', 'Unsure');
				updateScreenerDB('LastPageVisited', 'Vacation Plans');
				updateCustomerDB('LastPageVisited', 'Vacation Plans');
				incProgressBar('32');
				changeSection('studyRequirementsSomeoneElse', 'vacationSomeoneElse');
			}
		break;

		case 'vacationSelf':
			if(d.vacationSelf[0].checked){
				updateScreenerDB('VacationPlans', 'Yes');
				updateScreenerDB('LastPageVisited', 'Vacation Schedule');
				updateCustomerDB('LastPageVisited', 'Vacation Schedule');
				incProgressBar('33');
				changeSection('vacationSelf', 'vacationDatesSelf');
			}else{
				updateScreenerDB('VacationPlans', 'No');
				incProgressBar('34');
				updateScreenerDB('LastPageVisited', 'Sleep Center Experience');
				updateCustomerDB('LastPageVisited', 'Sleep Center Experience');
				changeSection('vacationSelf', 'sleepCenterSelf');
			}
		break;

		case 'vacationSomeoneElse':
			if(d.vacationSomeoneElse[0].checked){
				incProgressBar('33');
				updateScreenerDB('LastPageVisited', 'Vacation Schedule');
				updateCustomerDB('LastPageVisited', 'Vacation Schedule');
				updateScreenerDB('VacationPlans', 'Yes');
				changeSection('vacationSomeoneElse', 'vacationDatesSomeoneElse');
			}else{
				updateScreenerDB('VacationPlans', 'No');
				incProgressBar('34');
				updateScreenerDB('LastPageVisited', 'Sleep Center Experience');
				updateCustomerDB('LastPageVisited', 'Sleep Center Experience');
				changeSection('vacationSomeoneElse', 'sleepCenterSomeoneElse');
			}	
		break;

		case 'vacationDatesSelf':
			if(d.vacationDatesSelf.value == ''){
				displayError('');
				document.getElementById('vacationDatesSelf').style.color = 'red';
			} else {
				incProgressBar('34');
				updateScreenerDB('LastPageVisited', 'Sleep Center Experience');
				updateCustomerDB('LastPageVisited', 'Sleep Center Experience');
				updateScreenerDB('VacationSchedule', d.vacationDatesSelf.value);
				changeSection('vacationDatesSelf', 'sleepCenterSelf');
			}
		break;

		case 'vacationDatesSomeoneElse':
			if(d.vacationDatesSomeoneElse.value == ''){
				displayError('');
				document.getElementById('vacationDatesSomeoneElse').style.color = 'red';
			} else {
				incProgressBar('34');
				updateScreenerDB('VacationSchedule', d.vacationDatesSelf.value);
				updateScreenerDB('LastPageVisited', 'Sleep Center Experience');
				updateCustomerDB('LastPageVisited', 'Sleep Center Experience');
				changeSection('vacationDatesSomeoneElse', 'sleepCenterSomeoneElse');
			}
		break;

		case 'sleepCenterSelf':
			if(d.sleepCenterSelf[0].checked){
				updateScreenerDB('SleepCenterExperience', 'Yes');
			}else if(d.sleepCenterSelf[1].checked){
				updateScreenerDB('SleepCenterExperience', 'No');
			} else{
				updateScreenerDB('SleepCenterExperience', 'Unsure');
			}
			incProgressBar('35');
			updateScreenerDB('LastPageVisited', 'Willing to Not Smoke');
			updateCustomerDB('LastPageVisited', 'Willing to Not Smoke');
			changeSection('sleepCenterSelf', 'noSmokingSelf');	
		break;

		case 'sleepCenterSomeoneElse':
			if(d.sleepCenterSomeoneElse[0].checked){
				updateScreenerDB('SleepCenterExperience', 'Yes');
			}else if(d.sleepCenterSomeoneElse[1].checked){
				updateScreenerDB('SleepCenterExperience', 'No');
			} else{
				updateScreenerDB('SleepCenterExperience', 'Unsure');
			}
			incProgressBar('35');
			updateScreenerDB('LastPageVisited', 'Willing to Not Smoke');
			updateCustomerDB('LastPageVisited', 'Willing to Not Smoke');
			changeSection('sleepCenterSomeoneElse', 'noSmokingSomeoneElse');
		break;

		case 'noSmokingSelf':
			if(d.noSmokingSelf[0].checked){
				updateScreenerDB('WillingToNotSmoke', 'Yes');
			} else if(d.noSmokingSelf[1].checked){
				updateScreenerDB('WillingToNotSmoke', 'No');
			} else if(d.noSmokingSelf[2].checked){
				updateScreenerDB('WillingToNotSmoke', 'Do not use nicotine');
			} else {
				updateScreenerDB('WillingToNotSmoke', 'Unsure');
			}
			
			if(d.noSmokingSelf[1].checked){
				changeSection('noSmokingSelf', 'uqSelf');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				updateQuitCode('118'); 
			} else{
				if(readCookie('G') == 'F' && readCookie('A') < 60){
					updateScreenerDB('LastPageVisited', 'Birth Control');
					updateCustomerDB('LastPageVisited', 'Birth Control');
					changeSection('noSmokingSelf', 'birthControlSelf');
					incProgressBar('36');
				} else {
					if(readCookie('close') == 'site'){
						updateScreenerDB('LastPageVisited', 'Contact Information');
						updateCustomerDB('LastPageVisited', 'Contact Information');
						incProgressBar('39');
						changeSection('noSmokingSelf', 'contactInfo');
					} else {
						updateScreenerDB('LastPageVisited', 'Collect Contact Information');
						updateCustomerDB('LastPageVisited', 'Collect Contact Information');
						incProgressBar('38');
						changeSection('noSmokingSelf', 'collectContactSelf');
					}	
				}
			}
		break;

		case 'noSmokingSomeoneElse':
			if(d.noSmokingSomeoneElse[0].checked){
				updateScreenerDB('WillingToNotSmoke', 'Yes');
			} else if(d.noSmokingSomeoneElse[1].checked){
				updateScreenerDB('WillingToNotSmoke', 'No');
			} else if(d.noSmokingSomeoneElse[2].checked){
				updateScreenerDB('WillingToNotSmoke', 'Do not use nicotine');
			} else {
				updateScreenerDB('WillingToNotSmoke', 'Unsure');
			}
			
			if(d.noSmokingSomeoneElse[1].checked){
				changeSection('noSmokingSomeoneElse', 'uqSomeoneElse');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				updateQuitCode('118'); 
			} else{
				if(readCookie('G') == 'F' && readCookie('A') < 60){
					updateScreenerDB('LastPageVisited', 'Birth Control');
					updateCustomerDB('LastPageVisited', 'Birth Control');
					changeSection('noSmokingSomeoneElse', 'birthControlSomeoneElse');
					incProgressBar('36');
				} else {
					if(readCookie('close') == 'site'){
						updateScreenerDB('LastPageVisited', 'Contact Information');
						updateCustomerDB('LastPageVisited', 'Contact Information');
						incProgressBar('39');
						changeSection('noSmokingSomeoneElse', 'contactInfo');
					} else {
						updateScreenerDB('LastPageVisited', 'Collect Contact Information');
						updateCustomerDB('LastPageVisited', 'Collect Contact Information');
						incProgressBar('38');
						changeSection('noSmokingSomeoneElse', 'collectContactSomeoneElse');
					}	
				}
			}
		break;

		case 'birthControlSelf':
			if(d.birthControlSelf[0].checked){
				changeSection('birthControlSelf', 'pregnancySelf');
				updateScreenerDB('LastPageVisited', 'Pregnancy');
				updateCustomerDB('LastPageVisited', 'Pregnancy');
				incProgressBar('37');
				updateScreenerDB('BirthControl', 'Yes');
			} else if(d.birthControlSelf[1].checked){
				updateScreenerDB('BirthControl', 'No');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('birthControlSelf', 'uqSelf');
				incProgressBar('38');
				updateQuitCode('125');
			} else if(d.birthControlSelf[3].checked){
				updateScreenerDB('BirthControl', 'Postmenopausal/Sterile');
				if(readCookie('close') == 'site'){
					changeSection('birthControlSelf', 'contactInfo');
					incProgressBar('39');
					updateScreenerDB('LastPageVisited', 'Contact Information');
					updateCustomerDB('LastPageVisited', 'Contact Information');
				} else {
					changeSection('birthControlSelf', 'collectContactSelf');
					incProgressBar('38');
					updateScreenerDB('LastPageVisited', 'Collect Contact Information');
					updateCustomerDB('LastPageVisited', 'Collect Contact Information');
				}
			} else {
				changeSection('birthControlSelf', 'pregnancySelf');
				updateScreenerDB('LastPageVisited', 'Pregnancy');
				updateCustomerDB('LastPageVisited', 'Pregnancy');
				incProgressBar('37');
				updateScreenerDB('BirthControl', 'Unsure');
			}
		break;

		case 'birthControlSomeoneElse':
			if(d.birthControlSomeoneElse[0].checked){
				changeSection('birthControlSomeoneElse', 'pregnancySomeoneElse');
				updateScreenerDB('LastPageVisited', 'Pregnancy');
				updateCustomerDB('LastPageVisited', 'Pregnancy');
				updateScreenerDB('BirthControl', 'Yes');
				incProgressBar('37');
			} else if(d.birthControlSomeoneElse[1].checked){
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				changeSection('birthControlSomeoneElse', 'uqSomeoneElse');
				updateScreenerDB('BirthControl', 'No');
				updateQuitCode('125');
				incProgressBar('38');
			} else if(d.birthControlSomeoneElse[3].checked){
				updateScreenerDB('BirthControl', 'Postmenopausal/Sterile');
				if(readCookie('close') == 'site'){
					updateScreenerDB('LastPageVisited', 'Contact Information');
					updateCustomerDB('LastPageVisited', 'Contact Information');
					changeSection('birthControlSomeoneElse', 'contactInfo');
					incProgressBar('39');
				} else {
					updateScreenerDB('LastPageVisited', 'Collect Contact Information');
					updateCustomerDB('LastPageVisited', 'Collect Contact Information');
					incProgressBar('38');
					changeSection('birthControlSomeoneElse', 'collectContactSomeoneElse');
				}
			} else {
				changeSection('birthControlSomeoneElse', 'pregnancySomeoneElse');
				updateScreenerDB('LastPageVisited', 'Pregnancy');
				updateCustomerDB('LastPageVisited', 'Pregnancy');
				updateScreenerDB('BirthControl', 'Unsure');
				incProgressBar('37');
			}
		break;

		case 'pregnancySelf':
			if(d.pregnancySelf[0].checked){
				changeSection('pregnancySelf', 'uqSelf');
				updateScreenerDB('Pregnancy', 'Yes');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				incProgressBar('38');
				updateQuitCode('126');
			} else if(d.pregnancySelf[1].checked) {
				updateScreenerDB('Pregnancy', 'No');
				if(readCookie('close') == 'site'){
					changeSection('pregnancySelf', 'contactInfo');
					incProgressBar('39');
					updateScreenerDB('LastPageVisited', 'Contact Information');
					updateCustomerDB('LastPageVisited', 'Contact Information');
				} else {
					changeSection('pregnancySelf', 'collectContactSelf');
					incProgressBar('38');
					updateScreenerDB('LastPageVisited', 'Collect Contact Information');
					updateCustomerDB('LastPageVisited', 'Collect Contact Information');
				}
			} else if(d.pregnancySelf[2].checked) {
				updateScreenerDB('Pregnancy', 'Unsure');
				if(readCookie('close') == 'site'){
					incProgressBar('39');
					changeSection('pregnancySelf', 'contactInfo');
					updateScreenerDB('LastPageVisited', 'Contact Information');
					updateCustomerDB('LastPageVisited', 'Contact Information');
				} else {
					changeSection('pregnancySelf', 'collectContactSelf');
					incProgressBar('38');
					updateScreenerDB('LastPageVisited', 'Collect Contact Information');
					updateCustomerDB('LastPageVisited', 'Collect Contact Information');
				}
			}
		break;

		case 'pregnancySomeoneElse':
			if(d.pregnancySomeoneElse[0].checked){
				changeSection('pregnancySomeoneElse', 'uqSomeoneElse');
				updateScreenerDB('Pregnancy', 'Yes');
				updateScreenerDB('LastPageVisited', 'Unqualified');
				updateCustomerDB('LastPageVisited', 'Unqualified');
				updateQuitCode('126');
				incProgressBar('38');
			} else if(d.pregnancySomeoneElse[1].checked) {
				updateScreenerDB('Pregnancy', 'No');
				if(readCookie('close') == 'site'){
					incProgressBar('39');
					changeSection('pregnancySomeoneElse', 'contactInfo');
					updateScreenerDB('LastPageVisited', 'Contact Information');
					updateCustomerDB('LastPageVisited', 'Contact Information');
				} else {
					incProgressBar('38');
					changeSection('pregnancySomeoneElse', 'collectContactSomeoneElse');
					updateScreenerDB('LastPageVisited', 'Collect Contact Information');
					updateCustomerDB('LastPageVisited', 'Collect Contact Information');
				}
			} else if(d.pregnancySomeoneElse[2].checked) {
				updateScreenerDB('Pregnancy', 'Unsure');
				if(readCookie('close') == 'site'){
					incProgressBar('39');
					changeSection('pregnancySomeoneElse', 'contactInfo');
					updateScreenerDB('LastPageVisited', 'Contact Information');
					updateCustomerDB('LastPageVisited', 'Contact Information');
				} else {
					incProgressBar('38');
					changeSection('pregnancySomeoneElse', 'collectContactSomeoneElse');
					updateScreenerDB('LastPageVisited', 'Collect Contact Information');
					updateCustomerDB('LastPageVisited', 'Collect Contact Information');
				}
			}	
		break;

		case 'uqSelf':
			if(d.uqSelf[0].checked){
				incProgressBar('39');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=uq" + ";expires="+expire.toGMTString();+"path=/"
				updateScreenerDB('LastPageVisited', 'Contact Info');
				changeSection('uqSelf', 'contactInfo');
			}else{
				incProgressBar('40');
				updateScreenerDB('name', 'RR');
				updateScreenerDB('lastName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', 'RR');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				changeSection('uqSelf', 'courtesyClose');
			}	
		break;

		case 'uqSomeoneElse':
			if(d.uqSomeoneElse[0].checked){
				incProgressBar('39');
				var today = new Date();
				var expire = new Date();
				expire.setTime(today.getTime() + 3600000*24*1);
				document.cookie = "close=uq" + ";expires="+expire.toGMTString();+"path=/"
				updateScreenerDB('LastPageVisited', 'Contact Info');
				changeSection('uqSomeoneElse', 'contactInfo');
			}else{
				incProgressBar('40');
				updateScreenerDB('name', 'RR');
				updateScreenerDB('lastName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', 'RR');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
				changeSection('uqSomeoneElse', 'courtesyClose');
			}	
		break;

		case 'uqAgeSelf':
			if(d.uqAgeSelf[0].checked){
				incProgressBar('39');
				changeSection('uqAgeSelf', 'contactInfo');
				updateScreenerDB('LastPageVisited', 'Contact Info');
			}else{
				incProgressBar('40');
				updateScreenerDB('name', 'RR');
				updateScreenerDB('lastName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', 'RR');
				changeSection('uqAgeSelf', 'courtesyClose');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
			}
		break;

		case 'uqAgeSomeoneElse':
			if(d.uqAgeSomeoneElse[0].checked){
				incProgressBar('39');
				changeSection('uqAgeSomeoneElse', 'contactInfo');
				updateScreenerDB('LastPageVisited', 'Contact Info');
			}else{
				incProgressBar('40');
				updateScreenerDB('name', 'RR');
				updateScreenerDB('lastName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', 'RR');
				changeSection('uqAgeSomeoneElse', 'courtesyClose');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
			}	
		break;

		case 'collectContactSelf': //pre-qualified
			updateQuitCode('171');
			var today = new Date();
			var expire = new Date();
			expire.setTime(today.getTime() + 3600000*24*1);
			document.cookie = "close=preq" + ";expires="+expire.toGMTString();+"path=/"
			if(d.collectContactSelf[0].checked){
				incProgressBar('39');
				changeSection('collectContactSelf', 'contactInfo');
				updateScreenerDB('LastPageVisited', 'Contact Info');
			}else{
				incProgressBar('40');
				updateScreenerDB('name', 'RR');
				updateScreenerDB('lastName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', 'RR');
				changeSection('collectContactSelf', 'courtesyClose');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
			}
		break;

		case 'collectContactSomeoneElse': //pre-qualified
			updateQuitCode('171');
			var today = new Date();
			var expire = new Date();
			expire.setTime(today.getTime() + 3600000*24*1);
			document.cookie = "close=preq" + ";expires="+expire.toGMTString();+"path=/"
			if(d.collectContactSomeoneElse[0].checked){
				incProgressBar('39');
				changeSection('collectContactSomeoneElse', 'contactInfo');
				updateScreenerDB('LastPageVisited', 'Contact Info');
			}else{
				incProgressBar('40');
				updateScreenerDB('name', 'RR');
				updateScreenerDB('lastName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', 'RR');
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', 'RR');
				changeSection('collectContactSomeoneElse', 'courtesyClose');
				updateScreenerDB('LastPageVisited', 'Courtesy Close');
			}
		break;

		case 'contactInfo':
			if(document.contactForm.Pfname.value == '' ||document.contactForm.Plname.value == '' || document.contactForm.phone.value == '' || document.contactForm.bestTime.value == '' || document.contactForm.ampm.value == ''){
				displayError('')
				if(document.contactForm.Pfname.value == ''){
					document.getElementById('Pfname').style.color = 'red';	
				} else {
					document.getElementById('Pfname').style.color = 'black';
				}
				if(document.contactForm.Plname.value == ''){
					document.getElementById('Plname').style.color = 'red';	
				} else {
					document.getElementById('Plname').style.color = 'black';
				}
				if(document.contactForm.phone.value == ''){
					document.getElementById('phone').style.color = 'red';	
				} else {
					document.getElementById('phone').style.color = 'black';
				}
				if(document.contactForm.bestTime.value == '' || document.contactForm.ampm.value == ''){
					document.getElementById('bestTime').style.color = 'red';	
				} else {
					document.getElementById('bestTime').style.color = 'black';
				}
			} else {
				updateScreenerDB('name', document.contactForm.Pfname.value);
				updateScreenerDB('lastName', document.contactForm.Plname.value);
				updateCustomerDB('name', document.contactForm.Pfname.value);
				updateCustomerDB('lastName', document.contactForm.Plname.value);
				updateScreenerDB('SomeoneElseAskName_CaregiverFirstName', document.contactForm.Cfname.value);
				updateScreenerDB('SomeoneElseAskName_CaregiverLastName', document.contactForm.Clname.value);
				updateScreenerDB('address', document.contactForm.add.value);
				updateScreenerDB('phone', document.contactForm.phone.value);
				updateScreenerDB('phonetype', document.contactForm.phoneType.value);
				updateCustomerDB('phone', document.contactForm.phone.value);
				updateCustomerDB('typephone', document.contactForm.phoneType.value);
				updateScreenerDB('BestTime', document.contactForm.bestTime.value + ' ' + document.contactForm.ampm.value);
				updateCustomerDB('BestTime', document.contactForm.bestTime.value + ' ' + document.contactForm.ampm.value);
				updateScreenerDB('phone2', document.contactForm.altPhone.value);
				updateScreenerDB('phonetype2', document.contactForm.altPhoneType.value);
				updateScreenerDB('OK_LeaveMessage', document.contactForm.message.value);
				updateCustomerDB('MessageTakerName', document.contactForm.messagePerson.value);
				updateScreenerDB('MessageTakerName', document.contactForm.messagePerson.value);
				updateScreenerDB('OKEMail', document.contactForm.canemail.value);
				updateScreenerDB('email', document.contactForm.email.value);
				updateCustomerDB('email', document.contactForm.email.value);
				updateScreenerDB('FutureContact', 'Yes');
				
				if(readCookie('PatientName')){
					incProgressBar('40');
					if(readCookie('close') == 'preq'){
						updateScreenerDB('Qualified', 'Yes');
						updateCustomerDB('Qualified', 'Yes');
						updateQuitCode('1');
						updateCustomerDB('CallBackRequestBy', 'Initial Screener');
						updateCustomerDB('CallBackReason', '3 Day Callback');
						CallBack();
						changeSection('contactInfo', 'preqCloseSomeoneElse');
						updateScreenerDB('LastPageVisited', 'Prequalified Close');
						updateCustomerDB('LastPageVisited', 'Prequalified Close');
					} else if(readCookie('close') == 'site'){
						changeSection('contactInfo', 'badSiteCloseSomeoneElse');
						updateScreenerDB('LastPageVisited', 'Not Yet Avail/Not Yet Active/Not Interested');
						updateCustomerDB('LastPageVisited', 'Not Yet Avail/Not Yet Active/Not Interested');
					} else if(readCookie('close') == 'uq' || readCookie('close') == 'age'){
						changeSection('contactInfo', 'uqCloseSomeoneElse');
						updateScreenerDB('LastPageVisited', 'Unqualified Close');
						updateCustomerDB('LastPageVisited', 'Unqualified Close');
					} 
				} else {
					incProgressBar('40');
					if(readCookie('close') == 'preq'){
						updateScreenerDB('Qualified', 'Yes');
						updateCustomerDB('Qualified', 'Yes');
						updateQuitCode('1');
						updateCustomerDB('CallBackRequestBy', 'Initial Screener');
						updateCustomerDB('CallBackReason', '3 Day Callback');
						CallBack();
						updateScreenerDB('LastPageVisited', 'Prequalified Close');
						updateCustomerDB('LastPageVisited', 'Prequalified Close');
						changeSection('contactInfo', 'preqCloseSelf');
					} else if(readCookie('close') == 'site'){
						updateScreenerDB('LastPageVisited', 'Not Yet Avail/Not Yet Active/Not Interested');
						updateCustomerDB('LastPageVisited', 'Not Yet Avail/Not Yet Active/Not Interested');
						changeSection('contactInfo', 'badSiteCloseSelf');
					} else if(readCookie('close') == 'uq' || readCookie('close') == 'age'){
						updateScreenerDB('LastPageVisited', 'Unqualified Close');
						updateCustomerDB('LastPageVisited', 'Unqualified Close');
						changeSection('contactInfo', 'uqCloseSelf');
					} 
				}
			}
		break;

		default:
			alert("ERROR: Question not found");
		break;

	}
}