function removeFromCart(id) {
    document.location.href = 'action.jsp?actionId=removeFromCart&pid=' + id;
}

function loadInfo() {
    if (!xmlBusy) {
        var url = 'http://rbenjaminjones.com/action.jsp?actionId=getInfo';
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = displayInfo;
        xmlHttp.send(null);
        xmlBusy = true;
    } else {
        setTimeout("loadInfo()", 500);
        if (loadCount > 5) {
            loadCount = 0;
            xmlBusy = false;
        } else {
            loadCount++;
        }
    }
}

function displayInfo() {
    if (xmlHttp.readyState == 4) {
        var text = xmlHttp.responseText;
        text = text.substring(text.indexOf(':')+1,text.indexOf(';'));
        var custinfo = text.split('^');
        document.custForm.id.value = custinfo[0];
        document.custForm.prefix.value = custinfo[1];
        document.custForm.nameFirst.value = custinfo[2];
        document.custForm.nameLast.value = custinfo[3];
        document.custForm.address.value = custinfo[4];
        document.custForm.address2.value = custinfo[5];
        document.custForm.city.value = custinfo[6];
        document.custForm.state.value = custinfo[7];
        document.custForm.zip.value = custinfo[8];
        document.custForm.phone.value = custinfo[9];
        document.custForm.billNameFirst.value = custinfo[10];
        document.custForm.billNameLast.value = custinfo[11];
        document.custForm.billAddress.value = custinfo[12];
        document.custForm.billAddress2.value = custinfo[13];
        document.custForm.billCity.value = custinfo[14];
        document.custForm.billState.value = custinfo[15];
        document.custForm.billZip.value = custinfo[16];
        document.custForm.billPhone.value = custinfo[17];
        document.custForm.mailingOk.checked = (custinfo[18] == 'Y') ? true : false;
        document.custForm.email.value = custinfo[19];
        document.custForm.password.value = custinfo[20];
        document.custForm.confirmPassword.value = custinfo[20];
        document.custForm.ccType.value = custinfo[21];
        document.custForm.ccName.value = custinfo[22];
        document.custForm.ccNum.value = custinfo[23];
        document.custForm.ccExp.value = custinfo[24];
        document.custForm.ccCode.value = '';
        document.custForm.actionId.value = 'modCust';
        document.custForm.submit.value = 'Save Changes';
        document.custForm.requireCCV.value = 'Y';
        xmlBusy = false;
    }
    if (cartQuantity > 0) { showCart(); }
}

function showCart() {
    var url = document.location.href;
    var pageId = url.substring(url.lastIndexOf('/')+1, url.lastIndexOf('.'));
    if (pageId != 'cart' && pageId != 'checkout' && pageId != 'index') {
        document.getElementById('view-cart').style.display = 'block';
        document.getElementById('cartbox').style.display = 'block';
    }
}

function showPreview(id, alt) {
    document.getElementById('previewDiv').style.display = 'block';
    document.getElementById('previewImg').src = 'images/thumbs/sm/' + id + '.jpg';
    document.getElementById('previewImg').alt = alt;
}

function hidePreview() {
    document.getElementById('previewDiv').style.display = '';
    document.getElementById('previewImg').src = '';
    document.getElementById('previewImg').alt = '';
}

function checkLogin(customerId) {
    if (customerId < 1 || customerId == '') {
        document.getElementById('loginDiv').style.display = 'block';
        // do ajax quick login?
    } else {
        document.detailForm.submit();
    }
}
