function displayDownloadForm() {
	var event_download = document.getElementById("event_download");
	if ( event_download.style.display == "block" ) {
		event_download.style.display = "none";
	}
	else {
		event_download.style.display = "block";
		document.file_download.username.focus();
	}
}

function validField(content) {
	if ( content == '' ) {
		return false;
	}
	else {
		return true;
	}
}

function submit_file_form(f) {
	if ( validate_download_form(f) ) {
		sendFileForm(f);
	}
	
}

function validate_download_form(f) {
	var testAll = true;
	
	//check the Username Field
	if (!validField(f.username.value)) {
		alert("Please enter a value for Username.");
		testAll = false;
	}
		
	//check the Password Field
	if (!validField(f.name.value)) {
		alert("Please enter a value for Password.");
		testAll = false;
	}
	
	//if alls good... return true!
	return testAll;
}



/*Ajax Below*/
var http = createRequestObject();
	
function createRequestObject() {
	var ro;
	
	if (window.ActiveXObject) {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		ro = new XMLHttpRequest();
	}
	
	return ro;
}

function sendFileForm(f, file) {
	actions = "username="+f.username.value+"&password="+f.password.value+'&event_id='+f.event_id.value;
	http.open('get', '/events/file_download/' +'?'+actions);
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4){
		var response = http.responseText;
		if ( response == "" ) {
			alert("Incorrect");
			document.file_download.username.value = "";
			document.file_download.password.value = "";
			document.file_download.username.focus();
		}
		else {
			document.getElementById("event_download").innerHTML = response;
		}
	}
}
