function nuevoAjax() {
	var xmlhttp = false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

var navegador = window.event ? true : false;

function numeros(evento) {
  var tecla = navegador ? evento.which : evento.keyCode;
  teclas = tecla <= 13 || (tecla >= 48 && tecla <= 57);
  if (!teclas) {
    alert("Solo puede ingresar números en este campo.");
    return (teclas);
  }
}

function accion(dir) {
  document.form.action = dir;
  document.form.submit();
}
function inicio() {
  document.form.action = "?home=1";
  document.form.submit();
}
function buscar_rubro() {
  document.form.action = "?buscar_rub=1";
  document.form.submit();
}
function borrar_ajax_cont() {
	ajax_cont.innerHTML = "<b></b>";
}
function agregar_carrito(detalle, cont, codigo, cantidad) {
	var contenedor;
	contenedor = document.getElementById('ajax_cont');
	contenedor.style.position = "absolute";
	contenedor.innerHTML = '<span class="ajax_cont"><b>AGREGANDO AL CARRITO...</b></span>';
	contenedor.style.left = document.body.scrollLeft+document.body.clientWidth/2-parseInt(300)/2;
	contenedor.style.top = document.body.scrollTop+document.body.clientHeight/2-50/2;
	ajax = nuevoAjax();
    if (detalle == 1) {
	  ajax.open("GET", "agregar_carrito.php?cont="+cont+"&agregar="+codigo+"&cantidad="+cantidad,true);
    } else if (detalle == 2) {
	  ajax.open("GET", "agregar_carrito.php?cont="+cont+"&detalle="+codigo+"&agregar="+codigo+"&cantidad="+cantidad,true);
    }
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText;
	 	}
	}
	ajax.send(null)
}

function eliminar_carrito(cont) {
    document.form.action = "?cont="+cont+"&carrito=1&eliminar=1";
    document.form.submit();
}
function actualizar_carrito(cont, codigo, cantidad) {
  document.form.action = "?cont="+cont+"&carrito=1&codigo="+codigo+"&cantidad="+cantidad;
  document.form.submit();
}
function detalle(cont, codigo) {
  document.form.action = "?cont="+cont+"&detalle="+codigo;
  document.form.submit();
}
function carrito_detalle(cont, codigo) {
  document.form.action = "?cont="+cont+"&detalle="+codigo+"&carrito=1";
  document.form.submit();
}
function clientes(cont) {
	document.form.action = "?cont="+cont+"&carrito=2&clientes=1";
	document.form.submit();
}
function carrito(cont, id) {
  if (id == 3) {
	if (form.nombre.value == "") {
		alert("Por favor ingrese su nombre.");
  		form.nombre.focus();
		return;
	} else if (form.email.value == "") {
		alert("Por favor ingrese su e-mail.");
  		form.email.focus();
		return;
	} else if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1) {
		alert("Ha ingresado un e-mail incorrecto.");
		form.email.focus();
		return;
	} else {
		document.form.action = "?cont="+cont+"&carrito="+id;
		document.form.submit();
	}
  } else {
	document.form.action = "?cont="+cont+"&carrito="+id;
	document.form.submit();
  }
}
function borrar_datos() {
  document.form.nombre.value = "";
  document.form.email.value = "";
  document.form.telefono.value = "";
  document.form.domicilio.value = "";
  document.form.localidad.value = "";
  document.form.provincia.value = "";
  document.form.mensaje.value = "";
}
function borrar_datos_carr() {
  document.form.nombre.value = "";
  document.form.email.value = "";
  document.form.telefono.value = "";
  document.form.celular.value = "";
  document.form.domicilio.value = "";
  document.form.localidad.value = "";
  document.form.postal.value = "";
  document.form.cuit.value = "";
  document.form.cliente.value = "";
}

function sel(id) {
	if (document.getElementById("check"+id).checked == true) checked_cantidad += 1;
	else checked_cantidad -= 1;
	document.getElementById("check_todos").checked = false;
}
function sel_todos() {
	for (i = 1; i <= carrito_cantidad; i++) {
		if (document.getElementById("check_todos").checked == true) {
			document.getElementById("check"+i).checked = true;
			checked_cantidad = carrito_cantidad;
		} else {
			document.getElementById("check"+i).checked = false;
			checked_cantidad = 0;
	    }
	}
}
function eliminar(cont) {
  if (checked_cantidad <= 0) {
	window.alert('Seleccione el producto que desea eliminar.');
  } else {
	preguntar = window.confirm('¿Desea eliminar estos productos del carrito?');
	if (preguntar) {
		eliminar_carrito(cont);
	}
  }
}
function enviar_mensaje() {
	if (form.nombre.value == "") {
		alert("Por favor ingrese su nombre.");
  		form.nombre.focus();
		return;
	} else if (form.email.value == "") {
		alert("Por favor ingrese su e-mail.");
  		form.email.focus();
		return;
	} else if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1) {
		alert("Ha ingresado un e-mail incorrecto.");
		form.email.focus();
		return;
	} else {
	  document.form.action = "?cont=6&enviar=1";
	  document.form.submit();
	}
}

function contenido(id) {
  document.form.action = "?cont="+id;
  document.form.submit();
}
function precios() {
  document.form.action = "?precios=1";
  document.form.submit();
}

