<!-- Begin
function FP_callJS() {
	//v1.0
	eval(arguments[0]);
}
function FP_preloadImgs() {
	//v1.0
	var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
	for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}
function popUp(message) {
	alert(message);
	return false;  
}
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function validateRS(myForm) {
	// this validates all the fields.
	var curField = myForm.Industry;
	if (!validateDropdown(curField.value, "industry")) {curField.focus(); return false;};
	curField = myForm.Size;
	if (!validateDropdown(curField.value, "company's size")) {curField.focus(); return false;};
	curField = myForm.Level;
	if (!validateDropdown(curField.value, "job level")) {curField.focus(); return false;};
	curField = myForm.Education;
	if (!validateDropdown(curField.value, "highest level of education")) {curField.focus(); return false;};
	curField = myForm.Age;
	if (!validateAge(curField.value)) {curField.focus(); return false;};
	curField = myForm.Gender;
	if (!validateRadio(curField, 2, "gender")) {curField[0].focus(); return false;};
	//validate the responses to the RS questions
	for (x = 1; x <= 25; x++) {
		var count = -1;
		var leadingZero = "";
		if (x < 10) {leadingZero = "0"};
		var elementName = "Q" + leadingZero + x;
		curField = document.getElementsByName(elementName); 
		for (i = 0; i < 7; i++) {
			if (curField[i].checked) {count = i}
			}
		if (count == -1) {
			popUp("Question " + x + " not answered."); 
			return false;
			}
	}
	return true;
}
function validateDropdown(selectedValue, type) {
	if (selectedValue == "") {alert("Please select your " + type + " from the list."); return false;}
	return true;
}
function validateAge(sField){
	// called from the scoreRS function. It validates the Age field, which is different from all the radio button fields.
	// checks for empty field	
	if(sField.length==0) {alert("Please enter your age."); return false;}
	// this checks for single character decimal point, minus sign, comma.
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) {alert("Please enter your age."); return false;}	
	// this makes sure that the entry is numeric and if numeric, greater than 9 years old.
		for(x = 0; x < sField.length; x++) {
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else {alert("Please enter your age."); return false;}
	}
	// this makes sure that an entry is within the range
	if (sField <= 1){alert("Please enter an age greater than 1."); return false;}
	if (sField >= 120){alert("Please enter an age less than 120."); return false;}
	return true;
}
function validateRadio(curField, noOptions, tString) {
	// this is used in the scoreRS function to validate the radio buttons at the top. Parms passed are: Field, no of radio buttons, and message string.
	var count = -1;
	for (x = 0; x < noOptions; x++) {
		if (curField[x].checked) {count = 1}
	}
	if (count != 1) {alert("Please report your " + tString + "."); return false;}
	return true
}
function scoreRS(myForm) {
	if(!validateRS(myForm)) {return false};
	//This gets the total score and writes it to the proper fields to pass to the results page.
	var total = 0; 
	for (x = 1; x <= 25; x++) {
		var count = -1;
		var leadingZero = "";
		if (x < 10) {leadingZero = "0"}
		var elementName = "Q" + leadingZero + x;
		var curField = document.getElementsByName(elementName); 
		for (i = 0; i < 7; i++) {
			if (curField[i].checked) {count = i}
			}	
		if (count != -1){total = total + (curField[count].value - 0)}
	}
	myForm.TestScore.value = total;
	myForm.TestInterpretation.value = getInterpretation(total);
	myForm.AgreeToPublication.value = "I agree to the use of my answers in future publications.";
}
function getInterpretation(testScore){
	// used in the scoreRS function
	// depending on the test score, displays the appropriate result text.
	var crlf = String.fromCharCode(60, 112, 62, 60, 47, 112, 62); 
	var myString = new String();
	var resText1 = "Your resilience level is very low but this doesn’t mean you have zero resilience. Everyone is resilient to some degree. Others who have scored between 25 and 100 have reported depression. Finding meaning is sometimes a problem for individuals who score between 25-100. You may be lacking in energy. You may doubt your own abilities and see the glass as ‘half empty.’ You may be overwhelmed. You may feel as if no one in the world can understand what your life is like and therefore feel isolated and alone. It can be very difficult to keep going at times like these. You can strengthen your resilience and doing so will make a significant and positive change in your life.";
	var resText2 = "Your resilience level is low but this doesn’t mean you have zero resilience. Everyone is resilient to some degree. Others who have scored between 101 and 115 have reported feeling somewhat depressed and anxious about their life. Meaning may be lacking in your life. You may feel dissatisfied in general and feel a need to make some changes. Some who score between 101 and 115 say they tend to be pessimistic. Maybe you have a lot going on in your life and you feel a little out of control. You can strengthen your resilience and doing so will make a significant and positive change in your life.";
	var resText3 = "Your resilience level is on the low end but this doesn’t mean you have zero resilience. Everyone is resilient to some degree. Others who have scored between 116 and 130 report some depression and anxiety in their lives. If you are like others, you are experiencing some problems in your life and are trying to resolve them. Some people have trouble letting go of things they have no control over. Maybe you feel unappreciated. Life may not seem very fulfilling but there are times you can see the 'light at the end of the tunnel.' You can strengthen your resilience and doing so will make a significant and positive change in your life. ";
	var resText4 = "Your resilience level is moderate; neither high nor low. The good news is that you possess many characteristics of resilience and can build on those to keep strengthening your resilience. Others who scored between 131 and 145 have reported that while they are satisfied in general, many aspects of their life are not satisfactory. But you may be thinking that you need to make some changes. You are probably able to keep moving forward though you may not do so with enthusiasm. You may feel tired and emotionally drained at the end of the day. Overall, you are probably experiencing ups and downs. You can see the good things in your life if you work at it but tend to dwell on the things that aren’t going well. Your sense of humor may still be intact but you would like to laugh a little more and fret a little less. You can strengthen your resilience and doing so will make a significant and positive change in your life.";
	var resText5 = "Your resilience level is moderately high, which means that you are doing well but believe you could do better. You possess all of the characteristics of a solid resilient personality but would like to strengthen your resilience. Others who scored between 146 and 160 find life meaningful in general and are rarely or only sometimes depressed. There may be many aspects of your life with which you are not satisfied such as your work, personal and/or professional relationships, how you spend your leisure time, and physical health, for example. You recognize that there is ‘room for improvement.’ Most of the time you have enough energy to get through the day and then some. You probably have a balanced life perspective in which you recognize that sometimes things go well, and sometimes they don’t. You enjoy your own company most of the time. You are dependable. You would benefit from recognizing your strengths in resilience but also areas where you are not as strong. You know from taking the Resilience Scale where you probably scored lower.";
	var resText6 = "Your resilience level is high, which means that you are doing very well in almost all aspects of resilience. Others who scored between 161 and 175 report that they are rarely if ever depressed or anxious about their lives. When you score high in resilience, it usually means that you find life very purposeful and you are eager to get on with each new day. You tend to see life as an adventure and others describe you as optimistic and upbeat. You enjoy your own company and the company of others. Your life is balanced between work and play. Like everyone else, you sometimes have difficult and painful events including illness, death of family and friends, unemployment, and so forth. But unlike less resilient people, you are able to regain your equilibrium and keep moving forward. You have weathered many storms before and you are confident that you will manage again. You are dependable. You are definitely resourceful. Others seek you out because you are able to look at situations in a number of ways and therefore have a healthy perspective on life. You are self-confident. Overall, you are satisfied with your life.";
	//this will determine which score range the score falls into and return the appropriate text
	if (testScore == "") {return "No test score entered"}
		else if (testScore < 101) {return resText1}
		else if (testScore < 116) {return resText2}
		else if (testScore < 131) {return resText3}
		else if (testScore < 146) {return resText4}
		else if (testScore < 161) {return resText5}
		else {return resText6};
}
function setAllRadios(setting) {
	// this can be removed after initial testing
	var leadingZero = ""; 
	var count = -1;
	var elementName = "";
	for (var x = 1; x <= 25; x++) {
		count = -1;
		leadingZero = "";
		if (x < 10) {leadingZero = "0"}
		elementName = "Q" + leadingZero + x;
		var curRadio = document.getElementsByName(elementName); 
		curRadio[setting].checked = true;
	}
}
function todayStr() {
	//this generates the proper date string fort the RS form
	var today = new Date();
	var strMonth = "";
	switch(today.getMonth() + 1) {
		case 1:
			strMonth = "January"; break;
		case 2:
			strMonth = "February"; break;
		case 3:
			strMonth = "March"; break;
		case 4:
			strMonth = "April"; break;
		case 5:
			strMonth = "May"; break;
		case 6:
			strMonth = "June"; break;
		case 7:
			strMonth = "July"; break;
		case 8:
			strMonth = "August"; break;
		case 9:
			strMonth = "September";	break;
		case 10:
			strMonth = "October"; break;
		case 11:
			strMonth = "November"; break;
		case 12:
			strMonth = "December"; break;
	}
	return today.getDate() + " " + strMonth + " " + (today.getYear() + 1900);
}

