// JavaScript Document
function checkEditUserForm()
{
	with (window.document.frmEditUser) {
		if (!isEmpty(txtpassword, 'Enter new password', false)) {
			if(isEmpty(txtCrntpassword, 'Enter current password', true)){
				return;
			} else if(txtpassword.value.length<6 || txtpassword.value=='123456' || txtpassword.value.toLowerCase()=='abcdef' || txtpassword.value.toLowerCase()=='password'){
				alert("The password can't be less than 6 characters or 123456, abcdef, password");
				txtpassword.select();
				return false;
			} else if(isNotEqual(txtpassword,txtConfpassword, 'The confirm password does not match', true)){
				return;
			} else {
				txtNusername.value = trim(txtNusername.value);
				txtpassword.value = trim(txtpassword.value);
				txtNUserEmail.value = trim(txtNUserEmail.value);
				
				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();
			}
		} 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 {
				txtNusername.value = trim(txtNusername.value);
				txtpassword.value = trim(txtpassword.value);
				txtNUserEmail.value = trim(txtNUserEmail.value);
				
				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();
			}
		} else {
			txtNusername.value = trim(txtNusername.value);
			txtpassword.value = trim(txtpassword.value);
			txtNUserEmail.value = trim(txtNUserEmail.value);
			
			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 checkAddUserForm()
{
	with (window.document.frmAddUser) {
		if (isEmpty(txtusername, 'Enter user name', true)) {
			return;
		} else if (isEmpty(txtpassword, 'Enter password', true)) {
			return;
		} else if(txtpassword.value.length<6 || txtpassword.value=='123456' || txtpassword.value.toLowerCase()=='abcdef' || txtpassword.value.toLowerCase()=='password'){
				alert("The password can't be less than 6 characters or 123456, abcdef, password");
				txtpassword.select();
				return false;
		} 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 {
				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();
			}
		} 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 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;
	}
}

