// Requires ajax.js to be loaded prior to this script!
var _self = '';

/* ResponseHandler for CartAdd */
function rh_CartAdd() {
    var ajaxResponse = document.getElementById('divAjaxResponse');
    if (req.readyState == 1) {
        if (ajaxResponse) {
            ajaxResponse.innerHTML = 'LOADING...';
        }
    }
    // Make sure the request is loaded (readyState = 4)
    if (req.readyState == 4) {
        // Make sure the status is "OK"
        if (req.status == 200) {
            var xmlRoot = req.responseXML.getElementsByTagName('response').item(0);
            
            // Update elements in current document
            ajaxUpdateElement(xmlRoot);
            
            // Get method result (use for further processing)
            var methodResult = ajaxGetMethodResult(xmlRoot);

            // Display debug information
            if (ajaxResponse) {
                ajaxResponse.innerHTML = methodResult[0] + ': ' + methodResult[1];
            }
        }
        else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

/* ResponseHandler for CartRemove */
function rh_CartRemove() {
    var ajaxResponse = document.getElementById('divAjaxResponse');
    if (req.readyState == 1) {
        if (ajaxResponse) {
            ajaxResponse.innerHTML = 'LOADING...';
        }
    }
    // Make sure the request is loaded (readyState = 4)
    if (req.readyState == 4) {
        // Make sure the status is "OK"
        if (req.status == 200) {
            var xmlRoot = req.responseXML.getElementsByTagName('response').item(0);
            
            // Update elements in current document
            ajaxUpdateElement(xmlRoot);
            
            // Get method result (use for further processing)
            var methodResult = ajaxGetMethodResult(xmlRoot);
            // Display debug information
            if (ajaxResponse) {
                ajaxResponse.innerHTML = methodResult[0] + ': ' + methodResult[1];
            }
        }
        else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

/* cartAdd */
function cartAdd(file)
{
    xmlReq("POST", "/func/cart.php", "method=addItem&type=file&pid=" + file + "&self=" + _self, rh_CartAdd);
}

/* cartAdd2 */
function cartAdd2(prodcode)
{
    xmlReq("POST", "/func/cart.php", "method=addItem&type=prod&pid=" + prodcode + "&self=" + _self, rh_CartAdd);
}

/* cartAdd3 */
function cartAdd3(ota)
{
    xmlReq("POST", "/func/cart.php", "method=addItem&type=ota&pid=" + ota + "&self=" + _self, rh_CartAdd);
}

/* cartRemove */
function cartRemove(prodcode)
{
    xmlReq("POST", "/func/cart.php", "method=deleteItem&type=prodcode&pid=" + prodcode + "&self=" + _self, rh_CartRemove);
}

