function __login(form)
{
	var oForm = document.forms[form];
	
	if(oForm)
	{
		oForm['mode'].value = 'login';
	}
}

function __activate(form)
{
	var oForm = document.forms[form];
	
	if(oForm)
	{
		oForm['mode'].value = 'activate';
	}
}

function __send_password_recovery_email(form)
{
	var oForm = document.forms[form];
	
	if(oForm)
	{
		oForm['mode'].value = 'lookup';
	}	
}

function __reset_password(form)
{
	var oForm = document.forms[form];
	
	if(oForm)
	{
		oForm['mode'].value = 'reset';
	}	
}

function __handle_email_address_focus()
{
	var oForm = document.forms['loginForm'];
	
	if(oForm)
	{
		if(oForm['email'].value == 'email address')
		{
			oForm['email'].value = '';	
		}
	}
}

function __handle_email_address_blur()
{
	var oForm = document.forms['loginForm'];
	
	if(oForm)
	{
		if(oForm['email'].value == '')
		{
			oForm['email'].value = 'email address';	
		}
	}
}

function __toggle_buttons(state,form)
{
	var oForm = document.forms[form];
	
	if(oForm)
	{
		for(i=0 ; i<oForm.elements.length ; i++)
		{
			if(oForm.elements[i].type == 'button' || oForm.elements[i].type == 'submit' || oForm.elements[i].type == 'submit' || oForm.elements[i].type == 'image')
			{
				oForm.elements[i].disabled = (state == 'disabled' ? true : false);	
			}
		}	
	}
}

function __submit_contact_form()
{
	var oForm = document.forms['theForm'];
	
	if(oForm)
	{
		var error = false;
		var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		
		if(oForm['firstname'].value.replace(/\s+/g,'').length == 0)
		{
			error = true;
			
			alert('Please enter first name ! ');
			oForm['firstname'].focus();
		}
		else if(oForm['lastname'].value.replace(/\s+/g,'').length == 0)
		{
			error = true;
			
			alert('Please enter last name ! ');
			oForm['lastname'].focus();
		}
		else if(oForm['email'].value.replace(/\s+/g,"").length == 0)
		{
			error = true;
			
			alert('Please enter email address ! ');
			oForm['email'].focus();
		}
		else if(oForm['email'].value.search(regexp) == -1)
		{
			error = true;
			
			alert('Please enter a valid email address ! ');
			oForm['email'].focus();
		}
		
		if(error)
		{
			return false;
		}
		else
		{
			__toggle_buttons('disable','theForm');
			
			oForm['mode'].value = 'submit';
			oForm.submit();							
		}	
	}
}

function __format_phone_number(phone,target)
{
	phone = phone.replace(/[^\d]/g,'');
	string = "";
	
	if(phone.length >= 3)
	{
		string += "(" + phone.substr(0,3) + ")";
	}
	
	if(phone.length > 3 && phone.length >= 6)
	{
		string += " " + phone.substr(3,3);
	}
	
	if(phone.length > 6 && phone.length >= 10)
	{
		string += "-" + phone.substr(6,4);
	}
	
	if(phone.length > 10)
	{
		string += " ext. " + phone.substr(10,(phone.length)-1);
	}
	
	target.value = string;
}

function __format_fax_number(fax,target)
{
	fax = fax.replace(/[^\d]/g,'');
	string = "";
	
	if(fax.length >= 3)
	{
		string += "(" + fax.substr(0,3) + ")";
	}
	
	if(fax.length > 3 && fax.length >= 6)
	{
		string += " " + fax.substr(3,3);
	}
	
	if(fax.length > 6 && fax.length >= 10)
	{
		string += "-" + fax.substr(6,4);
	}
	
	target.value = string;
}

function __toggle_user(id)
{
	if(document.getElementById('i' + id))
	{
		if(document.getElementById('i' + id).className == 'details hidden')
		{
			document.getElementById('i' + id).className = 'details visible';
		}
		else
		{
			document.getElementById('i' + id).className = 'details hidden';	
		}
	}
}