$(document).ready(inicio)
function inicio(){
	$("#carrito").load("php/poncarrito.php");
	$(".botoncompra").click(anade);
	$(".det").click(detalles);
	$(".less").click(remove);
	var $IDS = document.getElementById("IDSX").value;
	$("#PRECTOTAL").load("php/total.php?IDS="+$IDS);
}

function nobackbutton(){
	window.location.hash="no-back-button";
	window.location.hash="Again-No-back-button"
	window.onhashchange=function(){window.location.hash="no-b";}
}

function anade(){
    $name ="#ms" + $(this).val()+ " option:selected";
	$value = ($($name).text());
	$("#carrito").load("php/poncarrito.php?p="+$(this).val()+"&q="+$value);
	$V = $(this).val();
	alert($value + " articulos agregados.");
	document.getElementById('BOTONCOMPRA-' + $V).disabled=true;
	document.getElementById("ms" + $V).disabled=true;
	//location.reload();
}

function quita(){
	alert("Se eliminara la clave " + $(this).val());
	window.location.href = "cancela.php?p="+ $(this).val();
}

function detalles(){
	$V = this.attributes["name"].value;
	$D = document.getElementById('DETALLE-' + $V).value;
	$N = document.getElementById('NOMBREP-' + $V).value;
	alert($N + "\nDetalles: " + $D );
}

function remove(){
	$V = this.attributes["name"].value;
	var $PROD = document.getElementById("PROD-" + $V).value;
	var $NOMB = document.getElementById("NOMBP-" + $V).value;
	var $IDS = document.getElementById("IDSX").value;
	if(confirm("¿Quitar "+$NOMB+"?")){
		$("#carrito").load("remove.php?IDS="+$IDS+"&p="+ $PROD);
		
		var $ROW = Number($PROD) + 1;
		$("#PRECTOTAL").load("php/total.php?IDS=" + $IDS);
		//setTimeout(function(){}, 5500);
		document.getElementById("CHECKOUT").deleteRow($ROW);
		if(window.matchMedia("screen and (max-width: 768px)")){location.reload();}else{}
		
		}
}






