function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}

// Build the URL that will ultimately result in an outbound call.
function get_url(num) {
    url = "http://cp.trixbox.com/call.cgi?server_id=120722&extension=7299&"
        + "number=" + num + "&username=120722_7299&password=7299&success"
        + "_redir=http://www.ocit247.com/contact/successPhone.shtml&faile"
        + "d_redir=http://www.ocit247.com/contact/failurePhone.shtml";
    return url;
}

// Is this a valid US number? Should have 10 digits, and may have the
// customary format (but might not be formatted at all).
function validate_number(num) {
    return num.match(/^(\()?\d{3}[\)\-\s\.]?(\s)?\d{3}[\-\.\s]?\d{4}$/);
}

// Scrub the number of any whitespace. Use this before validating with
// validate_number. This has the effect of forgiving the user an extra
// space (or ten).
function clean_number(num) {
    return num.replace(/\s/g, "");
}

// Strip the number of any formatting. This will return only digits.
// This is done to prep the number for building the URL only; using this
// before validating with validate_number would allow complete garbage
// to pass validation (as long as that garbage had, somewhere within,
// ten digits).
function strip_number(num) {
    return num.replace(/\D/g, "");
}

// This is where all the work happens-- the value of textPhone is cleaned
// of extra whitespace, validated, and based on validation the user is
// either redirected or asked for better input.
function call_me() {
     var num = clean_number(document.getElementById('textPhone').value);
     if (!validate_number(num)) {
         alert("Please enter a valid phone number, including area code.");
     }
     else {
        var url = get_url(strip_number(num));
        window.location.href = url;
     }
}
