// ******************************************************
// Hitchcock Cameo JS
// ******************************************************


var questans = new Array();
questans = [ ["O","Young and Innocent"],["R","Strangers on a Train"],
["Q","The Man Who Knew Too Much (1956)"],["B","The Paradine Case"],
["N","Psycho"],["K","The Lady Vanishes"],["S","The Lodger"],
["W","Family Plot"],["C","The Birds"],["H","Spellbound"],
["X","North by Northwest"],["D","Notorious"],["J","Rebecca"],
["M","Dial M for Murder"],["A","Rear Window"],["U","Topaz"],
["T","Blackmail"],["Y","To Catch a Thief"],["F","Lifeboat"],
["P","Stage Fright"],["L","Under Capricorn"],["E","The 39 Steps"],
["I","Frenzy"],["G","Shadow of a Doubt"],["V","Torn Curtain"] ];


var line, msg, err, corr, inval;

// ******************************************************
function findAns(question)  {  // anwser one question
  	msg =  'The Correct Answer ';
  	msg += 'to Question ' + question + ' is:\n\n';
	msg += '  ' + questans[question-1][0] + ')';
	msg += '   ' + questans[question-1][1];

  	myAlert (msg);

} // end function


// ******************************************************
// Get Rid of Spaces Surrounding String
// Example "  A  " = "A"
// Call looks like: 
//		stringOrNumber = stringOrNumber.trim();
//							- or -
//		stringOrNumber = GetRidofSpaces(stringOrNumber);
// ******************************************************
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
} // end String.prototype.trim


// Note: All "numbers" will be returned as String Numbers
function GetRidofSpaces(theVal) {
	theVal = String(theVal);						// make sure a string
	theVal = theVal.trim();							// get rid of surrounding spaces
	return theVal;
} // end function GetRidofSpaces()
// ******************************************************


function Verify()  {
	 var tform = window.document.cForm;

 	var cnt1 = 0;
	var cnt2 = 0;
 	var cnt3 = 0;
	var cnt4 = 0;
	
 	var c1;
 
 	msg  = "";											// Empty - cnt1
 	err  = "";											// Wrong - cnt2
 	corr = "";											// Right - cnt3
	inval = "";											// Invalid - cnt4
	
  
  	// Loop through all text input boxes
 	for ( var i=0; i<tform.elements.length; i++ )  {
   		if ( tform.elements[i].type == "text" ) { 
		
			// 2009 - Get rid of surrounding spaces
			c1 = tform.elements[i].value;
			c1 = GetRidofSpaces(c1);
	  	
			 // Text input box is empty
	 		 if (c1 == "")  { 							// empty
				msg +=  (i + 1);   						// question has not been answered - empty
				cnt1 += 1;
				
				if (cnt1 % 6 == 0) { 					// new line
			 		msg += ", \n";
				} // end if
				
				else msg += ", ";
   			 }  // end if
	 
	 	
			// Text input box is NOT empty
	 		 else {  										// not empty
	    		c1 = c1.toUpperCase();
			
				// 2009 - More than 1 character entered 
				if (c1.length > 1) {
					inval +=  (i + 1);   					// question has invalid entry
					cnt4 += 1;
				
					 if (cnt4 % 6 == 0) { 					// new line 
			   			 inval += ", \n";
			 		} // end if
				
					else inval  += ", ";
				} // end if
			
			
				// 2009 - Check if invalid entry
				else if (c1 < "A" || c1 > "Y")  {
					inval +=  (i + 1);   					// question has invalid entry
					cnt4 += 1;
				
					 if (cnt4 % 6 == 0) { 					// new line 
			   			 inval += ", \n";
			 		} // end if
				
					else inval  += ", ";
				} // end else if
	   	 	
			
				// Text input box is NOT correct
				else if ( c1 != questans[i][0] ) {  		// is it the correct answer
					err +=  (i + 1);   						// answer not correct
					cnt2 += 1;
				
					 if (cnt2 % 6 == 0) { 					// new line 
			   			 err += ", \n";
			 		} // end if
				
					else err  += ", ";
	    		} // end else if
		
		
				// Text input box is IS correct
				else  {  
					corr  +=  (i + 1);   					// answer correct
					cnt3 += 1;
				
					 if (cnt3 % 6 == 0) { 					// new line 
			  			corr += ", \n";
					 } // end if 
				 
					 else corr  += ", ";
				} // end else right
		
	 	 	}  // end else not empty
	 
		}   // end if 
	 }   // end for
 
 
	// ****************************************************************************************
 	var lastIn;
	
 	if (cnt1 != 0) {
		lastIn = msg.lastIndexOf(",");
		msg = msg.substr(0, lastIn);				// get rid of ", " at very end
		msg  = "The Following Questions were Not Answered:\n" + msg + "\n\n";
	} // end if
	
 
 	if (cnt2 != 0) {
		lastIn = err.lastIndexOf(",");
		err = err.substr(0, lastIn);				// get rid of ", " at very end
		err  = "The Following Question Answers are WRONG:\n" + err + "\n\n";
	} // end if
	
	
 	if (cnt3 != 0) {
		lastIn = corr.lastIndexOf(",");
		corr = corr.substr(0, lastIn);				// get rid of ", " at very end
		corr = "The Following Question Answers are RIGHT:\n" + corr + "\n\n";
	} // end if
	
	
 	if (cnt4 != 0) {
		lastIn = inval.lastIndexOf(",");
		inval = inval.substr(0, lastIn);			// get rid of ", " at very end
		inval = "The Following Question Answers were Invalid:\n(Answers must be 'A' through 'Y')\n" + inval + "\n\n";
	} // end if
	
	
	// ****************************************************************************************
	line = corr + err + inval + msg;			 	// join output

 	
 	// Got all answers correct 
 	if (cnt3 == 25 && cnt1 == 0 && cnt2 == 0 && cnt4 == 0) { 
		line = "\n\nVery Good!\n\nAll Your Answers Are Correct!!";
 	} // end if
 

	myAlert(line);  								// display how user did


	return true;
} //end function




// ******************************************************
function Answer()  {  									//display correct answers
 	var t1form = window.document.cForm;
 
 	t1form.reset();
   
	 for (var i=0; i<t1form.elements.length; i++ )  {
		 
  		  if ( t1form.elements[i].type == "text" ) { 
	 		 t1form.elements[i].value=questans[i][0];
		} // end if
		
 	} // end for
 
	return true;
} //end function
// ******************************************************


function myAlert (msg1)  { 							 // display alert or answer
	msg1 += "\n\n\n\n";
   	alert(msg1);
} //end function
// ******************************************************



