/////////////////////////////////////////////////
var ajax;
/////////////////////////////////////////////////

function addToCartAJX(productID,whatForm){ //productDetailForm or catalogForm
    
    var form = document.getElementById(whatForm);
    var productID = 0, colorID = 0, sizeID = 0, sid = 0, qty = 1, sale, price;
    
    if (form != null)
    {
        colorID = form.colorSelect[form.colorSelect.selectedIndex].value;
        sizeID = form.sizeSelect[form.sizeSelect.selectedIndex].value;
        productID = form.productID.value;
        sid = form.sid.value;
        
        if ("" == form.qty.value)
        {
            alert("Please enter a quantity.");
            form.qty.focus();
            return false;
        }
        
        if (!isNumber(form.qty.value))
        {
            alert("The quantity you have specified is not a valid number.");
            form.qty.focus();
            return false;
        }
        
        if ("0" == form.qty.value)
        {
            alert("Please enter a quantity greater than 0.");
            form.qty.focus();
            return false;
        }
        qty = form.qty.value;
        sale = form.sale.value;
        price = form.price.value;
    }
    else {alert("can't find the form to add cart item."); return;}
    
    $('status').innerHTML = $('ajax').innerHTML;
        
    var rand =  Math.floor(Math.random()*1000000);
    
    var url = "/ajax/addCart.ajax.asp?sid=" + sid + "&productID="  + productID + "&price="  + price + "&sale="  + sale + "&qty="  + qty + "&colorSelect=" + colorID + "&sizeSelect=" + sizeID + "&m=" + rand;

    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('status').innerHTML = t.responseText;}
    });
    
}

// for the catalog items (right panel)
function addToCartAJXIndex(productID,index){
    
    //
    //
    // for the catalog div, we need to specify which select etc. we're looking at.
    //
    //

    var colorID = 0, sizeID = 0, sid = 0, qty = 1, sale, price;
    var element = "";
    
    var input = document.getElementById('sizeSelect2_' + index); // this works, getelement fails!!

    if (input != null)
    {
        sizeID = input[input.selectedIndex].value;
     }
     
    //get colorID    
    var input = document.getElementById('colorSelect2_' + index); // this works, getelement fails!!

    if (input != null)
    {
        colorID = input[input.selectedIndex].value;
     }
    
    sid = $('sid').value;
    sale = $('sale'+index).value;
    price = $('price'+index).value;
        
    var rand =  Math.floor(Math.random()*1000000);
    
    var url = "/ajax/addCart.ajax.asp?sid=" + sid + "&productID="  + productID + "&price="  + price + "&sale="  + sale + "&qty=1&colorSelect=" + colorID + "&sizeSelect=" + sizeID + "&m=" + rand;
   
    var divToUpdate = 'status' + index;
    
    $('status'+index).innerHTML = $('ajax').innerHTML; // show ajax gif
    ajax = new Ajax.Request(
    url,
    {
            method: 'get',
            parameters: '',
            onComplete: function(t) { $('status'+index).innerHTML = t.responseText;}
    });
    
}
