function menuon(element){
    //alert("on");
    element.style.background = '#3f3f3f';
}

function menuoff(element){
    //alert("off");
    element.style.background = 'none';
}

function sendmail(emailForm) {
    if(emailForm.name.value.length==0)
        alert("You did not enter your name, please enter you name.");
    else if(emailForm.subject.value.length==0)
        alert("You did not enter a subject, please enter a subject.");
    else if(emailForm.message.value.length==0 || emailForm.message.value.length>500)
        alert("The message body must be between 1 and 500 characters.\n\n Currently your message is " + emailForm.message.value.length + " characters long.\n\nPlease re-enter your message.");
    else if( (emailForm.remail1.value.toLowerCase() !=  emailForm.remail2.value.toLowerCase()) || (emailForm.remail1.value.length + emailForm.remail2.value.length == 0) )
        alert("Email adresses do not match or are empty.\n\nPlease check your entries and click the Send Button again.");
    else if(!validEmail(emailForm.remail1.value))
        alert("Email adresses is not valid\nPlease check your entries and click the Send Button again.");
    else {
        //to be here, all ok
        stripHTML(emailForm.name, emailForm.subject, emailForm.message);
        trimText(emailForm.message, 1000);

        var p = "name=" + emailForm.name.value + "&" +
        "remail=" + emailForm.remail1.value + "&" +
        "subject=" + emailForm.subject.value + "&" +
        "message=" + emailForm.message.value;

        var xmlhttp = new XMLHttpRequest();
        if (xmlhttp){
            xmlhttp.open("POST", "lib/sendemail.php", false);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.setRequestHeader("Content-length", p.length);
            xmlhttp.setRequestHeader("Connection", "close");
            xmlhttp.send(p);
            //alert(xmlhttp.responseText);
            if(xmlhttp.responseText=="ok")
                window.location = "mailsent.php";
            else
                window.location = "contact.php?e=sendmailerror";
        }
        else window.location = "contact.php?e=xmlerror";
    }
}


