function addJob(aJob) {
    var jobList = thaw('jobList');
    jobList[aJob] = aJob;
    jobList = freeze('jobList', jobList);
    alert('Job reference ' + aJob + ' has been added to your basket');
}

function removeJob(aJob) {
    var jobList = thaw('jobList');
    var newJobList = new Object();
    for (key in jobList) {
	if (key != aJob && key > '') {
	    newJobList[key] = jobList[key];
	}
    }
    freeze('jobList', newJobList);
}

function addCandidate(aCandidate) {
    var candidateList = thaw('candidateList');
	candidateList[aCandidate] = aCandidate;
    candidateList = freeze('candidateList', candidateList);
	alert('Candidate reference ' + aCandidate + ' has been added to your basket');
}

function removeCandidate(aCandidate) {
    var candidateList = thaw('candidateList');
    var newCandidateList = new Object();
    for (key in candidateList) {
		if (key != aCandidate) {
			newCandidateList[key] = candidateList[key];
		}
    }
    freeze('candidateList', newCandidateList);
}

function DeleteRef(Ref) {
    var msg = "Are you sure?";
    if (confirm(msg)) {
	document.location.href = '/cgi-bin/jobs_update.plx?delete=' + escape(Ref);
    }else{
	return;
    }
}

function freeze(cookieName, jobList) {
    var cookieString = '';
    for (key in jobList) {
		cookieString += '&' + escape(key) + '=' + escape(jobList[key]);
    }
    SetCookie(cookieName, cookieString, '', '/');    
}

function thaw(cookieName) {
    var myObject = new Object();
    //  
    var strg = GetCookie(cookieName);
    if (strg == null) {
		return(myObject);
    }
    strg = strg.split('&').slice(1);
	for (i=0; i < strg.length; i++) {
		splitCrumb = strg[i].split('=');
		myObject[unescape(splitCrumb[0])] = unescape(splitCrumb[1]);
	}
	return(myObject);
}

function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
	}
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break; 
    }
    return null;
}

function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) { endstr = document.cookie.length; }
    return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name,value,expires,path,domain,secure) {
    document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
