function sendemail(){

	error = ""
    if(!$("email_friendname").value){
		error = "Please enter your friend's name."
    } else if(!$("email_friendemail").value){
		error = "Please enter your friend's email address."
	} else if(!new RegExp(/^[a-zA-Z0-9._-]+([+][a-zA-Z0-9._-]+){0,1}[@][a-zA-Z0-9._-]+[.][a-zA-Z]{2,6}$/).test($("email_friendemail").value)){
		error = "Please enter a valid email address for your friend."
	}
	
	  if(!$("email_name").value){
		error = "Please enter your name."
    } else if(!$("email_email").value){
		error = "Please enter your email address."
	} else if(!new RegExp(/^[a-zA-Z0-9._-]+([+][a-zA-Z0-9._-]+){0,1}[@][a-zA-Z0-9._-]+[.][a-zA-Z]{2,6}$/).test($("email_email").value)){
		error = "Please enter a valid email address for you."
	} 
	
	if(error){
		alert (error)
	} 	else {
		
		$("email_loading").style.display = 'block'
		$("email_form").style.display = 'none'
		
		
		req=new Object();
		req.url= document.location.href
		req.email_friendname= $("email_friendname").value
		req.email_friendemail= $("email_friendemail").value
		req.email_name= $("email_name").value
		req.email_email= $("email_email").value
		req.email_comments= $("email_comments").value
        
		new Ajax.Request(emailto_url, {method: 'post', parameters:{req:Object.toJSON(req)}, onSuccess: gotemail});
		
	} 
	
} 


function gotemail(response){
	$('email_loading').style.display = 'none'
	$('email_thankyou').style.display = 'block'

}





//OVERLAY JAVASCRIPT BELOW


var escapeOverlay = {
	fx: function(e) 
	{
		// To make script compatable with both MSIE and Firefox
		var kC  = (window.event) ? event.keyCode : e.keyCode;
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
		
		// If keypressed is escape and the new entry field is empty
		if(kC==Esc && ($F('newvalue') == '' || $F('newvalue') == null) )
			closeDialogue();
		else if(kC==Esc && window.confirm('Are you sure you wish to close the dialogue box?') )
			closeDialogue();
	}
}

// Save in cache (to be able to stopObserving() it), see Prototype API docs for more info:
// http://www.prototypejs.org/api/event
escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);

// loadPopup shows the overlay and dialogue box
function loadPopup()
{
    	// Show the overlay (disables rest of page)
	showOverlay();
	
	// Show dialogue and focus on newvalue
	$('dialogue').show();
	
}
 
// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	$('overlay').show();
	
	Event.observe(document, 'keypress', escapeOverlay.bfx );
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	$('overlay').hide();
	
	Event.stopObserving(document, 'keypress', escapeOverlay.bfx );
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue()
{
	hideOverlay();
	
	// Hide dialogue
	$('dialogue').hide();
	
	// Clear dialogue
	
}

/* Event handler for onKeyPress for the newvalue field. Enables the use of the ENTER (RETURN)
key when adding a new entry in the dialogue box */
function enterKey(event, field)
{
	// If the event key pressed was a return (code 13)
	if (event.which == 13 || event.keyCode == 13)
		addEntry(field.value);
}

// count is used to number the entries LI IDs
var count = 1;

// Adds an entry
function addEntry(message)
{
	// Close the dialogue
	closeDialogue();
	
	// If the value entered for the new entry is not empty
	if (message != '' && message != null)
	{		
		// Build a new LI, set its value and id and add it
		newLI= Builder.node('li', {id: count});
		newLI.innerHTML = message;
		count++;
		
		// Append the new LI to the entries UL
		$('entries').appendChild(newLI);
	}
}
//-->

