function init() {
    if (document.getElementById('watch') != null) {
        $('watch').onclick = function () {
            if(document.getElementById("userid").value == "") {
                alert('Please log in to add books to your watch list.');
                return false;
            }
            if(document.getElementById("watch_book_ids").value == '') {
                alert("Please select one or more books to add to your watch list.");
                return;
            }
            sendData();
        }
    }

    if (document.getElementById('watch2') != null) {
        $('watch2').onclick = function () {
            if(document.getElementById("userid").value == "") {
                alert('Please log in to add books to your watch list.');
                return false;
            }
            if(document.getElementById("watch_book_ids").value == '') {
                alert("Please select one or more books to add to your watch list.");
                return;
            }
            sendData();
        }
    }
}
function sendData() {
    var url = 'process.php';
    var pars = Form.serialize('frm');
    var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
}
function showLoad() {
    $('load').style.display = 'block';
}
function showResponse(originalRequest) {
    if (document.getElementById("watch_refresh").value == "true") {
        location.replace(location.href);
    }
    else {
        var newData = originalRequest.responseText;
        $('bidErrMsg').innerHTML = newData;
    }
}

// brought over from bookSearch
function chooseWatchBook(book_id, watch) {
    if (document.getElementById("watch_book_ids").value == "") {
        book_id_array = [];
    }
    else {
        book_id_array = document.getElementById("watch_book_ids").value.split("|");
    }
    for (i = 0; i < book_id_array.length; i++) {
        if (book_id_array[i] == book_id) {
            book_id_array.splice(i, 1);
        }
    }
    if (watch) {
        book_id_array.push(book_id);
    }
    book_id_array.sort();
    document.getElementById("watch_book_ids").value = book_id_array.join("|");
}

function watchBooks() {
    if(document.getElementById("userid").value == ""){
        alert('Please log in to add books to your watch list.');
        return false;
    } else if (document.getElementById("watch_book_ids").value == "") {
        alert("Please select one or more books.");
        return;
    }
}


