﻿// JScript File
function doSetCaretPosition (oField, iCaretPos) 
{

    // IE Support
    if (document.selection) 
    { 

        // Set focus on the element
        oField.focus ();

        // Create empty selection range
        var oSel = document.selection.createRange();

        // Move selection start and end to 0 position
        oSel.moveStart ('character', -oField.value.length);

        // Move selection start and end to desired position
        oSel.moveStart ('character', iCaretPos);
        oSel.moveEnd ('character', 0);
        oSel.select ();
    }

    // Firefox support
    else if (oField.selectionStart || oField.selectionStart == '0') 
    {
        oField.selectionStart = iCaretPos;
        oField.selectionEnd = iCaretPos;
        oField.focus ();
    }
}

function SendEmail()
{
    this.disabled = true;
    var message = '';
    //validate

    var obj = document.getElementById("textarea");
    if (obj.value == 'Message:')
    {
        message = 'message';
        doSetCaretPosition(obj, obj.value.length);
    }
    
    obj = document.getElementById("phone");
    if (obj.value == 'Phone:' && document.getElementById("email").value == 'E-mail:')
    {
        message = 'email or phone number';
        doSetCaretPosition(obj, obj.value.length);
    }
    
    obj = document.getElementById("name");
    if (obj.value == 'Name:')
    {
        message = 'name';
        doSetCaretPosition(obj, obj.value.length);
    }
    

    if (message == '')
    {
        alert("Thank you for contacting us. We'll get back to you as soon as possible.");
        document.formdetails.submit();    
    }
    else
    {
        alert("Please enter your " + message + " so we can contact you");
    }
}

function Load()
{
    //document.setFocus();
}