﻿// Functions for CV searching
// June 2007 : Javascript
// Tim Surtell @ Clario

var arrStoredSpecialismsValue = new Array;
var arrStoredSpecialismsText = new Array;

//************************************************************************************************************
function SetupPage()
	{
	// Set up expanding table
	SetupExpandingTable('candidate_view_ajax.aspx?CandidateID=', false, false, true)
	
	// Specialisms
	StoreSpecialisms(document.getElementById("lstSpecialism_lstSpecialisms"));
	SectorChanged(document.getElementById("lstSector_lstSectors"));
	
	// Set focus
	document.getElementById("lstSector_lstSectors").focus();
	}
//************************************************************************************************************
function StoreSpecialisms(Specialisms) {
    for (intLoopCounter = 1; intLoopCounter < Specialisms.length; intLoopCounter++) {
        arrStoredSpecialismsValue[intLoopCounter] = Specialisms.options[intLoopCounter].value;
        arrStoredSpecialismsText[intLoopCounter] = Specialisms.options[intLoopCounter].text;
		}
}
//************************************************************************************************************
function SectorChanged(Sector) {
    var Specialisms = document.getElementById("lstSpecialism_lstSpecialisms");
	
    var CurrentlySelectedSpecialism = Specialisms.value;
			
    // Clear list, except for prompt text
    do {
        Specialisms.remove(1);
    }
    while (Specialisms.length > 1)

    // Add back only those specialisms in the selected sector
    for (intLoopCounter = 1; intLoopCounter < arrStoredSpecialismsValue.length; intLoopCounter++) {
        if (arrStoredSpecialismsValue[intLoopCounter].substr(0, 1) == Sector.value) {
            Specialisms.options[Specialisms.length] = new Option(arrStoredSpecialismsText[intLoopCounter], arrStoredSpecialismsValue[intLoopCounter]);
            if (CurrentlySelectedSpecialism == arrStoredSpecialismsValue[intLoopCounter]) {
                Specialisms.value = CurrentlySelectedSpecialism;
			}
		}
	}
}
//************************************************************************************************************
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);
    }

