// Standard javascript functions.
// Author: Jon Upton.
// Date: 3rd May 2007.

// Sign in form functions.
function signin()
{
	if ( document.getElementById('email').value == '' || document.getElementById('password').value == '' )
	{
		document.getElementById('signin_error').innerHTML = 'FILL IN ALL FIELDS';
	}
	else
	{
		document.frm_signin.submit();
	}
}

// Register validation functions.
function check_title ( value )
{
	if ( value.length < 1 )
	{
		document.getElementById('status_title').style.color = '#ff0000';
		document.getElementById('status_title').innerHTML = 'Invalid Length';
		document.getElementById('approve_title').value = '0';
	}
	else
	{
		document.getElementById('status_title').style.color = '#00bd24';
		document.getElementById('status_title').innerHTML = 'Approved';
		document.getElementById('approve_title').value = '1';
	}
}

function fname ( value )
{
	if ( value.length < 3 )
	{
		document.getElementById('status_first_name').style.color = '#ff0000';
		document.getElementById('status_first_name').innerHTML = 'Invalid Length';
		document.getElementById('approve_first_name').value = '0';
	}
	else
	{
		document.getElementById('status_first_name').style.color = '#00bd24';
		document.getElementById('status_first_name').innerHTML = 'Approved';
		document.getElementById('approve_first_name').value = '1';
	}
}

function lname ( value )
{
	if ( value.length < 3 )
	{
		document.getElementById('status_last_name').style.color = '#ff0000';
		document.getElementById('status_last_name').innerHTML = 'Invalid Length';
		document.getElementById('approve_last_name').value = '0';
	}
	else
	{
		document.getElementById('status_last_name').style.color = '#00bd24';
		document.getElementById('status_last_name').innerHTML = 'Approved';
		document.getElementById('approve_last_name').value = '1';
	}
}

function check_email1 ( value )
{
	if ( value.length == 0 )
	{
		document.getElementById('status_email_address1').style.color = '#ff0000';
		document.getElementById('status_email_address1').innerHTML = 'Invalid Address';
		document.getElementById('approve_email_address1').value = '0';
	}
	else
	{
		var email = value.split("@");
		if  ( email.length != 2 )
		{
			document.getElementById('status_email_address1').style.color = '#ff0000';
			document.getElementById('status_email_address1').innerHTML = 'Invalid Address';
			document.getElementById('approve_email_address1').value = '0';
		}
		else
		{
			var domain = value.split (".");
			if ( domain.length == 2 || domain.length == 3 )
			{
				document.getElementById('status_email_address1').style.color = '#00bd24';
				document.getElementById('status_email_address1').innerHTML = 'Approved';
				document.getElementById('approve_email_address1').value = '1';
			}
			else
			{
				document.getElementById('status_email_address1').style.color = '#ff0000';
				document.getElementById('status_email_address1').innerHTML = 'Invalid Address';
				document.getElementById('approve_email_address1').value = '0';
			}
		}
	}
}

function check_email2 ( value )
{
	if ( value.length == 0 )
	{
		document.getElementById('status_email_address2').style.color = '#ff0000';
		document.getElementById('status_email_address2').innerHTML = 'Invalid Address';
		document.getElementById('approve_email_address2').value = '0';
	}
	else
	{
		if ( value != document.getElementById('email_address1').value )
		{
			document.getElementById('status_email_address2').style.color = '#ff0000';
			document.getElementById('status_email_address2').innerHTML = 'Addresses Do Not Match';
			document.getElementById('approve_email_address2').value = '0';
		}
		else
		{
			document.getElementById('status_email_address2').style.color = '#00bd24';
			document.getElementById('status_email_address2').innerHTML = 'Approved';
			document.getElementById('approve_email_address2').value = '1';
		}
	}
}

function check_password1 ( value )
{
	if ( value.length < 8 )
	{
		document.getElementById('status_password1').style.color = '#ff0000';
		document.getElementById('status_password1').innerHTML = 'Invalid Length';
		document.getElementById('approve_password1').value = '0';
	}
	else
	{
		document.getElementById('status_password1').style.color = '#00bd24';
		document.getElementById('status_password1').innerHTML = 'Approved';
		document.getElementById('approve_password1').value = '1';
	}
}

function check_password2 ( value )
{
	if ( value != document.getElementById('password1').value )
	{
		document.getElementById('status_password2').style.color = '#ff0000';
		document.getElementById('status_password2').innerHTML = 'Passwords Do Not Match';
		document.getElementById('approve_password2').value = '0';
	}
	else
	{
		document.getElementById('status_password2').style.color = '#00bd24';
		document.getElementById('status_password2').innerHTML = 'Approved';
		document.getElementById('approve_password2').value = '1';
	}
}

function load_terms()
{
	var newWindow = window.open ( 'terms.php' , 'newWindow' , 'height=300,width=600,scrollbars=yes' );
	document.getElementById('approve_terms').value = '1';
}

function verify_form()
{
	var errors = 0;
	var show_errors = new Array();
	
	if ( document.getElementById('approve_title').value == 0 )
	{
		errors++;
		show_errors[errors] = "Title";
	}				
	
	if ( document.getElementById('approve_first_name').value == 0 )
	{
		errors++;
		show_errors[errors] = "First Name";
	}
	
	if ( document.getElementById('approve_last_name').value == 0 )
	{
		errors++;
		show_errors[errors] = "Last Name";
	}
	
	if ( document.getElementById('approve_email_address1').value == 0 )
	{
		errors++;
		show_errors[errors] = "Email Address";
	}
	
	if ( document.getElementById('approve_email_address2').value == 0 )
	{
		errors++;
		show_errors[errors] = "Email Address Confirmation";
	}
	
	if ( document.getElementById('approve_password1').value == 0 )
	{
		errors++;
		show_errors[errors] = "Password";
	}
	
	if ( document.getElementById('approve_password2').value == 0 )
	{
		errors++;
		show_errors[errors] = "Password Confirmation";
	}
	
	if ( document.getElementById('approve_terms').value == 0 )
	{
		errors++;
		show_errors[errors] = "Please Read The Terms &#38; Conditions";
	}
	
	if ( errors != 0 )
	{
		var error_list;
		error_list = 'The following fields are invalid<br/><ul id="form_errors" style="margin-left: 20px;">';
		for ( i = 1; i < show_errors.length; i++ )
		{
			error_list += '<li>' + show_errors[i] + '</li>';
		}
		error_list += '</ul>';
		document.getElementById('errors').style.display = 'block';
		document.getElementById('errors').innerHTML = error_list;;
	}
	else
	{
		document.frm_register.submit();
	}
}

function activate_account()
{
	var code = document.getElementById('hidden_code');
	var email_address = document.getElementById('email_address');
	var password = document.getElementById('password');
	if ( ( code == '' ) || ( code == null )  || ( email_address == '' ) || ( email_address == null ) || ( password == '' ) || ( password == null ) )
	{
		alert ( "There is a problem with your activation details. Please try again." );
	}
	else
	{
		document.getElementById('activate_account_frm').submit();
	}
}

function request_password_reset ()
{
	var email_address = document.getElementById('reset_email').value;
	if ( ( email_address == '' ) || ( email_address == null ) )
	{
		alert ( "Please enter an email address." );
	}
	else
	{
		document.getElementById('reset_password_frm').submit();
	}
}

function request_activation_email ()
{
	var email_address = document.getElementById('activation_email').value;
	if ( ( email_address == '' ) || ( email_address == null ) )
	{
		alert ( "Please enter an email address." );
	}
	else
	{
		document.getElementById('activation_email_frm').submit();
	}
}