﻿// Functions for CV searching
// June 2007 : Javascript
// Tim Surtell @ Clario

//************************************************************************************************************
function SetupPage()
	{
	// Set up expanding table
	SetupExpandingTable('candidate_view_ajax.aspx?CandidateID=', false, false, true)
	
	// Set focus
	document.getElementById("lstSpecialism_lstSpecialisms").focus();
	}
//************************************************************************************************************
function SpecialismChanged(Specialism)
	{
	// Clear list
	do
		{
		document.getElementById("lstSpecialism_lstSpecialisms").remove(1);
		}
	while (document.getElementById("lstSpecialism_lstSpecialisms").length > 1)
	
	if (Specialism[Specialism.selectedIndex].value == 0)
		{
		// Clear list
		}
	else
		{
		var xmlHttp;
			
		// Instantiate a XMLHttpRequest object
		try
			{
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
			}
		catch (e)
			{
			// Internet Explorer
			try
				{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{
				try
					{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					}
				catch (e)
					{
					alert("Your browser does not support AJAX!");
					}
				}
			}
			
		// Create a function to respond to XMLHttpRequest state changes
		xmlHttp.onreadystatechange = function()
			{
			if(xmlHttp.readyState == 4)
				{
				// Populate list by splitting returned data on new line character
				var ReturnedFields = xmlHttp.responseText.split("\n");
				
				for (var LoopCounter = 0; LoopCounter < ReturnedFields.length - 1; LoopCounter++)
					{
					document.getElementById("lstSpecialism_lstSpecialisms").options.length++;
					document.getElementById("lstSpecialism_lstSpecialisms").options[document.getElementById("lstSpecialism_lstSpecialisms").options.length - 1].value = ReturnedFields[LoopCounter];
					document.getElementById("lstSpecialism_lstSpecialisms").options[document.getElementById("lstSpecialism_lstSpecialisms").options.length - 1].text = ReturnedFields[LoopCounter + 1];
					LoopCounter++
					}
				}
			}
			
			// Send request using XMLHttpRequest
			xmlHttp.open("GET", ajaxPath + "/get_specialisms_ajax.aspx?SpecialismID=" + Specialism[Specialism.selectedIndex].value, true);
			xmlHttp.send(null);
		}
	}
//************************************************************************************************************
function SpecialismChanged(Specialism)
	{
	// Do nothing
	}
//************************************************************************************************************
function AreaChanged(Area)
	{
	// Do nothing
	}
//************************************************************************************************************
function SalaryRangeChanged(SalaryRange)
	{
	// Do nothing
	}
//************************************************************************************************************
function HoursClicked(Hours)
	{
	if (document.getElementById("chkFulltime").checked == false && document.getElementById("chkParttime").checked == false)
		{
		if (Hours.id == "chkFulltime")
			{
				document.getElementById("chkParttime").checked = true;
			}
			else
			{
				document.getElementById("chkFulltime").checked = true;
			}
		}
	}
//************************************************************************************************************
function TypeClicked(Type)
	{
	if (document.getElementById("chkPermanent").checked == false && document.getElementById("chkTemporaryContract").checked == false)
		{
		if (Type.id == "chkPermanent")
			{
				document.getElementById("chkTemporaryContract").checked = true;
			}
			else
			{
				document.getElementById("chkPermanent").checked = true;
			}
		}
	}
//************************************************************************************************************
	function RequestCV(CandidateID) 
    {
		var xmlHttp;
			
		// Instantiate a XMLHttpRequest object
		try
			{
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
			}
		catch (e)
			{
			// Internet Explorer
			try
				{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{
				try
					{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					}
				catch (e)
					{
					alert("Your browser does not support AJAX!");
					}
				}
			}
			
		// Create a function to respond to XMLHttpRequest state changes
		xmlHttp.onreadystatechange = function()
			{
			if(xmlHttp.readyState == 4)
				{
				// Get return value
				var ReturnValue = xmlHttp.responseText;

				if (ReturnValue.substring(0,4) == "True")
					{
					alert("The candidate's CV has been successfully sent to you by email.");
					}
				else
					{
					alert("There was a problem sending the candidate's CV - please try again.");
					}
				}
			}
			
			// Send request using XMLHttpRequest
			xmlHttp.open("GET", ajaxPath + "client_request_cv_ajax.aspx?CandidateID=" + CandidateID, true);
			xmlHttp.send(null);
    }

