function openLargerImage(id, width, height)
{
  window.open('/imagePopup.php?id=' + id, 'richmondImage', 'width=' + width + ',height=' + height + ',scrollbars=no, status');
}

function decrementItem(prodId)
{
    document.getElementById('quantityStore' + prodId).value = parseInt(document.getElementById('quantityStore' + prodId).value) - 1;
    document.getElementById('override' + prodId).value = document.getElementById('quantityStore' + prodId).value;
    document.getElementById('formChange' + prodId).submit();
}

function incrementItem(prodId)
{
    document.getElementById('quantityStore' + prodId).value = parseInt(document.getElementById('quantityStore' + prodId).value) + 1;
    document.getElementById('override' + prodId).value = document.getElementById('quantityStore' + prodId).value;
    document.getElementById('formChange' + prodId).submit();
}

function overrideItem(prodId)
{
    document.getElementById('override' + prodId).value = document.getElementById('quantityStore' + prodId).value;
}

function engravingCosts()
{
    // init vars
    var tempCost = 0;
    
    // loop through and calc total cost
    for (var i = 0; i < costArray.length; i ++)
        if (costArray[i])
            tempCost += costArray[i] * cost;
    
    // change to a string
    tempCost = (Math.round(tempCost * 100) / 100).toString();
    
    if (tempCost.charAt(tempCost.length - 2) == '.')
        tempCost += '0';
    else if (tempCost.charAt(tempCost.length - 3) != '.')
        tempCost += '.00';
    
    document.getElementById('totalCost').innerHTML = tempCost;
}

function engravingChange(object, id, max)
{
    // recalc the number of chars left
    document.getElementById('line' + id).innerHTML = max - object.value.length;
    
    // update the temp array
    costArray[id] = object.value.length;
    
    // update the costs
    engravingCosts();
}

// init vars
var noSearch = false;

function swapSearch(element)
{
    if (!noSearch)
        element.value = '';
}

// clear the search box
if (document.getElementById('search').value != '')
    noSearch = true;
else
    document.getElementById('search').value = 'Search';