/*
	Form must have a hidden input "body" which will be set to the body of the message
*/

function IsValid(form) {
	var inputs = form.getElementsByTagName("input");
	var selects = form.getElementsByTagName("select");
	
	var valid = true;
	
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].className.substr(0, 2) == "re") {
			if (inputs[i].value == "") {
				valid = false;
				break;
			}
		}
	}
	for (var i=0; i<selects.length; i++) {
		if (selects[i].className.substr(0, 2) == "re") {
			if (selects[i].value == "") {
				valid = false;
				break;
			}
		}
	}
	
	return valid;
}

function Send(form) {
	if (IsValid(form)) {
		var inputs = form.getElementsByTagName('input');
		var textareas = form.getElementsByTagName('textarea');
		var selects = form.getElementsByTagName('select');
		
		form.body.value = "";
		for (var i=0; i<inputs.length; i++) 
			if (inputs[i].type == "text")
				form.body.value += inputs[i].alt + ": " + inputs[i].value + "\r\n";
			else if (inputs[i].type == "checkbox")
				if (inputs[i].checked)
					form.body.value += inputs[i].alt + "\r\n";
		for (var i=0; i<textareas.length; i++)
			form.body.value += textareas[i].alt + ": " + textareas[i].value + "\r\n";
		for (var i=0; i<selects.length; i++)
			form.body.value += selects[i].alt + ": " + selects[i].value + "\r\n";
		form.submit();
	} else {
		alert ("Please fill in all required fields!");
	}
}
