isEmailFeature = 1;
if (typeof DEBUGMODE == "undefined") DEBUGMODE = 0;

function doBeforeSubmitting() {testEmailText(EMAILSTRING);
destinationAddress = top.genWindowObject.document.mailButtonForm["toAddress"].value;


if (!(verifyAddress(destinationAddress)))
  {

   var confirmMsg = "The e-mail address \"" +destinationAddress+ "\" does not appear to be valid. It should be of the form:\n'name@somewhere.domain'\n(Your e-mail might not arrive at any destination.)\n \nDo you still wish to continue?";
   submitformOK = (window.confirm(confirmMsg));
/*
   if (submitformOK){
	 top.genWindowObject.onblur=new Function("top.genWindowObject.window.focus();top.genWindowObject.clickcount=(typeof top.genWindowObject.clickcount!='number')?2:++top.genWindowObject.clickcount;if(!(top.genWindowObject.clickcount % 3)){alert('Still attempting to submit your e-mail... Close the generated window in order to cancel attempt.')}");
	};
*/
   top.genWindowObject.focus();
   havesubmitted = 1;
   return(submitformOK);

  };

return true;
}


function verifyAddress(checkThisAddress) {
 if (checkThisAddress!=null && checkThisAddress!="")
  { atindx = checkThisAddress.indexOf("@");
	dotindx = checkThisAddress.indexOf(".");
	validaddress = (atindx>0 && dotindx>(atindx+1) && dotindx<checkThisAddress.length)?1:0;
	if (validaddress) {return true} else {return false};
  } else {return false};
return false;
}


var EMAILSTRING = new String(" ");
var emailSeparator = new String("");
var brokenSeparator = new String("\n \n--------------------------------------------------------------------");
	var solidSeparator = new String("\n_____________________________________________________________________\n ");
var mainHeadingH2 = " ";
var subHeadingH3 = " ";

var errornum = 0;
var errorlog = " ";

if (typeof this.bookTitle == "undefined") {bookTitle = "Interactive Edition"};

if (typeof pagename == "undefined")
   {
	 if (mainHeadingH2 != " ") {pagename = mainHeadingH2}
	 else if (subHeadingH3 != " ") {pagename = subHeadingH3}
	 else {pagename = bookTitle};
   };


var usersName="";
var senderAddress="";
var destinationAddress="";
var writeEmailTableSuccess=0;


function writeEmailTable(windowObjectName)
{
--writeEmailTableSuccess;
if (writeEmailTableSuccess<-2) {return false};
with (windowObjectName)
{

writeln("<center><FORM NAME=\"mailButtonForm\" METHOD=\"POST\" TARGET=\"_self\" ACTION=\"http://www.abacon.com/cgi-bin/abacon/intered/mailfwd.cgi\" onSubmit=\"if(typeof(top.opener)=='object'&&top.opener!=null){if(top.opener.document && typeof(top.opener.isEmailFeature)!='undefined'){return top.opener.doBeforeSubmitting();}};\">");




writeln("<table CELLSPACING=1 CELLPADDING=1 border=0>");




writeln("<TR><td><INPUT TYPE=\"HIDDEN\" NAME=\"mailText\" VALUE=\"" + escape(EMAILSTRING) + "\">");
writeln("<INPUT TYPE=\"HIDDEN\" NAME=\"bookTitle\" VALUE=\"" + escape(bookTitle) + "\"></td></TR>");
writeln("<TR><td><INPUT TYPE=\"HIDDEN\" NAME=\"emailSubject\" VALUE=\"" + escape(pagename) + "\">");
writeln("<INPUT TYPE=\"HIDDEN\" NAME=\"errorNum\" VALUE=\"" + escape(errornum) + "\">");
writeln("<INPUT TYPE=\"HIDDEN\" NAME=\"errorLog\" VALUE=\"" + escape(errorlog) + "\"></td></TR>");



writeln("<TR><td ALIGN=CENTER COLSPAN=2><b>"+EmailerDirections+"</b></td></TR>");

writeln("<TR><td ALIGN=RIGHT NOWRAP><tt>Your name:</tt> </td><td><INPUT TYPE=\"TEXT\" SIZE=30 NAME=\"studentName\" VALUE=\"" + usersName + "\" onChange=\"if(typeof(top.opener)=='object'&&top.opener!=null){if(top.opener.document && typeof(top.opener.isEmailFeature)!='undefined'){top.opener.SetAllCookies('studentName');}};\"></td></TR>");

writeln("<TR><td ALIGN=RIGHT NOWRAP><tt>Your e-mail address:</tt> </td><td> <INPUT TYPE=\"TEXT\" SIZE=30 NAME=\"fromAddress\" VALUE=\"" + senderAddress + "\" onChange=\"if(typeof(top.opener)=='object'&&top.opener!=null){if(top.opener.document && typeof(top.opener.isEmailFeature)!='undefined'){top.opener.SetAllCookies('fromAddress');}};\"></td></TR>");

writeln("<TR><td ALIGN=RIGHT NOWRAP><tt>E-mail to:</tt> </td><td> <INPUT TYPE=\"TEXT\" SIZE=30 NAME=\"toAddress\" VALUE=\"" + destinationAddress + "\" onChange=\"if(typeof(top.opener)=='object'&&top.opener!=null){if(top.opener.document && typeof(top.opener.isEmailFeature)!='undefined'){top.opener.SetAllCookies('toAddress');}};\"></td></TR>");

writeln("<TR><td COLSPAN=2 ALIGN=CENTER> <INPUT TYPE=\"SUBMIT\" NAME=\"emailSubmitter\" VALUE=\" Submit... \"> </td></tr></table></FORM></center>");


}
Fill_InFormValues();
writeEmailTableSuccess=1;
return true;
}



function GetCookieTempl(inputName)
{ ckString=document.cookie;

 if  (ckString!=null && ckString!="" && ckString.indexOf(inputName)!=-1)
	{
	 getCutPoints(inputName,ckString);
	 ckVal=ckString.substring(startcut,endcut);
	 return unescape(ckVal);
	 }
else  { return null };

return null;
}

  startcut=0;
  endcut=0;

function getCutPoints(inputName,inputString)
{   ckdelimiter=  ";";  inputName+=  "=";

 if (inputString!=""&&inputString!=null&&inputString.length>1)
	{
	 startcut = inputString.indexOf(inputName)+inputName.length;
	 endcut   = inputString.indexOf(ckdelimiter, startcut);
	 if (endcut==-1){endcut=ckString.length};
	};
}


 function SetCookieTempl(inputName,inputValue)
{
  todaysdate = new Date();
	expidate = new Date();

 if(typeof(todaysdate.setFullYear) == "function")
   { incrementYear = (parseInt(todaysdate.getFullYear())) + 1;
	 if (typeof incrementYear != "number" || isNaN(incrementYear) || incrementYear>2050) {incrementYear=2012};
	 expidate.setFullYear(incrementYear);
 } else {
  tdate_msec = todaysdate.getTime();
  mseconds_later = 1000*60*60*24*365;
  mseconds = tdate_msec + mseconds_later;
  expidate.setTime(mseconds);
 };

  if (inputValue!=null && inputValue.toUpperCase()=="DELETE"){alert("Deleting cookie\""+inputName+"\".");
  if (typeof notcapable=='number' && notcapable){expidate.setYear(1971)}else{expidate.setFullYear(1971)} };

  ckattributes= "; expires=" + expidate.toGMTString() + "; path=/";


  if (inputValue!=null && inputValue.indexOf("\r")==-1 && inputValue.indexOf("\n")==-1)
	 { document.cookie = inputName +"="+ escape(inputValue) +ckattributes };
}




var oldCookieVal = "<<enter an address>>";
var newCookieVal = "";


function SetAllCookies(cookieToGet)
{
oldCookieVal = GetCookieTempl(cookieToGet);

SetCookieTempl(cookieToGet, top.genWindowObject.document.mailButtonForm[cookieToGet].value);

newCookieVal = GetCookieTempl(cookieToGet);

if (cookieToGet!="studentName")
{
addressTypeMsg = (cookieToGet=="toAddress")? "the DESTINATION":"your REPLY e-mail";

invalidMsg = (!verifyAddress(newCookieVal))?  "\n \n(This does not appear to be a properly-formatted e-mail address.)":" ";

if (oldCookieVal!=newCookieVal && oldCookieVal!=null) {alert("You have changed  " +addressTypeMsg+ " address from: \"" + oldCookieVal + "\" to: \"" + newCookieVal + "\"." + invalidMsg)};
}

top.genWindowObject.focus();

}

Fill_InFormValuesSuccess=0;
function Fill_InFormValues() {
if(Fill_InFormValuesSuccess<=-1){return false;}
--Fill_InFormValuesSuccess;

destinationAddress = GetCookieTempl("toAddress");
senderAddress = GetCookieTempl("fromAddress");
usersName = GetCookieTempl("studentName");

if (destinationAddress==null) {destinationAddress = ""};
if (senderAddress==null) {senderAddress = ""};
if (usersName==null) {usersName = ""};
if (typeof top.genWindowObject != "undefined" && typeof top.genWindowObject.document != "undefined" &&  typeof top.genWindowObject.document.mailButtonForm != 'undefined')
  {
	with (top.genWindowObject.document) {
	  mailButtonForm["toAddress"].value=destinationAddress;
	  mailButtonForm["fromAddress"].value=senderAddress;
	  mailButtonForm["studentName"].value=usersName;
  };
 };
Fill_InFormValuesSuccess=1;
return true;
}


errorlog = navigator.appName + ":   " + navigator.appVersion + "\n" + this.location.pathname;


function logerrors(errmsg, locat, linenum) {  //"\r\n -- " + locat +
	errornum +=1;
	if (errornum < 10) {errorlog += "\r\n -- " + locat + "\n -- " + errmsg + "\n -- " +  linenum};

	if ((errmsg.indexOf("ccess") != -1 || errmsg.indexOf("ermission") != -1) && errmsg.indexOf("enied") != -1) {if (genWindowObject && errornum<20) {setTimeout("genWindowObject.close()",100)}; };

	if (typeof(newWinSuppressor) != "number" || newWinSuppressor!=0) {
	return true;
	} else {return false};
	
	return true;
}
	//if (!notcapable)
window.onerror = logerrors;




testEM=0;
function testEmailText(inputString)
{
if (testEM==1) {
 testWin = window.open('','testWINDOW');
 with (testWin.document) {
 open("text/html")
  writeln("<HTML><HEAD><TITLE>Test EMAILSTRING Wrapping</TITLE></HEAD><BODY>");
  writeln("<table><tr><td><FORM NAME='testForm'>");
  writeln("<TEXTAREA NAME='testwidth' ROWS=1 COLS=72></TEXTAREA>72<BR><P><BR>unescaped form value \"mailText\":<BR>");
  writeln("<TEXTAREA NAME='textar1' ROWS=20 COLS=90></TEXTAREA><BR><P><BR>mailText.value:(escaped)<BR>");
  writeln("<TEXTAREA NAME='textar2' ROWS=10 COLS=90></TEXTAREA>");
  writeln("</FORM></td></tr></table>");
  writeln("<HR>PRE:<HR><PRE>" + EMAILSTRING +"</PRE>");
  writeln("<HR>XMP:<HR><XMP>" + EMAILSTRING +"</XMP><P><HR>errorLog:</HR><BR><PRE>" + errornum +" errors  \n" + unescape(errorlog)  +"</PRE>");
  writeln("</BODY></HTML>");
  close();
  testForm.textar1.value = top.genWindowObject.document.mailButtonForm["studentName"].value + "\n" + unescape(top.genWindowObject.document.mailButtonForm["mailText"].value);
  testForm.textar2.value = top.genWindowObject.document.mailButtonForm["mailText"].value;
 };
};
}

function sd(m){DEBUGMODE=m;testEM=m;};



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~  All JavaScript written by:  Erwin O. Fox Tree, 1999  ~~
//~~  foxtree@tiac.net                   okwa@hotmail.com  ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~









