
function PostMailEvent()
{
    var Response;

    if (xmlHttp.readyState == 4)
    { 
        if (xmlHttp.status == 200)
        {
            Response = xmlHttp.responseText;
            
            var ReportCode = Response.substr (0, 1);
            
            Response = Response.replace(/^[0-9]* /, "");
 
            alert (Response);
    
            if (ReportCode == 0)
            {
                history.go (-1);
            }
        }
        else
        {
            alert ('Your mail was not sent due to a server problem (' + xmlHttp.status + '), you can try again and it may succeed.');
        }
    }
}

function PostMail()
{
    var SenderAddress = document.getElementById('EmailAddress').value;
    var Subject = document.getElementById('Subject').value;
    var Message = document.getElementById('Message').value;
    var SendButton = document.getElementById('SendButton');
    
    SendButton.display = 0;
    
    if ((xmlHttp = GetXmlHttpObject()) == null)
    {
        return;
    } 

    var url =           '/cgi-bin/sendmail.cgi';
    
    var parameters =    'SenderAddress=' + encodeURI(SenderAddress) +
                        '&SendTo=' + encodeURI('Turbo Electric Ltd <enquiries@turbo-electric.com>') +
                        '&Subject=' + encodeURI(Subject) +
                        '&Message=' + encodeURI(Message);


    xmlHttp.onreadystatechange = PostMailEvent;

    xmlHttp.open('POST', url, true);

    xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlHttp.setRequestHeader('Content-length', parameters.length);
    xmlHttp.setRequestHeader('Connection', 'close');

    xmlHttp.send(parameters);
}

