var Editor;

function Format(action) {
	Editor.execCommand(action, false, null);
    }

function Colour(colour) {		
	Editor.execCommand("forecolor",false, colour);
    }

window.onload = function() {
	Editor = document.getElementById('textbox').contentWindow.document;
	Editor.designMode = "on";
    }

function isValidEmail(str) {
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }

function publish() {
    var text = document.getElementById('text');
    text.value = Editor.body.innerHTML;
    var email = document.forms[0].email.value ;
    if (document.forms[0].doctitle.value == '') { alert("You must enter the document title.") ; }
    else if ((document.forms[0].doctype[0].checked == false) & (document.forms[0].doctype[1].checked == false) & (document.forms[0].doctype[2].checked == false) & (document.forms[0].doctype[3].checked == false)) { alert("You must select the document type.") ; }
    else if (document.forms[0].year.value == '') { alert("You must enter the year the document was written.") ; }
    else if (document.forms[0].description.value == '') { alert("You must enter a brief description of the document.") ; }
    else if (document.forms[0].author.value == '') { alert("You must enter your name.") ; }
    else if (document.forms[0].email.value == '') { alert("You must enter an email address so that we can contact you with questions and to let you know when your document is published.") ; }
    else if (!isValidEmail(email)) { alert("You must enter a valid email address.") ; }
    else if (document.forms[0].agreement1.checked == false) { alert("You must certify that you wrote this document by checking the checkbox.") ; }
    else if (document.forms[0].agreement2.checked == false) { alert("You must certify that you agree to this site's Terms & Conditions by checking the checkbox.") ; }
    else { document.forms[0].submit(); }
    }