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;
}

function insertarGrupo(user){
	var t1, contenedor, contenedor2, contenedor3;
	contenedor = document.getElementById('nuevo_grupo');
	contenedor2 = document.getElementById('botonVer');
	contenedor3 = document.getElementById('listaGrupos');
	t1 = document.getElementById('nombre').value;
	ajax=nuevoAjax();
	ajax.open("GET", "functions/grupos.php?insertar="+t1+"&user="+user,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText
		contenedor2.innerHTML = ""
		contenedor3.innerHTML = ""
	 	}
	}
	ajax.send(null)
}

function listarGrupos(user){
	var contenedor, contenedor2;
	contenedor = document.getElementById('listaGrupos');
	contenedor2 = document.getElementById('botonVer');
	ajax=nuevoAjax();
	ajax.open("GET", "functions/grupos.php?ver="+user,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText
		contenedor2.innerHTML = "<h5>Nombre</h5>"
	 	}
	}
	ajax.send(null)
}

function entrarGrupo(id, user){
	if (confirm("Estas seguro?")){
		var contenedor, contenedor2, contenedor3;
		contenedor = document.getElementById('listaGrupos');
		contenedor2 = document.getElementById('botonVer');
		contenedor3 = document.getElementById('nuevo_grupo');
		t1 = document.getElementById('nombre').value;
		ajax=nuevoAjax();
		ajax.open("GET", "functions/grupos.php?agregar="+user+"&grupo="+id,true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
			contenedor.innerHTML = ""
			contenedor2.innerHTML = ajax.responseText
			contenedor3.innerHTML = ""
			}
		}
		ajax.send(null)
	}
}

function nuevoPedido(user,obj){
	var sexo, talla, contenedor;
	contenedor = document.getElementById('nuevo_pedido');

      for (i=0; i<obj.childNodes.length; i++) 
      {
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
		  if(obj.childNodes[i].name=="sexo")
		  {
		      sexo=obj.childNodes[i].value;
		  }
		  else if(obj.childNodes[i].name=="talla")
		  {
		      talla=obj.childNodes[i].value;
		  }
               }
            }
         }

	ajax=nuevoAjax();
	ajax.open("GET", "functions/camisetas.php?insertar=1&user="+user+"&sexo="+sexo+"&talla="+talla,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText
		listaPedido(user);
	 	}
	}
	ajax.send(null)
}

function listaPedido(user){
	var contenedor;
	contenedor = document.getElementById('listaPedidos');
	ajax=nuevoAjax();
	ajax.open("GET", "functions/camisetas.php?actualizar="+user,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.send(null)
}

