function viewCart() {

    var xhr = getTransport_catr();
    xhr.onreadystatechange = function() {
        updateChange_catr(xhr);
    }

	xhr.open('post', 'datasource/miniCart.php', true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send('action=view');
 
}

function addCart(action,id) {

    var xhr = getTransport_catr();
    xhr.onreadystatechange = function() {
        updateChange_catr(xhr);
    }

	xhr.open('post', 'datasource/miniCart.php', true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send('action=' + action + '&p=' + id);
 
}
             
function getTransport_catr() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
        	return new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
    	}
    }
}

function updateContent_catr(html) {
                var content = document.getElementById('minicart');
                content.innerHTML = html;
                
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
function updateChange_catr(xhr) {	
    if (xhr.readyState != 4) {
		document.getElementById('minicart').innerHTML='<div align="center"><img src="imagenes/ajax-loader.gif" width="220" height="19" /></div>';
	}else{
        if (xhr.status == 200) {
            updateContent_catr(xhr.responseText);           
        } else {
            //alert('Error: ' + xhr.status + '!');
        }
    }
}