var hideProgress;
var client_package_id;
var client_id;
var client_user_id;
var client_page_id;
var callback_id;
var payment_id;

var time_tracker_type = '';
var time_tracker_time = 0;
var current_project_add = 0;
var current_project_edit = 0;
var current_project_view = 0;
var last_project = 0;

var current_time_tracker_id = 0;
var time_total = 0;
var updateTime = '';

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

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';
	}
}

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

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

	if ( password && ( password == password_again ) )
	{
		/* add the ajax request to the end of defined url variable */
		var url = 'billing_ajax.php?user=1';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'password=' + password,
			onSuccess: function(xhrResponse) {
				/* set error text to a loading box */
				$('progress_text').innerHTML = 'Login information updated.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else
	{
		if ( password == '' )
		{
			/* set error text to a loading box */
			$('progress_text').innerHTML = 'Password required.';
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else
		{
			/* set error text to a loading box */
			$('progress_text').innerHTML = 'Passwords must match.';
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
	}
}

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

	//grab submitted information
	var first_name = document.getElementById('first_name').value;
	var last_name = document.getElementById('last_name').value;
	var state = document.getElementById('state').value;
	var address = document.getElementById('address').value;
	var city = document.getElementById('city').value;
	var zip = document.getElementById('zip').value;
	var invoice_type = document.getElementById('invoice_email').value;
	var auto = ( document.getElementById('auto_withdraw').checked == true ? 1 : 0 );

	var cc_type = document.getElementById('cc_type').value;
	var cc_exp_date = document.getElementById('cc_year').value + '-' + document.getElementById('cc_month').value + '-01';
	var cc_number = document.getElementById('cc_number').value;
	var cc_sec_code = document.getElementById('cc_sec_code').value;
	var cc_name = document.getElementById('cc_name').value;

	/* 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 = 'billing_ajax.php';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'first_name=' + first_name + '&last_name=' + last_name + '&state=' + state + '&address=' + address + '&city=' + city + '&zip=' + zip + '&invoice_type=' + invoice_type + '&auto_withdraw=' + auto + '&cc_type=' + cc_type + '&cc_exp_date=' + cc_exp_date + '&cc_number=' + cc_number + '&cc_sec_code=' + cc_sec_code + '&cc_name=' + cc_name,
		onSuccess: function(xhrResponse) {
			$('progress_text').innerHTML = xhrResponse.responseText;
			if ( cc_number )
			{
				document.getElementById('cc_number').value = '************' + cc_number.substring(12, cc_number.length);
			}
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function checkEnter(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 )
	{
		loginClient();
	}
}

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

	//grab submitted information
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;

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

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

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'username=' + username + '&password=' + password,
		onSuccess: function(xhrResponse) {
			if ( xhrResponse.responseText == 0 )
			{
				/* set error text to a loading box */
				$('progress_text').innerHTML = 'Invalid username or password.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			}
			else if ( xhrResponse.responseText == 1 )
			{
				/* set error text to a loading box */
				$('progress_text').innerHTML = 'You have been suspended from logging in because of 7 failed attempts.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			}
			else if ( xhrResponse.responseText == 2 )
			{
				parent.window.location.href = 'account.php';
			}
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

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

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

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

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'clients_id=' + clients_id,
		onSuccess: function(xhrResponse) {
			$('view_client').innerHTML = xhrResponse.responseText;
			parent.location.hash = 'id=' + clients_id;
			Element.show('view_client');
			Element.hide('progress_box');
			Element.hide('clients_list');
			client_id = clients_id;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewAllClients(type)
{
	Element.hide('view_client');
	Element.hide('add_' + type);
	Element.show('clients_list');
	parent.location.hash = '';
	$('view_client').innerHTML = '';
	client_id = 0;
}

function managePackage(type, package_id)
{
	clearTimeout(hideProgress); // clear any existing timeouts

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

	Element.hide('add_package_button');

	/* add the ajax request to the end of defined url variable */
	var url = 'packages_ajax.php?mode=view&type=' + type;

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'package_id=' + package_id,
		onSuccess: function(xhrResponse) {
			if ( type == 'edit' )
			{
				$('package_edit_' + package_id).innerHTML = xhrResponse.responseText;
				Element.show('package_edit_' + package_id);
				client_package_id = package_id;
				Element.hide('package_' + package_id);
			}
			else
			{
				$('add_package').innerHTML = xhrResponse.responseText;
				Element.show('add_package');
				Element.show('view_packages');
			}

			Element.hide('progress_box');
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewClientMain(type)
{
	if ( type == 'edit' )
	{
		Element.hide('package_edit_' + client_package_id);
		Element.show('package_' + client_package_id);
		$('package_edit_' + client_package_id).innerHTML = '';
	}
	else
	{
		Element.hide('add_package');
	}

	Element.show('add_package_button');
	Element.show('view_packages');
	Element.show('added_packages');
}

function viewClientMainPages(type)
{
	if ( type == 'edit' )
	{
		Element.hide('page_edit_' + client_page_id);
		Element.show('page_' + client_page_id);
		$('page_edit_' + client_page_id).innerHTML = '';
	}
	else
	{
		Element.hide('add_page');
	}

	Element.show('add_page_button');
	Element.show('view_pages');
	Element.show('added_pages');
}

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

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');
	if ( type == 'edit' || type == 'add' )
	{
		var package_title = document.getElementById('packages_title').value;
		var package_amount = document.getElementById('packages_amount').value;
		var package_start_date = document.getElementById('start_date_year').value + '-' + document.getElementById('start_date_month').value + '-' + document.getElementById('start_date_day').value;
		var package_end_date = document.getElementById('end_date_year').value + '-' + document.getElementById('end_date_month').value + '-' + document.getElementById('end_date_day').value;

		/* add the ajax request to the end of defined url variable */
		var url = 'packages_ajax.php?mode=' + type + '&type=client&client_id=' + client_id;

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'package_id=' + client_package_id + '&package_title=' + package_title + '&package_amount=' + package_amount + '&package_start_date=' + package_start_date + '&package_end_date=' + package_end_date,
			onSuccess: function(xhrResponse) {
				if ( type == 'edit' )
				{
					$('package_title_' + client_package_id).innerHTML = package_title;
					$('package_amount_' + client_package_id).innerHTML = '$' + package_amount;

					var date_length = xhrResponse.responseText;
					var date_length_position = date_length.indexOf('-');
					var date_length_plus = (date_length_position + 1);
					$('package_start_date_' + client_package_id).innerHTML = date_length.substring(0, date_length_position);
					$('package_length_' + client_package_id).innerHTML = date_length.substring(date_length_plus, date_length.length) + ' months';

					Element.hide('package_edit_' + client_package_id);
					Element.show('package_' + client_package_id);
					$('package_edit_' + client_package_id).innerHTML = '';
					client_package_id = 0;

					$('progress_text').innerHTML = 'Package updated.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					$('added_packages').innerHTML += xhrResponse.responseText;
					Element.hide('add_package');

					$('progress_text').innerHTML = 'Package added.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}

				Element.show('add_package_button');
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else if ( type == 'drop' )
	{
		/* add the ajax request to the end of defined url variable */
		var url = 'packages_ajax.php?mode=drop&type=client';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'package_id=' + client_package_id,
			onSuccess: function(xhrResponse) {
				Element.hide('package_edit_' + client_package_id);
				Element.hide('package_' + client_package_id);
				$('package_edit_' + client_package_id).innerHTML = '';
				Element.hide('drop_message');
				client_package_id = 0;

				$('progress_text').innerHTML = 'Package removed.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
}

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

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

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

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'user_id=' + user_id,
		onSuccess: function(xhrResponse) {
			Element.hide('progress_box');
			$('edit_client_users').innerHTML = xhrResponse.responseText;
			Element.show('edit_client_users');
			Element.hide('view_client_users');
			Element.hide('added_users');
			client_user_id = user_id;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewAllUsers()
{
	Element.hide('edit_client_users');
	Element.hide('add_client_users');
	Element.show('view_client_users');
	Element.show('added_users');
	$('edit_client_users').innerHTML = '';
	client_user_id = 0;
}

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

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

	var user_first_name = document.getElementById('users_first_name').value;
	var user_last_name = document.getElementById('users_last_name').value;
	var user_username = document.getElementById('users_username').value;
	var user_password = document.getElementById('users_password').value;
	var user_password_repeat = document.getElementById('users_password_repeat').value;
	var add_client = '';

	if ( type == 'add-newclient' )
	{
		var clients_name = document.getElementById('clients_name').value;
		var clients_db_abrev = document.getElementById('clients_db_abrev').value;
		add_client = '&clients_name=' + clients_name + '&clients_db_abrev=' + clients_db_abrev;
	}

	if ( type == 'add' || type == 'add-newclient' )
	{
		if ( type == 'add' )
		{
			Element.hide('add_user');
		}
		else
		{
			Element.hide('add_client_button');
		}

		if ( user_first_name == '' )
		{
			Element.show('add_client_button');
			/* set error text to a loading box */
			$('progress_text').innerHTML = 'First Name required.';
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( user_last_name == '' )
		{
			Element.show('add_client_button');
			/* set error text to a loading box */
			$('progress_text').innerHTML = 'Last Name required.';
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( user_username == '' )
		{
			Element.show('add_client_button');
			/* set error text to a loading box */
			$('progress_text').innerHTML = 'Username required.';
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else if ( user_password == '' || ( user_password != user_password_repeat ) )
		{
			Element.show('add_client_button');
			if ( user_password == '' )
			{
				/* set error text to a loading box */
				$('progress_text').innerHTML = 'Must supply a password.';
			}
			else
			{
				/* set error text to a loading box */
				$('progress_text').innerHTML = 'Passwords did not match.';
			}
			Element.show('progress_box');
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else
		{
			var continue_add = 1;
			if ( type == 'add-newclient' )
			{
				if ( clients_name == '' )
				{
					Element.show('add_client_button');
					/* set error text to a loading box */
					$('progress_text').innerHTML = 'Clients Name required.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
					continue_add = 0;
				}
				else if ( clients_db_abrev == '' )
				{
					Element.show('add_client_button');
					/* set error text to a loading box */
					$('progress_text').innerHTML = 'Client DB Abrev required.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
					continue_add = 0;
				}
			}

			if ( continue_add == 1 )
			{
				/* add the ajax request to the end of defined url variable */
				var url = 'account_ajax.php?mode=add&type=user';

				/* make the ajax request for the information */
				new Ajax.Request(url, {
					method: 'post',
					parameters: 'client_id=' + client_id + '&user_first_name=' + user_first_name + '&user_last_name=' + user_last_name + '&user_username=' + user_username + add_client + '&user_password=' + user_password,
					onSuccess: function(xhrResponse) {
						if ( xhrResponse.responseText == 0 )
						{
							/* set error text to a loading box */
							$('progress_text').innerHTML = 'Username already in use.';
							hideProgress = setTimeout(hideProgressBox, 24000);

							if ( type == 'add' )
							{
								Element.hide('add_user');
							}
							else if ( type == 'add-newclient' )
							{
								Element.show('add_client_button');
							}
						}
						else
						{
							if ( type == 'add-newclient' )
							{
								var grab_client_id = xhrResponse.responseText;
								var grab_client_id_position = grab_client_id.indexOf(',');
								var grab_client_id_plus = (grab_client_id_position + 1);
								client_id = grab_client_id.substring(0, grab_client_id_position);
								$('added_users').innerHTML += grab_client_id.substring(grab_client_id_plus, grab_client_id.length);
							}
							else
							{
								$('added_users').innerHTML += xhrResponse.responseText;
							}
							Element.show('added_users');
							Element.hide('add_client_users');
							Element.show('view_client_users');

							document.getElementById('users_first_name').value = '';
							document.getElementById('users_last_name').value = '';
							document.getElementById('users_username').value = '';
							document.getElementById('users_password').value = '';
							document.getElementById('users_password_repeat').value = '';

							if ( type == 'add' )
							{
								Element.hide('add_user');
								$('progress_text').innerHTML = 'User added to client account.';
								hideProgress = setTimeout(hideProgressBox, 24000);
							}
							else
							{
								Element.hide('add_client_button');
								Element.show('add_clients_users_back');
								Element.show('view_packages');
								Element.show('view_pages');
								$('added_clients').innerHTML += '<div id="client_' + client_id + '"><table width="820" border="0" cellspacing="2" cellpadding="2" bgcolor="#D5D5D5" style="margin-top: -2px;"><tr><td align="left" valign="top" bgcolor="#EAEAEA" class="welcometext"><span class="welcometextCopy"><div id="main_clients_name_' + client_id + '">' + clients_name + '</div></td><td align="center" width="60" valign="top" bgcolor="#EAEAEA" class="welcometext"><a style="cursor: pointer;" onclick="viewClient(' + client_id + ');"><img src="images/edit.png" border="0"></a> <a style="cursor: pointer;" onclick="showDropClient(' + client_id + ');"><img src="images/drop.png" border="0"></a></td></tr></table></div>';

								$('progress_text').innerHTML = 'Client saved.';
								hideProgress = setTimeout(hideProgressBox, 24000);
							}

							$('progress_text').innerHTML = 'Client saved.';
							hideProgress = setTimeout(hideProgressBox, 24000);
						}
					},
					onFailure: function(xhrResponse) {
						$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
					}
				});
			}
		}
	}
	else if ( type == 'edit' )
	{
		if ( user_password != user_password_repeat )
		{
			/* set error text to a loading box */
			$('progress_text').innerHTML = 'Passwords did not match.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		}
		else
		{
			Element.hide('update_user');

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

			/* make the ajax request for the information */
			new Ajax.Request(url, {
				method: 'post',
				parameters: 'user_id=' + client_user_id + '&user_first_name=' + user_first_name + '&user_last_name=' + user_last_name + '&user_username=' + user_username + '&user_password=' + user_password + '&user_password_repeat=' + user_password_repeat,
				onSuccess: function(xhrResponse) {
					if ( xhrResponse.responseText == 1 )
					{
						Element.hide('progress_box');
						$('client_users_name_' + client_user_id).innerHTML = user_first_name + ' ' + user_last_name;
						$('client_users_username_' + client_user_id).innerHTML = user_username;
						Element.hide('edit_client_users');
						Element.show('view_client_users');
						Element.show('added_users');
						$('edit_client_user').innerHTML = '';
						client_user_id = 0;
					}
					else
					{
						/* set error text to a loading box */
						$('progress_text').innerHTML = 'Username already in use.';
						hideProgress = setTimeout(hideProgressBox, 24000);
						Element.show('update_user');
					}
				},
				onFailure: function(xhrResponse) {
					$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
				}
			});
		}
	}
	else if ( type == 'drop' )
	{
		/* add the ajax request to the end of defined url variable */
		var url = 'account_ajax.php?mode=drop&type=user';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'user_id=' + client_user_id,
			onSuccess: function(xhrResponse) {
				$('progress_text').innerHTML = 'User removed.';
				Element.hide('drop_message');
				Element.hide('user_' + client_user_id);
				client_user_id = 0;
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
}

function viewAddClientUser()
{
	Element.show('add_client_users');
	Element.hide('view_client_users');
	Element.hide('added_users');
}

function viewDropClientUser(user_id)
{
	client_user_id = user_id;
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this user?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_user" id="drop_user" onclick="manageClientUser(\'drop\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_user" id="drop_user" onclick="closeDropClientUser();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeDropClientUser()
{
	client_user_id = 0;
	Element.hide('drop_message');
}

function viewAddClient()
{
	Element.show('add_client');
	Element.hide('clients_list');
}

function addClient()
{
	manageClientUser('add-newclient');
}

function viewDropClientPackage(package_id)
{
	client_package_id = package_id;
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this package?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_package" id="drop_package" onclick="manageClientPackage(\'drop\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_package" id="drop_package" onclick="closeDropClientPackage();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeDropClientPackage()
{
	client_package_id = 0;
	Element.hide('drop_message');
}

function showSaveBasic()
{
	Element.show('save_basic');
}

function manageClientBasic(type)
{
	if ( type == 'edit' )
	{
		clearTimeout(hideProgress); // clear any existing timeouts

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

		var clients_name = document.getElementById('clients_name').value;
		var clients_db_abrev = document.getElementById('clients_db_abrev').value;

		/* add the ajax request to the end of defined url variable */
		var url = 'clients_ajax.php?mode=edit&type=basic';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'client_id=' + client_id + '&clients_name=' + clients_name + '&clients_db_abrev=' + clients_db_abrev,
			onSuccess: function(xhrResponse) {
				$('main_clients_name_' + client_id).innerHTML = clients_name;
				Element.hide('save_basic');
				$('progress_text').innerHTML = 'Basic Information saved.';
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
}

function showDropClient(c_id)
{
	client_id = c_id;
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this client?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_client" id="drop_client" onclick="manageClient(\'drop\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_client" id="drop_client" onclick="closeDropClient();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeDropClient()
{
	client_id = 0;
	Element.hide('drop_message');
}

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

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

	/* add the ajax request to the end of defined url variable */
	var url = 'clients_ajax.php?mode=drop&type=client';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'client_id=' + client_id,
		onSuccess: function(xhrResponse) {
			Element.hide('drop_message');
			Element.hide('client_' + client_id);
			$('progress_text').innerHTML = 'Client removed.';
			hideProgress = setTimeout(hideProgressBox, 24000);
			client_id = 0;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function managePage(type, page_id)
{
	clearTimeout(hideProgress); // clear any existing timeouts

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

	Element.hide('add_page_button');

	/* add the ajax request to the end of defined url variable */
	var url = 'pages_ajax.php?mode=view&type=' + type;

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'page_id=' + page_id + '&client_id=' + client_id,
		onSuccess: function(xhrResponse) {
			if ( type == 'edit' )
			{
				$('page_edit_' + page_id).innerHTML = xhrResponse.responseText;
				Element.show('page_edit_' + page_id);
				client_page_id = page_id;
				Element.hide('page_' + page_id);
			}
			else
			{
				$('add_page').innerHTML = xhrResponse.responseText;
				Element.show('add_page');
				Element.show('view_pages');
			}

			Element.hide('progress_box');
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

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

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');
	if ( type == 'edit' || type == 'add' )
	{
		var page_title = document.getElementById('pages_title').value;
		var page_url = document.getElementById('pages_url').value;
		var page_home = ( document.getElementById('pages_home').checked == true ? 1 : 0 );

		/* add the ajax request to the end of defined url variable */
		var url = 'pages_ajax.php?mode=' + type + '&type=client' + ( type != 'add' ? '&client_id=' + client_id : '' );

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'page_id=' + client_page_id + '&page_title=' + page_title + '&page_url=' + page_url + '&page_home=' + page_home,
			onSuccess: function(xhrResponse) {
				if ( type == 'edit' )
				{
					$('page_title_' + client_page_id).innerHTML = page_title;
					$('page_url_' + client_page_id).innerHTML = page_url;

					var old_home = xhrResponse.responseText;
					var old_home_position = old_home.indexOf('-');
					var old_home_plus = (old_home_position + 1);
					if ( old_home.substring(0, old_home_position) != old_home.substring(old_home_plus, old_home.length) )
					{
						$('page_home_' + old_home.substring(0, old_home_position)).innerHTML = '<img src="images/spacer.gif">';
						$('page_home_' + old_home.substring(old_home_plus, old_home.length)).innerHTML = 'Yes';
					}

					Element.hide('page_edit_' + client_page_id);
					Element.show('page_' + client_page_id);
					$('page_edit_' + client_page_id).innerHTML = '';
					client_page_id = 0;

					$('progress_text').innerHTML = 'Page updated.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					$('added_pages').innerHTML += xhrResponse.responseText;
					Element.hide('add_page');

					$('progress_text').innerHTML = 'Page added.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}

				Element.show('add_page_button');
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else if ( type == 'drop' )
	{
		/* add the ajax request to the end of defined url variable */
		var url = 'pages_ajax.php?mode=drop&type=client';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'page_id=' + client_page_id,
			onSuccess: function(xhrResponse) {
				Element.hide('page_edit_' + client_page_id);
				Element.hide('page_' + client_page_id);
				$('page_edit_' + client_page_id).innerHTML = '';
				Element.hide('drop_message');
				client_page_id = 0;

				$('progress_text').innerHTML = 'Page removed.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
}

function showDropPage(c_id)
{
	client_page_id = c_id;
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this page?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_page" id="drop_page" onclick="manageClientPage(\'drop\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_page" id="drop_page" onclick="closeDropClientPage();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeDropPage()
{
	client_page_id = 0;
	Element.hide('drop_message');
}

function manageCallback(type, c_id)
{
	clearTimeout(hideProgress); // clear any existing timeouts

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

	Element.hide('add_callback_button');

	/* add the ajax request to the end of defined url variable */
	var url = 'callbacks_ajax.php?mode=view&type=' + type;

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'callback_id=' + c_id,
		onSuccess: function(xhrResponse) {
			if ( type == 'edit' )
			{
				callback_id = c_id;
				$('callback_edit_' + callback_id).innerHTML = xhrResponse.responseText;
				Element.show('callback_edit_' + callback_id);
				Element.hide('callback_' + callback_id);
			}
			else
			{
				$('add_callback').innerHTML = xhrResponse.responseText;
				Element.show('add_callback');
			}

			Element.hide('progress_box');
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewDropCallback(c_id)
{
	callback_id = c_id;
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this callback?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_callback" id="drop_callback" onclick="manageChangeCallback(\'drop\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_callback" id="drop_callback" onclick="closeDropCallback();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeDropCallback()
{
	callback_id = 0;
	Element.hide('drop_message');
}

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

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');
	if ( type == 'edit' || type == 'add' )
	{
		var callback_company = document.getElementById('callbacks_company').value;
		var callback_contact = document.getElementById('callbacks_contact').value;
		var callback_phone = document.getElementById('callbacks_phone').value;
		var callback_email = document.getElementById('callbacks_email').value;
		var callback_comments = document.getElementById('callbacks_comments').value;
		var callback_sold = ( document.getElementById('callbacks_sold').checked == true ? 1 : 0 );
		var callback_date = document.getElementById('date_year').value + '-' + document.getElementById('date_month').value + '-' + document.getElementById('date_day').value;

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

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'callback_id=' + callback_id + '&callback_company=' + callback_company + '&callback_contact=' + callback_contact + '&callback_phone=' + callback_phone + '&callback_email=' + callback_email + '&callback_comments=' + callback_comments + '&callback_sold=' + callback_sold + '&callback_date=' + callback_date,
			onSuccess: function(xhrResponse) {
				if ( type == 'edit' )
				{
					$('main_callbacks_name_' + callback_id).innerHTML = callback_company;
					$('main_callbacks_phone_' + callback_id).innerHTML = callback_phone;
					$('main_callbacks_callback_date_' + callback_id).innerHTML = document.getElementById('date_month').value + '/' + document.getElementById('date_day').value + '/' + document.getElementById('date_year').value;

					Element.hide('callback_edit_' + callback_id);
					Element.show('callback_' + callback_id);
					$('callback_edit_' + callback_id).innerHTML = '';
					callback_id = 0;

					$('progress_text').innerHTML = 'Callback updated.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					$('added_callbacks').innerHTML += xhrResponse.responseText;
					Element.hide('add_callback');

					$('progress_text').innerHTML = 'Callback added.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}

				Element.show('add_callback_button');
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else if ( type == 'drop' )
	{
		/* add the ajax request to the end of defined url variable */
		var url = 'callbacks_ajax.php?mode=drop';

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'callback_id=' + callback_id,
			onSuccess: function(xhrResponse) {
				Element.hide('callback_edit_' + callback_id);
				Element.hide('callback_' + callback_id);
				$('callback_edit_' + callback_id).innerHTML = '';
				Element.hide('drop_message');
				callback_id = 0;

				$('progress_text').innerHTML = 'Callback removed.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
}

function viewCallbacksMain(type)
{
	if ( type == 'edit' )
	{
		Element.hide('callback_edit_' + callback_id);
		Element.show('callback_' + callback_id);
		$('callback_edit_' + callback_id).innerHTML = '';
	}
	else
	{
		Element.hide('add_callback');
	}

	Element.show('add_callback_button');
	Element.show('view_callbacks');
	Element.show('added_callbacks');
}

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

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

	/* add the ajax request to the end of defined url variable */
	var url = 'clients_ajax.php?mode=view&type=payments';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'clients_id=' + clients_id,
		onSuccess: function(xhrResponse) {
			$('view_client').innerHTML = xhrResponse.responseText;
			parent.location.hash = 'id=' + clients_id;
			Element.show('view_client');
			Element.hide('progress_box');
			Element.hide('clients_list');
			client_id = clients_id;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function managePayment(type, p_id)
{
	clearTimeout(hideProgress); // clear any existing timeouts

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

	Element.hide('add_payment_button');

	/* add the ajax request to the end of defined url variable */
	var url = 'payments_ajax.php?mode=view&type=' + type;

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'payment_id=' + p_id,
		onSuccess: function(xhrResponse) {
			if ( type == 'edit' )
			{
				$('payment_edit_' + p_id).innerHTML = xhrResponse.responseText;
				Element.show('payment_edit_' + p_id);
				payment_id = p_id;
				Element.hide('payment_' + p_id);
			}
			else
			{
				$('add_payment').innerHTML = xhrResponse.responseText;
				Element.show('add_payment');
				Element.show('view_payments');
			}

			Element.hide('progress_box');
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewDropPayment(p_id)
{
	payment_id = p_id;
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this payment?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_payment" id="drop_payment" onclick="manageChangePayment(\'drop\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_payment" id="drop_payment" onclick="closeDropPayment();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
}

function closeDropPayment()
{
	payment_id = 0;
	Element.hide('drop_message');
}

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

	/* set text to a loading box */
	$('progress_text').innerHTML = 'Loading...';
	Element.show('progress_box');
	if ( type == 'edit' || type == 'add' )
	{
		var payment_type = ( document.getElementById('payments_cc').checked == true ? 1 : 2 );
		var payment_amount = document.getElementById('payments_amount').value;
		var payment_date = document.getElementById('date_year').value + '-' + document.getElementById('date_month').value + '-' + document.getElementById('date_day').value;
		var payment_amount_due = document.getElementById('payments_amount_due').value;

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

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'payment_id=' + payment_id + '&payment_date=' + payment_date + '&payment_amount=' + payment_amount + '&payment_type=' + payment_type + '&client_id=' + client_id + '&amount_due=' + payment_amount_due,
			onSuccess: function(xhrResponse) {
				if ( type == 'edit' )
				{
					$('payment_date_' + payment_id).innerHTML = document.getElementById('date_month').value + '/' + document.getElementById('date_day').value + '/' + document.getElementById('date_year').value;
					$('payment_amount_' + payment_id).innerHTML = '$' + payment_amount;
					$('payment_type_' + payment_id).innerHTML = ( payment_type == 1 ? 'Credit Card' : 'Check' );
					$('amount_due').innerHTML = '$' + xhrResponse.responseText;
					document.getElementById('payments_amount_due').value = xhrResponse.responseText;

					Element.hide('payment_edit_' + payment_id);
					Element.show('payment_' + payment_id);
					$('payment_edit_' + payment_id).innerHTML = '';
					payment_id = 0;

					$('progress_text').innerHTML = 'Payment updated.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				else
				{
					var amount_due = xhrResponse.responseText;
					var amount_due_position = amount_due.indexOf('-');
					var amount_due_plus = (amount_due_position + 1);
					$('amount_due').innerHTML = '$' + amount_due.substring(0, amount_due_position);
					document.getElementById('payments_amount_due').value = amount_due.substring(0, amount_due_position);

					$('added_payments').innerHTML = amount_due.substring(amount_due_plus, amount_due.length) + $('added_payments').innerHTML;
					Element.hide('add_payment');

					$('progress_text').innerHTML = 'Payment added.';
					Element.show('progress_box');
					hideProgress = setTimeout(hideProgressBox, 24000);
				}
				$('main_payments_due_' + client_id).innerHTML = $('amount_due').innerHTML;

				Element.show('add_payment_button');
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
	else if ( type == 'drop' )
	{
		/* add the ajax request to the end of defined url variable */
		var url = 'payments_ajax.php?mode=drop';

		var payment_amount_due = document.getElementById('payments_amount_due').value;

		/* make the ajax request for the information */
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'payment_id=' + payment_id + '&amount_due=' + payment_amount_due,
			onSuccess: function(xhrResponse) {
				Element.hide('payment_edit_' + payment_id);
				Element.hide('payment_' + payment_id);
				$('payment_edit_' + payment_id).innerHTML = '';
				Element.hide('drop_message');
				payment_id = 0;

				$('amount_due').innerHTML = '$' + xhrResponse.responseText;
				$('main_payments_due_' + client_id).innerHTML = '$' + xhrResponse.responseText;
				document.getElementById('payments_amount_due').value = xhrResponse.responseText;

				$('progress_text').innerHTML = 'Payment removed.';
				Element.show('progress_box');
				hideProgress = setTimeout(hideProgressBox, 24000);
			},
			onFailure: function(xhrResponse) {
				$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
			}
		});
	}
}

function viewPaymentsMain(type)
{
	if ( type == 'edit' )
	{
		Element.hide('payment_edit_' + payment_id);
		Element.show('payment_' + payment_id);
		$('payment_edit_' + payment_id).innerHTML = '';
	}
	else
	{
		Element.hide('add_payment');
	}

	Element.show('add_payment_button');
	Element.show('view_payments');
	Element.show('added_payments');
}

function onlyOnePaymentType(type)
{
	document.getElementById('payments_cc').checked = false;
	document.getElementById('payments_check').checked = false;
	document.getElementById('payments_' + type).checked = true;
}

function stealthMode(client_id, client_db, user_id, user_type)
{
	clearTimeout(hideProgress); // clear any existing timeouts

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

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

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

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

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

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

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

function chargeCustomers()
{
	window.open('https://www.eboltmedia.com/oo_orders.php?charge=1','Customers Charged for Monthly Service','width=518,height=500,resizable=yes,scrollbars=yes');
}

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

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

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

	var project_title = escape(document.getElementById('add_project_title').value);

	var url = 'time_tracker.php?mode=ajax&type=add_project';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'project_title=' + project_title,
		onSuccess: function(xhrResponse) {
			$('added_project').innerHTML += xhrResponse.responseText;
			$('progress_text').innerHTML = 'Project added.';
			hideProgress = setTimeout(hideProgressBox, 24000);
			Element.hide('add_project');
			document.getElementById('add_project_title').value = '';
			current_project_add = 0;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

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

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

	var project_title = escape(document.getElementById('project_title_' + project_id).value);

	var url = 'time_tracker.php?mode=ajax&type=edit_project';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'project_id=' + project_id + '&project_title=' + project_title,
		onSuccess: function(xhrResponse) {
			$('project_title_edit_' + project_id).innerHTML = xhrResponse.responseText;
			$('progress_text').innerHTML = 'Project updated.';
			hideProgress = setTimeout(hideProgressBox, 24000);
			Element.hide('edit_project_' + project_id);
			current_project_edit = 0;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewAddProject()
{
	if ( current_project_edit > 0 )
	{
		Element.hide('edit_project_' + current_project_edit);
		current_project_edit = 0;
	}

	if ( current_project_add == 0 )
	{
		Element.show('add_project');
		current_project_add = 1;
	}
	else
	{
		Element.hide('add_project');
		current_project_add = 0;
	}
}

function viewEditProject(project_id)
{
	if ( current_project_edit != project_id )
	{
		Element.show('edit_project_' + project_id);
	}

	Element.hide('add_project');
	current_project_add = 0;

	if ( current_project_edit > 0 )
	{
		Element.hide('edit_project_' + current_project_edit);
	}
	current_project_edit = ( current_project_edit == project_id ? 0 : project_id );
}

function viewDeleteProject(project_id)
{
	$('drop_message_text').innerHTML = '<table width="300" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"class="welcometext"><span class="welcometextCopy">Are you sure you want to remove this project?</span></td></tr><tr><td align="center" valign="top" class="welcometext"><input type="button" name="drop_account" id="drop_account" onclick="deleteProject(\'' + project_id + '\');" value="Yes" style="cursor: pointer;"> <input type="button" name="drop_account" id="drop_account" onclick="closeDeleteProject();" value="No" style="cursor: pointer;"></td></tr></table>';
	Element.show('drop_message');
	grayOut(true);
}

function closeDeleteProject()
{
	$('drop_message_text').innerHTML = '';
	Element.hide('drop_message');
	grayOut(false);
}

function deleteProject(project_id)
{
	grayOut(false);
	Element.hide('drop_message');

	clearTimeout(hideProgress); // clear any existing timeouts

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

	var url = 'time_tracker.php?mode=ajax&type=delete_project';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'project_id=' + project_id,
		onSuccess: function(xhrResponse) {
			$('progress_text').innerHTML = 'Project deleted.';
			hideProgress = setTimeout(hideProgressBox, 24000);
			Element.hide('project_' + project_id);
			Element.hide('edit_project_' + project_id);
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

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

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

	var url = 'time_tracker.php?mode=ajax&type=view_project';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'project_id=' + project_id,
		onSuccess: function(xhrResponse) {
			$('view_project').innerHTML = xhrResponse.responseText;
			Element.show('view_project');
			Element.hide('all_projects');
			Element.hide('progress_box');
			
			document.location.hash = 'id=' + project_id;
			current_project_view = project_id;
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function viewAllProjects()
{
	Element.hide('view_project');
	Element.show('all_projects');
	last_project = current_project_view;
	document.location.hash = '';
}

function trackHours(type, project_id)
{
	clearTimeout(hideProgress); // clear any existing timeouts

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

	var url = 'time_tracker.php?mode=ajax&type=time_tracker';

	/* make the ajax request for the information */
	new Ajax.Request(url, {
		method: 'post',
		parameters: 'project_id=' + project_id + '&type=' + type,
		onSuccess: function(xhrResponse) {
			var time_tracker_response = xhrResponse.responseText;
			var time_tracker_response_position = time_tracker_response.indexOf('-eboltajaxmedia-');
			var time_tracker_response_plus = (time_tracker_response_position + 16); // 16 because -eboltajaxmedia- is 16 chars
			
			/*if ( time_tracker_response.substring(0, time_tracker_response_position)[0] == 1 ) // start timer
			{
				var time_tracker_response = xhrResponse.responseText;
				var time_tracker_response_position = time_tracker_response.indexOf('-eboltajaxmedia-');
				var time_tracker_response_plus = (time_tracker_response_position + 16); // 16 because -eboltajaxmedia- is 16 chars
				current_time_tracker_id = time_tracker_id;
				time_total = (current_time - last_time);
				updateTime = setInterval(updateTimeStamp, 1000);
			}*/
			
			if ( type == 1 )
			{
				$('display_tracker').innerHTML = '<a style="cursor: pointer;" onclick="trackHours(\'0\', \'' + project_id + '\');" class="bluetext">Take a Break</a> <a style="cursor: pointer;" onclick="trackHours(\'2\', \'' + project_id + '\');" class="bluetext">End Session</a>';
			}
			else
			{
				$('display_tracker').innerHTML = '<a style="cursor: pointer;" onclick="trackHours(\'1\', \'' + project_id + '\');" class="bluetext">Start Session</a>';
			}
			$('added_time').innerHTML = time_tracker_response.substring(time_tracker_response_plus, time_tracker_response.length) + $('added_time').innerHTML;
			Element.hide('progress_box');
			$('progress_text').innerHTML = 'Time stamp submitted.';
			hideProgress = setTimeout(hideProgressBox, 24000);
		},
		onFailure: function(xhrResponse) {
			$('progress_text').innerHTML = 'Error: ' + xhrReponse.statusText;
		}
	});
}

function startSession(last_time, current_time, time_tracker_id)
{
	current_time_tracker_id = time_tracker_id;
	time_total = (current_time - last_time);
	updateTime = setInterval(updateTimeStamp, 1000);
}

function updateTimeStamp()
{
	time_total += 1;
	document.write(current_time_tracker_id + '<br>' + howMuchTime(time_total) + '<br>');
	$('time_total_' + current_time_tracker_id).innerHTML = howMuchTime(time_total);
}

function howMuchTime(time) // highest is hours
{
	var hours = 0;
	var minutes = 0;
	var seconds = 0;
	var how_many_hours = floor(time / 3600);
	if ( how_many_hours > 1 )
	{
		hours = how_many_hours;
		time -= (how_many_hours * 3600);
	}
	
	if ( time > 0 )
	{
		how_many_minutes = floor(time / 60);
		if ( how_many_minutes > 1 )
		{
			minutes = how_many_minutes;
			time -= (how_many_minutes * 60);
		}
		
		seconds = time;
	}
	
	return ( hours > 0 ? hours + ' Hour' + ( hours == 1 ? ' ' : 's ' ) : '' ) + ( minutes > 0 ? minutes + ' Minute' + ( minutes == 1 ? ' ' : 's ' ) : '' ) + seconds + ' Second' + ( seconds == 1 ? '' : 's' );
}