// ajaxFriend
// ---
// sends a video url to a number of email addresses

function ajaxFriend( theForm )
{
	// if no emails are being passed, return an alert
	
	if( !theForm.email_list.value.match(/([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4})/i) )
	{
		alert("You must enter at least one valid email");
		return false;
	}
	else
	{
		// if there are more than 10 @ symbols in the text area, we 
		// are exceeding our 10 email limit so error out
		var results = theForm.email_list.value.match(/@/g);
		if( results.length > 10 )
		{
			alert("You can't send more than 10 emails at a time");
			return false;
		}
	}
	
	var ajaxURL = '_friend.php?ajax=1&video_id='+escape(theForm.video_id.value)+'&email_list='+escape(theForm.email_list.value)+'&message='+escape(theForm.message.value)+'&name='+escape(theForm.name.value);
	ajax.open('get', ajaxURL,true);
	ajax.onreadystatechange = friendResponse;
	ajax.send(null);
}

// friendResponse
// ---
// receives response from posting a friend and hides the friend box on success

function friendResponse()
{
	// defaultResponse parses the response for an error, redirect or success
	if( defaultResponse(ajax) )
	{
		// show confirmation information in the popup box
		toggleSuccess('sendtofriendbox',true);
		clearPopboxForm('sendtofriendbox');
	
		//theForm.email_list.value = "";
		//theForm.message.value = "";
		//theForm.name.value = "";
	}
}
