/*	Emerson College		Enrollment Management		Performing Arts Application Evaluation form JS		*/function eval_getForm(search_id_lastname,type) {		var score_saveBlock_id = 'saveBlock';	var saveBlock_bool = true;		// Check if scores were modified		// Check if comments are present and moddified			if ($('score_comments') != undefined && $F('score_comments') != "") {				alert_comments = true;			} else {				alert_comments = false;			}		if ($F(score_saveBlock_id) == 1 || alert_comments === true) {			saveBlock_bool = confirm("Are you sure you want to lose your scores?\n\nClick 'OK' to continue and NOT save these scores or 'Cancel' to stay with the current view.");		}		// Check vars		if (search_id_lastname == "" || type < 1 && saveBlock_bool === true) {			alert("Please enter a name or student ID.");		} else if (saveBlock_bool === true) {			// Variables (Even though we're sending as POST, you have to declair vars as if it was a GET string.				var opt_getInformation = "&id_lastname="+search_id_lastname+"&type="+type;			// Request data from the Ajax Pull								var getInformationAjax = new Ajax.Updater(						'eval_stage',						ajaxurl_root,						{							method: 'post',							parameters: "&id=eval_getForm"+opt_getInformation,							evalScripts: true,							onSuccess: eval_getForm_success,							onFailure: eval_getForm_failure						}						);		}		}function eval_getForm_success(x) {		//alert("eval_getForm_sucess(x)");	$('saveBlock').value = 0;	}function eval_getForm_failure(x) {		alert("eval_getForm_failure(x);");	$('debug').innerHTML = x.responseText;	}function eval_processScores(id) {		var score_totalElems = $F('score_totalForm');	var score_total = 0;	var score_total_avg = 0;	var score_results = new Array();		for (c=0;c<score_totalElems;c++) {		score_results[c] = eval_getScoreSelected(c+1);		if (score_results[c][0] == 1) {			score_total = score_total + parseInt(score_results[c][1]);			score_total_avg++;		}	}		$('eval_elementScoreAverage').innerHTML = (score_total / score_total_avg).toFixed(2);		// Clear alert if in an active alert state.		if (id != undefined) {			eval_error_highlight(id,0);		}	}function eval_getScoreSelected(inputBace) {		/*		Output Array			[0] = Average flag			[1] = Selected value			[2] = Score Value			[3] = Required flag			[4] = Check flag if required is actually set	*/		var outputValue = new Array($F('score_type_avg_'+inputBace),0,$F('score_id_'+inputBace),$F('score_type_req_'+inputBace),0);	var type = $F('score_type_'+inputBace);	var score_saveBlock_id = 'saveBlock';		// Search through group for a select		if (type == 1) {						for (abc = 1;abc <= 5;abc++) {								if ($('score_'+inputBace+'_'+abc).checked === true) {					//alert('score_'+inputBace+'_'+abc+" true: "+$('score_'+inputBace+'_'+abc).value)					outputValue[1] = $('score_'+inputBace+'_'+abc).value;					outputValue[4] = 1;				}			}								} else if (type == 2) {						for (abc = 1;abc <= $F('score_valuerange_'+inputBace);abc++) {								if ($('score_'+inputBace+'_'+abc).checked === true) {					//alert('score_'+inputBace+'_'+abc+" true: "+$('score_'+inputBace+'_'+abc).value)					outputValue[1] = $('score_'+inputBace+'_'+abc).value;					outputValue[4] = 1;				}			}					} else if (type == 3) {						// Checkboxes (with other box)								var value_array = new Array();								for(abc=1;abc <= $F('score_valuerange_6');abc++) {					/*alert('score_'+inputBace+'_'+abc+'\n\n'						  +$('score_'+inputBace+'_'+abc).type						  +"\n"						  +$('score_'+inputBace+'_'+abc).checked						  +"\n"						  +$F('score_'+inputBace+'_'+abc)						  );*/					if ($('score_'+inputBace+'_'+abc).checked === true) {						value_array.push($F('score_'+inputBace+'_'+abc));					} else if ($F('score_'+inputBace+'_'+abc) != "" && $('score_'+inputBace+'_'+abc).type != "checkbox") {						value_array.push($F('score_'+inputBace+'_'+abc));					}				}								if (value_array.length > 0) {					outputValue[1] = value_array;					outputValue[4] = 1;				} else {					outputValue[4] = 0;				}					} else {						alert("eval_getScoreSelected("+inputBace+"): Type not scripted!");					}			// Break the save seal if something did change		if (outputValue[4] == 1) {			$(score_saveBlock_id).value = 1;		}			// Return selected value, or 0 if nothing shows up.		return outputValue;		}function eval_saveScores() {		// Vars Declare		var score_totalElems = $F('score_totalForm');		var score_results = new Array();		var alert_required = new Array();			// Check and process all variables, making sure required vars are set right.		eval_processScores();				for (c=0;c<score_totalElems;c++) {			score_results[c] = eval_getScoreSelected(c+1);			/*alert("c:"+c				  +"\n flag_arg: "+score_results[c][0]				  +"\n value: "+score_results[c][1]				  +"\n value.length: "+score_results[c][1].length				  +"\n score_id: "+score_results[c][2]				  +"\n falg_reg: "+score_results[c][3]				  +"\n flag_req_set: "+score_results[c][4]				  );*/			if (score_results[c][3] == 1 && score_results[c][4] == 0) {				alert_required.push(c);				eval_error_highlight(c+1,1);			} else if (score_results[c][3] == 1 && score_results[c][4] == 1) {				eval_error_highlight(c+1,0);			}		}		// Check if all required is set, otherwise save scores		if (alert_required.length > 0) {			//alert("Please fill out all required vars.\n"+alert_required.length);			eval_saveScoresFail();		} else {			// Assemble and launch Ajax.Updater(?)				// Var assembly					var eval_saveScores_vars_pre = "&id=eval_saveForm"						+"&student_id="+$F('score_student_id')						+"&score_comments="+encodeURIComponent($F('score_comments'))						+"&score_count="+score_results.length;					var eval_saveScores_vars_loop = "";					var tempID = "";					var tempValue = "";					var tempTempValue = "";										for (scoreLoop = 0; scoreLoop < score_results.length; scoreLoop++) {												// send score ID							tempID = "&score_id_"+scoreLoop+"="+score_results[scoreLoop][2];						// set value							if (score_results[scoreLoop][1] instanceof Array) {								tempTempValue = score_results[scoreLoop][1].join("|");									//alert("tempTempValue\n\n" + tempTempValue);								tempValue = "&score_value_"+scoreLoop+"="+tempTempValue;									//alert("Array\n\n tempValue = " + tempValue);							} else {								tempValue = "&score_value_"+scoreLoop+"="+score_results[scoreLoop][1];									//alert("NOT Array\n\n tempValue = " + tempValue);							}						// Publish to grand loop vars							eval_saveScores_vars_loop = eval_saveScores_vars_loop + tempID + tempValue;												}										var eval_saveScores_vars = eval_saveScores_vars_pre + eval_saveScores_vars_loop;					//$('debug').innerHTML = "<p>"+ eval_saveScores_vars + "<\/p>";									// Ajax Send								if (true) {					var eval_saveScores_ajax = new Ajax.Request(						ajaxurl_root,							{								method: 'post',								parameters: eval_saveScores_vars,								onComplete: eval_saveScoresSuccess,								onFailure: eval_saveScoresFail							});				}		}	}function eval_saveScoresFail(x) {		// Make notices		//$('eval_row_notice').innerHTML = "Please complete the required form fields.";		eval_error_highlight('notice',1);			// Show Debug		if (Application['staging'] === true) {			//alert("eval_saveScoresFail();");			if (x != undefined) {				$('debug').innerHTML = x.responseText;			}		}	}function eval_saveScoresSuccess(x) {		// Parse XML		var phazed_xml = x.responseXML.getElementsByTagName('paapp');				if (phazed_xml[0].getElementsByTagName('status')[0].firstChild != null) {			var eval_saveScoresSuccess_text = phazed_xml[0].getElementsByTagName('status')[0].firstChild.data;			var eval_saveScoresSuccess_code = phazed_xml[0].getElementsByTagName('status')[0].getAttribute('code');		}				//alert("eval_saveScoresSuccess();\n error_text: '" + eval_saveScoresSuccess_text + "'\n error_code: " + eval_saveScoresSuccess_code);				if (eval_saveScoresSuccess_code == 0) {			// Run sucess				var successContent = '<div align="center" id="eval_saveSuccess">'					+'<p><img src="/images/special_app/checkbox_yes_big.png" alt="A large green checkmark" title="" width="150" height="150" border="0" /><\/p>'					+'<p><strong>'+eval_saveScoresSuccess_text+'<\/strong>'					+'<br \/>You may continue by entering another applicant.<\/p>'					+'<\/div>';								$('eval_stage').innerHTML = successContent;				$('saveBlock').value = 0;						} else {			// Run fail				alert("SCORE SAVES FAILED!\n\nThe scores didn't save for some reason. I've saved your inputs below, so please try again by clicking the 'Save Evaluation' buttion.\nCode #"+eval_saveScoresSuccess_code);		}	}function eval_error_highlight(id,action) {	/*		id = Number of row effected		action			0 = Clear to default			1 = Set to alert	*/		var colorStart = "#ffffff";	var colorClear = "#ccffcc";	var colorAlert = "#ffff99";	var idBace = 'eval_row_';	var startColorVar = "";		if ($(idBace+id).style.backgroundColor == "") {			startColorVar = colorStart;		} else {			startColorVar = rgbtohex($(idBace+id).style.backgroundColor);		}		if (action == 1) {		if (startColorVar != hextorgb(colorAlert)) {			new Effect.Highlight(idBace+id, { startcolor:startColorVar, endcolor:colorAlert, restorecolor:colorAlert } );		}	} else {		if (startColorVar != hextorgb(colorClear) && startColorVar != "") {			new Effect.Highlight(idBace+id, { startcolor:startColorVar, endcolor:colorClear, restorecolor:colorClear } );		}	}	}