<!--
// 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 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\"> <input type='button' value='Print' onclick='javascript:self.print();'><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>");
            //alert(parseInt(myForm.elements[i].value.substr(0, 1)));
            if (parseInt(myForm.elements[i].value.substr(0, 1)) > 0) {
              printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\">");
            }
            if (myForm.elements[i].name.substr(0,8) == "Question") {
              printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\">");
            }
	  }
	  else if(myForm.elements[i].type=="text"){ //print text
		printwin.document.writeln(myForm.elements[i].value+"<br>");
	    printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br>\n\n");
	  }
      else if(myForm.elements[i].type == "radio") { //print radio button values
        if (myForm.elements[i].checked) {
          printwin.document.writeln(myForm.elements[i].value+"<br>");
          printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br>\n\n");
        }
      }
      else if(myForm.elements[i].type == "textarea") { //print textareas
        printwin.document.writeln(myForm.elements[i].value+"<br>");
		if ((myForm.elements[i].name.substr(0,6) == "Answer") || (myForm.elements[i].name.substr(0,8) == "Possible")) {
		  printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+newline+"\"><br>\n\n");
		} else {
		  printwin.document.writeln("<input type=\"hidden\" name=\""+myForm.elements[i].name+"\" value=\""+newstr+"\"><br>\n\n");
		}
      }

	}
	printwin.document.writeln("<input type=\"submit\" name=\"Submit\" value=\"Send\"> <input type=\"button\" name=\"Print\" value=\"Print\" onclick=\"javascript:self.print()\"");
	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>");
		//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><br>");
            if (parseInt(myForm.elements[i].value.substr(0, 1)) > 0) {
              bodyText += newline+newstr+newline;
            } else {
              bodyText+=newstr+newline;
            }
	  }
	  else if(myForm.elements[i].type=="text"){ //print text
		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>\n\n");
		bodyText+=myForm.elements[i].value+newline;
		//add a couple lines for extra space
	  	bodyText+= newline+"*****"+newline;
	  }
          else if(myForm.elements[i].type=="radio") { //print radio buttons
            if (myForm.elements[i].checked) {
              printwin.document.writeln(myForm.elements[i].value+"<br><br>");
              bodyText+= myForm.elements[i].value+newline+newline;
            }
          }
          else if(myForm.elements[i].type=="textarea") { //print textareas
            printwin.document.writeln(myForm.elements[i].value+"<br><br>");
            bodyText+= myForm.elements[i].value+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> <a href='javascript:self.print();'>Print</a>");
}
printwin.document.writeln("</font>");

printwin.document.close();
}//end if(document.MM_returnValue)
}//end function

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 == '');
}
//-->
