////////////////////////////////////////////////////////////////////////////////
//   Script Name: js_functions.js
//        Author: Randy Carlson
//          Desc: Global JavaScript functions
//  Date Created: 8/12/03
// Date Modified: 
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
// ValidateLogin(form)
//   Validates the information submitted in the Admin Login screen
////////////////////////////////////////////////////////////////////////////////
function ValidateLogin(formObj)	{
	if (emptyField(formObj.Username))		{
		alert("Please enter a value for the Username.");
		formObj.Username.focus();
		return false;
	}	else if (emptyField(formObj.Password))		{
			alert("Please enter a value for the Password.");
			formObj.Password.focus();
			return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateJob(form)
//   Validates the information submitted in the Create/Edit Job screen
////////////////////////////////////////////////////////////////////////////////
function ValidateJob(formObj)	{
	if (emptyField(formObj.JobPostDate))		{
		alert("Please enter a value for the Post Date.");
		formObj.JobPostDate.focus();
		return false;
	}	else if (emptyField(formObj.JobRecruiterID))		{
		alert("Please enter a recruiter.");
		formObj.JobRecruiterID.focus();
		return false;
	}	else if (emptyField(formObj.JobEmailList))		{
		alert("Please enter an email address to send resumes to.");
		formObj.JobEmailList.focus();
		return false;
	}	else if (emptyField(formObj.JobTitle))		{
		alert("Please enter a value for the Job Title.");
		formObj.JobTitle.focus();
		return false;
	}	else if (emptyField(formObj.JobDeptID))		{
		alert("Please enter a value for the Job Department.");
		formObj.JobDeptID.focus();
		return false;
	}	else if (emptyField(formObj.JobTypeID))		{
		alert("Please enter a value for the Job Type.");
		formObj.JobTypeID.focus();
		return false;
	}	else if (emptyField(formObj.JobCity) || emptyField(formObj.JobState))		{
			if (emptyField(formObj.JobOtherLocation))	{
				alert("You must either enter a City/State combination or enter a value for Other Location.");
				formObj.JobCity.focus();
				return false;
			}	else	{
				return true;
			}
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateJobArea(form)
//   Validates the information submitted in the CreateEdit Job Area screen
////////////////////////////////////////////////////////////////////////////////
function ValidateJobArea(formObj)	{
	if (emptyField(formObj.JobArea))		{
		alert("Please enter a value for the Job Area.");
		formObj.JobArea.focus();
		return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateJobDept(form)
//   Validates the information submitted in the CreateDept screen
////////////////////////////////////////////////////////////////////////////////
function ValidateJobDept(formObj)	{
	if (emptyField(formObj.JobDepartment))		{
		alert("Please enter a value for the Job Department.");
		formObj.JobDepartment.focus();
		return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateJobType(form)
//   Validates the information submitted in the CreateDept screen
////////////////////////////////////////////////////////////////////////////////
function ValidateJobType(formObj)	{
	if (emptyField(formObj.JobType))		{
		alert("Please enter a value for the Job Type.");
		formObj.JobType.focus();
		return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateUserInfo(form)
//   Validates the information submitted in the Create User screen
////////////////////////////////////////////////////////////////////////////////
function ValidateUserInfo(formObj)	{
	if (emptyField(formObj.Username))		{
		alert("Please enter a value for the Username.");
		formObj.Username.focus();
		return false;
	}	else if (emptyField(formObj.Password))		{
		alert("Please enter a value for the Password.");
		formObj.Password.focus();
		return false;
	}	else if (emptyField(formObj.SecurityLevel))		{
		alert("Please enter a value for the Security Level.");
		formObj.SecurityLevel.focus();
		return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateRecruiter(form)
//   Validates the information submitted in the Create Recruiter screen
////////////////////////////////////////////////////////////////////////////////
function ValidateRecruiter(formObj)	{
	if (emptyField(formObj.RecruiterFirstName))		{
		alert("Please enter a value for the Recruiter First Name.");
		formObj.RecruiterFirstName.focus();
		return false;
	}	else if (emptyField(formObj.RecruiterLastName))		{
		alert("Please enter a value for the Recruiter Last Name.");
		formObj.RecruiterLastName.focus();
		return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateApplicant(form)
//   Validates the information submitted in the Apply For job Screen
////////////////////////////////////////////////////////////////////////////////
function ValidateApplicant(formObj)	{
	if (emptyField(formObj.FirstName))		{
		alert("Please enter a value for the First Name.");
		formObj.FirstName.focus();
		return false;
	}	else if (emptyField(formObj.LastName))		{
			alert("Please enter a value for the Last Name.");
			formObj.LastName.focus();
			return false;
	}	else if (emptyField(formObj.Address1))		{
			alert("Please enter a value for the Address Line 1.");
			formObj.Address1.focus();
			return false;
	}	else if (emptyField(formObj.City))		{
			alert("Please enter a value for the City.");
			formObj.City.focus();
			return false;
	}	else if (emptyField(formObj.State))		{
			alert("Please enter a value for the State.");
			formObj.State.focus();
			return false;
	}	else if (emptyField(formObj.Zip))		{
			alert("Please enter a value for the Zip.");
			formObj.Zip.focus();
			return false;
	}	else if (emptyField(formObj.HomePhone))		{
			alert("Please enter a value for the Home Phone.");
			formObj.HomePhone.focus();
			return false;
	}	else if (emptyField(formObj.Salary))		{
			alert("Please enter a value for the Salary Requirements.");
			formObj.Salary.focus();
			return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// ValidateEmail(form)
//   Validates the information submitted in the Send a friend page
////////////////////////////////////////////////////////////////////////////////
function ValidateEmail(formObj)	{
	if (emptyField(formObj.EmailTo))		{
		alert("Please enter a value to Send this job to.");
		formObj.EmailTo.focus();
		return false;
	}	else if (emptyField(formObj.EmailFrom))		{
			alert("Please enter a value for your email address.");
			formObj.EmailFrom.focus();
			return false;
	}	else	{
		return true;
	}
	return false;
}	

////////////////////////////////////////////////////////////////////////////////
// emptyField(obj)
//   Checks to see if the field passed to the function was empty or not
////////////////////////////////////////////////////////////////////////////////
function emptyField(textObj)	{
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; i++)	{
		var ch = textObj.value.charAt(i);
			if (ch != '' && ch != '\t') return false;		
	}
	return true;	
}

// Opens a new window
function OpenWindow(URL, WindowName, Toolbar, Menubar, Status, Scrollbar, Resize, Width, Height)	{
	var NewWindow;
	var Properties;
	
	Properties = "toolbar=" + Toolbar + ",menubar=" + Menubar + ",status=" + Status + ",scrollbars=" + Scrollbar + ",resizable=" + Resize + ",width=" + Width + ",height=" + Height;
	NewWindow = window.open(URL, WindowName, Properties);
	if (NewWindow.focus)	{
		NewWindow.focus;
		NewWindow.moveTo(100,100);
	}
}