// JavaScript Document

function fromHTML(html) {
	var root = document.createElement('div');
	root.innerHTML = html;
	return root.firstChild;
}

function closePopup() { 
	divThing = document.getElementById('contact');
	divThing.parentNode.removeChild(divThing); 
}

function checkForm(a) { 
	if(a.elements['name'].value == "" || a.elements['email'].value == "" || a.elements['comment'].value == "") {
		alert("All fields must be filled in.");
		return false;
	}
	/*if(a.elements['name'].value == "") {
		alert("A valid email is required.");
		return false;
	}*/
	return true;
}

function contact() { 
	var popup = fromHTML('<div id="contact">' +
								   '<form action="/" method="post" onsubmit="return checkForm(this);">' +
									   '<h2>Contact</h2>' +
									   '<ul>' +
										   '<li><label>Name:</label> <input type="text" name="name" /></li>' +
										   '<li><label>Email:</label> <input type="text" name="email" /></li>' +
										   '<li><label>Comment / Question:</label> <textarea name="comment" rows="5" cols="10" /></textarea></li>' +
										   '<li><input type="submit" name="submit" value="Send" /></li>' +
										   '<li><input type="button" name="close" onclick="closePopup();" value="Cancel" /></li>' +
										   '<li><input type="hidden" name="contact" value="" /></li>' +
									   '</ul>' +
								   '</form>' +
							   '</div>');
	document.getElementById('content').parentNode.appendChild(popup);
}