<%@ LANGUAGE="VBSCRIPT" EnableSessionState=True TRANSACTION=NOT_SUPPORTED%>

<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Usuarios", "no-cache" %>
<% Response.Expires = -1 %>
<% Response.Buffer = true %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<!--#include file="comunes/accesoData.asp" -->
<link rel="stylesheet" href="clases.css" type="text/css" />

<script language="vbscript" runat="server">
	
	sub ValidarUsuarioInternet()
	    Dim oStored
		Dim OBJdbConnection
		Dim OBJRecordset
		Dim strCmdText
		Dim Codigo_Agencia
					
		strCmdText = "SELECT name FROM Internet_Users WHERE ClientID = " + cstr(ClienteDirectoBalcao) + " AND " + " username = '" + Request.Form("Usuario") + "' AND Password = '" + Request.Form("Password") + "'" 
		
		Set OBJdbConnection = Server.CreateObject("ADODB.Connection")		
		On Error Resume Next
				
		OBJdbConnection.Open strCnn
						
	    Set oStored = server.CreateObject("ADODB.Command")
		Set OBJRecordset = Server.CreateObject("ADODB.RecordSet")
		
		oStored.ActiveConnection = strCnn
	    oStored.CommandText = strCmdText
		oStored.CommandType = adCmdText

		Set OBJRecordset = oStored.Execute()
		
	    if OBJdbConnection.Errors.Count > 0 then			
        	nErro = OBJdbConnection.Errors(0).NativeError
		else
			If Err.Number <> 0 Then
        		nErro = Err.Number        
			end if	
		end if
		
		NomeUsuarioInternet = ""
		IF NOT OBJRecordset.EOF THEN
			NomeUsuarioInternet = OBJRecordset("name")
		END IF
		
		OBJdbConnection.Close
		Set OBJdbConnection = Nothing
		Set OBJRecordset = Nothing		
		Set oStored = nothing
	End sub
		
</script>

<%
main()

Sub main()

Dim Datos
Dim NumeroReserva
Dim sAccion

nErro = 0
sMensaje = ""

if request("Accion")<>"" then
	sAccion = request("Accion")
else
	sAccion = "Default"
end if

if sAccion = "CONFIRMAR" then
	ValidarUsuarioInternet()
		
	if nErro <> 0 and nErro <> 5701 then
		response.Redirect("V_Int_PT.asp")
	end if
	
	if NomeUsuarioInternet <> "" then	
		Session("Nome_Usuario_Internet") = NomeUsuarioInternet
		response.Redirect("Relatorios_PT.asp")
	else	
		sMensaje = "Alguma informação é inválida. Por favor tente novamente"
	end if
end if

%>

<HTML>
<HEAD>
	<TITLE>Bravacar - Utilizadores</TITLE>
</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">
	
	var mensaje='<%=sMensaje%>'
	if (mensaje!='')
		alert(mensaje)
	  	
	function Confirmar()
	{
	 var nResultado, sMensaje
	 var errores =''
	 var forma = document.Usuarios
		
	 if (forma.Usuario.value=='')
	    errores+='O usuário é obrigatório\n'

	 if (forma.Password.value=='')
	    errores+='A senha é obrigatória\n'
	
	 if (errores!='') 
		{
	     alert('Alguma informação é obrigatória ou inválida:\n' + errores)
	     return
		}
				
		forma.Accion.value = 'CONFIRMAR'	
		forma.submit()
	}	
	
	function Cancelar()	
	{
		var forma = document.Usuarios
		forma.Accion.value = ''	
		forma.submit()	 
	}	
	
</SCRIPT>

<FORM NAME="Usuarios" METHOD="post" ACTION="Utilizadores_PT.asp">

	<input type="hidden" name="Accion" value="<%=sAccion%>">

	<center>
	
	<div id="Imagem" class="Imagem">
		<img src="Images/Bravacar.bmp">
	</div>
	
	<table width="738" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		  <tr>
			<td height="25" align="left"><img src="IMAGES/Esquina1.bmp"/></td>	
			<td height="25" align="right"><img src="IMAGES/Esquina2.bmp"/></td>	
		  </tr>
	</table>	
	
	<table width="738" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		<tr>
			<td align="center" height="210">

				<table width="260" border="0" cellpadding="0" cellspacing="0">
				  <tr>
					<td height="22"><img src="Images/Usuarios.bmp"></td>
				  </tr>
				</table>
	
				<table width="260" border="1" cellpadding="0" cellspacing="0" bordercolor="#333399" bgcolor="#EEEEEE">
				  <tr>
					<td height="70">				
						<table >
							<tr>
								<td height="22" class="Estilo2" style="vertical-align:middle; width:110px; padding-left:6px">&nbsp;Utilizador: </td>
								<td style="vertical-align:middle"><input name="Usuario" type="text" id="ID_Usuario" class="Estilo3" style="width:120px;height:19px" maxlength="20"></td>
							</tr>
							<tr>
								<td height="22" class="Estilo2" style="vertical-align:middle; width:110px; padding-left:6px">&nbsp;Palavra-passe: </td>
								<td style="vertical-align:middle"><input name="Password" type="password" id="ID_Password" class="Estilo3" style="width:120px;height:19px" maxlength="20"></td>
							</tr>	  	  
						</table>  		
					</td>
				  </tr>				  
				</table>		
				
				<table width="250">
					<td align="center" valign="bottom" height="35">
						<input type="button" name="btConfirmar" class="Estilo5" value="Confirmar" onClick="javascript:Confirmar()">
						<input type=submit name="btCancelar" class="Estilo5" value="Cancelar" onClick="javascript:Cancelar()">
					</td>	
				</table>
				
			</td>
		</tr>
	</table>		
	
	<table width="738" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		  <tr> 
			<td height="25" align="left"><img src="IMAGES/Esquina3.bmp"/></td>	
			<td height="25" align="right"><img src="IMAGES/Esquina4.bmp"/></td>	
		  </tr>
	</table>			
				
<table>
	<tr>
		<td height="4"></td>
	</tr>
</table>
</center>
</form>

</BODY>
</HTML>

<%	
end sub
%>
