<!--
// This functionality will popup a new window that contains all questions
// and given answers to a filled in essay test.
// The window will contain an email link allowing the user to submit the quiz.
// ***HAS SPECIAL FUNCTIONALITY TO USE A FORM INSTEAD OF A LINK FOR IE DUE TO 
// IE'S CHARACTER LIMIT IN URL STRINGS

var newline;
var isWin=navigator.appVersion.indexOf("Win");
var isIE=navigator.appName.indexOf('Microsoft');
function checkPlatform(){
	if(navigator.appVersion.indexOf("Mac") >= 0){
		newline="\r";
	}else{
		newline="\n";
		
	}
}
/************************************************/
function sendMatching(myForm){
// this function prints the contents of the passed form item



printwin=window.open("",'EmailBox','toolbar,menubar,scrollbars,width=640,height=480')
printwin.document.open();
printwin.document.writeln("<font face=\"arial\" size=\"3\">");

printwin.document.writeln("<center>Results</center><br><hr>");
// begin the form

	//use a form
	printwin.document.writeln("<form>");
	//include the student's name
	printwin.document.writeln(" <input type='button' value='Print' onclick='javascript:self.print();'> <input type='button' value='Close' onclick='javascript:self.close();'><br><br>");

	//print out the form
	for (i=0; i<myForm.elements.length-4; i+=3){
		// change quotes into &quot;
	  	re = /"/gi;
	    mystring = myForm.elements[i].value;
	    newstr = mystring.replace(re, "&quot;");
		// get rid of line returns, tabs
	    re = /\s+/gi;
	    mystring = newstr;
	    newstr = mystring.replace(re, " ");
		
		// first do the question
	    	printwin.document.writeln("<b>"+myForm.elements[i].value+"</b><br>");
		printwin.document.writeln("<input type=\"hidden\" name=\"Definition\" value=\""+newstr+"\">");
	 	// then do the selection
		
		printwin.document.writeln("Student Answer: "+myForm.elements[i+1].options[myForm.elements[i+1].selectedIndex].value+"<br>");
		printwin.document.writeln("<input type=\"hidden\" name=\"Student Answer\" value=\""+myForm.elements[i+1].options[myForm.elements[i+1].selectedIndex].value+"\">");
		// then do the correct answer
		printwin.document.writeln("Correct Answer: "+myForm.elements[i+2].value+"<br><br>");
		printwin.document.writeln("<input type=\"hidden\" name=\"Correct Answer\" value=\""+myForm.elements[i+2].value+"\">");

/*	  if (myForm.elements[i].type == "hidden"){
	    printwin.document.writeln("<b>"+myForm.elements[i].value+"</b><br>");
	    printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br>");
	  }
	  else if(myForm.elements[i].type=="textarea"){ //print textareas
		printwin.document.writeln(myForm.elements[i].value+"<br>");
	    printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br><br>\n\n");
	  }*/

	}
	printwin.document.writeln('<input type="button" value="Print" onClick="self.print();"> <input type="button" value="Close" onclick="javascript:self.close();">' );
	printwin.document.writeln("</form>");


printwin.document.writeln("</font>");

printwin.document.close();

}//end function sendMatching



/************************************************/


function emailvalue(myForm){
// this function prints the contents of the passed form item
MM_validateForm('sendTo','','RisEmail');
MM_validateForm('studentAddress','','RisEmail');
MM_validateForm('studentName','','R');

if(document.MM_returnValue){//only act if the necessary info is filled in
printwin=window.open("",'EmailBox','toolbar,menubar,scrollbars,width=640,height=480')
printwin.document.open();
printwin.document.writeln("<font face=\"arial\" size=\"3\">");

printwin.document.writeln("<center>Click the \"Send\" button to email the document</center><br><hr>");
// begin the form
if(isWin != -1 && isIE != -1){
	//use a form
	printwin.document.writeln("<form name=\"sendform\" action=\"mailto:"+myForm.elements.sendTo.value+"\" enctype=\"text/plain\" method=\"post\">");
	//include the student's name
	printwin.document.writeln("<input type=\"submit\" name=\"Submit\" value=\"Send\"><br>");
		printwin.document.writeln(myForm.elements.studentName.value+"<br>");
	    printwin.document.writeln("<input type=\"hidden\" name=\"from\" value=\""+myForm.elements.studentName.value+" "+myForm.elements.studentAddress.value+"\"><br><br>\n\n");

	//print out the form
	for (i=0; i<myForm.elements.length-1; i++){
		// change quotes into &quot;
	  	re = /"/gi;
	    mystring = myForm.elements[i].value;
	    newstr = mystring.replace(re, "&quot;");
		// get rid of line returns, tabs
	    re = /\s+/gi;
	    mystring = newstr;
	    newstr = mystring.replace(re, " ");
	  if (myForm.elements[i].type == "hidden"){
	    printwin.document.writeln("<b>"+myForm.elements[i].value+"</b><br>");
	    printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br>");
	  }
	  else if(myForm.elements[i].type=="textarea"){ //print textareas
		printwin.document.writeln(myForm.elements[i].value+"<br>");
	    printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br><br>\n\n");
	  }

	}
	printwin.document.writeln("<input type=\"submit\" name=\"Submit\" value=\"Send\">");
	printwin.document.writeln("</form>");
}
else{//use the link
	var bodyText="";
	//print out the form
	for (i=0; i<myForm.elements.length-1; i++){
	  if (myForm.elements[i].type == "hidden"){
	    printwin.document.writeln("<b>"+myForm.elements[i].value+"</b><br><br>");
		//strip out all line breaks and extra spaces into 1 space
	    re = /\s+/gi;
	    mystring = myForm.elements[i].value;
	    newstr = mystring.replace(re, " ");
	    //printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+myForm.elements[i].value+"\"><br>");
		bodyText+=newstr+newline;
	  }
	  else if(myForm.elements[i].type=="textarea"){ //print textareas
		printwin.document.writeln(myForm.elements[i].value+"<br><br>");
	    //printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+myForm.elements[i].value+"\"><br><br>\n\n");
		bodyText+=myForm.elements[i].value+newline;
		//add a couple lines for extra space
	  	bodyText+= newline+"*****"+newline;
	  }
  
	}

	//URL encode the bodytext
	bodyText=escape(bodyText);
	subjectText=escape(myForm.elements.studentName.value);
	copy=myForm.elements.studentAddress.value;
	printwin.document.writeln("<a href=\"mailto:"+myForm.elements.sendTo.value+"?Body="+bodyText+ "&CC="+copy+ "&Subject="+subjectText+ "\">Send</a>");
}
printwin.document.writeln("</font>");

printwin.document.close();
}//end if(document.MM_returnValue)
}//end function emailvalue

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

