function __handle_newsletter_focus()
{
	var oForm = document.forms['footerForm'];
	
	if(oForm)
	{
		if(oForm['newsletter'])
		{
			if(oForm['newsletter'].value.toLowerCase() == 'your email address')
			{
				oForm['newsletter'].value = '';	
			}
		}
	}
}

function __handle_newsletter_blur()
{
	var oForm = document.forms['footerForm'];
	
	if(oForm)
	{
		if(oForm['newsletter'])
		{
			if(oForm['newsletter'].value.replace(/\s+/g,'').length == 0)
			{
				oForm['newsletter'].value = 'your email address';	
			}
		}
	}
}

function __handle_taf_focus()
{
	var oForm = document.forms['footerForm'];
	
	if(oForm)
	{
		if(oForm['email'])
		{
			if(oForm['email'].value.toLowerCase() == 'friend\'s email address')
			{
				oForm['email'].value = '';	
			}
		}
	}
}

function __handle_taf_blur()
{
	var oForm = document.forms['footerForm'];
	
	if(oForm)
	{
		if(oForm['email'])
		{
			if(oForm['email'].value.replace(/\s+/g,'').length == 0)
			{
				oForm['email'].value = 'friend\'s email address';	
			}
		}
	}
}

function __toggle_registration_submit(boolean)
{
	var oForm = document.forms['registerForm'];
	
	if(oForm)
	{
		oForm['continue'].disabled = (boolean == true ? false : true);		
	}
}

function __submit_registration()
{
	var oForm = document.forms['registerForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'register';
		
		__toggle_buttons('disable','registerForm');
		
		oForm.submit();
	}
}

function __finish_registration()
{
	var oForm = document.forms['registerForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'finalize';
		
		__toggle_buttons('disable','registerForm');
		
		oForm.submit();
	}	
}

function __cancel_registration()
{
	var oForm = document.forms['registerForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to CANCEL your registration ? '))
		{
			oForm['mode'].value = 'cancel';
			
			__toggle_buttons('disable','registerForm');
		
			oForm.submit();
		}
	}
}

function __toggle_interest_other(integer,boolean,form)
{
	var oForm = document.forms['registerForm'];
	
	if(form != null)
	{
		oForm = document.forms[form];	
	}
	
	if(oForm)
	{
		if(parseInt(integer) == 10)
		{
			if(boolean == true)
			{
				oForm['interest_other'].disabled = false;
				
				jQuery(document.getElementById('row_interest_other')).show();	
			}
			else
			{
				oForm['interest_other'].disabled = true;
				
				jQuery(document.getElementById('row_interest_other')).hide();	
			}
		}
	}
}

function __handle_source_other(string,form)
{
	var oForm = document.forms['registerForm'];
	
	if(form != null)
	{
		oForm = document.forms[form]
	}
	
	if(oForm)
	{
		if(string.toLowerCase() == 'other')
		{
			oForm['source_other'].disabled = false;
			
			jQuery(document.getElementById('row_source_other')).show();	
		}
		else
		{
			oForm['source_other'].disabled = true;
			
			jQuery(document.getElementById('row_source_other')).hide();
		}
	}
}

function __account_login()
{
	var oForm = document.forms['loginForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'login';
		
		__toggle_buttons('disable','loginForm');
		
		oForm.submit();
	}
}

function __lookup_email()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'lookup';
		
		__toggle_buttons('disable','theForm');
		
		oForm.submit();
	}	
}

function __reset_password()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'reset';
		
		__toggle_buttons('disable','theForm');
		
		oForm.submit();
	}	
}

function __handle_age_preference(boolean)
{
	var oForm = document.forms['projectForm'];
	
	if(oForm)
	{
		if(boolean == true)
		{
			oForm['ages'].disabled = true;
			oForm['ages'].className = 'fTextBoxDisabled';
		}
		else
		{
			oForm['ages'].disabled = false;
			oForm['ages'].className = 'fTextBoxDefault';
		}
	}
}

function __handle_project_category(data)
{
	var oForm = document.forms['projectForm'];
	
	if(oForm)
	{
		if(parseInt(data) > 0)
		{
			__toggle_buttons('disable','projectForm');
			
			oForm['category'].disabled = true;
			oForm['activity'].disabled = true;	
			
			jQuery.ajax
			(
				{
					type: 		"POST",
					url: 		"rpc.php?mode=list&xml=true",
					data: 		"mode=list&data=" + data,
					dataType:	"xml",
					
					success: function(xml)
					{
						__toggle_buttons('enable','projectForm');
						__remove_select_options('activity','projectForm');
						
						if(jQuery(xml).find('activity').size() > 0)
						{
							oForm['category'].disabled = false;
							oForm['activity'].disabled = false;
							
							oForm['activity'].options[oForm['activity'].options.length] = new Option('',0);
						
							jQuery(document.getElementById('row_activity')).show();
						
							jQuery(xml).find('activity').each
							(
								function()
								{
									oForm['activity'].options[oForm['activity'].options.length] = new Option(jQuery(this).text(),jQuery(this).attr('id'));
								}
							);
						}
						else
						{
							oForm['category'].disabled = false;
							oForm['activity'].disabled = true;
							
							jQuery(document.getElementById('row_activity')).hide();
						}
					}
				}
			);
		}
		else
		{
			__remove_select_options('activity','projectForm');
			
			jQuery(document.getElementById('row_activity')).hide();
		}
	}
}

function __date_time_example()
{
	var oForm = document.forms['projectForm'];
	
	if(oForm)
	{
		var example = "1. January 24, 2008, All Day\n2. 04/24/2008, 10:00 AM - 5:00 PM\n3. May 4th, 2007, 9:00";
		
		oForm['input'].value = oForm['datetime'].value;		
		oForm['datetime'].value = example;
		
		document.getElementById('dte').innerHTML = '<a href="" onclick="__revert_original_content(); return false;">revert</a>';
	}
}

function __revert_original_content()
{
	var oForm = document.forms['projectForm'];
	
	if(oForm)
	{
		oForm['datetime'].value = oForm['input'].value;
		
		document.getElementById('dte').innerHTML = 'see an <a href="" onclick="__date_time_example(); return false;">example</a>';
	}
}

function __create_project()
{
	var oForm = document.forms['projectForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'create';
		
		__toggle_buttons('disable','projectForm');
		
		oForm.submit();
	}
}

function __cancel_project()
{
	var oForm = document.forms['projectForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to CANCEL creating this project ? '))
		{
			oForm['mode'].value = 'cancel';
			
			__toggle_buttons('disable','projectForm');
			
			oForm.submit();
		}
	}
}

function __agree_disclaimer()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'agree';
		
		__toggle_buttons('disable','theForm');
		
		oForm.submit();
	}
}

function __disagree_disclaimer()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'disagree';
		
		__toggle_buttons('disable','theForm');
		
		oForm.submit();
	}
}

function __submit_contact_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		oForm['mode'].value = 'send';
		
		__toggle_buttons('disable','theForm');
		
		oForm.submit();
	}
}

function __reset_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to RESET this form ? '))
		{
			oForm.reset();	
		}
	}
}

function __submit_form(message,section)
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		if(section != null)
		{
			oForm['section'].value = section;	
		}
		
		if(message != null)
		{	
			if(confirm(message))
			{
				__toggle_buttons('disable','theForm');
			
				oForm.submit();
			}
		}
		else
		{
			__toggle_buttons('disable','theForm');
			
			oForm.submit();
		}
	}
}

function __submit_sponsoring_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		__toggle_buttons('disable','theForm');
		
		oForm['mode'].value = 'submit';
		
		oForm.submit();		
	}
}

function __cancel_sponsoring_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		__toggle_buttons('disable','theForm');
			
		oForm['mode'].value = 'cancel';
		
		oForm.submit();	
	}
}

function __submit_leader_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		__toggle_buttons('disable','theForm');
		
		oForm['mode'].value = 'create';
		
		oForm.submit();		
	}
}

function __cancel_leader_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to CANCEL creating your team leader profile ? '))
		{	
			__toggle_buttons('disable','theForm');
				
			oForm['mode'].value = 'cancel';
			
			oForm.submit();
		}
	}
}

function __cancel_form_submission(message,method,target)
{
	if(method == 'form')
	{
		var oForm = document.forms['theForm'];
		
		if(oForm)
		{
			if(message != null)
			{
				if(confirm(message))
				{
					__toggle_buttons('disable','theForm');
					
					oForm['mode'].value = target;
					oForm.submit();
				}
			}
			else
			{
				__toggle_buttons('disable','theForm');
					
				oForm['mode'].value = target;
				oForm.submit();
			}
		}
	}
	else if(method == 'location')
	{
		if(message != null)
		{
			if(confirm(message))
			{
				__toggle_buttons('disable','theForm');
				
				window.location.href = target;
			}
		}
		else
		{
			__toggle_buttons('disable','theForm');
				
			window.location.href = target;	
		}
	}
}

function __upload_user_photo()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to UPLOAD a new photo ? '))
		{
			__toggle_buttons('disable','theForm');
			
			oForm.encoding = "multipart/form-data";
			oForm['section'].value = 'photo';
			
			oForm.submit();
		}
	}
}

function __format_phone_number(string,target)
{
	string = string.replace(/[^\d]/g,'');
	newstring = "";
	
	if(string.length >= 3)
	{
		newstring += "(" + string.substr(0,3) + ")";
	}
	
	if(string.length > 3 && string.length >= 6)
	{
		newstring += " " + string.substr(3,3);
	}
	
	if(string.length > 6 && string.length >= 10)
	{
		newstring += "-" + string.substr(6,4);
	}
	
	if(string.length > 10)
	{
		newstring += " ext. " + string.substr(10,(string.length)-1);
	}
	
	target.value = newstring;
}

function __format_fax_number(string,target)
{
	string = string.replace(/[^\d]/g,'');
	newstring = "";
	
	if(string.length >= 3)
	{
		newstring += "(" + string.substr(0,3) + ")";
	}
	
	if(string.length > 3 && string.length >= 6)
	{
		newstring += " " + string.substr(3,3);
	}
	
	if(string.length > 6 && string.length >= 10)
	{
		newstring += "-" + string.substr(6,4);
	}
	
	target.value = newstring;
}

function __newsletter_signup()
{
	var oForm = document['footerForm'];	
	var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	
	if(oForm)
	{
		if(oForm['newsletter'].value.replace(/\s+/g,'').length > 0 && oForm['newsletter'].value.search(regexp) != -1)
		{
			__toggle_buttons('disable','footerForm');
			
			jQuery.ajax
			(
				{
					type: 		"POST",
					url: 		"rpc.php?mode=newsletter&xml=true",
					data: 		"mode=newsletter&data=" + oForm['newsletter'].value,
					dataType:	"xml",
					
					success: function(xml)
					{
						__toggle_buttons('enable','footerForm');
						
						if(jQuery(xml).find('response').size() > 0)
						{
							response = jQuery(xml).text();
							
							if(response == 'exists')
							{
								alert('You already signed up for our newsletter ! ');	
							}
							else if(response == 'success')
							{
								alert('Thank you for signing up for our newsletter ! ');
								
								oForm['newsletter'].value = '';
							}
							
							return false;
						}
					}
				}
			);
		}
		else
		{
			alert('Please enter valid email address ! ');
			
			oForm['newsletter'].focus();
			
			return false;
		}
	}
}

function __disable_enter_key(e)
{
	var key;

	if(window.event)
	{
		key = window.event.keyCode;
	}
	else
	{
		key = e.which; 
	}	
	
	if(key == 13)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function __toggle_checkboxes(entity,state)
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		for(i=0 ; i<oForm.elements.length ; i++)
		{
			if(oForm.elements[i].type == 'checkbox')
			{
				if(oForm.elements[i].name == entity && oForm.elements[i].disabled == false)
				{
					oForm.elements[i].checked = (state == 'on' ? true : false);
				}
			}
		}
	}
}

function __toggle_notification_checkboxes(entity,state)
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		for(i=0 ; i<oForm.elements.length ; i++)
		{
			if(oForm.elements[i].type == 'checkbox')
			{
				if(oForm.elements[i].name == entity)
				{
					oForm.elements[i].checked = (oForm.elements[i].alt == state ? true : false);
				}
			}
		}
	}	
}

function __approve_volunteer_request(data)
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to APPROVE this volunteer ? '))
		{
			__toggle_buttons('disable','theForm');
			
			oForm['mode'].value = 'approve';
			oForm['data'].value = data;
			
			oForm.submit();
		}
	}
}

function __reject_volunteer_request(data)
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		if(confirm('Are you sure you want to REJECT this volunteer ? '))
		{
			__toggle_buttons('disable','theForm');
			
			oForm['mode'].value = 'reject';
			oForm['data'].value = data;
			
			oForm.submit();
		}
	}
}

function __approve_checked_volunteers()
{
	var oForm = document.forms['theForm'];
	var index = 0;
	
	if(oForm)
	{
		for(i=0 ; i<oForm.elements.length ; i++)
		{
			if(oForm.elements[i].type == 'checkbox')
			{
				if(oForm.elements[i].name == 'requests[]' && oForm.elements[i].checked == true)
				{
					index++;
				}
			}
		}
		
		if(index > 0)
		{
			if(confirm('Are you sure you want to APPROVE all checked volunteers ? '))
			{
				__toggle_buttons('disable','theForm');
				
				oForm['mode'].value = 'approve_checked';
				
				oForm.submit();	
			}
		}
		else
		{
			alert('Please select AT LEAST one volunteer ! ');
			
			return false;
		}
	}
}

function __notify_checked_volunteers()
{
	var oForm = document.forms['theForm'];
	var selection = new Array;
	
	if(oForm)
	{
		for(i=0 ; i<oForm.elements.length ; i++)
		{
			if(oForm.elements[i].type == 'checkbox')
			{
				if(oForm.elements[i].name == 'requests[]' && oForm.elements[i].checked == true)
				{
					selection[selection.length] = oForm.elements[i].value;
				}
			}
		}
		
		if(selection.length > 0)
		{
			oForm['ids'].value = selection.join(',');
			
			for(i=0 ; i<oForm.elements.length ; i++)
			{
				if(oForm.elements[i].type == 'checkbox')
				{
					if(oForm.elements[i].name == 'requests[]')
					{
						oForm.elements[i].disabled = true;
					}
				}
			}
			
			jQuery(document.getElementById('options')).hide();
			jQuery(document.getElementById('email')).show();
			jQuery(document.getElementById('invisible')).show();
			
			oForm['subject'].focus();
		}
		else
		{
			alert('Please select AT LEAST one volunteer ! ');
			
			return false;
		}
	}
}

function __send_notifications()
{
	var oForm = document.forms['theForm'];
	var error = false;
	
	if(oForm)
	{
		if(oForm['subject'].value.replace(/\s+/g,'').length == 0)
		{
			error = true;
			
			alert('Please enter email subject ! ');
			oForm['subject'].focus();
		}
		
		else if(oForm['message'].value.replace(/\s+/g,'').length == 0)
		{
			error = true;
			
			alert('Please enter email message ! ');
			oForm['message'].focus();
		}
		
		if(!error)
		{
			if(confirm('Are you sure you want to SEND notifications to selected members ? '))
			{
				__toggle_buttons('disable','theForm');
				
				oForm['mode'].value = 'notify';
				
				oForm.submit();
			}
		}
		else
		{
			return false;	
		}
	}
}

function __cancel_notifications()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		__toggle_buttons('disable','theForm');
			
		window.location.href = 'membership-user-home.php#leadership';
	}
}