' VB Script Document

'client side scripts follow to check something is entered in search boxes on the main pages
'if there is it then uses the criterion to create the SQL statement needed to display the data

'it also has a script to deal with logging on

'this script was written by Chloe Thomas - January 2005
'it is for the IT2 (smith)
'and this project assumes it is stored with index.htm

Option Explicit ' force variables to be declared

'check search by name 
Sub btnSearchNameGo_OnClick 
	Dim strNewSearch
	Dim strSQL
	
	If Trim(frmSearchName.strSearch.value) <> "" Then
		strNewSearch="%" & UCase(Trim(frmSearchName.strSearch.value)) & "%" 'trim and put into uppercase before adding to strSQL
		strSQL = "SELECT * FROM tbl_Products WHERE UCASE(product_name) LIKE '" & strNewSearch & "' ORDER BY product_name ASC"
		frmSearchName.strSQLStatement.value=strSQL
		document.frmSearchName.submit() 
	Else
		msgBox "Please enter your search criteria", vbOK + vbExclamation, "Search by Name - Nothing Entered"
	End If	
End Sub

'check search by category 
Sub btnSearchCategoryGo_OnClick 
	Dim strNewSearch
	Dim strSQL
	
	If Trim(frmSearchCategory.strSearch.value) <> "" Then
		strNewSearch="%" & UCase(Trim(frmSearchCategory.strSearch.value)) & "%" 'trim and put into uppercase before adding to strSQL
		strSQL = "SELECT product_id, product_name, product_desc, unit_price, pot_size, product_category FROM tbl_Products WHERE UCASE(product_category) LIKE '" & strNewSearch & "' ORDER BY product_name ASC"	
		frmSearchCategory.strSQLStatement.value=strSQL
		document.frmSearchName.submit() 
	Else	
		msgBox "Please enter your search criteria", vbOK + vbExclamation, "Search by Category - Nothing Entered"
	End If	
End Sub

' check search by max price 
Sub btnSearchPriceGo_OnClick 
	Dim strSQL
	Dim sngNewSearch	

	If Trim(frmSearchPrice.strSearch.value) <> "" Then
		sngNewSearch=CSng(Trim(frmSearchPrice.strSearch.value)) 'trim and convert to real number before adding to strSQL
		strSQL="SELECT * FROM tbl_Products WHERE unit_price <= " & sngNewSearch & " ORDER BY unit_price DESC"	
		frmSearchPrice.strSQLStatement.value=strSQL
		document.frmSearchPrice.submit() 
	Else
		msgBox "Please enter your search criteria", vbOK + vbExclamation, "Search by Max Price - Nothing Entered"
	End If	
End Sub

'********************************************************************************

' check login page - checks values have been added 
Sub btnLogin_OnClick 

	If Trim(frmLogin.txtLoginID.value) <> "" Then 'login has been entered
		If IsNumeric(frmLogin.txtLoginID.value) Then 'can it be converted to a number
			If Trim(frmLogin.txtPassword.value) <> "" Then 'password has been entered
				frmLogin.strStatus.value="success"
				document.frmLogin.submit() 
			Else
				frmLogin.strStatus.value="" 'not successful
				msgBox "Please enter your password", vbOK + vbExclamation, "Missing Password"
			End If
		Else
			frmLogin.strStatus.value="" 'not successful
			msgBox "Please enter your customer ID for your login (this will be a number)", vbOK + vbExclamation, "Login needs to be a Number"
		End If
	Else
		frmLogin.strStatus.value="" 'not successful
		msgBox "Please enter your login", vbOK + vbExclamation, "Missing Login"
	End If	
End Sub
