function ajax (url, valores, funcion) {

  var objetoAjax = false;
  try {
    objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {

		try {
      objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
			objetoAjax = false;
    }

	}

  if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
    objetoAjax = new XMLHttpRequest();
  }
  
  var ajax = objetoAjax;

	ajax.open ('POST', url, true);
  ajax.onreadystatechange = function() {

    if (ajax.readyState == 4) {

	  	 if (ajax.status == 200) {
				 
				 funcion (ajax.responseText);

			 }
						 
  	}
					 
	}

  ajax.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
  ajax.send (valores);

}

function GEBI (id) {

	return (document.getElementById (id));

}

function checkEnter (e) {

	var characterCode;

	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode; 
	}

	return (characterCode == 13);

}				

function checkNumbers (e) {

	var characterCode;

	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode; 
	}

	if ((characterCode >= 48) && (characterCode <= 57)) return (true);
	if (characterCode == 8) return (true);
	return (false);

}

function comprar (codigoArticulo, cantidad) {

	location.href = '_carrito.php?accion=comprar&codigoArticulo='+codigoArticulo+'&cantidad='+cantidad;

}

function actualizar (codigoArticulo, cantidad) {

	location.href = '_carrito.php?accion=actualizar&codigoArticulo='+codigoArticulo+'&cantidad='+cantidad;

}

function eliminar (codigoArticulo) {

	location.href = '_carrito.php?accion=eliminar&codigoArticulo='+codigoArticulo;

}

function alertar (mensaje, funcion) {

  document.getElementById ('alerta').style.display = 'block';	
  document.getElementById ('alerta-mensaje').innerHTML = mensaje;	
		
	ancho = 0;
	alto = 0;
		
	if (window.innerWidth) {
		
		ancho = window.innerWidth;
		alto = window.innerHeight;
		
	} else if (document.all) {

		ancho = document.body.clientWidth
		alto = document.body.clientHeight
		
	}
		
	document.getElementById ('alerta-boton').onclick = funcion;	
		
	document.getElementById ('alerta').style.left = (ancho / 2 - 160) + "px";	
	document.getElementById ('alerta').style.top = (alto / 2 - 120) + "px";	

}


