function createRequestObject() {
	if (window.XMLHttpRequest) 
	{
		return new XMLHttpRequest(); //Not IE
	} 
	else if(window.ActiveXObject) 
	{
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	}
}

var http = createRequestObject();

function sndReq() {
    //send the string
    http.open('get', '../projectPdf.php');
    http.onreadystatechange = handleResponse;
    http.send(null);
}
        
function handleResponse() {
	
    if(!document.getElementById('projectPDF')) return;
	
    var theLink = document.getElementById('projectPDF');
    
    if(http.readyState == 4){
	var response = http.responseText;
	
	if(response == 'error') {
	    theLink.innerHTML = "Error!";
	} else {
	    theLink.href = "/"+response;
	    theLink.id = "pdfGenerated";
	    theLink.target = "_blank";
	    theLink.innerHTML = "Click to Download";
	}
	
    } else {
	//dont keep the people waiting without knowing what is going on
	theLink.innerHTML = "Generating PDF...";
    }    
}
function changePriority(direction, position)
{
	//send the string
	var d = new Date();
	
    http.open('get', '/projectFuncs.php?option=reorder&pos=' + position + '&direction=' + direction + "&nocache=" + d.getTime());
    http.onreadystatechange = reloadPage;
    http.send(null);
}
function reloadPage()
{
	if (http.readyState == 4)
	{
		// only if "OK"
    	if (http.status == 200) 
		{
			document.location.reload();
		}
	}
}


