var cart_response = '';
var ajaxurl = '';
var wishlistajaxurl = '';
document.onload = set_ajaxurl();

function set_ajaxurl(){
        ajaxurl = document.getElementsByTagName('base')[0].href + 'ajax/' + cms_language + '/cart/';
}
function check_cart(sid){
    var opt = {
    // Use POST
    method: 'post',
    // Send this lovely data
    postBody: 'check=yes',
    // Handle successful response
    onSuccess: function(t) {
        //alert(t.responseText);
        cart_response = t.responseText;
        if (t.responseText = '1') {
                alert('aauu');
        }
        return false;
    },
    // Handle 404
    on404: function(t) {
        alert('Error 404: location "' + t.statusText + '" was not found.');
    },
    // Handle other errors
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
}
new Ajax.Request(ajaxurl, opt);
}


function add_to_cart(pid){


    var opt = {
    // Use POST
    method: 'post',
    // Send this lovely data
    postBody: 'add=' + pid,
    // Handle successful response
    onSuccess: function(t) {
        //alert(t.responseText);
        cart_response = t.responseText;
        refresh_cart_list();
    },
    // Handle 404
    on404: function(t) {
        alert('Error 404: location "' + t.statusText + '" was not found.');
    },
    // Handle other errors
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
}
new Ajax.Request(ajaxurl, opt);
}

function add_to_cart_reserve(pid){
    var opt = {
    // Use POST
    method: 'post',
    // Send this lovely data
    postBody: 'reserve=' + pid,
    // Handle successful response
    onSuccess: function(t) {
        //alert(t.responseText);
        cart_response = t.responseText;
        refresh_cart_list();
    },
    // Handle 404
    on404: function(t) {
        alert('Error 404: location "' + t.statusText + '" was not found.');
    },
    // Handle other errors
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
}
new Ajax.Request(ajaxurl, opt);
}

/**
 *
 * @access public
 * @return void
 **/
function refresh_cart_list(){
        new Effect.Appear('cart', {duration: 0.5, to:0.0} );
        window.setTimeout('refresh2()',500);
        return false;
}

/**
 *
 * @access public
 * @return void
 **/
function refresh2() {
        document.getElementById('cart').innerHTML = cart_response;
        //new Effect.Appear('cart', {duration: 0.0, to:0.0} );
        new Effect.Appear('cart', {duration: 0.5, to:1.0} );
        return false;
}
/**
 *
 * @access public
 * @return void
 **/
function show_cart(){
        new Effect.Appear('cart', {duration: 0.5, to:1.0} );
}
/**
 *
 * @access public
 * @return void
 **/
function remove_from_cart(pid) {
    var opt = {
    // Use POST
    method: 'post',
    // Send this lovely data
    postBody: 'del=' + pid,
    // Handle successful response
    onSuccess: function(t) {
        //alert(t.responseText);
        cart_response = t.responseText;
        refresh_cart_list();
    },
    // Handle 404
    on404: function(t) {
        alert('Error 404: location "' + t.statusText + '" was not found.');
    },
    // Handle other errors
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
}
new Ajax.Request(ajaxurl, opt);
}

/**
 *
 * @access public
 * @return void
 **/
function remove_from_cart2(pid){
    var opt = {
    // Use POST
    method: 'post',
    // Send this lovely data
    postBody: 'del=' + pid,
    // Handle successful response
    onSuccess: function(t) {
        //alert(t.responseText);
        window.location.reload();
    },
    // Handle 404
    on404: function(t) {
        alert('Error 404: location "' + t.statusText + '" was not found.');
    },
    // Handle other errors
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
}
new Ajax.Request(ajaxurl, opt);
}
