// JavaScript Document
function checkEditUserForm()
{
	with (window.document.frmEditUser) {
		if(hidAdminTypeId.value!=1){
			if (!isEmpty(txtpassword, 'Enter new password', false)) {
				if(isEmpty(txtCrntpassword, 'Enter current password', true)){
					return;
				} else if(isWrongLength(txtpassword, 'The password length is from 5 to 20 characters', true)){
					return;
				} else if(isWrongFormartLetNum(txtpassword, 'The password allow only letters and numbers', true)){
					return;
				} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
					return;
				} else {
					submit();
				}
			} else if (!isEmpty(txtNUserEmail, 'Enter new email address', false)) {
				if(isNotEmail(txtNUserEmail, 'The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter your Email address.')){
					return;
				} else if (isNotEqual(txtNUserEmail,txtConfUserEmail, 'The confirm email address does not match')){
					return;
				} else {
					submit();
				}
			}
			else submit();
		} else {
			if(hidAdminId.value==hidUserId.value){
				if(!isEmpty(txtNusername, 'Enter username', false)){
					if (isWrongLength(txtNusername, 'Username length is from 5 to 20 characters', true)){
						return;
					} else if(isWrongFormart(txtNusername, 'The username allow only letters, numbers, and underscores', true)){
						return;
					} else if (!isEmpty(txtpassword, 'Enter new password', false)) {
						if(isEmpty(txtCrntpassword, 'Enter current password', true)){
							return;
						} else if(isWrongLength(txtpassword, 'The password length is from 5 to 20 characters', true)){
							return;
						} else if(isWrongFormartLetNum(txtpassword, 'The password allow only letters and numbers', true)){
							return;
						} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
							return;
						} else {
							submit();
						}
					}  else if (!isEmpty(txtNUserEmail, 'Enter new email address', false)) {
						if(isNotEmail(txtNUserEmail, 'The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter your Email address.')){
							return;
						} else if (isNotEqual(txtNUserEmail,txtConfUserEmail, 'The confirm email address does not match')){
							return;
						} else {
							submit();
						}
					} else {
						submit();
					}
				} else if (!isEmpty(txtpassword, 'Enter new password', false)) {
					if(isEmpty(txtCrntpassword, 'Enter current password', true)){
						return;
					} else if(isWrongLength(txtpassword, 'The password length is from 5 to 20 characters', true)){
						return;
					} else if(isWrongFormartLetNum(txtpassword, 'The password allow only letters and numbers', true)){
						return;
					} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
						return;
					} else {
						submit();
					}
				} else if (!isEmpty(txtNUserEmail, 'Enter new email address', false)) {
					if(isNotEmail(txtNUserEmail, 'The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter your Email address.')){
						return;
					} else if (isNotEqual(txtNUserEmail,txtConfUserEmail, 'The confirm email address does not match')){
						return;
					} else {
						submit();
					}
				} else {
					submit();
				}
			}
			else{
/*				if(isEmpty(txtUserType, 'Select user type', true)){
					return;
				} else if(isEmpty(cboDepartment, 'Select department', true)){
					return;
				} else */
				if(!isEmpty(txtNusername, 'Enter username', false)){
					if (isWrongLength(txtNusername, 'Username length is from 5 to 20 characters', true)){
						return;
					} else if(isWrongFormart(txtNusername, 'The username allow only letters, numbers, and underscores', true)){
						return;
					} else if (!isEmpty(txtpassword, 'Enter new password', false)) {
						if(isWrongLength(txtpassword, 'The password length is from 5 to 20 characters', true)){
							return;
						} else if(isWrongFormartLetNum(txtpassword, 'The password allow only letters and numbers', true)){
							return;
						} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
							return;
						} else {
							submit();
						}
					} else {
						submit();
					}
				} else if (!isEmpty(txtpassword, 'Enter new password', false)) {
					if(isWrongLength(txtpassword, 'The password length is from 5 to 20 characters', true)){
						return;
					} else if(isWrongFormartLetNum(txtpassword, 'The password allow only letters and numbers', true)){
						return;
					} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
						return;
					} else {
						submit();
					}
				} else if (!isEmpty(txtNUserEmail, 'Enter new email address', false)) {
					if(isNotEmail(txtNUserEmail, 'The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter your Email address.')){
						return;
					} else if (isNotEqual(txtNUserEmail,txtConfUserEmail, 'The confirm email address does not match')){
						return;
					} else {
						submit();
					}
				} else {
					submit();
				}
			}
		}
	}
}

function checkAddUserForm()
{
	with (window.document.frmAddUser) {
		if (isEmpty(txtusername, 'Enter username', true)) {
			return;
		} else if(isWrongLength(txtusername, 'Username length is from 5 to 20 characters', true)){
			return;
		} else if(isWrongFormart(txtusername, 'The username allow only letters, numbers, and underscores', true)){
			return;
		} else if (isEmpty(txtpassword, 'Enter password', true)) {
			return;
		} else if(isWrongLength(txtpassword, 'The password length is from 5 to 20 characters', true)){
			return;
		} else if(isWrongFormartLetNum(txtpassword, 'The password allow only letters and numbers', true)){
			return;
		} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
			return;
		} else if(isEmpty(txtUserType, 'Select user type', true)){
			return;
		} else if (!isEmpty(txtUserEmail, 'Enter email address', false)) {
			if(isNotEmail(txtUserEmail, 'The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter your Email address.')){
				return;
			} else if (isNotEqual(txtUserEmail,txtConfUserEmail, 'The confirm email address does not match')){
				return;
			} else {
				submit();
			}
		} else {
			submit();
		}
	}
}

function checkMemberSignupForm()
{
	with (window.document.frmAddUser) {
		if (isEmpty(txtusername, 'Enter user name', true)) {
			return;
		} else if(isEmpty(txtCompName, 'Enter company name', true)){
			return;
		} else if (isEmpty(txtUserEmail, 'Enter email address', true)) {
			return;
		} else if(isNotEmail(txtUserEmail, 'The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter your Email address.')){
			return;
		} else if (isNotEqual(txtUserEmail,txtConfUserEmail, 'The confirm email address does not match')){
			return;
		} else {
			txtCompName.value = trim(txtCompName.value);
			txtCompRepresentName.value = trim(txtCompRepresentName.value);
			txtCompAddress.value = trim(txtCompAddress.value);
			txtCompState.value = trim(txtCompState.value);
			txtCompCity.value = trim(txtCompCity.value);
			txtCompTel.value = trim(txtCompTel.value);
			txtCompFax.value = trim(txtCompFax.value);
			
			submit();
		}
	}
}

function addUser()
{
	window.location.href = 'index.php?view=add';
}

function changePassword(userId)
{
	window.location.href = 'index.php?view=modify&user=' + userId;
}

function deleteUser(userId)
{
	if (confirm('Delete this user?')) {
		window.location.href = 'processUser.php?action=delete&user=' + userId;
	}
}

