// ***************************************************
// Common javascript functions for WakingTheGiant
// Author: Andi Friedman
// Creation Date: 12-11-2005
// Last Modified: 12-11-2005 (Andi Friedman)

// Copyright: AMPT 2005
// ***************************************************

// -----------------------------------------------------------------------------------------------------------------------------------
// Function: selectField
// 
// Selects the text in the field passed.
// 
// Parameters:
//		fld_obj - field object
//
// Return value: none
// -----------------------------------------------------------------------------------------------------------------------------------

function selectField(fld_obj)
{
	if ( fld_obj.value == 'email address' || fld_obj.value == 'password' )
	{
		fld_obj.value = '';
	}
}
// -----------------------------------------------------------------------------------------------------------------------------------
function ClearSelection(objid)
{
	obj = document.getElementById(objid);
	obj.selectedIndex = -1;
}
// -----------------------------------------------------------------------------------------------------------------------------------

function validateRegistration(frm)
{
	// Call Generic Form Validation Before Checking
	if ( ValidateForm() == false)
		return false;
		
	
	/*if ( frm.first_name.value == '' )
	{
		alert("First name is a required field");
		return false;
	}
	
	if ( frm.last_name.value == '' )
	{
		alert("Last name is a required field");
		return false;
	}
	
	if ( frm.email_address.value == '' )
	{
		alert("Email Address is a required field");
		return false;
	}
	
	if ( frm.email_address.value.indexOf('@') == -1 )
	{
		alert("Email address is invalid");
		return false;
	}
	
	if ( frm.email_address.value.indexOf('.') == -1 )
	{
		alert("Email address is invalid");
		return false;
	}
	
	if ( frm.email_address.value.indexOf('@') > frm.email_address.value.lastIndexOf('.') )
	{
		alert("Email address is invalid");
		return false;
	}
	*/
	if ( frm.home_number.value == '' && frm.cell_number.value == '' )
	{
		alert("A home number or cell number is required");
		return false;
	}
	
	if ( frm.occupation.selectedIndex == frm.occupation.length - 1 && frm.otherprofession.value == '' )
	{
		alert("Please specify your profession");
		return false;
	}
	
	/*usertypes = document.getElementById("usertypes[]");
	if ( usertypes.selectedIndex == -1 )
	{
		alert("You must select at least one user type.  Use the CTRL key to select multiple user types");
		return false;
	}
	
	if ( frm.username.value.length < 5 )
	{
		alert("Invalid username.  Username must be at least 5 characters");
		return false;
	}
	
	if ( frm.password.value.length < 5 )
	{
		alert("Invalid password.  Passwords must be at least 5 characters");
		return false;
	}
	
	if ( frm.password.value != frm.confirm.value )
	{
		alert("Passwords do not match");
		return false;
	}*/
	
	if ( frm.password.value.toUpperCase() == frm.username.value.toUpperCase() )
	{
		alert("Your password cannot be the same as your username");
		return false;
	}
	
	if ( frm.password.value.toUpperCase() == frm.first_name.value.toUpperCase() )
	{
		alert("Your password cannot be the same as your first name");
		return false;
	}
	
	if ( frm.password.value.toUpperCase() == frm.last_name.value.toUpperCase())
	{
		alert("Your password cannot be the same as your last name");
		return false;
	}
	
	return true;
}

function validateUpdateProfile(frm)
{
	// Call Generic Form Validation Before Checking
	if ( ValidateForm() == false)
		return false;
	
	/*if ( frm.first_name.value == '' )
	{
		alert("First name is a required field");
		return false;
	}
	
	if ( frm.last_name.value == '' )
	{
		alert("Last name is a required field");
		return false;
	}
	
	if ( frm.email_address.value == '' )
	{
		alert("Email Address is a required field");
		return false;
	}*/
	
	if ( frm.home_number.value == '' && frm.cell_number.value == '' )
	{
		alert("A home number or cell number is required");
		return false;
	}
	
	if ( frm.password.value.length < 5 && frm.password.value.length != 0 )
	{
		alert("Invalid password (Minimum Length: 5 characters)");
		return false;
	}
	
	if ( frm.password.value != frm.confirm.value )
	{
		alert("Passwords do not match");
		return false;
	}
	

	return true;
}


// The followiong function catches a backspace key event to prevent users accidentally pressing backspace
document.onkeydown = keyCatcher;

function keyCatcher() 
{
var e = event.srcElement.tagName;

if (event.keyCode == 8 && e != "INPUT" && e != "TEXTAREA") 
{
	event.cancelBubble = true;
	event.returnValue = false;
}
}
