﻿// JScript File

function HtmlSelecionaCliente()
{
    var sb = new StringBuilder();
    sb.append("<table cellpadding='0' cellspacing='0' style='FONT-SIZE:10px;FONT-FAMILY:tahoma' border=0>");
        sb.append("<tr>");
            sb.append("<td valign='top'>");
                
                sb.append("<table cellpadding='0' cellspacing='0' width='100%' bgcolor='#CCCCCC'>");
                  sb.append("<tr>");
                    sb.append("<td colspan='2'><img src='images/login_top.gif' border='0'></td>");
                  sb.append("</tr>");
                sb.append("</table>");
                
            sb.append("</td>");
        sb.append("</tr>");
            
        sb.append("<tr>");
            sb.append("<td bgcolor='#CCCCCC'>");
                
                sb.append("<table>");
                  sb.append("<tr>");
                    sb.append("<td height='10px'></td>");
                  sb.append("</tr>");   
                sb.append("</table>");  
                
                sb.append("<table width='100%' border=0 height='100%' style='FONT-SIZE:10px;FONT-FAMILY:tahoma'>");
                
                  sb.append("<tr>");
                    sb.append("<td align='right' width='75px'>");
                      sb.append("Cliente:");
                    sb.append("</td>");
                    sb.append("<td>");
                      sb.append("<select id='cmbSelecionaCliente' onkeypress='SelecionaClienteKeyPress(event);' style='width:200px'></select>");
                    sb.append("</td>");
                  sb.append("</tr>");
                  
                  sb.append("<tr>");
                    sb.append("<td colspan='2' align='center' valign='center' height='36px'>");
                      sb.append("<input type=button class='classbtn' id='btnLogaCliente' onclick='javascript:SelecionaClienteAtivo();' style='height: 20px; width:90px' value=' Ok ' />");
                    sb.append("</td>");
                  sb.append("</tr>");
                  
                  
                sb.append("</table>");
            sb.append("</td>");
        sb.append("</tr>");
    sb.append("</table>");
    return sb.toString();
}

function SelecionaClienteKeyPress(e)
{
    var tecla = 0;
    
    if(window.event)//IE
    {
        tecla = e.keyCode;
    }
    else
    {
        if(e.which)//FIREFOX
        {
            tecla = e.which;
        }
    }
    
    if(tecla == 13)
    {
        SelecionaClienteAtivo();
    }
}

function AbrirSelecionaClientes()
{
    var dtClientes = verificaSessao(WCAjax.GetDtClientes());
 
    win.open("winSelecionaCliente", true);

    
    var oComboSelCliente = $('cmbSelecionaCliente');
    oComboSelCliente.options.length = 0;
        
    if(dtClientes != null)
    {
        for(var i = 0; i < dtClientes.rows.length; i++)
        {
            oComboSelCliente.options[i] = new Option(dtClientes.rows[i].Nome, 
                                                     dtClientes.rows[i].Codigo);
        }
    }
    
    oComboSelCliente.focus();
}

function SelecionaClienteAtivo()
{   
    var res = verificaSessao(WCAjax.SelecionaCliente(GetCampo('cmbSelecionaCliente')));
    if(res)
    {
        location.href = "Admin.aspx";
    }
    else
    {
        alert("Não foi possível selecionar o cliente");
        location.href = "Login.aspx";
    }
}

