sub window_onload()
	call SetColor ("lblNewPassword", true)
	document.Form1.R_chrNewPassword.Disabled=true

	if right(document.getElementByID("R_chrAgentCode").value,2) = "-1" then
		document.Form1.R_chrAgentCode.value=mid(document.Form1.R_chrAgentCode.value,1, Len(document.Form1.R_chrAgentCode.value)-2)
		lblError.innerHTML=""
		Call ColorRequiredFields()
		alert("Some required fields need to be completed before continuing.")
	end if
	
	document.Form1.R_chrAgentCode.focus()
end sub

sub DisableRequiredFields()
	Dim e
	set e = document.getElementById("R_chrPassword")
	e.style.color = "#ffffff"
	
	set e = document.getElementById("R_chrEmailAddress")
	e.style.color = "#ffffff"
	
	document.Form1.R_chrPassword.value="New@New.New"
	document.Form1.R_chrEmailAddress.value="New"
	
end sub

Sub SetColor(byval strField, byval bDisable)
	Dim e
	set e = document.getElementById(strField)
	if bDisable then
		e.style.color = "#666666"
	else
		e.style.color = "#000000"
	end if
End Sub

sub ShowNewPass
	if document.Form1.R_chrNewPassword.Disabled=true then
		if trim(document.Form1.R_chrPassword.value)<>"" and trim(document.Form1.R_chrEmailAddress.value)<>"" then
			call SetColor ("lblNewPassword", false)
			document.Form1.R_chrNewPassword.Disabled=false
			document.Form1.R_chrNewPassword.focus
		elseif trim(document.Form1.R_chrPassword.value)="" then
			alert("You must enter your email address before you can change your password.")
			document.Form1.R_chrPassword.focus
		elseif trim(document.Form1.R_chrEmailAddress.value)="" then
			alert("You must enter your current password in order to change your password.")
			document.Form1.R_chrEmailAddress.focus
		end if
	else
		call SetColor ("lblNewPassword", true)
		document.Form1.R_chrNewPassword.value=""
		document.Form1.R_chrNewPassword.Disabled=true
	end if
end sub

Sub CheckRequiredFields()
	Dim j, bIsOk
	bIsOk=true
	
	For j=0 to document.all.length-1
		set e = document.all(j)
		If e.ID<>"" Then
			If left(e.ID,1)="R" and not e.Disabled and e.style.visibility<>"hidden" Then
				Select Case mid(e.ID,3,3)
					Case "cur", "chr"
						If trim(e.value) = "" Then
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
					Case  "dte"
						If trim(e.value) = "" Then 
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
					Case "rbl"
						If not e.checked Then
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
					Case "ddl"
						If e.value="?" Then
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
				End Select
			End If
		End If
	Next
	If not bIsOk Then document.getElementByID("R_chrAgentCode").value = document.getElementByID("R_chrAgentCode").value + "-1"

End Sub

Sub ColorRequiredFields()
	Dim j, bIsOk
	bIsOk=true

	For j=0 to document.all.length-1
		set e = document.all(j)
		If e.ID<>"" Then
			If left(e.ID,1)="R" and not e.Disabled and e.style.visibility<>"hidden" Then
				Select Case mid(e.ID,3,3)
					Case "cur", "chr"
						If trim(e.value) = "" Then 
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
					Case "ddl"
						If e.value="?" Then
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
					Case "dte"
						If trim(e.value) = "" Then 
							bIsOk = False
							Call SetBackgroundColor(e.ID, true)
						Else
							Call SetBackgroundColor(e.ID, false)
						End If
				End Select
			End If
		End If
	Next
End Sub

Sub SetBackgroundColor(byval strField, byval bDisable)
	Dim e
	set e = document.getElementById(strField)
	if bDisable then
		e.style.Background = "#B6d4c2"
	else
		e.style.Background = "White"
	end if
End Sub

sub setNameFields()
	If UCase(document.getElementById("R_chrAgentCode").value) = "GORSTADMIN" or UCase(document.getElementById("R_chrAgentCode").value) = "GORSTUW" Then
		document.getElementById("R_chrFirstName").Disabled=True
		document.getElementById("R_chrLastName").Disabled=True
		
		call SetColor ("lblLast", true)
		call SetColor ("lblFirst", true)
		
		document.getElementById("R_chrEmailAddress").focus()
	else
		document.getElementById("R_chrFirstName").Disabled=False
		document.getElementById("R_chrLastName").Disabled=False
		
		call SetColor ("lblLast", false)
		call SetColor ("lblFirst", false)
		
		document.getElementById("R_chrFirstName").focus()
	end if	
end sub
