
var imgSrc = "http://www.mcgrawhill.ca/college/olcsupport/mcshane6e/selfassess/";
// ---------------------------------------

var ansWin = null;
var qCount = 16;
// ---------------------------------------
function WriteResponse(content) {
if (ansWin && !ansWin.closed) {
	ansWin.close()
}
ansWin = window.open("","","toolbar=NO,location=NO,resizable,scrollbars,width=650,height=450");
ansWin.document.write(content);
ansWin.document.close();
}

// ---------------------------------------
function GradeAssess(theForm) {

// cats[0] is ignored, simply makes others directly readable from values 1 to 4
// cats[1] is "Problem Solving"
// cats[2] is "Social Support"
// cats[3] is "Avoidance"
// cats[4] is "Blame Others"

var cats = new Array(0,0,0,0,0);

for (var i = 0; i < qCount; i++) {
	var catID = "Q" + (i+1) + "Cat";	// digit 1 to 4
	var catValue = theForm[catID].value;
	var cntlname = "pd"+ (i+1);
	var cont = theForm[cntlname].options[theForm[cntlname].selectedIndex].value;
	if (cont == 99) {
		alert("One or more questions are unanswered. Please complete the form and try again.");
		return false;
	}
	cats[catValue] = cats[catValue] + (cont/1);
}


var rsp = "";
rsp += BeginPage();

rsp += GetFeedback();
	
var llabel = "" + "0";
var rlabel = "" + "16";
var scoreLow = 0;
var scoreHigh = 16;

var header = "<hr />Problem Solving";

var divLabel = new Array("Low<br>0 to 6","Average<br>7 to 11","High<br>12 to 16");
var divLow = new Array(0,7,12);
var divHigh = new Array(6,11,16);

rsp += MakeTable(scoreLow,scoreHigh,cats[1],llabel,rlabel,divLabel,divLow,divHigh,header);
rsp += GetFeedback1();

header = "<hr />Social Support";
divLabel = new Array("Low<br>0 to 5","Average<br>6 to 10","High<br>11 to 16");
divLow = new Array(0,6,11);
divHigh = new Array(5,10,16);

rsp += MakeTable(scoreLow,scoreHigh,cats[2],llabel,rlabel,divLabel,divLow,divHigh,header);
rsp += GetFeedback2();

header = "<hr />Avoidance";
divLabel = new Array("Low<br>0 to 4","Average<br>5 to 9","High<br>10 to 16");
divLow = new Array(0,5,10);
divHigh = new Array(4,9,16);

rsp += MakeTable(scoreLow,scoreHigh,cats[3],llabel,rlabel,divLabel,divLow,divHigh,header);
rsp += GetFeedback3();

header = "<hr />Blame Others";
divLabel = new Array("Low<br>0 to 5","Average<br>6 to 10","High<br>11 to 16");
divLow = new Array(0,6,11);
divHigh = new Array(5,10,16);

rsp += MakeTable(scoreLow,scoreHigh,cats[4],llabel,rlabel,divLabel,divLow,divHigh,header);
rsp += GetFeedback4();

rsp += EndPage();
WriteResponse(rsp);
return false;

}
// ---------------------------------------
function MakeTable(datamin,datamax,dscore,ll,lr,divLabel,divLow,divHigh,scalehead) {

var colorBars = new Array("blackspacer.gif","grayspacer.gif");

var spread = datamax - datamin;
var maxwidth = 550;
var gwidth = maxwidth - (maxwidth%spread);
var dfactor = gwidth/spread;
var halffactor = (dfactor - (dfactor%2))/2;

var gscore = (dscore - datamin) * dfactor;

var ptricon = "redpointer.gif";
var ptrwidth = 15;
var ptrloc = gscore - 7 + halffactor;
	// 7 is determined by halfwidth of graphic rounded

if ( ptrloc < 0 ) {
	ptricon = "redpointerleft.gif"
	ptrloc = gscore;
	ptrwidth = 8;
} else {
	if ( (ptrloc + ptrwidth) > gwidth ) {
		ptricon = "redpointerright.gif";
		ptrwidth = 8;
		ptrloc = gscore - 8;
	}
}

var winCode = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";

if (scalehead != "") {
	winCode += "<tr valign=\"top\"><td colspan=\"5\" align=\"center\" style=\"padding-bottom: 3px;\"><b>" + scalehead + "</b></td></tr>";
}

winCode += "<tr valign=\"bottom\"><td></td><td></td><td width=\"" + gwidth + "\" align=\"center\">";

winCode += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr valign=\"bottom\" align=\"center\">";

var pctally = 0;
var barTotalWidth = 0;
var bars = new Array();

for (var i=0; i<divLabel.length; i++) {
	var divWidth = divHigh[i] - divLow[i] + 1;
	var divPercent = (divWidth/gwidth)*100;
	divPercent = divPercent - (divPercent%1);
	if (i == (divLabel.length-1)) {
		bars[i] = gwidth - barTotalWidth;
		divPercent = 100 - pctally;
	} else {
		bars[i] = divWidth*dfactor;
		barTotalWidth = barTotalWidth + (bars[i]/1);
		pctally = pctally +  (divPercent/1);
	}
	winCode += "<td style=\"padding-bottom: 3px;\" class=\"smlabel\" width=\"" + bars[i] + "\">" + divLabel[i] + "</td>";
}

winCode += "</tr></table></td><td></td><td></td></tr>";

winCode += "<tr valign=\"top\"><td rowspan=\"2\" align=\"right\" valign=\"middle\" class=\"smlabel\">" + ll + "</td>";
winCode += "<td align=\"right\" rowspan=\"2\"><img src=\"" + imgSrc + "whitespacer.gif\" width=\"4\" height=\"1\"><img src=\"" + imgSrc + "blackspacer.gif\" width=\"1\" height=\"25\"></td>";
winCode += "<td nowrap align=\"center\">";

for (var i=0; i<divLabel.length; i++) {
	var divWidth = divHigh[i] - divLow[i];
	var divPercent = (divWidth/gwidth)*100;
	divPercent = divPercent - (divPercent%1);
	if (i == (divLabel.length-1)) {
		divPercent = 100 - pctally;
	} else {
		pctally += divPercent;
	}
	winCode += "<img src=\"" + imgSrc + colorBars[(i+1)%2] + "\" width=\"" + bars[i] + "\" height=\"10\">";
}

winCode += "</td>";
winCode += "<td rowspan=\"2\"><img src=\"" + imgSrc + "blackspacer.gif\" width=\"1\" height=\"25\"><img src=\"" + imgSrc + "whitespacer.gif\" width=\"4\" height=\"1\"></td>";
winCode += "<td rowspan=\"2\" valign=\"top\" class=\"smlabel\">" + lr + "</td></tr>";

winCode += "<tr valign=\"top\"><td nowrap valign=\"bottom\"><img src=\"" + imgSrc + "whitespacer.gif\" width=\"" + ptrloc + "\" height=\"1\"><img height=\"12\" src=\"" + imgSrc + ptricon + "\" width=\"" + ptrwidth + "\"></td></tr>";

winCode += "</table>";

winCode += "<p align=\"center\"><font color=\"#cc0000\"><b>Your score was " + dscore + ".</b></font> The range of possible scores is from " + datamin + " to " + datamax + ".</p>";

return winCode
}

// ---------------------------------------
function GetFeedback() {
var winCode = "<h3 class=\"explanation\">Understanding Your Scores on the Stress Coping Preference Scale</h3><p>People cope in various ways with stress and various challenges in life. While the preferred coping strategy depends to some degree on the source of the stress, people also have a natural preference for some types of coping strategies more than others. Coping strategies also change over different stages of one's life.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The Stress Coping Preference Scale estimates your current preference to use four sets of coping strategies: problem solving, social support, avoidance, and blaming others.  These do not represent the full set of ways that people cope with life's challenges, but they are common tactics. Moreover, they are identified as helpful or dysfunctional approaches to stress management.</p>\n";
return winCode;
}

// ---------------------------------------
function GetFeedback1() {
var winCode = "<h3 class=\"explanation\">Problem Solving</h3><p>People with high scores on this subscale tend to deal with stress by actively attempting to remove the stressor by changing the situation. This coping strategy is associated with higher resilience and usually improves your ability to manage stress. Scores on this subscale range from 0 to 16. The average score in similar measures of coping is between 8 and 9.</p>\n";
return winCode;
}

// ---------------------------------------
function GetFeedback2() {
var winCode = "<h3 class=\"explanation\">Social Support</h3><p>People with high scores on this subscale tend to deal with stress by actively seeking emotional support, information, or guidance from others. This coping strategy is part of the \"tend and befriend\" response that some research suggests is more common among women than among men. Generally, coping through social support has a beneficial effect and is identified as a favorable approach to stress management. Scores on this subscale range from 0 to 16. The average score in similar measures of coping is slightly less than 8.</p>\n";
return winCode;
}

// ---------------------------------------
function GetFeedback3() {
var winCode = "<h3 class=\"explanation\">Avoidance</h3><p>People with high scores on this subscale tend to deal with stress by cognitively and/or behaviourally acting in ways that prevent the person from coming to terms with and resolving the source of stress. While avoidance may be effective when the problem is short-lived and beyond one's control, research concludes that this coping strategy is usually an ineffective approach to stress management. In fact, it significantly differentiates people with high and low resilience. Scores on this subscale range from 0 to 16. The average score in similar measures of coping is around 6.</p>\n";
return winCode;
}

// ---------------------------------------
function GetFeedback4() {
var winCode = "<h3 class=\"explanation\">Blaming Others</h3><p>People with high scores on this subscale tend to deal with stress by directing their energy to identify and seek justice against those perceived as the source of the stressor. This form of coping may include exhibiting emotions or engaging in behaviours that get back at the alleged perpetrators. Blaming others is generally considered a maladaptive response to stress because it redirects energy away from productive approaches to deal with the stressor.  Furthermore, this strategy can potentially alienate others, which reduces opportunities for social support. Scores on this subscale range from 0 to 16. The average score in similar measures of coping is around 7.</p>\n";
return winCode;
}


// ---------------------------------------
function BeginPage() {
var winCode = "<html><head><title>Organizational Behaviour Self-Assessment Exercises</title>\n\n";
winCode += "<script language=\"JavaScript\">\n<!--\n// ---------------------------\n";
winCode += "function printScreen(){\nif (window.print) {\n window.print();\n} else {\n alert(\"Your browser does not support printer links embedded within a web page. PC users, however, can right-click within the window and a popup menu will appear from which you can print. Macintosh users can access a similar menu by holding down the mouse for several seconds.\");\n}\n}\n";
winCode += "//-" + "->\n</script>\n" + GetStyles() + "</head>\n";
winCode += "<body bgcolor=\"#ffffff\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr><td bgcolor=\"#000000\"><font size=\"4\">&nbsp;</font></td></tr>\n</table>\n<table border=\"0\" width=\"100%\" cellpadding=\"20\" cellspacing=\"0\">\n<tr valign=\"top\"><td>\n\n";
return winCode
}
//----------------------------------------
function GetStyles() {

return "\n<link href=\"http://www.mcgrawhill.ca/college/olcsupport/mcshane6e/selfassess/selfassess.css\" type=\"text/css\" rel=\"stylesheet\"></link>\n";

}
// ---------------------------------------
function EndPage() {
var winCode = "\n\n<p class=\"footer\"><hr noshade size=\"1\" />\n<font face=\"Symbol\" color=\"ff0000\">&#168;</font> <a href=\"javascript:printScreen()\"><b>Print Screen</b></a>\n</p>\n<p class=\"footer\"><a href=\"mailto:highered_web@mcgrawhill.ca\">Comments or questions?</a><br>Copyright &copy; 2006 McGraw-Hill Ryerson Limited<br>&nbsp;</p></td></tr></table></body></html>";
return winCode
}


