Function notEmpty(theElement)
	notEmpty = True
	If theElement.value = "" Then
		MsgBox "You can't sign in because a required field was left blank.", 48, "Missing Input"
		theElement.focus()
		notEmpty = False
	End If	
End Function

Function checkForm()
	checkForm = False
	If notEmpty(document.signinForm.txtUsername) And _
		notEmpty(document.signinForm.txtPassword) Then
		checkForm = True
	End If
End Function

Sub document_onkeypress()
	Dim vbKeyReturn 
	vbKeyReturn = 13
	If window.event.keycode = vbKeyReturn Then btnSignin_OnClick()
End Sub

Sub btnBack_OnClick()
	msgbox "back"
End Sub

Sub btnSignin_OnClick()
	If checkForm Then
	    GetXMLData
	Else
		document.signinForm.txtUsername.value = ""
		document.signinForm.txtPassword.value = ""
		document.signinForm.txtUsername.focus()
	End If
End Sub


Sub GetXMLData()
Dim strRequest
Dim rsXML
    XMLData.async = False
    strRequest="signin.asp?XML=1&txtUsername=" & signinForm.txtUsername.value & "&txtPassword=" & signinForm.txtPassword.value & "&chkRememberMe=" & signinForm.chkRememberMe.checked 
	If XMLData.Load(strRequest)=false Then
	    msgBox "XML Data Load Failed"
	Else
	    Set rsXML = XMLData.recordset
	    If Not rsXML("authenticated").value Then
	        msgBox "The system could not log you on." & vbCR & vbCR & _
                "Make sure your User name is correct, then type your password again" & vbCR & _
                "Letters must be typed using the correct case." & vbCR & _
                "Make sure that Caps Lock is not accidentaly on.", 16, "Signin Error"
                document.signinForm.txtUsername.value = ""
				document.signinForm.txtPassword.value = ""
				document.signinForm.txtUsername.focus()
        Else
            window.location = rsXML("redirect").value
        End If
	End If
End Sub

Sub Window_onLoad()
    parent.frmTitleBar.window.location = "titlebar.asp?title=PAC Manager Secured Access"
    document.signinForm.txtUsername.Focus
    document.signinForm.txtUsername.Select
    
    If signinForm.autosignin.value = "true" Then		
		btnSignin_OnClick()	
    End If
    
End Sub

