
/*
	Show's email from for sending a link to a friend.
*/
function showEmailForm(id)
{
	html = "<div><form id=\"sendLinkForm\" method=\"get\" action=\"\">";
	html += "<input type=\"hidden\" value=" + id + " name=\"uid\" id=\"uid\">";
	html += "<table width=\"100%\" border=\"0\">";
	html +=	"<tr><td width=\"100\">";
	html +=	"<label>Your Email: </label>";
	html +=	"</td><td>";
	html +=	"<input type=\"text\" name=\"fromEmail\" value=\"\">";
	html +=	"</td></tr><tr><td>"
	html +=	"<label>Their Email: </label>";
	html +=	"</td><td>";
	html +=	"<input type=\"text\" name=\"toEmail\" value=\"\">";
	html +=	"</td></tr><tr><td colspan=\"2\">";
	html +=	"<label>Your Message (a link will be included): </label>";
	html +=	"</td></tr><tr><td colspan=\"2\">";
	html +=	"<textarea name=\"description\"></textarea>";
	html +=	"</td></tr><tr><td><button class=\"button negative\" onclick=\"Effect.SlideUp('msgCenter'); return false;\"><img src=\"img/icons/cross.png\" alt=\"\"/> Cancel</a></td><td align=\"right\">";
	html +=	"<button type=\"submit\" class=\"button positive\" onClick=\"sendEmail(this.form);return false;\"><img src=\"img/icons/tick.png\" alt=\"\"/> Send Email &rarr;</button>";
	html +=	"</td></tr></table></form></div>";
	$('msgCenter').innerHTML = html;
	new Effect.SlideDown('msgCenter');
}

/*
	Send email from email form
*/
function sendEmail(form)
{
	toEmail = form.toEmail.value;
	fromEmail = form.fromEmail.value;
	msg = form.description.value;
	uid = form.uid.value;
	
	var url = '../ajaxhandlers/sendEmail.php';
	var params = 'id=' + encodeURIComponent("1") + '&toEmail=' + encodeURIComponent(toEmail) + '&fromEmail=' + encodeURIComponent(fromEmail) + '&msg=' + encodeURIComponent(msg) + '&uid=' + encodeURIComponent(uid);
	new Ajax.Request(url, {
	  method: 'post',
	  parameters: params,
	  onSuccess: function(transport) {
	  },
	  onCreate: function(){
		new Effect.SlideUp('msgCenter');
	 }
	});
}

/*
	Pretend Sleep Function for Javascript
*/
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

/*
	Select contents of form field
*/
function selectAll(field)
{
	field.focus();
	field.select();
}
