// JavaScript Document

//////////////////////////////////////////////////////////////////////////////////
function doMailto(thePage) {
	
	var theform = document.getElementById("gbcmailtoform");
	var theMailto = 'mailto:';

	// quick hack for special custom check of age dropdowns on contact page
	// construct the recipient address
	var msgRecipient = theform.elements['gbcrecipientusername'].value + '@' + theform.elements['gbcrecipientdomain'].value;
	
	// construct the message body
	var msgBody = "Name\n" + theform.elements['gbcmailtofirst'].value + ' '  + theform.elements['gbcmailtolast'].value + "\n\n"; 
	msgBody = msgBody + "Email address\n" + theform.elements['gbcmailtosender'].value;
	
	var theCheckbox = document.getElementById("gbcmailtonews");
	if (theCheckbox.checked == true) {
			msgBody = msgBody + "\n\nPlease add me to the mailing list.\n";
	}else{
			msgBody = msgBody + "\n\nPlease DO NOT add me to the mailing list.\n";
	}

	
	// add the comments
	if (theform.elements['gbcmailtocomments'].value != '') {
			var msgBody = msgBody + " \n\nAdditional comments\n" + theform.elements['gbcmailtocomments'].value + "\n\n";
	}
	
	// urlencode subject and message body for mailto url string
	msgBody = urlencode(msgBody);
	var msgSubject = theform.elements['gbcsubject'].value;
	msgSubject = urlencode(msgSubject);
	
	// contruct mailto url
	theMailto = theMailto + msgRecipient + '?subject=' + msgSubject + '&body=' + msgBody;
	
	// attempt to open mail in a new window
	window.location = theMailto;
	
} // end doMailto function

////////////////////////////////////////////////////////////////
// escape characters for url-encoding of mailto
function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '%20').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}
