var examples = [
                 {
                    "fromname":"Bill Gates",
                    "from":"bgates@microsoft.com",
                    "subject":"Advantages of Linux",
                    "message":"Dear friends,\n   I am pleased to announce that Microsoft has decided to migrate all of our current software technologies to a Linux base.  The most noticeable change for our users will be increased stability.  No more blue screens of death!\n\nYour bud,\n   Bill"
                 } ,
                 {
                    "fromname":"Orlando Bloom",
                    "from":"bloom@hollywood.com",
                    "subject":"I've been thinking...",
                    "message":"Hey there,\n   I saw you awhile back in the mall when I was in your area and haven't been able to get you out of my head.  I'm not sure what to do.\n   Write me,\n      Orlando"
                 } ,
                 {
                    "fromname":"Martha Stewart",
                    "from":"martha@marthastewart.com",
                    "subject":"New Recipe",
                    "message":"My latest recipe is one you might want to try, if you've got some time on your hands!\n\nJailbird Stew\n1 cup Remorse\n2 pinches of stocks\n1 large, tearful onion\n\nMix thoroughly, and chill overnight.  Serves 1."
                 }
              ];
var lastexample = -1;

function get_example()
{
	var i = Math.floor((examples.length)*Math.random());
        if(lastexample == i) {get_example(); return;}
	try { console.log(i); console.log(examples[i]); } catch (exe) {}
        lastexample = i;
	$("fromname").value = examples[i].fromname;
	$("from").value = examples[i].from;
	$("subject").value = examples[i].subject;
	$("message").value = examples[i].message;

}

function $(id)
{
	return document.getElementById(id);
}

function submit()
{
	if(!$('tos').checked) {alert("You must agree to play nice!"); return false;}
	if(!$('to').value || !$('from').value || !$('subject').value || !$('message').value) {alert("You did not fill in all the fields!"); return false;}
	var url = 'email.php?tos&ajax&to=' + encodeURIComponent($('to').value) + '&from=' + encodeURIComponent($('from').value) + '&subject=' + encodeURIComponent($('subject').value) + '&message=' + encodeURIComponent($('message').value) + '&fromname=' + encodeURIComponent($('fromname').value);
	if($('bcc-check').checked)
		url += '&bcc=' + encodeURIComponent($('bcc').value);
	$('content').innerHTML = "<div id=\"loading\"><img src=\"loading.gif\" \\></div>";
	ajax = new sack(url);
	ajax.element = 'content';
	ajax.runAJAX(); 
        $('homelink').style.display = 'block';
}

function bcc_toggle()
{
	if($('bcc-check').checked)
	{
		$('bcc').style.display = "inline";
	}
	else
	{
		$('bcc').style.display = "none";
	}
}
