
womAdd("document.getElementById('contactName').focus();");

function doAjaxSendEmail(contactName, companyName, address, city, state, zip, country,
						email, phone, fax, itemNumber, itemName, quantity, itemColor,
						imprintLocation, numImprintColors, shipAddress, comments, needDate)
{
    ajax = new Ajax.Request('/ajax.php', {
        method: 'post',
        parameters: {
            requestType: 'sendQuoteEmail',
            contactName: contactName,
            companyName: companyName,
            address: address,
            city: city,
            state: state,
            country: country,
            zip: zip,
            email: email,
            phone: phone,
            fax: fax,
            itemNumber: itemNumber,
            itemName: itemName,
            quantity: quantity,
            itemColor: itemColor,
            imprintLocation: imprintLocation,
            numImprintColors: numImprintColors,
            shipAddress: shipAddress,
            comments: comments,
            needDate: needDate
        },
        onSuccess: function(response) { parseEmail(response); },
        onFailure: function(){ alert('Something went wrong...') }
    });
}

parseEmail = function(response)
{
    type = response.responseJSON.type;
    html = response.responseJSON.html;

    if( type == "OK" ) {
        $('infoMsg').innerHTML = "Request sent.";
    } else {
        $('errorMsg').innerHTML = response.responseJSON.html;
    }

    sendButton = $('sendButton');
    sendButton.value = "Send Quote Request";
    sendButton.disabled = false;
}

function clearResponses()
{
    // Clear any existing response
    $('errorMsg').innerHTML = "";
    $('infoMsg').innerHTML = "";
}

function sendEmail()
{
    clearResponses();
    
    var sendButton = $('sendButton');
    
    var contactName = document.getElementById('contactName').value;
    var companyName = document.getElementById('companyName').value;
    var address = document.getElementById('address').value;
    var city = document.getElementById('city').value;
    var state = document.getElementById('state').value;
    var zip = document.getElementById('zip').value;
    var country = document.getElementById('country').value;
    var email = document.getElementById('email').value;
    var phone = document.getElementById('phone').value;
    var fax = document.getElementById('fax').value;
    var itemNumber = document.getElementById('itemNumber').value;
    var itemName = document.getElementById('itemName').value;
    var quantity = document.getElementById('quantity').value;
    var itemColor = document.getElementById('itemColor').value;
    var imprintLocation = document.getElementById('imprintLocation').value;
    var numImprintColors = document.getElementById('numImprintColors').value;
    var shipAddress = document.getElementById('shipAddress').value;
    var comments = document.getElementById('comments').value;
    var needDate = document.getElementById('needDate').value;
    
	// Make sure the required fields are entered.
	// If so, send email.  If not, warn user.
    var errorMessage  = "";
    errorMessage += (contactName == "") ? "Contact Name, " : "" ;
    errorMessage += (email == "") ? "Email, " : "" ;
    errorMessage += (itemNumber == "") ? "Item Number, " : "" ;
    errorMessage += (phone == "") ? "Phone, " : "" ;
    
    if( errorMessage == "" )
    {
        sendButton.value = "Processing";
        sendButton.disabled = true;
        doAjaxSendEmail(contactName, companyName, address, city, state, zip, country,
						email, phone, fax, itemNumber, itemName, quantity, itemColor,
						imprintLocation, numImprintColors, shipAddress, comments, needDate);
    } else {
        errorMessage  = "Please fill in the following: " + errorMessage.slice(0, -2) + ".";
        document.getElementById('errorMsg').innerHTML = errorMessage;
    }
}
