/** mailto.js : A JavaScript to email the results of a form to a specified
                email address.  This script attempts to limit the amount
                of form specific JavaScript that must be embedded into the
                HTML file containing the form.  Ideally the user would have
                to do nothing but name the form elements and specific that
                this JavaScript is to be run with the 'submit' button is
		pressed.
    Version :	1.0
    Created:	1999-01-15
    Modified:	1999-01-18
    Author:	Michael McDonnell <michael@winterstorm.org>
    License:	GPL 2.0 (or newer)
    Copyright:	(c) 1999 Michael McDonnell and The School of Hope

 **/

/*
**
** fetch values from passed form and make an email body then browse to mailto:
** to send it to the specified address, user gets to see and edit the submission
** text in their defined mail client
**
******************************************************************/
function sendEmail(myForm, Address, Subject) 
{
	var myBody = new String;
	var myURL = new String;
	var myNotFirst = Boolean;
	var i = new Number;

	for(i = 0; i < myForm.elements.length; i++) 
	{
		fe = myForm.elements[i];
//alert("fe.type = "+fe.type);
		switch(fe.type) 
		{
			case "hidden":
			case "password":
			case "text":
				myBody += fe.name + ": " + fe.value + "\n";
				break;
			case "textarea":
				myBody += fe.name + ": " + fe.value + "\n";
				break;
			case "select-multiple":
			case "select-one":
				myNotFirst = false;
				myBody += fe.name + ": "
				for(j = 0; j < fe.options.length; j++) 
				{
					if(fe.options[j].selected) 
					{
						if(myNotFirst) 
						{
							myBody += ", " + fe.options[j].value;
						}
						else 
						{
							myNotFirst = true;
							myBody += fe.options[j].value;
						}
					}
				}
				myBody += "\n";
				break;
			case "radio":
				myBody += fe.name + ": ";
				if(fe.checked) 
				{
					myBody += fe.value;
				}
				myBody += "\n";
				break;
			case "checkbox":
				if(fe.checked) 
				{
					myBody += fe.name + ": " + fe.value + "\n";
				}
				break;
		}
	}
//alert(myBody);//constructed bdy text string

	//specific to gest book, to save a cookie as well as do the email posting.
	if (document.all.item("confirmation") != null)
	{
		SaveCookie('UserName',myForm.elements["username"].value);
	}

	myURL = "mailto:" + escape(Address) + "?subject=" + 
		escape(Subject) + "&body=" + escape(myBody);

//alert(myURL);
	window.location = myURL;

	return true;
}


