function validateUserCreateForm()
{
	
	error = 0;
	
	if ((document.userCreateForm.username.value == '') && (error == 0))
	{
		alert('Username is required.');
		error = 1;
	}
	
	if ((document.userCreateForm.password.value == '') && (error == 0))
	{
		alert('Password is required.');
		error = 1;
	}
	
	if ((document.userCreateForm.password2.value == '') && (error == 0))
	{
		alert('Re-type password is required.');
		error = 1;
	}
	
	if ((document.userCreateForm.email.value == '') && (error == 0))
	{
		alert('Email is required.');
		error = 1;
	}
	
	if ((document.userCreateForm.email2.value == '') && (error == 0))
	{
		alert('Re-type email is required.');
		error = 1;
	}
	
	if ((document.userCreateForm.password.value != document.userCreateForm.password2.value) && (error == 0))
	{
		alert('Passwords do not match. Please re-type them to make sure the password is correct.');
		error = 1;
	}
	
	if ((document.userCreateForm.email.value != document.userCreateForm.email2.value) && (error == 0))
	{
		alert('Emails fo not match. Please re-type them to make sure the email is correct.');
	}
	else
	{
		if (!check_email(document.userCreateForm.email.value) && (error == 0))
		{
			alert('Email is not valid.');
			error = 1;
		}
	}
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
	
}


function validateUserLoginForm()
{
	
	error = 0;
	
	if ((document.userLoginForm.username.value == '') && (error == 0))
	{
		alert('Username is required.');
		error = 1;
	}
	
	if ((document.userLoginForm.password.value == '') && (error == 0))
	{
		alert('Password is required.');
		error = 1;
	}
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
	
}


function checkAutologin() {
	
	if (document.userLoginForm.autologin.checked != true) {
		return true;
	} else {
		return confirm('This function will save your login on this computer. If others have access to this computer they will have access to your community account too.\n\nAre you sure you want to save your login?');
	}
	
}


function validateRequestForm()
{
	
	error = 0;
	
	if ((document.requestForm.name.value == '') && (error == 0))
	{
		alert('Name is required.');
		error = 1;
	}
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
	
}


function validateCommunityProfileForm()
{
	
	error = 0;
	
	if (!check_email(document.communityProfileForm.email.value) && (error == 0)) {
		alert('Email is not valid.');
		error = 1;
	}
	
	if (((document.communityProfileForm.birth_day.value != '0') || (document.communityProfileForm.birth_month.value != '0') || (document.communityProfileForm.birth_year.value != '0')) && (error == 0)) {
		
		if ((document.communityProfileForm.birth_day.value == '0') && (error == 0)) {
			alert('Birthday is required.');
			error = 1;
		}
		
		if ((document.communityProfileForm.birth_month.value == '0') && (error == 0)) {
			alert('Birthmonth is required.');
			error = 1;
		}
		
		if ((document.communityProfileForm.birth_year.value == '0') && (error == 0)) {
			alert('Birthyear is required.');
			error = 1;
		}
		
		if (!check_date(document.communityProfileForm.birth_day.value, document.communityProfileForm.birth_month.value, document.communityProfileForm.birth_year.value) && (error == 0)) {
			alert('Birthdate is not valid.');
			error = 1;
		}
			
	}
	
	if (document.communityProfileForm.website.value != '') {
		
		if (((document.communityProfileForm.website.value.substring(0,7) != 'http://') || (document.communityProfileForm.website.value.length < 8)) && (error == 0)) {
			alert('Website is required to begin with http://');
			error = 1;
		}
		
	}
	
	if ((document.communityProfileForm.password.value != '') || (document.communityProfileForm.password2.value != '')) {
		
		if ((document.communityProfileForm.password.value == '') && (error == 0)) {
			alert('Password is required to change password.');
			error = 1;
		}
		
		if ((document.communityProfileForm.password2.value == '') && (error == 0)) {
			alert('Re-type password is required to change password.');
			error = 1;
		}
		
		if ((document.communityProfileForm.password.value != document.communityProfileForm.password2.value) && (error == 0)) {
			alert('Passwords do not match. Please re-type them to make sure the password is correct.');
			error = 1;
		}
		
	}
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
	
}


function validateUploadForm1()
{
	
	error = 0;
	
	if ((document.uploadForm.categoryID.value == '0') && (error == '0'))
	{
		alert('Category is required.');
		error = 1;
	}
	
	if ((document.uploadForm.celebrityID.value == '0') && (error == '0'))
	{
		alert('Celebrity is required.');
		error = 1;
	}
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
	
}


function validateMailinglistForm()
{
	
	error = 0;
	
	if (!check_email(document.mailinglistForm.email.value) && (error == 0))
	{
		alert('Email is not valid');
		error = 1;
	}
	
	if (error == 0) {
		return true;
	} else {
		return false;
	}
	
}


function clearMailinglistForm()
{
	
	if (document.mailinglistForm.email.value == 'Enter email')
	{
		document.mailinglistForm.email.value = '';
	}
	
}


/* FUNCTIONS */

function check_date(intDay, intMonth, intYear)
{
	
	var maxdays = 0;
	
	if (intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) {
		maxdays = 31;
	}
	
	if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) {
		maxdays = 30;
	}
	
	if (intMonth == 2) {
		if (intYear % 4 == 0) {
			maxdays = 29;
		} else {
			maxdays = 28;
		}
	}
	
	if (intDay <= maxdays) {
		return true;
	} else {
		return false;
	}
	
}

function check_email(address)
{
	if ((address == "")
		|| (address.length < 6)
	  || (address.indexOf ('@') == -1)
	  || (address.indexOf ('.') == -1)
	  || (address.indexOf ('<') >= 0)
	  || (address.indexOf ('>') >= 0)
	  || (address.indexOf ('"') >= 0)
	  || (address.indexOf ("'") >= 0)
	  || (address.indexOf ('|') >= 0)
	  || (address.indexOf ('!') >= 0)
	  || (address.indexOf ('/') >= 0)
	  || (address.indexOf ('\\') >= 0)
	  || (address.indexOf ('>') >= 0)
	  || (address.indexOf ('#') >= 0)
	  || (address.indexOf ('¤') >= 0)
	  || (address.indexOf ('$') >= 0)
	  || (address.indexOf ('%') >= 0)
	  || (address.indexOf ('&') >= 0)
	  || (address.indexOf ('{') >= 0)
	  || (address.indexOf ('}') >= 0)
	  || (address.indexOf ('[') >= 0)
	  || (address.indexOf (']') >= 0)
	  || (address.indexOf ('(') >= 0)
	  || (address.indexOf (')') >= 0)
	  || (address.indexOf ('=') >= 0)
	  || (address.indexOf ('+') >= 0)
	  || (address.indexOf ('?') >= 0)
	  || (address.indexOf ('´') >= 0)
	  || (address.indexOf ('`') >= 0)
	  || (address.indexOf ('¨') >= 0)
	  || (address.indexOf ('^') >= 0)
	  || (address.indexOf ('~') >= 0)
	  || (address.indexOf ('½') >= 0)
	  || (address.indexOf ('§') >= 0)
	  || (address.indexOf ('*') >= 0)
	  || (address.indexOf (',') >= 0)
	  || (address.indexOf (';') >= 0)
	  || (address.indexOf (':') >= 0))
	    return false;
	return true;
}