/* ------------------------ G E N E R A L E S ----------------------------
   ---------------------------------------------------------------------*/

// Exhibe mensaje y dispara proceso php

function popUp(mensaje_popup,ancho_popup,alto_popup,nombre_proceso,argumento_proceso)
    {
    
	if(confirm(mensaje_popup))
            { 
            if (argumento_proceso=="")
                {
                // es el caso de un popup de alta
                window.open(nombre_proceso,"","width=" + ancho_popup + ",height=" + alto_popup + ",scrollbars=1")
                }
            else
                {
                window.open(nombre_proceso + "?" + argumento_proceso,"","width=" + ancho_popup + ",height=" + alto_popup + ",scrollbars=1")
		}
            }     
    }
    
function Cprohibidos( argumento ) // retorna true: mal, false: ok
    {
        var prohibidos=new Array("!" , "\"", "#", "$", "%", "&", "\'",
                                 "(" , ")" , "*", "+", "`", "-", ".",
                                 ":" , ";" , "<", "=", ">", "?", "@", 
                                 "\\", "[" , "]", "_", "{", "}");
        // rastreo argumento verificando por cada caracter, si el mismo
        // se encuentra dentro del array de prohibidos
        
        var j, i;
        var resultado;
       
        resultado = false;
        
        for (j=0; j< argumento.length; j++)
            {
            for (i=0; i<prohibidos.length; i++ )
                {
       
                if (argumento.charAt(j)==prohibidos[i]) 
                    {
                        resultado=true;
                    }
                }
            }    
        return ( resultado );        
    
    }


function validarEmail(argumento) 
	{
		var validos="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_@";
		var j;
		var can=0;
        var resultado;
       
        resultado = true;
        
        for (j=0; j< argumento.length; j++)
            {
                if (validos.indexOf(argumento.charAt(j))==-1) 
                    {
                        resultado=false;
                    }
				else
					{
						if (argumento.charAt(j)=="@") 
							{
								can++;
								if (j==0 || j==argumento.length-1)
									{
										resultado=false;
									}
							}
					}
			}
        
		if (can!=1)
			{
				resultado=false;
			}
		
		return ( resultado );
	}


/* ------------------------ L O G I N------- -----------------------------
   ---------------------------------------------------------------------*/


function validarLogin() 
          {
              var mensaje="";
              var n=document.f_login.nombre.value;
              var c=document.f_login.clave.value;
              if (n=="")
                {
                    mensaje +="Debe indicar el nombre\n\r";
                }
              
              if (c=="")
                {
                    mensaje +="Debe indicar la clave\n\r";
                }
              if (mensaje=="")
                  {
                    return true;
                  }
              else
                  {
                   alert(mensaje);
                   return false;
                  }
           }

function validarParticipante() 
          {
              var mensaje="";
              var n=document.f_participante.nom_par.value;
			  var a=document.f_participante.ape_par.value;
              var e=document.f_participante.ema_par.value;
              var c=document.f_participante.idprofesion.value;
              var p=document.f_participante.idpais.value;
              if (n=="")
                {
                    mensaje +="Debe indicar el nombre\n\r";
                }
              
			if (a=="")
                {
                    mensaje +="Debe indicar el apellido\n\r";
                }
			
              if (e=="" )
                {
                    mensaje +="Debe indicar su correo electronico\n\r";
                }
			else
				{
					if (validarEmail(e)==false)
						{
							mensaje +="Correo el ectronico invalido\n\r";
						}
				}
              if (c==0)
                {
                    mensaje +="Debe seleccionar su categoria como participante\n\r";
                }  
              if (p==0)
                {
                    mensaje +="Debe seleccionar su pais de origen\n\r";
                }  
                
              if (mensaje=="")
                  {
                    return true;
                  }
              else
                  {
                   alert(mensaje);
                   return false;
                  }
           }


function validarPerfil() 
          {
              var mensaje="";
              var n=document.f_perfil.nom_par.value;
			  var a=document.f_perfil.ape_par.value;
              var e=document.f_perfil.ema_par.value;
              var c=document.f_perfil.idprofesion.value;
              var p=document.f_perfil.idpais.value;
              var k=document.f_perfil.cla_par.value;
              
              if (n=="")
                {
                    mensaje +="Debe indicar el nombre\n\r";
                }
             
			if (a=="")
                {
                    mensaje +="Debe indicar el apellido\n\r";
                }	
			
              if (k=="")
                {
                    mensaje +="Debe indicar su clave\n\r";
                }
              if (c==0)
                {
                    mensaje +="Debe seleccionar su categoría como participante\n\r";
                }  
              if (p==0)
                {
                    mensaje +="debe seleccionar su país de origen\n\r";
                }  
                
              if (mensaje=="")
                  {
                    return true;
                  }
              else
                  {
                   alert(mensaje);
                   return false;
                  }
           }


/* ------------------------ T R A B A J O  -----------------------------
   ---------------------------------------------------------------------*/
   

function habilitarGrupo(campos)
{
    var nombres=campos.split(",");
    var elementos = document.f_trabajo.elements.length;
    var i=0, j=0;
    
    // recorro el formulario 
    for(i=0; i<elementos; i++)
        {
        var elemento_actual=document.f_trabajo.elements[i].name;
        // verifico si el elemento actual está dentro del argumento ingresado
        var esta=false;
        for (j=0; j<nombres.length; j++)
            {
            if (nombres[j]==elemento_actual) esta=true;
            }
        // si esta es verdadero, habilito el elemento del formulario
        if (esta==true)
            {
            document.f_trabajo.elements[i].disabled = "";
            // background activo
            document.f_trabajo.elements[i].style.background= "#FFFFFF"//"#FFFFCC";
            }
        else
            {
            // inhabilito el control si no pertenece al grupo
            document.f_trabajo.elements[i].disabled = "disabled";
            // background inactivo
            document.f_trabajo.elements[i].style.background="#CCCCCC" //"#FF0000";
            }
        }
 }


		

function validarTrabajo()
{
    
    var titulo=document.f_trabajo.g1titulo.value;
    var subtitulo=document.f_trabajo.g1subtitulo.value;
    var resumen=document.f_trabajo.g2resumen.value;
    var bibliografia=document.f_trabajo.g2bibliografia.value;
    var categoria=document.f_trabajo.g3idcategoria.value;
    var area=document.f_trabajo.g3idarea.value;
    var eje=document.f_trabajo.g3ideje.value;
    
    var mensaje="";
    
    if (titulo=="")
        {
        mensaje +="El titulo es obligatorio\n\r";
        }
        
    if (subtitulo=="")
        {
        mensaje +="El subtitulo es obligatorio\n\r";
        }
        
    if (resumen=="")
        {
        mensaje +="El resumen es obligatorio\n\r";
        }
      
    if (bibliografia=="")
        {
        mensaje +="La bibliografia es obligatoria\n\r";
        }
     
    if (categoria==0)
        {
        mensaje +="La categoria debe ser seleccionada\n\r";
        }
     
    if (area==0)
        {
        mensaje +="El area debe ser seleccionado\n\r";
        }    
        
    if (eje==0)
        {
        mensaje +="El eje debe ser seleccionado\n\r";
        }    
        
    if (mensaje=="")
        {
        return (true);
        }
    else
        {
        alert (mensaje);
        return (false);
        }
        
}


function EditarCliente(idcliente)
	{
	if (confirm("Procede a editar el registro"))
		{
		window.open ("cliente/popcliente.php?idcliente=" + idcliente,"","height=450,width=650");
		}	
	}
function BorrarCliente(idcliente)
	{
	if(confirm("Procede a eliminar el registro?"))
		{
		window.open ("cliente/popcliente.php?idcliente=" + idcliente + "&accion=Eliminar","","height=1,width=1");
		}
	}
	

function IngresarTrabajo()
	{
	if (confirm("Procede a ingresar un nuevo registro"))
		{
		window.open ("cliente/popcliente.php","","height=450,width=650");
		}
	}


/* -------------- CERTIFICADO
   ---------------------------------
*/

function validarCertificado()
	{
		var idparticipante=document.f_certificado.idparticipante.value;
		var mensaje="";
		
		if(idparticipante=="")
			{
					mensaje="Debe escribir el Codigo de Asistente";
			}

		if (mensaje=="")
			{
				return (true);
			}
		else
			{
				alert (mensaje);
				return (false);
			}
	}
	
	
/* --------------------------------------- L I S T A S    D E    P R E C I O S -----------------------
   ---------------------------------------------------------------------------------------------------*/
   
   
	function EditarPrecio()
	{
		
		var producto=document.f_precio_busca.producto.value;
		var cliente=document.f_precio_busca.cliente.value;
		if (producto=="0" || cliente=="0")
			{
			alert("Seleccione el producto y el tipo de cliente");
			}
		else
			{
			if (confirm("Procede a editar el precio"))
				{
				window.open ("listas/popprecio.php?idproducto=" + producto + "&idtipocliente=" + cliente,"","height=200,width=300");
				}	
			}
		
	}	
	
		function EditarStock()
	{
		
		var producto=document.f_stock_busca.producto.value;
		var sucursal=document.f_stock_busca.sucursal.value;
		if (producto=="0" || sucursal=="0")
			{
			alert("Seleccione el producto y la sucursal");
			}
		else
			{
			if (confirm("Procede a editar el stock"))
				{
				window.open ("listas/popstock.php?idproducto=" + producto + "&idsucursal=" + sucursal,"","height=200,width=300");
				}	
			}
		
	}

		function EditarComision()
	{
		
		var producto=document.f_comision_busca.producto.value;
		var tipocliente=document.f_comision_busca.cliente.value;
		if (producto=="0" || tipocliente=="0")
			{
			alert("Seleccione el producto y el tipo de cliente");
			}
		else
			{
			if (confirm("Procede a editar la comisi�n"))
				{
				window.open ("listas/popcomision.php?idproducto=" + producto + "&idtipocliente=" + tipocliente,"","height=200,width=300");
				}	
			}
		
	}
	
	function validarPrecio()
	{
		var mensaje="";
		var neto=document.f_alta_precio.net_precio.value;
		var iva=document.f_alta_precio.iva_precio.value;

		if (neto=="")
			{
			mensaje +="Neto obligatorio\n\r";
			}
		if (iva=="")
			{
			mensaje +="IVA obligatorio\n\r";
			}
		
		if (mensaje=="")
			{
				return true;	
			}
		else
			{
				alert(mensaje);
				return false;
			}
	}
	

	function validarStock()
	{
		var mensaje="";
		var stk=document.f_alta_stock.sto_stock.value;
		var ant=document.f_alta_stock.ant_stock.value;
		
		if (stk=="")
			{
			mensaje +="Stock obligatorio\n\r";
			}
		
		if (!/^([0-9])*$/.test(stk))
			{
			mensaje +="S�lo se admite un n�mero entero superior al actual\n\r";	
			}
			
		if (parseFloat(stk)<parseFloat(ant))
			{
			mensaje +="No puede modificar el stock con un valor inferior al actual\n\r";
			}
		
		if (mensaje=="")
			{
				return true;	
			}
		else
			{
				alert(mensaje);
				return false;
			}
	}


function validarComision()
	{
		var mensaje="";
		var com=document.f_alta_comision.com_comision.value;
		
		
		if (com=="")
			{
			mensaje +="Comisi�n obligatoria\n\r";
			}	
		
		if (mensaje=="")
			{
				return true;	
			}
		else
			{
				alert(mensaje);
				return false;
			}
	}


	
	/* ------------------------ V E N D E D O R  -----------------------------
   ---------------------------------------------------------------------*/

	
	function EditarVendedor(idvendedor)
	{
	if (confirm("Procede a editar el registro"))
		{
		window.open ("vendedor/popvendedor.php?idvendedor=" + idvendedor,"","height=300,width=650");
		}	
	}
function BorrarVendedor(idvendedor)
	{
	if(confirm("Procede a eliminar el registro?"))
		{
		window.open ("vendedor/popvendedor.php?idvendedor=" + idvendedor + "&accion=Eliminar","","height=1,width=1");
		}
	}
	

function IngresarVendedor()
	{
	if (confirm("Procede a ingresar un nuevo registro"))
		{
		window.open ("vendedor/popvendedor.php","","height=300,width=650");
		}
	}


function validarVendedor()
	{
		var mensaje="";
		var idvendedor=document.f_vendedor.idvendedor.value;
		var ape_vendedor=document.f_vendedor.ape_vendedor.value;
		var nom_vendedor=document.f_vendedor.nom_vendedor.value;
		var idsucursal=document.f_vendedor.idsucursal.value;
		var idlocalidad=document.f_vendedor.idlocalidad.value;
		var cpo_vendedor=document.f_vendedor.cpo_vendedor.value;
		var tel_vendedor=document.f_vendedor.tel_vendedor.value;
		var dni_vendedor=document.f_vendedor.dni_vendedor.value;
		var com_vendedor=document.f_vendedor.com_vendedor.value;
		
			
		if (ape_vendedor=="")
			{
			mensaje +="Apellido obligatorio\n\r";
			}
		if (nom_vendedor=="")
			{
			mensaje +="Nombre obligatorio\n\r";
			}
		if (idsucursal==0)
			{
			mensaje +="Seleccione la sucursal\n\r";
			}	
		if (idlocalidad==0)
			{
			mensaje +="Seleccione la localidad\n\r";
			}	
		if (cpo_vendedor=="")
			{
			mensaje +="Codigo Postal obligatorio\n\r";
			}
		if (tel_vendedor=="")
			{
			mensaje +="Telefono obligatorio\n\r";
			}
		if (dni_vendedor=="")
			{
			mensaje +="DNI obligatorio\n\r";
			}
		if (com_vendedor=="")
			{
			mensaje +="Comision obligatoria\n\r";
			}
		
		
		if (mensaje=="")
			{
				return true;	
			}
		else
			{
				alert(mensaje);
				return false;
			}
	}
	

	/* ------------------------ C O M P R A  ------------------------
   ---------------------------------------------------------------------*/

function IngresarCompra()
	{
	if (confirm("Procede a ingresar un nuevo registro"))
		{
		window.open ("compra/popcompra.php","","height=300,width=650");
		}
	}

	
	/* ------------------------ U S U A R I O S  ------------------------
   ---------------------------------------------------------------------*/

	
	function EditarUsuario(idusuario)
	{
	if (confirm("Procede a editar el registro"))
		{
		window.open ("usuario/popusuario.php?idusuario=" + idusuario,"","height=300,width=650");
		}	
	}
function BorrarUsuario(idusuario)
	{
	if(confirm("Procede a eliminar el registro?"))
		{
		window.open ("usuario/popusuario.php?idusuario=" + idusuario + "&accion=Eliminar","","height=1,width=1");
		}
	}
	

function IngresarUsuario()
	{
	if (confirm("Procede a ingresar un nuevo registro"))
		{
		window.open ("usuario/popusuario.php","","height=300,width=650");
		}
	}


function validarUsuario()
	{
		var mensaje="";
		var idusuario=document.f_usuario.idusuario.value;
		var nom_usuario=document.f_usuario.nom_usuario.value;
		var cta_usuario=document.f_usuario.cta_usuario.value;
		var cla_usuario=document.f_usuario.cla_usuario.value;
		var cat_usuario=document.f_usuario.cat_usuario.value;
			

		if (nom_usuario=="")
			{
			mensaje +="Nombre Completo obligatorio\n\r";
			}
		if (cta_usuario=="")
			{
			mensaje +="Cuenta para login obligatoria\n\r";
			}
		if (cla_usuario=="")
			{
			mensaje +="Clave para login obligatoria\n\r";
			}
	
		
		if (mensaje=="")
			{
				return true;	
			}
		else
			{
				alert(mensaje);
				return false;
			}
	}


	/* ------------------------ P E D I D O S  ------------------------
   ---------------------------------------------------------------------*/
	
	function validarPedidoBuscar()
	{
		var mensaje="Ingrese correctamente el rango de fechas";
		
		var b_mesi=document.f_pedido_buscar.b_mesi.value;
		var b_anioi=document.f_pedido_buscar.b_anioi.value;
		var b_mesf=document.f_pedido_buscar.b_mesf.value;
		var b_aniof=document.f_pedido_buscar.b_aniof.value;
			
		
		if (b_mesi==0 && b_anioi==0 && b_mesf==0 && b_aniof==0) return (true);
		if (b_mesi!=0 && b_anioi!=0 && b_mesf!=0 && b_aniof!=0) return (true);
		
		alert(mensaje);
		return false;
	}

	function CabeceraPedido()
	{
	if (confirm("Procede a ingresar un nuevo Pedido"))
		{
		window.open ("pedido/cabecerapedido.php","","height=150,width=650");
		}
	}

	function EditarPedido(idpedidoc)
	{
	if (confirm("Procede a editar el pedido"))
		{
		window.open ("pedido/detallepedido.php?idpedidoc=" + idpedidoc,"","height=550,width=600");
		}
	}

	function BorrarDetalle(idpedidoc,idpedidod)
	{
	if(confirm("Procede a eliminar el registro?"))
		{
		window.open ("detallepedido.php?idpedidoc=" + idpedidoc + "&idpedidod=" + idpedidod + "&accion=Eliminar","","height=550,width=600");
		}
	}

	function BorrarPedido(idpedidoc)
	{
	if(confirm("Procede a eliminar el registro?"))
		{
		window.open ("pedido/detallepedido.php?idpedidoc=" + idpedidoc  + "&accion=EliminarP","","height=550,width=600");
		}
	}
	
	
/* ------------------------ R E P O R T E S   ------------------------
   ---------------------------------------------------------------------*/	
   
   function validarReportePedidosBuscar()
	{
		var mensaje="Ingrese correctamente el rango de fechas";
		
		var b_mesi=document.f_reportepedidos_buscar.b_mesi.value;
		var b_anioi=document.f_reportepedidos_buscar.b_anioi.value;
		var b_mesf=document.f_reportepedidos_buscar.b_mesf.value;
		var b_aniof=document.f_reportepedidos_buscar.b_aniof.value;
			
		
		if (b_mesi==0 && b_anioi==0 && b_mesf==0 && b_aniof==0) return (true);
		if (b_mesi!=0 && b_anioi!=0 && b_mesf!=0 && b_aniof!=0) return (true);
		
		alert(mensaje);
		return false;
	}

  function validarReporteProductosBuscar()
	{
		var mensaje="Ingrese correctamente el rango de fechas";
		
		var b_mesi=document.f_reporteproductos_buscar.b_mesi.value;
		var b_anioi=document.f_reporteproductos_buscar.b_anioi.value;
		var b_mesf=document.f_reporteproductos_buscar.b_mesf.value;
		var b_aniof=document.f_reporteproductos_buscar.b_aniof.value;
			
		
		if (b_mesi==0 && b_anioi==0 && b_mesf==0 && b_aniof==0) return (true);
		if (b_mesi!=0 && b_anioi!=0 && b_mesf!=0 && b_aniof!=0) return (true);
		
		alert(mensaje);
		return false;
	}
	
	function validarReporteComisionesBuscar()
	{
		var mensaje="Ingrese correctamente el rango de fechas";
		
		var b_mesi=document.f_rc.b_mesi.value;
		var b_anioi=document.f_rc.b_anioi.value;
		var b_mesf=document.f_rc.b_mesf.value;
		var b_aniof=document.f_rc.b_aniof.value;
			
		
		if (b_mesi==0 && b_anioi==0 && b_mesf==0 && b_aniof==0) return (true);
		if (b_mesi!=0 && b_anioi!=0 && b_mesf!=0 && b_aniof!=0) return (true);
		
		alert(mensaje);
		return false;
	}