function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        var req = new XMLHttpRequest();
        // req.onreadystatechange = processReqChange; // We're not going to do any processing dependant on the result
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        var req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.open("GET", url, true);
            req.send();
        }
    } else {
    	alert("loadXMLDoc fell through!");
    }
}

function setArchived(jobId,archive)
{
	var url = "/AmendVacancy";
	url = url + "?jobid=" + jobId;
	url = url + "&action=setArchived"
	url = url + "&status="+archive;
	loadXMLDoc(url);
	setTimeout("location.reload(true)",500);
}

function applyForJob(jobId,cbState)
{
        // Update the counter on the side as well.

        var mText = document.getElementById("jobcount").firstChild.nodeValue;
        var jobCount = parseInt(mText);

        if ( cbState == true ) {
                jobCount++;
        } else {
                jobCount--;
                if ( jobCount < 0 ) {
                        jobCount = 0;
                }
        }

        document.getElementById("jobcount").innerHTML = jobCount + '';

        var url = "/JobApplication";
        url = url + "?jobid=" + jobId;
        url = url + "&status=" + cbState;
        loadXMLDoc(url);
}

function sendToAFriend(jobId,email)
{
	var url = "/SendToAFriend";
	url = url + "?jobid=" + jobId;
	url = url + "&email=" + email;
	loadXMLDoc(url);
	alert('Thank you. An email has been sent to ' + url );
}
