function initWindow() {
	document.getElementById("name").focus();
}

/*
    This function validates the send to friend e-mail form.
*/
function validate() {
    var theForm = document.getElementById("entry");

    /* Check pathological cases first. */
    if (!theForm) {
        alert("Cannot find the form");
        return false;
    }
    
    var debug;
    var errors=0;

    /* Validate the fields */
    errors += performCheck(theForm.name, "name-label");
    errors += performCheck(theForm.email, "email-label");
    errors += performCheck(theForm.subject, "subject-label");
    errors += performCheck(theForm.message, "message-label");

    if (errors > 0) {
        alert("All fields are required - please fill in all missing details!");
        return false;
    } else {
        return true;
    }
}

/*
	Reset all to black
*/
function resetAll() {
	var theForm = document.getElementById("entry");

    /* Check pathological cases first. */
    if (!theForm) {
        alert("Cannot find the form");
        return false;
    }
    
    right("name-label");
    right("email-label");
    right("subject-label");
    right("message-label");
    
    return true;
 }
 
function performCheck(field, label) {
    if (field && field.value == "") {
        wrong(label, "red");
		return 1;
    } 
    else {
        right(label, "black");
        return 0;
    }
}

function right(label) {
    changeLabel(label, "black");
    return;
}

function wrong(label) {
    changeLabel(label, "red");
    return;
}

function changeLabel(label, labelColour) {
    var theLabel = document.getElementById(label);

    if (!theLabel) {
        return;
    }

    theLabel.style.color = labelColour;
    return;
}

