function enterLogin(fieldName, eventName)
{
	var keyValue;
	if(window.event)
	{
		keyValue = window.event.keyCode;
	}
	else if(eventName)
	{
		keyValue = eventName.which;
	}
   
	if(keyValue == 13)
	{
		processLogin();
	}
}

function urlencode(str)
{
	var ret = str;
	ret = ret.toString();
	ret = encodeURIComponent(ret);
	ret = ret.replace(/%20/g, '+');
	return ret;
}

function hideWarning(optionalRedirect)
{
	setTimeout("popOutDiscreet('WARNING')", 4000);
	
	if((optionalRedirect != undefined) && (optionalRedirect != ''))
	{
		setTimeout("window.location='" + optionalRedirect + "'", 4500);
	}
}

function reportPrompt(commentId)
{
	$("input[name='reportCommentId']").attr('value', commentId);
	
	popIn('REPORT', '120px', '-280px');
}

function reportComment()
{
	var Integer_CommentID = $("input[name='reportCommentId']").attr('value');
	
	$("#REPORT").load("process_reportcomment.php", { commentId: Integer_CommentID } );
	
	setTimeout("popOut('REPORT')", 2500);
}

function saveComment(commentMode)
{
	var Integer_TopicID = $("input[name='topicId']").attr('value');
	var String_TopicSubject = $("input[name='topicSubject']").attr('value');
	var String_CommentSubject = $("input[name='commentSubject']").attr('value');
	var String_CommentContents = $("textarea[name='commentContents']").attr('value');
	var String_PosterName = $("input[name='posterName']").attr('value');
	
	if(commentMode == 'Public')
	{
		var String_PosterMail = $("input[name='posterMail']").attr('value');
	}
	else
	{
		var String_PosterMail = 'False';
	}
	
	$("#ADDCOMMENT").load("process_addcomment.php", { topicId: Integer_TopicID, commentSubject: String_CommentSubject, commentContents: String_CommentContents, posterName: String_PosterName, posterMail: String_PosterMail } );

	if(commentMode == 'LoggedIn')
	{
		setTimeout("window.location='blog.php?Topic=" + String_TopicSubject + "'", 2500);
	}
}

function changeColor(obj)
{
	obj.style.color = '#6F81C2';
}

function changeCard(Id)
{
	var cardElement = document.getElementById('CARDIMG');
	cardElement.src = 'images/cards/' + Id + '.gif';
}

function loadHtml(elementId, processScript)
{
	try{
		$("#" + elementId).load(processScript);
	}catch(err){
	}
}

function searchPersonnel(sortOrder, pageNumber)
{
	document.searchFilters.action = 'search_personnel.php?fo=' + sortOrder + '&p=' + pageNumber;
	document.searchFilters.submit();
}


function searchVacancies(sortOrder, pageNumber)
{
	document.searchFilters.action = 'search_vacancies.php?fo=' + sortOrder + '&p=' + pageNumber;
	document.searchFilters.submit();
}

function processLogin()
{
	// Process Login
	document.userLogin.action = 'process_login.php';
	document.userLogin.submit();
}

function processRegistration()
{
	var validated = true;
	var validateError = '';
	
	// Check For Applicant Registration
	if((document.userRegistration.applicantFirstName.value != '')&&(document.userRegistration.applicantFirstName.value != 'First Name'))
	{
		// Check Applicant Fields
		if((document.userRegistration.applicantLastName.value == '')||(document.userRegistration.applicantLastName.value == 'Last Name')) { validated = false; validateError = 'You have not given a last name'; }
		if((document.userRegistration.applicantEmail.value == '')||(document.userRegistration.applicantEmail.value == 'E-Mail')) { validated = false; validateError = 'You have not given an e-mail address'; }
	}

	// Check For Recruiter Registration
	if((document.userRegistration.recruiterFirstName.value != '')&&(document.userRegistration.recruiterFirstName.value != 'First Name'))
	{
		// Check Recruiter Fields
		if((document.userRegistration.recruiterLastName.value == '')||(document.userRegistration.recruiterLastName.value == 'Last Name')) { validated = false; validateError = 'You have not given a last name'; }
		if((document.userRegistration.recruiterCompany.value == '')||(document.userRegistration.recruiterCompany.value == 'Company')) { validated = false; validateError = 'You have not given a company name'; }
		if((document.userRegistration.recruiterEmail.value == '')||(document.userRegistration.recruiterEmail.value == 'E-Mail')) { validated = false; validateError = 'You have not given an e-mail address'; }
	}
	
	// Neither
	if(((document.userRegistration.recruiterFirstName.value == 'First Name')||(document.userRegistration.recruiterFirstName.value == ''))&&((document.userRegistration.applicantFirstName.value == 'First Name')||(document.userRegistration.applicantFirstName.value == '')))
	{
		validated = false;
		validateError = 'You have not given a first name';
	}
	
	// Check Password
	if((document.userRegistration.applicantPassword.value != 'Password') && (document.userRegistration.applicantPasswordConfirm.value != 'Re-Enter Password'))
	{
		if(document.userRegistration.applicantPasswordConfirm.value != document.userRegistration.applicantPassword.value)
		{
			// Passwords Don't Match
			document.userRegistration.applicantPassword.value = 'Password';
			document.userRegistration.applicantPasswordConfirm.value = 'Re-Enter Password';
			validated = false;
			validateError = 'Your confirmation password does not match';
		}
		if(document.userRegistration.applicantPassword.length < 5)
		{
			document.userRegistration.applicantPassword.value = 'Password';
			document.userRegistration.applicantPasswordConfirm.value = 'Re-Enter Password';
			validated = false;
			validateError = 'Please use a password of at least 5 characters';
		}
	}
	else if((document.userRegistration.recruiterPassword.value != 'Password') && (document.userRegistration.recruiterPasswordConfirm.value != 'Re-Enter Password'))
	{
		if(document.userRegistration.recruiterPasswordConfirm.value != document.userRegistration.recruiterPassword.value)
		{
			// Passwords Don't Match
			document.userRegistration.recruiterPassword.value = 'Password';
			document.userRegistration.recruiterPasswordConfirm.value = 'Re-Enter Password';
			validated = false;
			validateError = 'Your confirmation password does not match';
		}
		if(document.userRegistration.recruiterPassword.length < 5)
		{
			document.userRegistration.recruiterPassword.value = 'Password';
			document.userRegistration.recruiterPasswordConfirm.value = 'Re-Enter Password';
			validated = false;
			validateError = 'Please enter a password of at least 5 characters';
		}
	}
	else
	{
		// No Password Entered
		validated = false;
		validateError = 'Please enter a password of at least 5 characters';
	}
	
	if(validated == true)
	{
		document.userRegistration.action = 'process_registration.php';
		document.userRegistration.submit();
	}
	else
	{
		// Notify
		alert(validateError);
	}
}

function sendEnquiry()
{
	// Get Element And Message
	obj = document.getElementById('ENQUIRY');
	var enquiryText = urlencode(document.getElementById('MESSAGE').value);

	// Set Background To Loader
	obj.innerHTML = '<img src="images/background_popup_contact_process.png" style="width: 580px; height: 310px;" alt="" />';

	// Send Data To Processor
	loadHtml('ENQUIRY','process_enquiry.php?enquiryText=' + enquiryText);
	
	setTimeout("popOut('ENQUIRY')", 5000);
}




function sendExpertQuestion()
{
	// Get Element And Question
	obj = document.getElementById('EXPERTQUESTION');
	var questionText = urlencode(document.getElementById('QUESTION').value);
	
	// Set Loading Content
	obj.innerHTML = '<p><strong>Please wait...</strong></p>';

	// Send Data To Processor
	loadHtml('EXPERTQUESTION','process_expertquestion.php?questionText=' + questionText);
}

function sendTopicSuggestion()
{
	// Get Element And Suggestion
	obj = document.getElementById('TOPICSUGGESTION');
	var suggestionText = urlencode(document.getElementById('SUGGESTION').value);

	// Set Loading Content
	obj.innerHTML = '<p><strong>Please wait...</strong></p>';

	// Send Data To Processor
	loadHtml('TOPICSUGGESTION','process_topicsuggestion.php?suggestionText=' + suggestionText);
}



function sendVacancyEnquiry(sortOrder, pageNumber, vacancyId)
{
	// Get Element
	obj = document.getElementById('VACANCYENQUIRY');
	
	// Get Values
	var Enquiry = document.vacancyEnquiry.Enquiry.value;

	if(document.vacancyEnquiry.Check_ShareProfile.checked)
	{ var Check_ShareProfile = 'True'; } else { var Check_ShareProfile = 'False'; }
	

	// Set Background To Loader
	obj.innerHTML = '<img src="images/background_popup_enquiry_process.png" style="width: 580px; height: 450px;" alt="" />';

	// Send Data To Processor
	loadHtml('VACANCYENQUIRY','process_vacancyenquiry.php?enq=' + escape(Enquiry) + '&shr=' + Check_ShareProfile + '&vid=' + vacancyId);


	setTimeout("searchVacancies(" + sortOrder + ", " + pageNumber + ")", 5000);
}


function sendApplicantEnquiry(sortOrder, pageNumber, applicantId)
{
	// Get Element
	obj = document.getElementById('APPLICANTENQUIRY');

	// Get Values
	var Enquiry = document.applicantEnquiry.Enquiry.value;

	if(document.applicantEnquiry.Check_ShareProfile.checked)
	{ var Check_ShareProfile = 'True'; } else { var Check_ShareProfile = 'False'; }


	// Set Background To Loader
	obj.innerHTML = '<img src="images/background_popup_enquiry_process.png" style="width: 580px; height: 450px;" alt="" />';

	// Send Data To Processor
	loadHtml('APPLICANTENQUIRY','process_applicantenquiry.php?enq=' + escape(Enquiry) + '&shr=' + Check_ShareProfile + '&aid=' + applicantId);


	setTimeout("searchPersonnel(" + sortOrder + ", " + pageNumber + ")", 5000);
}


function sendReplyToEnquiry(messageId)
{
	// Get Element
	obj = document.getElementById('REPLYTOENQUIRY');

	// Get Values
	var Enquiry = document.replyToEnquiry.Enquiry.value;

	if(document.replyToEnquiry.Check_ShareProfile.checked)
	{ var Check_ShareProfile = 'True'; } else { var Check_ShareProfile = 'False'; }


	// Set Background To Loader
	obj.innerHTML = '<img src="images/background_popup_enquiry_process.png" style="width: 580px; height: 450px;" alt="" />';

	// Send Data To Processor
	loadHtml('REPLYTOENQUIRY','process_replytoenquiry.php?enq=' + escape(Enquiry) + '&shr=' + Check_ShareProfile + '&msgid=' + messageId);


	setTimeout("popOut('REPLYTOENQUIRY')", 5000);
}


function updateNotificationPreferences()
{
	// Get Element
	obj = document.getElementById('NOTIFICATIONPREFERENCES');

	// Get Variables
	if(document.notificationPreferences.Check_Messages.checked)
	{ var Check_Messages = 'True'; } else { var Check_Messages = 'False'; }
	
	if(document.notificationPreferences.Check_Suggestions.checked)
	{ var Check_Suggestions = 'True'; } else { var Check_Suggestions = 'False'; }
	
	if(document.notificationPreferences.Check_Offers.checked)
	{ var Check_Offers = 'True'; } else { var Check_Offers = 'False'; }
	
	if(document.notificationPreferences.Check_Credits != null)
	{
		if(document.notificationPreferences.Check_Credits.checked)
		{ var Check_Credits = 'True'; } else { var Check_Credits = 'False'; }
	}
	
	// Set Background To Loader
	obj.innerHTML = '<img src="images/background_popup_notificationpreferences_process.png" style="width: 580px; height: 340px;" alt="" />';

	// Send Data To Processor	
	loadHtml('NOTIFICATIONPREFERENCES','process_notificationpreferences.php?Check_Messages=' + Check_Messages + '&Check_Suggestions=' + Check_Suggestions + '&Check_Offers=' + Check_Offers + '&Check_Credits=' + Check_Credits);
	
	setTimeout("popOut('NOTIFICATIONPREFERENCES')", 5000);
}


function updateProfile(pageRef)
{
	document.workProfile.action = 'process_workprofileupdate.php?ps=' + pageRef;
	document.workProfile.submit();
}


function updateRecruiterProfile()
{
	// Get Element
	obj = document.getElementById('RECRUITERPROFILE');

	// Get Values
	var Title = document.recruiterProfile.Title.value;
	var FirstName = document.recruiterProfile.FirstName.value;
	var LastName = document.recruiterProfile.LastName.value;
	var Company = document.recruiterProfile.Company.value;
	var Email = document.recruiterProfile.Email.value;
	var Building = document.recruiterProfile.Building.value;
	var Street = document.recruiterProfile.Street.value;
	var City = document.recruiterProfile.City.value;
	var County = document.recruiterProfile.County.value;
	var Postcode = document.recruiterProfile.Postcode.value;
	var Telephone = document.recruiterProfile.Telephone.value;
	var Mobile = document.recruiterProfile.Mobile.value;
	var Fax = document.recruiterProfile.Fax.value;
	var NewPassword = document.recruiterProfile.NewPassword.value;
	
	
	// Check Password Where Entered
	if((document.recruiterProfile.NewPassword.value != 'Password') && (document.recruiterProfile.NewPassword.value != 'Error - Re-Enter Password'))
	{
		if(document.recruiterProfile.NewPassword.value != document.recruiterProfile.NewPasswordConfirm.value)
		{
			// Passwords Don't Match
			document.recruiterProfile.NewPassword.value = 'Error - Re-Enter Password';
			document.recruiterProfile.NewPasswordConfirm.value = 'Error - Re-Enter Password';
			var validated = 'False';
		}
		else
		{
			var validated = 'True';
		}
	}
	else
	{
		var validated = 'True';
	}

	// Submit Data
	if(validated == 'True')
	{
		// Set Background To Loader
		obj.innerHTML = '<img src="images/background_popup_profile_process.png" style="width: 580px; height: 530px;" alt="" />';
   		var targetURL = 'process_profileupdate.php?FirstName=' + escape(FirstName) + '&LastName=' + escape(LastName) + '&Title=' + escape(Title) + '&Company=' + escape(Company) + '&Email=' + escape(Email) + '&Building=' + escape(Building) + '&Street=' + escape(Street) + '&City=' + escape(City) + '&County=' + escape(County) + '&Postcode=' + escape(Postcode) + '&Telephone=' + escape(Telephone) + '&Mobile=' + escape(Mobile) + '&Fax=' + escape(Fax) + '&Password=' + escape(NewPassword);
		
		// Send Data To Processor
		loadHtml('RECRUITERPROFILE', targetURL);
   
		setTimeout("popOut('RECRUITERPROFILE')", 5000);
	}
	
}


function updateApplicantProfile()
{
	// Get Element
	obj = document.getElementById('APPLICANTPROFILE');

	// Get Values
	var Title = document.applicantProfile.Title.value;
	var FirstName = document.applicantProfile.FirstName.value;
	var LastName = document.applicantProfile.LastName.value;
	var Gender = document.applicantProfile.Select_Gender.value;
	var Email = document.applicantProfile.Email.value;
	var Building = document.applicantProfile.Building.value;
	var Street = document.applicantProfile.Street.value;
	var City = document.applicantProfile.City.value;
	var County = document.applicantProfile.County.value;
	var Postcode = document.applicantProfile.Postcode.value;
	var Telephone = document.applicantProfile.Telephone.value;
	var Mobile = document.applicantProfile.Mobile.value;
	var BirthDate = document.applicantProfile.BirthDate.value;
	var NewPassword = document.applicantProfile.NewPassword.value;


	// Check Password Where Entered
	if((document.applicantProfile.NewPassword.value != 'Password') && (document.applicantProfile.NewPassword.value != 'Error - Re-Enter Password'))
	{
		if(document.applicantProfile.NewPassword.value != document.applicantProfile.NewPasswordConfirm.value)
		{
			// Passwords Don't Match
			document.applicantProfile.NewPassword.value = 'Error - Re-Enter Password';
			document.applicantProfile.NewPasswordConfirm.value = 'Error - Re-Enter Password';
			var validated = 'False';
		}
		else
		{
			var validated = 'True';
		}
	}
	else
	{
		var validated = 'True';
	}



	// Submit Data
	if(validated == 'True')
	{
		// Set Background To Loader
		obj.innerHTML = '<img src="images/background_popup_profile_process.png" style="width: 580px; height: 530px;" alt="" />';
		var targetURL = 'process_profileupdate.php?FirstName=' + escape(FirstName) + '&LastName=' + escape(LastName) + '&Title=' + escape(Title) + '&Gender=' + escape(Gender) + '&Email=' + escape(Email) + '&Building=' + escape(Building) + '&Street=' + escape(Street) + '&City=' + escape(City) + '&County=' + escape(County) + '&Postcode=' + escape(Postcode) + '&Telephone=' + escape(Telephone) + '&Mobile=' + escape(Mobile) + '&BirthDate=' + escape(BirthDate) + '&Password=' + escape(NewPassword);

		// Send Data To Processor
		loadHtml('APPLICANTPROFILE', targetURL);

		setTimeout("popOut('APPLICANTPROFILE')", 5000);
	}

}


function popIn(divId, yoff, xoff)
{
	var targetId = divId;
	var targetElement = document.getElementById(targetId);
	targetElement.style.visibility = "visible";
	// targetElement.style.position = "fixed";
	// targetElement.style.top = "10%";
	

	if(xoff != null)
	{
		targetElement.style.marginLeft = xoff;
	}
/*
	if(yoff != null)
	{
		targetElement.style.marginTop = yoff;
	}
*/	
	// IE7 Temp Bug Fix
	if(divId == 'VACANCYENQUIRY')
	{
		document.vacancyEnquiry.Enquiry.focus();
	}
}

function popOut(divId, yoff, xoff)
{
	var targetId = divId;
	var targetElement = document.getElementById(targetId);
	targetElement.style.visibility = "hidden";

	if(xoff != null)
	{
		targetElement.style.marginLeft = xoff;
	}
	if(yoff != null)
	{
		targetElement.style.marginTop = yoff;
	}
	
	window.location.href = unescape(window.location.pathname);
}

function popOutDiscreet(divId)
{
	var targetId = divId;
	var targetElement = document.getElementById(targetId);
	targetElement.style.visibility = "hidden";
}

function expandPersonnelPanel(objId, totalPanels, appId)
{
	// Reset Other Panels
	var i = 0;
	while (i < totalPanels)
	{
		// Get Element
		var obj = document.getElementById('panel' + i);
		
		// Not The One We're Expanding
		if(i != objId)
		{
			// Check If We're Not Already In Summary Mode
			if(obj.className == 'panel_490_expanded')
			{
				// Update Contents
				loadHtml('panel' + i,'process_personneldata.php?id=' + obj.title + '&m=summary&t=' + totalPanels);
			}
   
			// Set Style
			if(i%2)
			{
				obj.className = 'panel_490_A';
			}
			else
			{
				obj.className = 'panel_490_B';
			}
		}
		else
		{
			// Update Contents
			try{
				loadHtml('panel' + i,'process_personneldata.php?id=' + appId + '&m=full&t=' + totalPanels);
			} catch(err) {
			}
			obj.title
			// Set Style
			obj.className = 'panel_490_expanded';
		}
		
		// Reset
		obj = null;
		i++;
	}
}



function expandVacancyPanelCrop(objId, totalPanels, vacId)
{
	// Reset the size of the vacancyListing div to allow for the extra info... adding 200px to height
	document.getElementById("vacancyListing").style.height = "670px";
	// Reset Other Panels
	var i = 0;
	var tempPanelRemove = "";
	while (i < totalPanels)
	{
		// Get Element
		var obj = document.getElementById('panel' + i);

		// Not The One We're Expanding
		if(i != objId)
		{
			// Check If We're Not Already In Summary Mode
			if(obj.className == 'panel_490_expanded')
			{
				try {
					document.getElementById("panel" + i).innerHTML = document.getElementById("panelRemoved").innerHTML;
				} catch(err) {
				}
			}			
			
			// Set Style
			if(i%2)
			{
				obj.className = 'panel_490_A';
			}
			else
			{
				obj.className = 'panel_490_B';
			}	
		}
		else
		{
			// Update Contents
			try {
				tempPanelRemove = document.getElementById("panel" + i).innerHTML;
				loadHtml('panel' + i,'process_vacancydata.php?id=' + vacId + '&i=' + i + '&m=experience&t=' + totalPanels);
			} catch(err) {
			}
			
			// Set Style
			obj.className = 'panel_490_expanded';
		}

		// Reset
		obj = null;
		i++;
	}
	
	try {
		document.getElementById("panelRemoved").innerHTML = tempPanelRemove;
	} catch(err) {
	}
		
}


function expandVacancyPanel(objId, totalPanels, vacId)
{
	// Reset Other Panels
	var i = 0;
	while (i < totalPanels)
	{
		// Get Element
		var obj = document.getElementById('panel' + i);

		// Not The One We're Expanding
		if(i != objId)
		{
			// Check If We're Not Already In Summary Mode
			if(obj.className == 'panel_490_expanded')
			{
				// Update Contents
				loadHtml('panel' + i,'process_vacancydata.php?id=' + obj.title + '&i=' + i + '&m=summary&t=' + totalPanels);
			}			

			// Set Style
			if(i%2)
			{
				obj.className = 'panel_490_A';
			}
			else
			{
				obj.className = 'panel_490_B';
			}
		}
		else
		{
			// Update Contents
			try {
				loadHtml('panel' + i,'process_vacancydata.php?id=' + vacId + '&i=' + i + '&m=full&t=' + totalPanels);
			} catch(err) {
			}
			
			// Set Style
			obj.className = 'panel_490_expanded';
		}

		// Reset
		obj = null;
		i++;
	}
}





function expandMessagePanel(objId, totalPanels, msgId)
{
	// Reset Other Panels
	var i = 0;
	while (i < totalPanels)
	{
		// Get Element
		var obj = document.getElementById('panel' + i);

		// Not The One We're Expanding
		if(i != objId)
		{
			// Check If We're Not Already In Summary Mode
			if(obj.className == 'panel_490_expanded')
			{
				// Update Contents
				loadHtml('panel' + i,'process_messagedata.php?id=' + obj.title + '&i=' + i + '&m=summary&t=' + totalPanels);
			}

			// Set Style
			if(i%2)
			{
				obj.className = 'panel_490_A';
			}
			else
			{
				obj.className = 'panel_490_B';
			}
		}
		else
		{
			// Update Contents
			loadHtml('panel' + i,'process_messagedata.php?id=' + msgId + '&i=' + i + '&m=full&t=' + totalPanels);

			// Set Style
			obj.className = 'panel_490_expanded';
		}

		// Reset
		obj = null;
		i++;
	}
}





function previewVacancy()
{
	// Update Page
	document.newVacancy.action = 'add_vacancies.php';
	document.newVacancy.submit();
}

function submitVacancy(previewed)
{
	// Check For Preview
	if(previewed == 'true')
	{
		// Check Data
		var validated = true;
   
		if(document.newVacancy.Title.value == '') { validated = false; }
   
		if(document.newVacancy.Description.value == '') { validated = false; }
   
		if(validated == true)
		{
			// Submit Vacancy
			document.newVacancy.action = 'process_addvacancy.php';
			document.newVacancy.submit();
		}
		else
		{
			// Notify
			alert('Please ensure you have supplied at least a title and description before submitting your vacancy');
   
			// Update Page
			document.newVacancy.action = 'add_vacancies.php';
			document.newVacancy.submit();
		}
	}
	else
	{
		// Notify
		alert("You don't appear to have previewed your vacancy yet. It will now be previewed automatically. Once the preview has appeared, please press 'Submit' once more to post your vacancy.");
		
		// Update Page
		document.newVacancy.action = 'add_vacancies.php';
		document.newVacancy.submit();
	}
}
/*
function toggleOpacity(element)
{
	var obj = document.getElementById(element);
	
	// Update Class
	if(obj.class == 'disabled')
	{
		obj.class = 'none';
	}
	else
	{
		obj.class = 'disabled';
	}
}
*/
