// JavaScript Document
/////////////////// CLASE PARA AJAX ////////////////////////////////
	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	
	var http = createRequestObject();
////////////////////////////////////////////////////////////////////

function solonumeros(e) { // 1
    tecla = window.event ? e.keyCode : e.which; // 2
    //alert(tecla);
	 if (tecla==8) return true; // supr
	 if (tecla==0) return true; // tab y otras
    //patron =/[\W@_-]/; // patron para email
	patron =/[\d]/; // patron para email
    te = String.fromCharCode(tecla); // 5
   	return patron.test(te); // 6
} 
////////////////////////////////////////////////////////////////////

function solonumerosbusca(busc,e) { // 1
    tecla = window.event ? e.keyCode : e.which; // 2
     if (tecla==13){ValidaBusqueda(busc);}
	 if (tecla==8) return true; // supr
	 if (tecla==0) return true; // tab y otras
    patron =/\d/; // 4
    te = String.fromCharCode(tecla); // 5
   	return patron.test(te); // 6
} 
////////////////////////////////////////////////////////////////////
function Envia_form(busc,e){
    var key = window.event ? e.keyCode : e.which;
    if(key==13)
	    {
		  ValidaBusqueda(busc);
		  return(key!=13);  
		}
   }

///////////////////////Funcion Valida formulario////////////////////////
function ValidaForma(axn)
                  {
                    var f = document.getElementById('forma');
					
					
                    for (i = 0; i < f.elements.length; i++)
					     {
                          if ((f.elements[i].type == "text" || f.elements[i].type == "password") && f.elements[i].disabled==false && f.elements[i].value == "") 
						       { 
                                alert("Por favor complete todos los campos del formulario"); 
								f.elements[i].focus(); 
                                return false;         
								}
								//alert(f.elements[i].name);
                        }
						//var validaemail=/^\w+([\.-]?\w+)[\w-]*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
						  var validaemail=/^[A-Za-z.-][A-Za-z0-9_.-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;

						
						if (!(validaemail.test(document.getElementById('email').value)))
                             {
                               alert("La dirección de email es incorrecta.");
                                return false;
                             }
						
						if(document.getElementById('fecha').value=='')
						    {
							  alert('Seleccione la fecha del evento.');	
							  return false;
						    }
							
						if(document.getElementById('estado1').value==0)
						    {
							  alert('Seleccione el estado del novio.');	
							  return false;
						    }	
							
						if(document.getElementById('estado2').value==0)
						    {
							  alert('Seleccione el estado de la novia.');	
							  return false;
						    }	
							
							if(document.getElementById('ciudad1'))
						       {
							      if(document.getElementById('ciudad1').value==0)
						              {
							             alert('Seleccione la ciduad del novio.');	
							              return false;
						              }
							   }
							
						if(document.getElementById('ciudad2'))
						       {
							      if(document.getElementById('ciudad2').value==0)
						              {
							             alert('Seleccione el ciduad de la novia.');	
							              return false;
						              }
							   }
							   
							   if(document.getElementById('colonia1'))
						       {
							      if(document.getElementById('colonia1').value==0)
						              {
							             alert('Seleccione la colonia del novio.');	
							              return false;
						              }
							   }
							
						if(document.getElementById('colonia2'))
						       {
							      if(document.getElementById('colonia2').value==0)
						              {
							             alert('Seleccione el colonia de la novia.');	
							              return false;
						              }
							   }
							
					   if(document.getElementById('pass1').value!=document.getElementById('pass2').value)		
					       {
							  alert('La confirmacion de su contraseña no coincide');   
							  return false;
						   }
                    
					if(axn=='AxnGrabar')
					     {
							 Graba_mesa();
						 }


					if(axn=='AxnModificar')
					     {
							if(confirm('¿Esta seguro de modificar los datos?'))
							   {
							     Modifica_mesa(); 
							   }
						 }
				  }
//////////////////////////////////////////////////////////////////////////
function Graba_mesa()
             {
                        var url='ajax_consultas.php';	
						
						var params='op=7&novio='+document.getElementById('novio').value+'&novia='+document.getElementById('novia').value+
						'&email='+document.getElementById('email').value+'&fevento='+document.getElementById('fecha').value+'&edonovio='+
						document.getElementById('estado1').value+'&cdnovio='+document.getElementById('ciudad1').value+'&otracdnovio='+
						document.getElementById('otraciudad1').value+'&cpnovio='+document.getElementById('codpost1').value+'&colnovio='+
						document.getElementById('colonia1').value+'&otracolnovio='+document.getElementById('otracolonia1').value+'&callenovio='+
						document.getElementById('calle1').value+'&numnovio='+document.getElementById('numero1').value+'&refnovio='+
						document.getElementById('referencia1').value+'&telnovio='+document.getElementById('telefono1').value+'&edonovia='+
						document.getElementById('estado2').value+'&cdnovia='+document.getElementById('ciudad2').value+'&otracdnovia='+
						document.getElementById('otraciudad2').value+'&cpnovia='+document.getElementById('codpost2').value+'&colnovia='+
						document.getElementById('colonia2').value+'&otracolnovia='+document.getElementById('otracolonia2').value+'&callenovia='+
						document.getElementById('calle2').value+'&numnovia='+document.getElementById('numero2').value+
						'&refnovia='+document.getElementById('referencia2').value+'&telnovia='+document.getElementById('telefono2').value+'&contra='+
						document.getElementById('pass1').value;
						
						//alert(params);
						http.open('POST',url,true);
						http.onreadystatechange=resp_Graba_mesa;
						http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
						http.send(params);
		     }
			 
function resp_Graba_mesa()
         {
		   if(http.readyState==4)
		      {
				 if(http.status==200)
				    {
					 
					  var resp=http.responseText;
					  if(resp==-5){ alert('YA EXISTE UN REGISTRO CON ESTE EMAIL.');return false;}
					  if(resp>0)
					          {
								  location.href='grabado.php?id='+resp;
							  }
					  else{ alert('Ha ocurrido un error intente de nuevo');}		  
					  //alert('insertada:'+resp);	
					  //limpiar();
				    }
			  }
		 }
//////////////////////////////////////////////////////////////////////////
function Modifica_mesa()
             {
                        var url='ajax_consultas.php';	
						
						var params='op=14&novio='+document.getElementById('novio').value+'&novia='+document.getElementById('novia').value+
						'&email='+document.getElementById('email').value+'&fevento='+document.getElementById('fecha').value+'&edonovio='+
						document.getElementById('estado1').value+'&cdnovio='+document.getElementById('ciudad1').value+'&otracdnovio='+
						document.getElementById('otraciudad1').value+'&cpnovio='+document.getElementById('codpost1').value+'&colnovio='+
						document.getElementById('colonia1').value+'&otracolnovio='+document.getElementById('otracolonia1').value+'&callenovio='+
						document.getElementById('calle1').value+'&numnovio='+document.getElementById('numero1').value+'&refnovio='+
						document.getElementById('referencia1').value+'&telnovio='+document.getElementById('telefono1').value+'&edonovia='+
						document.getElementById('estado2').value+'&cdnovia='+document.getElementById('ciudad2').value+'&otracdnovia='+
						document.getElementById('otraciudad2').value+'&cpnovia='+document.getElementById('codpost2').value+'&colnovia='+
						document.getElementById('colonia2').value+'&otracolnovia='+document.getElementById('otracolonia2').value+'&callenovia='+
						document.getElementById('calle2').value+'&numnovia='+document.getElementById('numero2').value+
						'&refnovia='+document.getElementById('referencia2').value+'&telnovia='+document.getElementById('telefono2').value+'&contra='+
						document.getElementById('pass1').value;
						
						//alert(params);
						http.open('POST',url,true);
						http.onreadystatechange=resp_Modifica_mesa;
						http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
						http.send(params);
		     }
			 
function resp_Modifica_mesa()
         {
		   if(http.readyState==4)
		      {
				 if(http.status==200)
				    {
					 
					  var resp=http.responseText;
					  if(resp==-5){ alert('YA EXISTE UN REGISTRO CON ESTE EMAIL.');return false;}
					  if(resp==1)
					          {
								 alert('Los cambios han sido guardados exitosamente');
	 								 Salir();

							  }
					  else{ alert('Ha ocurrido un error al guardar cambios, intente de nuevo');}		  
					  //alert('insertada:'+resp);	
					  //limpiar();
				    }
			  }
		 }
//////////////////////////////////////////////////////////////////////////
function ValidaBusqueda(tipo)
          {
			  switch(tipo)
			        { 
					  case 1:
					         if(document.getElementById('evento').value=='')
							   {
								 alert("¡Escriba un numero de evento por favor!");
							     document.getElementById('evento').focus();
							     return false;
							   }
							   var func='BuscaxId';
							   var param=document.getElementById('evento').value;
					  break;
					  
					  case 2:
					         if(document.getElementById('novia').value=='')
							   {
							     alert("¡Escriba el nombre de la novia por favor!");
							     document.getElementById('novia').focus();
							     return false;
							   }
							    var func='Busquedaxnombre';
								var param=document.getElementById('novia').value;
					  break;
					  
					  case 3:
					         if(document.getElementById('novio').value=='')
							   {
							     alert("¡Escriba el nombre de la novio por favor!");
							     document.getElementById('novio').focus();
							     return false;
							   }
							   var func='Busquedaxnombre';
							   var param=document.getElementById('novio').value;
					  break;
					  
					  case 4:
					         if(document.getElementById('fecha').value=='')
							   {
							     alert("Seleccione la fecha del evento");
							     document.getElementById('porfecha').focus();
							     return false;
							   }
							   var func='Busquedaxfecha';
							   var param=document.getElementById('fecha').value;
					  break;
					
					}
					  Busqueda(tipo,func,param);
		  }
/////////////////////////////////////////////////////////////////////////////////////////
function Busqueda(op,vfunc,vparam)
         {
			 http.open('get','ajax_consultas.php?op='+op+'&func='+vfunc+'&param='+vparam);
			 http.onreadystatechange=Resp_Busqueda;
			 http.send(null);
			   
		 }
		 
function Resp_Busqueda()
         {
			 //alert('valor'+val);
		   if(http.readyState==4)
		      {
				  if(http.status==200)
				     {
						 var resp=http.responseText.split('|');
						     //alert('respuesta:'+resp);
						 if(resp[0]==1)//busqueda por numero de evento
						    {
								if(resp[1]==0)
								   {
									   alert("NO SE ENCONTRARON RESULTADOS.");
									   document.getElementById('loadevento').innerHTML='';
								   }
								   else if(resp[1]==-3){
									  //location.replace("verlista.php?idm="+resp[1]);
									  alert("LA MESA DE REGALOS HA CADUCADO.");
									   document.getElementById('loadevento').innerHTML='';
									}   
								else{
									  //location.replace("verlista.php?idm="+resp[1]);
									  location.href="verlista.php?idm="+resp[1];
									}   
						    }//finbusqueda por numero de evento
							
							else if(resp[0]==2)//busqueda por nombre novia
						    {
								if(resp[1]==0)
								   {
									   alert("NO SE ENCONTRARON RESULTADOS.");
									   document.getElementById('loadevento').innerHTML='';
								   }
								else{
									  document.getElementById("resultado").innerHTML=resp[1];
									}   
						    }//finbusqueda por nombre novia
							
							else if(resp[0]==3)//busqueda por nombre novio
						    {
								if(resp[1]==0)
								   {
									   alert("NO SE ENCONTRARON RESULTADOS.");
									   document.getElementById('loadevento').innerHTML='';
								   }
								else{
									  document.getElementById("resultado").innerHTML=resp[1];
									  
									}   
						    }//finbusqueda por nombre novio
							
							else if(resp[0]==4)//busqueda por fecha
						    {
								if(resp[1]==0)
								   {
									   alert("NO SE ENCONTRARON RESULTADOS.");
									   document.getElementById('loadevento').innerHTML='';
								   }
								else{
									  document.getElementById("resultado").innerHTML=resp[1];
									}   
						    }//finbusqueda por fecha
						 
						 //alert('RESPUESTA:'+resp);
					 }
			  }
			else{document.getElementById('loadevento').innerHTML='<img src="images/ajax-loader.gif" />';}  
		 }

///////////////////////////////////////////////////////////////////
function Selec_ciudad(band,edo)
          {
			  
			  var url='ajax_consultas.php?op=5&edo='+edo+'&band='+band;
			   
			  http.open('get',url);
			  http.onreadystatechange = Respuesta_ciudades;
			  http.send(null);
			  }
function Respuesta_ciudades()
          {
			  if(http.readyState==4)
			      {
					  if(http.status==200)
					        {
							   var arr_resp=http.responseText.split('|');
							   var cd='ciudades'+arr_resp[0];
							  
							  document.getElementById(cd).innerHTML=arr_resp[1];		
							  
							  }
					  }
			  }	
//////////////////////////////////////
function Otra_ciudad(campo)
         {
	      
		   var campociudad='ciudad'+campo;
		   var campootra='otraciudad'+campo;
		  
		  if(document.getElementById(campociudad).value==-1)
		       {
			     document.getElementById(campootra).disabled=false;
				 document.getElementById(campootra).className='textos';
				 document.getElementById(campootra).focus();
			   }
			   else
			      {
					  document.getElementById(campootra).value='';
					   document.getElementById(campootra).className='otras';
					  document.getElementById(campootra).disabled=true;
					  return false;
					  }
		 }
////////////////////////////////////////
function Bus_Colonias(band,codpos)
           {
	    var campo='codpost'+band;
                if (codpos!=0)
				       {
					     if (codpos.length==5)
						      {
							    http.open("get","ajax_consultas.php?op=6&codigo="+codpos+"&band="+band);
								http.onreadystatechange=Resp_Bus_Colonias;
								http.send(null);
							  }
						  else
						      {
							     alert("Codigo Postal Incorrecto");
								document.getElementById(campo).focus();
								return false;
							  }
					   }
				   else
				       {
					     alert("Codigo Postal Incorrecto");
						 document.getElementById(campo).focus();
						 return false;
					   }
		     
		   }
		   
function Resp_Bus_Colonias()
            {
			  
			  if(http.readyState==4)
			      {	//alert(http.readyState);
				//alert(http.status);	
				    if(http.status==200)
					    {
						  var resp=http.responseText.split('|');
						  //alert(resp);
						  var campo='selcol'+resp[0];
						  document.getElementById(campo).innerHTML=resp[1];
						}
				  }
			}
///////////////////////////////////////////
function Sel_colonia(band,valcol) 
          {
		     		    
		   var campootra='otracolonia'+band;
		  
		  if(valcol==-1)
		       {
			      document.getElementById(campootra).disabled=false;
				  document.getElementById(campootra).className='textos';
				  document.getElementById(campootra).focus();
			   }
			   else
			      {
					  document.getElementById(campootra).value='';
					  document.getElementById(campootra).className='otras';
					  document.getElementById(campootra).disabled=true;
					  return false;
					  }
		  }
/////////////////////////////////////////////
function limpiar()
          {
			 document.getElementById('novio').value='';
			 document.getElementById('novia').value='';
			 document.getElementById('email').value='';
			 document.getElementById('fecha').value='';
			 document.getElementById('estado1').value=0;
			 document.getElementById('ciudades1').innerHTML='';
			 document.getElementById('otraciudad1').value='';
			 document.getElementById('codpost1').value='';
			 document.getElementById('selcol1').innerHTML='';
			 document.getElementById('otracolonia1').value='';
			 document.getElementById('calle1').value='';
			 document.getElementById('numero1').value='';
			 document.getElementById('referencia1').value='';
			 document.getElementById('telefono1').value='';
			 document.getElementById('estado2').value=0;
			 document.getElementById('ciudades2').innerHTML='';
			 document.getElementById('otraciudad2').value='';
			 document.getElementById('codpost2').value='';
			 document.getElementById('selcol2').innerHTML='';
			 document.getElementById('otracolonia2').value='';
			 document.getElementById('calle2').value='';
			 document.getElementById('numero2').value='';
			 document.getElementById('referencia2').value='';
			 document.getElementById('telefono2').value='';
			 document.getElementById('pass1').value='';
			 document.getElementById('pass2').value='';
		     document.getElementById('novio').focus();
		  }
/////////////////////////////////////////////////
function Foco(campo)
      {
		 document.getElementById(campo).focus(); 
		   
	  }
///////////////////////////////////////////////
function Valida_Login()
         {
		   var f=document.getElementById('forma');
		   
		   for(i=0;i<f.elements.length;i++)
		        {
					if((f.elements[i].type=="text"||f.elements[i].type=="password")&&f.elements[i].value=='')
					   {
						   alert('Complete todos los campos del formulario');
						   f.elements[i].focus();
						   return false;
						   }
			    }
				Envia_Login();
		 }
/////////////////////////////////////////////////
function Envia_login(e)
         {
		   	 var key = window.event ? e.keyCode : e.which;
		 	 if(key==13)
			    {
					Valida_Login();
					return(key!=13);
					}
		 }
//////////////////////////////////////////////////
function Envia_Login()
          {
			 var f=document.getElementById('forma');
			 var url='ajax_consultas.php?op=8&vemail='+f.email.value+'&vpass='+f.pass.value+'&voplogin='+f.oplogin.value;
			 //alert(url);
			 http.open('get',url);  
			 http.onreadystatechange=resp_Envia_login;
			 http.send(null);
		  }
//////////////////////////////////////////////////
function resp_Envia_login()
         {
		   if(http.readyState==4)
		      {
				  if(http.status==200)
				     {
						 var resp=http.responseText.split('|');
						//alert(resp);
						if(resp[0]==1)
						    {
								if(resp[3]==1)
						         {
								  location.replace('deptos.php');
								 }
								else if(resp[3]==2)
								       {
								        location.replace('editardatos.php');
									   }
								else{alert('Ocurrio un error al direccionar login');return false;}	   
							}
						 else if(resp[0]==0)
						        {
									alert('email y/o contraseña incorrectos');
									limpiar_login();
							     }
						else if(resp[0]==2)
						        {
									location.replace('verlista_venc.php');
							     }	
						else if(resp[0]==3)
						        {
									alert('Su mesa de regalos ha caducado.');
									limpiar_login();
							     }			 
								
						else{alert('Ha ocurrido un error, intente de nuevo');}
						 
						 }
				  }
				  else{document.getElementById('loadevento').innerHTML='<img src="images/ajax-loader.gif" />';}
	     }
////////////////////////////////////////////////////
function Abrir_Ventana(val)
         {
            var url='http://www.coppel.com/capturamesa/index.php?id='+val;
			window.open(url,'popup','width=700,height=600,scrollbars=no');
	     }
////////////////////////////////////////////////////
function Add_articulo(codigo,band)
         {
		   	 //alert('MESA:'+idmesa+'CODIGO:'+codigo);
			 var tiempo="&ms="+new Date().getTime();
			 var url='ajax_consultas.php?op=9&codigo='+codigo+'&band='+band+tiempo;
			 
			 http.open('GET',url);
			 http.onreadystatechange=resp_Add_articulo;
			 http.send(null);
		 }
/////////////////////////////////////////////////////
function resp_Add_articulo()
         {
		   if(http.readyState==4)
		       {
				 if(http.status==200)
				     {
						var respuesta=http.responseText.split('|');
						if(respuesta[0]==1)
						   {
						     alert("Articulo agregado."); 
							 if(respuesta[1]==2)
							    {Limpia_add_cod();}
						   }
						 else if(respuesta[0]==-1)
						       {
								 Salir();
							   }
						else{
							  alert("Ocurrio un error al agregar el articulo.");
							}	   
					 }
					 else{
						   alert("Error, intente de nuevo");
					     }
			   }
		 }
//////////////////////////////////////////////////////
function Salir()
           {
		     http.open('get','ajax_consultas.php?op=10');
			 http.onreadystatechange = Resp_Salir;
			 http.send(null);
		   }
//////////////////////////////////////////////////////
function Resp_Salir()
          {
		    if(http.readyState==4)
			    {
				  if(http.status==200)
				       {
					     var respuesta=http.responseText;
						 //alert(respuesta);
						 if(respuesta==1)
						     {
						        location.replace('index.php');
							 }	 
					   }
				    else
					     {
						   alert('Intente de nuevo');
						   return false;
						 }	   
				}
				/*else
				   {
				     alert('Intente de nuevo. '+http.readyState);
					 return false;
				   }*/
		  }
////////////////////////////////////////////////////
function Del_articulo(codigo)
         {
		   	 //alert('MESA:'+idmesa+'CODIGO:'+codigo);
			 var tiempo="&ms="+new Date().getTime();
			 var url='ajax_consultas.php?op=11&codigo='+codigo+tiempo;
			 
			 http.open('GET',url);
			 http.onreadystatechange=resp_Del_articulo;
			 http.send(null);
		 }
/////////////////////////////////////////////////////
function resp_Del_articulo()
         {
		   if(http.readyState==4)
		       {
				 if(http.status==200)
				     {
						var respuesta=http.responseText;
						if(respuesta==1)
						   {
						     alert("Articulo Borrado.");
							 Act_carrito();
						   }
						 else if(respuesta==-1)
						       {
								 Salir();
							   }
						else{
							  alert("Ocurrio un error al borrar el articulo.");
							}	   
					 }
					 else{
						   alert("Error, intente de nuevo");
					     }
			   }
		 }
/////////////////////////////////////////////////////////
function Act_carrito()
         {
		   	 //alert('MESA:'+idmesa+'CODIGO:'+codigo);
			 var tiempo="&ms="+new Date().getTime();
			 var url='ajax_consultas.php?op=12'+tiempo;
			 
			 http.open('GET',url);
			 http.onreadystatechange=resp_Act_carrito;
			 http.send(null);
		 }
/////////////////////////////////////////////////////
function resp_Act_carrito()
         {
		   if(http.readyState==4)
		       {
				 if(http.status==200)
				     {
						var respuesta=http.responseText.split('|');
						if(respuesta[0]==1)
						   {
						     document.getElementById("carrito").innerHTML=respuesta[1];
						   }
						 else if(respuesta[0]==-1)
						       {
								 Salir();
							   }   
					 }
					 else{
						   alert("Error, intente de nuevo");
					     }
			   }
		 }
/////////////////////////////////////////////////////
function limpiar_login()
          {
			 document.getElementById('email').value='';
			 document.getElementById('pass').value='';
			 document.getElementById('loadevento').innerHTML='';
			 document.getElementById('email').focus();
			 
		  }
/////////////////////////////////////////////////////
function Consulta_cod()
			    {
				 
			  var f = document.getElementById('forma');
				   //var key = window.event ? e.keyCode : e.which;
				       //if(key==13)
				         //{
						 if(f.codigo.value!="")
						    {
						     http.open('get', 'ajax_consultas.php?op=13&codigo='+f.codigo.value);
				             http.onreadystatechange = respuestaConsulta_cod;
				             http.send(null);
						    }
					    else{
						     f.codigo.focus();
							}
						 //}
				}
				////////////////////FUNCION RESPUESTA BUSCA CODIGO////////////////////////////////////////	
	function respuestaConsulta_cod()
	{
		if(http.readyState == 4)
		{
		    if(http.status==200)
			{
			    var respuesta = http.responseText;
			    var arr_resp = respuesta.split('|');
			   			  
				      if(arr_resp[0]==0)
					      {
				           alert(arr_resp[1]);
				
				          }
				else if(arr_resp[0]==1)
				         {
				          document.getElementById('img').innerHTML = "<IMG SRC='"+arr_resp[4]+arr_resp[1]+".jpg'   ALT='' border=0>";
									  
						  document.getElementById('desc').innerHTML = "<FONT class='menblack' >"+arr_resp[2]+"</FONT>";
				                      
						  document.getElementById('precio').innerHTML = "<B><FONT class='menblackb'>Precio: $</FONT><FONT class='menredb'>" 
                                                                      +arr_resp[3]+"</FONT></B>";
				             if(confirm('¿Desea agregar el articulo?'))
				                 {
				                    Add_articulo(arr_resp[1],2);
				                 }                      
				            else		            
						         { 
						           Limpia_add_cod();
						  
						         }   
			            }else{
				              alert('Intente de nuevo.');
				
			                 }
			
		     }
		}
		
			else
			   {document.getElementById('codigo').innerHTML='<img src="images/ajax-loader.gif" />';}
	}
//////////////////////////////////////////////////
function solonumerosbuscacod(e) { // 1
    tecla = window.event ? e.keyCode : e.which; // 2
     if (tecla==13){Consulta_cod();}
	 if (tecla==8) return true; // supr
	 if (tecla==0) return true; // tab y otras
    patron =/\d/; // 4
    te = String.fromCharCode(tecla); // 5
   	return patron.test(te); // 6
} 
///////////////////////////////////////////////////
////////////////////////FUNCION AGREGA CODIGO///////////////////////////
function Agregar_cod()
         {
		   var f=document.getElementById('forma');
		  
		     if(f.codigo.value!="")
		       {
			     http.open('get','ajax_consultas.php?op=14&codigo='+f.codigo.value);
				 http.onreadystatechange = respuestaAgrega_cod;
				 http.send(null);
			   }
		 }

////////////////////////////////////////////////////////////////////////
////////////////////FUNCION RESPUESTA BUSCA CODIGO//////////////////////
function respuestaAgrega_cod()
          {
		    if(http.readyState==4)
			   {
			     if(http.status==200)
				    {
					  var resp = http.responseText;

					  if(resp==1)
					     {
						   alert('Articulo agregado');
						   Limpia_add_cod();
						 }
					 else if(resp==0)
					     {
					       alert('No se pudo agregar el articulo');
						   Limpia_add_cod(); 
						 }	 
					}
					
			   }
		  }
////////////////////////////////////////////////////////////////////////
function Limpia_add_cod()
          {
		     document.getElementById('img').innerHTML="";
			 document.getElementById('desc').innerHTML="";
			 document.getElementById('precio').innerHTML="";
			 document.getElementById('codigo').value="";
			 document.getElementById('codigo').focus();
		  }	