var hideProgress;
var opened_jobs = '';
var new_card = 0;

function hideProgressBox()
{
	Element.hide('progress_box');
}

function userLogin(type)
{
	clearTimeout(hideProgress); // clear any existing timeouts

	//grab submitted information
	var email = escape(document.getElementById(type + '_user_email').value);
	var password = escape(document.getElementById(type + '_user_password').value);

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	if ( email != '' && password != '' )
	{
		var url = 'login_ajax.php';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'email=' + email + '&password=' + password,
			onSuccess: function(xhrResponse) {
				if ( xhrResponse.responseText == 0 )
				{
					$('progress_text').innerHTML = 'Invalid email address or password.';
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else if ( xhrResponse.responseText == 'suspend' )
				{
					$('progress_text').innerHTML = 'Your account is suspended.';
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else if ( xhrResponse.responseText == 'deleted' )
				{
					$('progress_text').innerHTML = 'Invalid email address or password.';
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					if ( type == 'mini' && !document.getElementById('login_page') )
					{
						$('logged_in_text').innerHTML = xhrResponse.responseText;
						Element.show('logged_in');
						Element.hide('login_box');
						Element.hide('progress_box');
					}
					else
					{
						parent.location = 'account.php';
					}
				}
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else
	{
		if ( email == '' )
		{
			$('progress_text').innerHTML = 'Email address required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( password == '' )
		{
			$('progress_text').innerHTML = 'Password required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

function clearEmail()
{
	if ( document.getElementById('mini_user_email').value == 'email' )
	{
		document.getElementById('mini_user_email').value = '';
	}
}

function clearPassword()
{
	if ( document.getElementById('mini_user_password').value == 'password' )
	{
		document.getElementById('mini_user_password').value = '';
	}
}

function checkEnterLoginMini(inField, e)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		userLogin('mini');
	}
}

function checkEnterLoginMain(inField, e)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		userLogin('main');
	}
}

function userLogout(type)
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var url = 'login_ajax.php?mode=logout';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'logout=1',
		onSuccess: function(xhrResponse) {
			if ( type == 'account' )
			{
				parent.location = 'index.php';
			}
			else
			{
				$('logged_in_text').innerHTML = '';
				Element.hide('logged_in');
				Element.show('login_box');
				document.getElementById('mini_user_email').value = 'email';
				document.getElementById('mini_user_password').value = 'password';
				Element.hide('progress_box');
			}
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function userRegister()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var read_terms = ( document.getElementById('read_terms').checked ? 1 : 0 );
	var first_name = escape(document.getElementById('register_first_name').value);
	var last_name = escape(document.getElementById('register_last_name').value);
	var email = escape(document.getElementById('register_email').value);
	var username = escape(document.getElementById('register_username').value);
	var password = escape(document.getElementById('register_password').value);
	var password_again = escape(document.getElementById('register_password_again').value);

	if ( read_terms == 1 && first_name != '' && last_name != '' && email != '' && username != '' && ( password != '' && password == password_again ) && username.length >= 6 && password.length >= 6 )
	{
		var url = 'register_ajax.php';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'first_name=' + first_name + '&last_name=' + last_name + '&email=' + email + '&username=' + username + '&password=' + password,
			onSuccess: function(xhrResponse) {
				if ( xhrResponse.responseText == 'email' )
				{
					$('progress_text').innerHTML = 'E-Mail in use.';
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else if ( xhrResponse.responseText == 'username' )
				{
					$('progress_text').innerHTML = 'Account Name in use.';
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					//parent.location = 'account.php';
					var url = 'account_ajax.php?mode=paypal';

					/* make the ajax request for the information */
					new Ajax.Request(url, {
						method: 'post',
						parameters: 'register=1',
						onSuccess: function(xhrResponse) {
							parent.location = 'account.php';
						},
						onFailure: function(xhrResponse) {
							$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
						}
					});
				}
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else
	{
		if ( first_name == '' )
		{
			$('progress_text').innerHTML = 'First name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( last_name == '' )
		{
			$('progress_text').innerHTML = 'Last name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( email == '' )
		{
			$('progress_text').innerHTML = 'Email address required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( username == '' )
		{
			$('progress_text').innerHTML = 'Account name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( password == '' )
		{
			$('progress_text').innerHTML = 'Password required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( username.length < 6 )
		{
			$('progress_text').innerHTML = 'Username must be atleast six characters.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( password.length < 6 )
		{
			$('progress_text').innerHTML = 'Password must be atleast six characters.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( read_terms == 0 )
		{
			$('progress_text').innerHTML = 'Must confirm that you understand the terms of service.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else
		{
			$('progress_text').innerHTML = 'Passwords did not match.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

function checkEnterRegister(inField, e)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		userRegister();
	}
}

function userContact()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');
	Element.hide('contact');

	var first_name = escape(document.getElementById('contact_first_name').value);
	var last_name = escape(document.getElementById('contact_last_name').value);
	var email = escape(document.getElementById('contact_email').value);
	var username = escape(document.getElementById('contact_username').value);
	var question = escape(document.getElementById('contact_question').value);

	if ( first_name != '' && last_name != '' && email != '' && question != '' )
	{
		var url = 'contact_ajax.php';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'first_name=' + first_name + '&last_name=' + last_name + '&email=' + email + '&username=' + username + '&question=' + question,
			onSuccess: function(xhrResponse) {
				if ( xhrResponse.responseText == 'username' )
				{
					Element.show('contact');
					$('progress_text').innerHTML = 'Invalid username.';
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					$('progress_text').innerHTML = 'Message sent.';
					hideProgress = setTimeout(hideProgressBox, 24000);
					Element.hide('progress_box');
					Element.hide('contact_form');
					Element.show('contact_sent');
				}
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else
	{
		Element.show('contact');
		if ( first_name == '' )
		{
			$('progress_text').innerHTML = 'First name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( last_name == '' )
		{
			$('progress_text').innerHTML = 'Last name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( email == '' )
		{
			$('progress_text').innerHTML = 'Email address required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( question == '' )
		{
			$('progress_text').innerHTML = 'Question required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

function viewJobCategory(category_id)
{
	var open_category = 1;
	if ( opened_jobs != '' )
	{
		var new_opened_jobs = '';
		var all_jobs_open = opened_jobs.split(',');
		var i = 0;
		while ( all_jobs_open[i] )
		{
			if ( all_jobs_open[i] == category_id )
			{
				open_category = 0;
			}
			else
			{
				var new_opened_jobs = ( new_opened_jobs ? new_opened_jobs + ',' : '' ) + all_jobs_open[i];
			}
			i++;
		}
		opened_jobs = new_opened_jobs;
	}

	if ( open_category == 1 )
	{
		clearTimeout(hideProgress); // clear any existing timeouts

		/* set text to a loading box */
		$('progress_text').innerHTML = 'Loading...';
		Element.show('progress_box');

		var url = 'account_ajax.php?mode=view_jobs';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'category_id=' + category_id,
			onSuccess: function(xhrResponse) {
				$('category_jobs_' + category_id).innerHTML = xhrResponse.responseText;
				document.getElementById('bluearrow_' + category_id).src = 'images/arrowdown.jpg';
				Element.show('category_jobs_' + category_id);
				Element.hide('progress_box');
				opened_jobs = ( opened_jobs ? opened_jobs + ',' : '' ) + category_id;
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else
	{
		document.getElementById('bluearrow_' + category_id).src = 'images/bluearrow.jpg';
		Element.hide('category_jobs_' + category_id);
		$('category_jobs_' + category_id).innerHTML = '';
	}
}

function checkEnterRegisterNew(inField, e, type)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		userOrder(type);
	}
}

function cancelNewCard()
{
	Element.show('display_full_name');
	Element.show('display_type');
	Element.show('display_number');
	Element.show('display_security');

	Element.hide('form_full_name');
	Element.hide('form_type');
	Element.hide('form_number');
	Element.hide('form_security');

	new_card = 0;
	Element.show('new_card');
	Element.hide('cancel_new_card');
}

function newCard()
{
	Element.hide('display_full_name');
	Element.hide('display_type');
	Element.hide('display_number');
	Element.hide('display_security');

	Element.show('form_full_name');
	Element.show('form_type');
	Element.show('form_number');
	Element.show('form_security');

	new_card = 1;
	Element.hide('new_card');
	Element.show('cancel_new_card');
}

function userOrder(type)
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	Element.hide('order');
	if ( document.getElementById('order_new') )
	{
		Element.hide('order_new');
	}
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var membership = ( document.getElementById('membership_monthly').checked == true ? 30 : ( document.getElementById('membership_lifetime').checked == true ? 60 : 0 ) );
	var membership_type = ( membership == 30 ? 1 : 2 );
	var read_terms = ( document.getElementById('read_terms').checked == true ? 1 : 0 );

	var billing_first_name = document.getElementById('billing_first_name').value;
	var billing_last_name = document.getElementById('billing_last_name').value;
	var billing_address = document.getElementById('billing_address').value;
	var billing_address2 = document.getElementById('billing_address2').value;
	var billing_city = document.getElementById('billing_city').value;
	var billing_state = document.getElementById('billing_state').value;
	var billing_zip = document.getElementById('billing_zip').value;

	if ( type == 'new' || ( type == 'add' && new_card == 1 ) )
	{
		var cc_full_name = document.getElementById('cc_full_name').value;
		var cc_type = document.getElementById('cc_type').value;
		var cc_number = document.getElementById('cc_number').value;
		var cc_expiration = document.getElementById('cc_expiration_month').value + '-' + document.getElementById('cc_expiration_year').value;
		var cc_expiration_month = document.getElementById('cc_expiration_month').value;
		var cc_expiration_year = document.getElementById('cc_expiration_year').value;
		var cc_security = document.getElementById('cc_security').value;

		var pass = ( read_terms > 0 ? '' : 1 ) + ( membership != '' ? '' : 1 ) + ( billing_first_name != '' ? '' : 1 ) + ( billing_last_name != '' ? '' : 1 ) + ( billing_address != '' ? '' : 1 ) + ( billing_city != '' ? '' : 1 ) + ( billing_state != '' ? '' : 1 ) + ( billing_zip != '' ? '' : 1 ) + ( cc_full_name != '' ? '' : 1 ) + ( cc_type != '' ? '' : 1 ) + ( cc_number != '' ? '' : 1 ) + ( cc_expiration_month != '' ? '' : 1 ) + ( cc_expiration_year != '' ? '' : 1 ) + ( cc_security != '' ? '' : 1 );
	}
	else
	{
		var cc_full_name = '';
		var cc_type = '';
		var cc_number = '';
		var cc_expiration = '';
		var cc_security = '';

		var pass = ( read_terms > 0 ? '' : 1 ) + ( membership != '' ? '' : 1 ) + ( billing_first_name != '' ? '' : 1 ) + ( billing_last_name != '' ? '' : 1 ) + ( billing_address != '' ? '' : 1 ) + ( billing_city != '' ? '' : 1 ) + ( billing_state != '' ? '' : 1 ) + ( billing_zip != '' ? '' : 1 );
	}

	if ( pass == '' )
	{
		if ( type == 'new' )
		{
			var url = 'account_ajax.php?mode=paypal';

			/* make the ajax request for the information */
			new Ajax.Request(url, {
				method: 'post',
				parameters: 'membership_type=' + membership_type + '&membership=' + membership + '&billing_first_name=' + billing_first_name + '&billing_last_name=' + billing_last_name + '&billing_address=' + billing_address + '&billing_address2=' + billing_address2 + '&billing_city=' + billing_city + '&billing_state=' + billing_state + '&billing_zip=' + billing_zip + '&cc_full_name=' + cc_full_name + '&cc_type=' + cc_type + '&cc_number=' + cc_number + '&cc_expiration=' + cc_expiration + '&cc_security=' + cc_security,
				onSuccess: function(xhrResponse) {
					if ( xhrResponse.responseText == 'fail' )
					{
						//$('progress_text').innerHTML = xhrResponse.responseText;
						$('progress_text').innerHTML = 'An error occurred while processing your credit card.<br>Please review your information.';
						hideProgress = setTimeout(hideProgressBox, 24000);
						Element.show('order');

						if ( document.getElementById('order_new') )
						{
							Element.show('order_new');
						}
					}
					else
					{
						$('billing_info').innerHTML = xhrResponse.responseText;
						Element.hide('progress_box');
					}
				},
				onFailure: function(xhrResponse) {
					$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
				}
			});
		}
		else
		{
			var url = 'account_ajax.php?mode=edit';
			/* make the ajax request for the information */
			new Ajax.Request(url, {
				method: 'post',
				parameters: 'new_card=' + new_card + '&membership_type=' + membership_type + '&membership=' + membership + '&billing_first_name=' + billing_first_name + '&billing_last_name=' + billing_last_name + '&billing_address=' + billing_address + '&billing_address2=' + billing_address2 + '&billing_city=' + billing_city + '&billing_state=' + billing_state + '&billing_zip=' + billing_zip + '&cc_full_name=' + cc_full_name + '&cc_type=' + cc_type + '&cc_number=' + cc_number + '&cc_expiration=' + cc_expiration + '&cc_security=' + cc_security,
				onSuccess: function(xhrResponse) {
					Element.show('order');
					if ( xhrResponse.responseText == 'fail' )
					{
						$('progress_text').innerHTML = 'An error occurred while processing your credit card.<br>Please review your information.';
						hideProgress = setTimeout(hideProgressBox, 24000);
						Element.show('order');
					}
					else
					{
						$('progress_text').innerHTML = 'Account updated.';
						hideProgress = setTimeout(hideProgressBox, 24000);
					}
				},
				onFailure: function(xhrResponse) {
					$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
				}
			});
		}
	}
	else
	{
		Element.show('order');
		if ( document.getElementById('order_new') )
		{
			Element.show('order_new');
		}

		if ( membership == '' )
		{
			$('progress_text').innerHTML = 'Membership required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( read_terms == 0 )
		{
			$('progress_text').innerHTML = 'Must confirm that you understand the terms of service.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( billing_first_name == '' )
		{
			$('progress_text').innerHTML = 'Billing: First name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( billing_last_name == '' )
		{
			$('progress_text').innerHTML = 'Billing: Last name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( billing_address == '' )
		{
			$('progress_text').innerHTML = 'Billing: Address required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( billing_city == '' )
		{
			$('progress_text').innerHTML = 'Billing: City required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( billing_state == '' )
		{
			$('progress_text').innerHTML = 'Billing: State required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( billing_zip == '' )
		{
			$('progress_text').innerHTML = 'Billing: Zip code required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( cc_full_name == '' )
		{
			$('progress_text').innerHTML = 'Credit Card: Name required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( cc_type == '' )
		{
			$('progress_text').innerHTML = 'Credit Card: Type required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( cc_number == '' )
		{
			$('progress_text').innerHTML = 'Credit Card: Number required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( cc_expiration_month == '' )
		{
			$('progress_text').innerHTML = 'Credit Card: Expiration month required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( cc_expiration_year == '' )
		{
			$('progress_text').innerHTML = 'Credit Card: Expiration year required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( cc_security == '' )
		{
			$('progress_text').innerHTML = 'Credit Card: Security required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

function onlyOneMembership(type)
{
	document.getElementById('membership_monthly').checked = false;
	document.getElementById('membership_lifetime').checked = false;
	document.getElementById('membership_' + type).checked = true;
}

function forgotUsername()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var email = escape(document.getElementById('send_email').value);

	var url = 'forgot_ajax.php?type=username';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'email=' + email,
		onSuccess: function(xhrResponse) {
			if ( xhrResponse.responseText == 0 )
			{
				$('progress_text').innerHTML = 'No accounts with that email address.';
				hideProgress = setTimeout(hideProgressBox, 24000);
			}
			else
			{
				Element.hide('progress_box');
				Element.hide('send_email_form');
				Element.show('send_email_success');
			}
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function checkEnterForgotUsername(inField, e)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		forgotUsername();
	}
}

function resetPassword()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var password = escape(document.getElementById('reset_password').value);
	var password_again = escape(document.getElementById('reset_password_again').value);
	var user_key = escape(document.getElementById('user_key').value);

	if ( password != '' && password == password_again && password.length >= 6 )
	{
		var url = 'forgot_ajax.php?type=reset_password';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'user_key=' + user_key + '&reset_password=' + password,
			onSuccess: function(xhrResponse) {
				$('progress_text').innerHTML = 'Password reset.';
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else
	{
		if ( password == '' )
		{
			$('progress_text').innerHTML = 'Password required.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( password.length < 6 )
		{
			$('progress_text').innerHTML = 'Password must be atleast six characters.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else
		{
			$('progress_text').innerHTML = 'Passwords do not match.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

function checkEnterResetPassword(inField, e)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		resetPassword();
	}
}

function forgotPassword()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var email = escape(document.getElementById('send_email').value);

	var url = 'forgot_ajax.php?type=password';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'email=' + email,
		onSuccess: function(xhrResponse) {
			if ( xhrResponse.responseText == 0 )
			{
				$('progress_text').innerHTML = 'No accounts with that email address.';
				hideProgress = setTimeout(hideProgressBox, 24000);
			}
			else
			{
				Element.hide('progress_box');
				Element.hide('send_email_form');
				Element.show('send_email_success');
			}
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function checkEnterForgotPassword(inField, e)
{
	var key_pressed;

	if ( e && e.which )
	{
		key_pressed = e.which;
	}
	else if ( window.event )
	{
		e = window.event;
		key_pressed = e.keyCode;
	}

	if ( key_pressed == 13 )
	{
		forgotPassword();
	}
}

function openTerms()
{
	//window.open('http://www.findjobsoo.com/terms.php','Terms_of_Service','width=1000,height=800,resizable=yes,scrollbars=yes');
	grayOut(true);
	Element.show('terms_of_service');
}

function closeTerms()
{
	grayOut(false);
	Element.hide('terms_of_service');
}

function openCancelService()
{
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top" class="newstext"><span class="newstext">Are you sure you want to cancel your membership?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_account" id="drop_account" onclick="cancelService();" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_account" id="drop_account" onclick="closeCancelService();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeCancelService()
{
	$('drop_message_text').innerHTML = '';
	Element.hide('drop_message');
}

function cancelService()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');

	var url = 'account_ajax.php?mode=cancel_service';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'cancel=1',
		onSuccess: function(xhrResponse) {
			parent.location = 'index.php';
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function userMembership()
{
	document.getElementById('membership_lifetime').checked = true;
}

function userEdit()
{
	clearTimeout(hideProgress); // clear any existing timeouts

	//grab submitted information
	var first_name = escape(document.getElementById('user_first_name').value);
	var last_name = escape(document.getElementById('user_last_name').value);
	var username = escape(document.getElementById('user_username').value);
	var password = escape(document.getElementById('user_password').value);
	var password2 = escape(document.getElementById('user_password2').value);
	var email = escape(document.getElementById('user_email').value);
	var cancel_save = 0;

	if ( username != '' && first_name != '' && last_name != '' )
	{
		if ( password != '' )
		{
			if ( password != password2 )
			{
				/* set text to password didnt match */
				$('progress_text').innerHTML = 'Passwords did not match.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
				var cancel_save = 1;
			}
		}
		else
		{
			password = '';
		}

		if ( cancel_save == 0 )
		{
			/* set text to a loading box */
			$('progress_text').innerHTML = 'Saving...';
			Element.show('progress_box');

			/* add the ajax request to the end of defined url variable */
			var url = 'account_ajax.php?mode=edit_user';

			/* make the ajax request for the information */
			new Ajax.Request(url, {
				method: 'post',
				parameters: 'first_name=' + first_name + '&last_name=' + last_name + '&username=' + username + ( password == '' ? '' : '&password=' + password ) + '&email=' + email,
				onSuccess: function(xhrResponse) {
					
					if ( xhrResponse.responseText == 'username' )
					{
						$('progress_text').innerHTML = 'Account Name in use.';
						Element.show('progress_box');
						hideProgress = setTimeout(hideProgressBox, 24000);
					}
					else if ( xhrResponse.responseText == 'email' )
					{
						$('progress_text').innerHTML = 'E-Mail in use.';
						Element.show('progress_box');
						hideProgress = setTimeout(hideProgressBox, 24000);
					}
					else
					{
						$('logged_in_text').innerHTML = xhrResponse.responseText;
						$('progress_text').innerHTML = 'Account updated.';
						document.getElementById('user_password').value = '';
						document.getElementById('user_password2').value = '';
						Element.show('progress_box');
						hideProgress = setTimeout(hideProgressBox, 24000);
					}
				},
				onFailure: function(xhrResponse) {
					$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
				}
			});
		}
	}
	else
	{
		if ( first_name == '' )
		{
			/* set text to password didnt match */
			$('progress_text').innerHTML = 'First name required.';
			Element.show('error_first_name');
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( last_name == '' )
		{
			/* set text to password didnt match */
			$('progress_text').innerHTML = 'Last name required.';
			Element.show('error_last_name');
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( username == '' )
		{
			/* set text to password didnt match */
			$('progress_text').innerHTML = 'Account Name required.';
			Element.show('error_employee_number');
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( password != password2 || password == '' )
		{
			/* set text to password didnt match */
			$('progress_text').innerHTML = ( password == '' ? 'Password required.' : 'Passwords did not match.' );
			Element.show('error_password');
			Element.show('error_password2');
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

function grayOut(vis, options)
{
	var options = options || {};
	var zindex = options.zindex || 50;
	var opacity = options.opacity || 70;
	var opaque = (opacity / 100);
	var bgcolor = options.bgcolor || '#000000';
	var dark = document.getElementById('darkenScreenObject');
	if ( !dark ) {
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('div');
		tnode.style.position = 'absolute';
		tnode.style.top = '0px';
		tnode.style.left = '0px';
		tnode.style.overflow = 'hidden';
		tnode.style.display = 'none';
		tnode.id = 'darkenScreenObject';
		tbody.appendChild(tnode);
		dark = document.getElementById('darkenScreenObject');
	}

	if ( vis )
	{
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) )
		{
			var pageWidth = document.body.scrollWidth + 'px';
			var pageHeight = document.body.scrollHeight + 'px';
		}
		else if ( document.body.offsetWidth )
		{
			var pageWidth = document.body.offsetWidth + 'px';
			var pageHeight = document.body.offsetHeight + 'px';
		}
		else
		{
			var pageWidth = '100%';
			var pageHeight = '100%';
		}
		dark.style.opacity = opaque;
		dark.style.MozOpacity = opaque;
		dark.style.filter = 'alpha(opacity='+opacity+')';
		dark.style.zIndex = zindex;
		dark.style.backgroundColor = bgcolor;
		dark.style.width = pageWidth;
		dark.style.height = pageHeight;
		dark.style.display = 'block';
	}
	else
	{
		dark.style.display = 'none';
	}
}

var checkSession;
var user_browser = '';
var user_page = '';

function trackSessions(browser, page)
{
	clearInterval(checkSession);
	
	var screenW = 640;
	var screenH = 480;
	
	if ( parseInt(navigator.appVersion) > 3 )
	{
		screenW = screen.width;
		screenH = screen.height;
	}
	else if ( navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled() )
	{
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}

	var url = 'track-sessions.php';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'browser=' + browser + '&page=' + page + '&screen_width=' + screenW + '&screen_height=' + screenH + '&new_page=1',
		onSuccess: function(xhrResponse) {
			checkSession = setInterval("updateSession('" + browser + "', '" + page + "', " + screenW + ", " + screenH + ")", 1000);
		},
		onFailure: function(xhrResponse) {

		}
	});
}

function updateSession(browser, page, screenW, screenH)
{
	var url = 'track-sessions.php';
	
	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'browser=' + browser + '&page=' + page + '&screen_width=' + screenW + '&screen_height=' + screenH + '&new_page=0',
		onSuccess: function(xhrResponse) {
			
		},
		onFailure: function(xhrResponse) {

		}
	});

}