function toggleLogin() {
	styleObj=document.getElementById('login').style;
	if (styleObj.display=='none') {
		styleObj.display='';
		document.images['loginbutton'].src='images/close.gif';
	} else {
		styleObj.display='none';
		document.images['loginbutton'].src='images/open.gif';
	}
}

function togglePassword() {
	styleObj=document.getElementById('password').style;
	if (styleObj.display=='none') {
		styleObj.display='';
		document.images['passwordbutton'].src='images/close.gif';
	} else {
		styleObj.display='none';
	document.images['passwordbutton'].src='images/open.gif';
	}
}

function toggleProfile() {
	styleObj=document.getElementById('write').style;
	styleObj_read=document.getElementById('read').style;
	if (styleObj.display=='none') {
		styleObj.display='';
		styleObj_read.display='none';
		document.images['editprofile'].src='images/close.gif';
	} else {
		styleObj.display='none';
		styleObj_read.display='';
	document.images['editprofile'].src='images/edit.gif';
	}
}

function toggleAdminPasswd() {
	styleObj=document.getElementById('newpassword').style;
	styleObj_read=document.getElementById('password').style;
	if (styleObj.display=='none') {
		styleObj.display='';
		styleObj_read.display='none';
		document.images['editpassword'].src='images/close.gif';
	} else {
		styleObj.display='none';
		styleObj_read.display='';
	document.images['editpassword'].src='images/edit.gif';
	}
}

function verifyLogin() {
	pass = 'okay';
	regex_login = /^[a-zA-Z0-9.\-_@]*$/i;
	regex_passwd = /^[a-zA-Z0-9.\-_]*$/i;

//LOGIN
	if (document.login.newlogin.value == '') {
		alert('Please provide a new User Name');
		pass = "no";
	}
	login=document.login.newlogin.value;
	if ((login.length < 4 || login.length > 100) && pass == 'okay') {
		alert('User Names require a minimum of 4 and a maximum of 100 characters');
		pass = "no";
	}
	if (document.login.newlogin.value.search(regex_login) && pass == 'okay') {
		alert('Login invalid. Logins may only contain letters, numbers, periods and dashes.');
		pass = "no";
	}

//PASSWORDS
	if (document.login.checkpasswd.value == '' && pass == 'okay') {
		alert('Please verify your password');
		pass = "no";
	}
	passwd=document.login.checkpasswd.value;
	if ((passwd.length < 6 || passwd.length > 20) && pass == 'okay') {
		alert('Passwords require a minimum of 6 and a maximum of 20 characters');
		pass = "no";
	}
	if (document.login.checkpasswd.value.search(regex_passwd) && pass == 'okay') {
		alert('Password invalid. Passwords may only contain letters, numbers, periods, dashes and underscores.');
		pass = "no";
	}

	return pass;
}


function verifyPassword() {
	pass = 'okay';
	regex_login = /^[a-zA-Z0-9]*$/i;
	regex_passwd = /^[a-zA-Z0-9.\-_]*$/i;

//OLD PASSWORD
	if (document.password.oldpasswd.value == '') {
		alert('Please enter your old password');
		pass = "no";
	}
	password=document.password.oldpasswd.value;
	if ((password.length < 6 || password.length > 20) && pass == 'okay') {
		alert('Passwords require a minimum of 6 and a maximum of 20 characters');
		pass = "no";
	}
	if (document.password.oldpasswd.value.search(regex_passwd) && pass == 'okay') {
		alert('Old password invalid. Passwords may only contain letters, numbers, periods, dashes and underscores.');
		pass = "no";
	}

//NEW PASSWORDS
	if (document.password.newpasswd.value == '' && pass == 'okay') {
		alert('Please enter your new password');
		pass = "no";
	}
	password=document.password.newpasswd.value;
	if ((password.length < 6 || password.length > 20) && pass == 'okay') {
		alert('Passwords require a minimum of 6 and a maximum of 20 characters');
		pass = "no";
	}
	if (document.password.newpasswd.value.search(regex_passwd) && pass == 'okay') {
		alert('New password invalid. Passwords may only contain letters, numbers, periods, dashes and underscores.');
		pass = "no";
	}
	if (document.password.newpasswd.value != document.password.newpasswdd.value && pass == 'okay') {
		alert('Your new passwords do not match');
		pass = "no";
	}

	return pass;
}


function verifyParentLogin() {
	pass = 'okay';
	regex_passwd = /^[a-zA-Z0-9.\-_]*$/i;

//PASSWORDS
	if (document.form.passwd.value == '') {
		alert('Please enter your password');
		pass = "no";
	}
	passwd=document.form.passwd.value;
	if ((passwd.length < 6 || passwd.length > 20) && pass == 'okay') {
		alert('Passwords require a minimum of 6 and a maximum of 20 characters');
		pass = "no";
	}
	if (document.form.passwd.value.search(regex_passwd) && pass == 'okay') {
		alert('Password invalid. Passwords may only contain letters, numbers, periods, dashes and underscores.');
		pass = "no";
	}

	return pass;
}

function toggleEdit(variable) {
	styleObj=document.getElementById('profile_' + variable).style;
	styleObj_member=document.getElementById('member_' + variable).style;
	if (styleObj.display=='none') {
		styleObj.display='';
		styleObj_member.display='';
		document.images['edit_' + variable].src='images/close.gif';
	} else {
		styleObj.display='none';
		styleObj_member.display='none';
		document.images['edit_' + variable].src='images/edit.gif';
	}
}

function toggleNewAccount() {
	styleObj=document.getElementById('newaccountdiv').style;
	if (styleObj.display=='none') {
		styleObj.display='';
		document.images['newaccount'].src='images/cancel.gif';
	} else {
		styleObj.display='none';
		document.images['newaccount'].src='images/add-account.gif';
	}
}

function logoutUpdate() {
	confirmed = window.confirm('If you logout before updating your membership, your changes will be lost. Do you wish to continue?');
	if (confirmed) window.location='destroy_admin.php';
}

function logoutSave() {
	confirmed = window.confirm('If you logout before saving your account changes, your changes will be lost. Do you wish to continue?');
	if (confirmed) window.location='destroy_admin.php';
}

function confirmRemoveAccount() {
	confirmed = window.confirm('Are you sure you want to remove this account?');
	if (confirmed) pass = 'okay';
	else pass = 'no';
	return pass;
}

function confirmCancelMembership() {
	confirmed = window.confirm('Are you sure you want to cancel your membership?');
	if (confirmed) pass = 'okay';
	else pass = 'no';
	return pass;
}

function checkProfileUpdate() {
	pass = 'okay';
	regex_name = /^[a-zA-Z]+[-]?[a-zA-Z]+$/i;
	regex_city = /^[a-zA-Z \-]{2,}$/i;
	regex_email = /^[a-zA-Z0-9.\-_]+[@][a-zA-Z0-9.\-_]+[.][a-zA-Z]+$/i;

//FIRST NAME
	if (document.profile.newfirst.value == '') {
		alert('Please provide a first name.');
		pass = "no";
	}
	if (document.profile.newfirst.value.search(regex_name) && pass == 'okay') {
		alert('First name invalid. Names may only contain letters and one hyphen.');
		pass = "no";
	}

//LAST NAME
	if (document.profile.newlast.value == '' && pass == 'okay') {
		alert('Please provide a last name.');
		pass = "no";
	}
	if (document.profile.newlast.value.search(regex_name) && pass == 'okay') {
		alert('Last name invalid. Names may only contain letters and one hyphen.');
		pass = "no";
	}

//CITY
	if (document.profile.newcity.value == '' && pass == 'okay') {
		alert('Please provide a city name.');
		pass = "no";
	}
	if (document.profile.newcity.value.search(regex_city) && pass == 'okay') {
		alert('City name invalid. City names may only contain letters, hyphens and spaces.');
		pass = "no";
	}
	
//STATE
	if (document.profile.newstate.value == '' && pass == 'okay') {
		alert('Please select a state.');
		pass = "no";
	}

//COUNTRY
	if (document.profile.newcountry.value == '' && pass == 'okay') {
		alert('Please provide a country name.');
		pass = "no";
	}
	if (document.profile.newcountry.value.search(regex_city) && pass == 'okay') {
		alert('Country name invalid. Country names may only contain letters, hyphens and spaces.');
		pass = "no";
	}

//EMAIL
	if (document.profile.newemail.value == '' && pass == 'okay') {
		alert('Please provide an email address.');
		pass = "no";
	}
	if (document.profile.newemail.value.search(regex_email) && pass == 'okay') {
		alert('Email invalid. Emails may only contain letters, numbers, periods, dashes and underscores.');
		pass = "no";
	}

	return pass;
}

function checkProfilePasswords() {
	pass = 'okay';
	regex_passwd = /^[a-zA-Z0-9.\-_]*$/i;

//OLD PASSWORD
	if (document.passwords.oldpasswd.value == '') {
		alert('Please provide your old password');
		pass = "no";
	}
	passwd=document.passwords.oldpasswd.value;
	if ((passwd.length < 6 || passwd.length > 20) && pass == 'okay') {
		alert('Passwords require a minimum of 6 and a maximum of 20 characters.');
		pass = "no";
	}
	if (document.passwords.oldpasswd.value.search(regex_passwd) && pass == 'okay') {
		alert('Old password invalid. Passwords may only contain letters, numbers, periods, dashes and underscores.');
		pass = "no";
	}

//NEW PASSWORD
        if (document.passwords.newpasswd.value == '' && pass == 'okay') {
                alert('Please provide a new password');
                pass = "no";
        }
        passwd=document.passwords.newpasswd.value;
        if ((passwd.length < 6 || passwd.length > 20) && pass == 'okay') {
                alert('Passwords require a minimum of 6 and a maximum of 20 characters.');
                pass = "no";
        }
        if (document.passwords.newpasswd.value.search(regex_passwd) && pass == 'okay') {
                alert('New password invalid. Passwords may only contain letters, numbers, periods, dashes and underscores.');
                pass = "no";
        }
	if (document.passwords.newpasswd.value != document.passwords.newpasswdd.value && pass == 'okay') {
		alert('Your new password entries do not match');
		pass = "no";
	}

	return pass;
}

function checkCountry() {
	if (document.profile.newstate.value == "ZZ") {
		document.getElementById('domestic').style.display='none';
		document.getElementById('foreign').style.display='';
		document.profile.newcountry.value = '';
	} else {
		document.getElementById('domestic').style.display='';
		document.getElementById('foreign').style.display='none';
		document.profile.newcountry.value = 'United States';
	}
}
