// Madgex Limited
// Copyright (c) 2004 Madgex Limited. All Rights Reserved.
// Jobs Validation - Core Components Project
// 12 August 2004
// Version 1.0.0

function ValidateJobApplication()
{

	var sTitle = document.ApplyOnline.sTitle.value.Trim();
	var sFirstName = document.ApplyOnline.sFirstName.value.Trim();
	var sLastName = document.ApplyOnline.sLastName.value.Trim();
	var sEmailAddress = document.ApplyOnline.sEmailAddress.value.Trim();
	var sMessage = document.ApplyOnline.sCoverMessage.value.Trim();
	
	if ( sTitle == '' )
	{
		alert( "You must enter a title (eg Mr, Mrs, Ms etc)" );
		document.ApplyOnline.sTitle.focus();
		document.ApplyOnline.sTitle.select();
		return false;	
	}
	
	if ( sFirstName == '' )
	{
		alert( "You must enter a first name" );
		document.ApplyOnline.sFirstName.focus();
		document.ApplyOnline.sFirstName.select();
		return false;	
	}
	
	if ( sLastName == '' )
	{
		alert( "You must enter a last name" );
		document.ApplyOnline.sLastName.focus();
		document.ApplyOnline.sLastName.select();
		return false;	
	}
	
	if ( sEmailAddress == '' )
	{
		alert( "You must enter an email address" );
		document.ApplyOnline.sEmailAddress.focus();
		document.ApplyOnline.sEmailAddress.select();
		return false;	
	}
	
	if ( !CheckValidEmail(sEmailAddress) )
	{
		alert( "Invalid email address" );
		document.ApplyOnline.sEmailAddress.focus();
		document.ApplyOnline.sEmailAddress.select();
		return false;	
	}
	
	if ( sMessage == '' )
	{
		alert( "You must support your application with a covering note" );
		document.ApplyOnline.sCoverMessage.focus();
		document.ApplyOnline.sCoverMessage.select();
		return false;	
	}	
	
	//loop through each form element
	for(var i = 0; i < document.ApplyOnline.elements.length; i++)
	{
		var e = document.ApplyOnline.elements[i];
		var chbxname ="";
		var sum = 0;
		var sother="";
		
		//checking for radio type
		if(e.type == "radio")
		{
			chbxname = e.name;
			if (document.ApplyOnline.elements[chbxname].length != null)
			{
				if (chbxname.substring(0, 2) == 'SQ')
				{
					sum = 0;
					for ( var k=0; k < document.ApplyOnline.elements[chbxname].length; k++ )
					{
						if ( document.ApplyOnline.elements[chbxname][k].checked==true )
							sum ++;
					}
					if(sum == 0)
					{	
						alert( "You must answer all the screening questions" );
						e.focus();
						return false;	
					}
				}
			}
		}
	}
	
	return true;
}


function ValidatePostAJob()
{

	var sJobTitle = document.TCLJobForm.sTitle.value.Trim();
	var sDescription = document.TCLJobForm.sDescription.value.Trim();
	var sJobRef = document.TCLJobForm.sJobRef.value.Trim();
	var sPackage = document.TCLJobForm.sPackage.value.Trim();
	var sRecruiterName = document.TCLJobForm.sRecruiterName.value.Trim();
	var sJobContactFirstName = document.TCLJobForm.sJobContactFirstName.value.Trim();
	var sJobContactLastName = document.TCLJobForm.sJobContactLastName.value.Trim();
	
	if ( sJobTitle == '' )
	{
		alert( "You must enter a job title" );
		document.TCLJobForm.sTitle.focus();
		document.TCLJobForm.sTitle.select();
		return false;	
	}
	
	if ( sDescription == '' )
	{
		alert( "You must enter a job description" );
		document.TCLJobForm.sDescription.focus();
		document.TCLJobForm.sDescription.select();
		return false;	
	}
	
	if ( sJobRef == '' )
	{
		alert( "You must enter a job reference" );
		document.TCLJobForm.sJobRef.focus();
		document.TCLJobForm.sJobRef.select();
		return false;	
	}
	
	if ( sPackage == '' )
	{
		alert( "You must enter a job package" );
		document.TCLJobForm.sPackage.focus();
		document.TCLJobForm.sPackage.select();
		return false;	
	}
	
	if ( sRecruiterName == '' )
	{
		alert( "You must enter a company name" );
		document.TCLJobForm.sRecruiterName.focus();
		document.TCLJobForm.sRecruiterName.select();
		return false;	
	}
	
	if ( sJobContactFirstName == '' )
	{
		alert( "You must enter a contact first name" );
		document.TCLJobForm.sJobContactFirstName.focus();
		document.TCLJobForm.sJobContactFirstName.select();
		return false;	
	}
	
	if ( sJobContactLastName == '' )
	{
		alert( "You must enter a contact last name" );
		document.TCLJobForm.sJobContactLastName.focus();
		document.TCLJobForm.sJobContactLastName.select();
		return false;	
	}
}

function ValidateEmailAlert()
{
	var sJobAlertTitle = document.AddEmailAlert.sJobAlertTitle.value.Trim();
	var sEmailAddress = document.AddEmailAlert.sEmailAddress.value.Trim();
	
	if ( sJobAlertTitle == '' )
	{
		alert( "You must enter a job alert title" );
		document.AddEmailAlert.sJobAlertTitle.focus();
		document.AddEmailAlert.sJobAlertTitle.select();
		return false;	
	}
	
	if ( sEmailAddress == '' )
	{
		alert( "You must enter an email address" );
		document.AddEmailAlert.sEmailAddress.focus();
		document.AddEmailAlert.sEmailAddress.select();
		return false;	
	}
	
	if ( !CheckValidEmail(sEmailAddress) )
	{
		alert( "Invalid email address" );
		document.AddEmailAlert.sEmailAddress.focus();
		document.AddEmailAlert.sEmailAddress.select();
		return false;	
	}
}

function ValidateJobSeekerProfile()
{
	var sName = document.JobSeekerProfile.sName.value.Trim();
	var sFirstName = document.JobSeekerProfile.sFirstName.value.Trim();
	var sLastName  = document.JobSeekerProfile.sLastName.value.Trim();
	var jobTypes   = document.JobSeekerProfile.PreferredJobTypes;
	
	if ( sName == '' )
	{
		alert( "You must enter a profile name" );
		document.JobSeekerProfile.sName.focus();
		document.JobSeekerProfile.sName.select();
		return false;	
	}
	
	if ( sFirstName == '' )
	{
		alert( "You must enter your firstname" );
		document.JobSeekerProfile.sFirstName.focus();
		document.JobSeekerProfile.sFirstName.select();
		return false;	
	}

	if ( sLastName == '' )
	{
		alert( "You must enter your lastname" );
		document.JobSeekerProfile.sLastName.focus();
		document.JobSeekerProfile.sLastName.select();
		return false;	
	}
	
	if (jobTypes.selectedIndex == -1)
	{
		alert( "You must select at least one preferred job type" );
		jobTypes.focus();
		return false;	
	}
}
/* Used by Jobs Search */
function AddJobsExternalClick(pageName, contentGroups)
{
	_hbSet('n', pageName);
	_hbSet('vcon', contentGroups);
	_hbSend();
}


function deleteJobSeekerProfile()
{
	var msg;
	
	msg = "Are you sure you want to delete your profile?";
	if (confirm(msg)) {
		document.location.href = "Profile.aspx?bDelete=true";
	}
}
