// Add some employment variables to the session
function add_education(){
	// Load into variables
	var institution 	 = escape(encodeURI(document.getElementById('education_institution').value));
	var educationlevel	 = escape(encodeURI(document.getElementById('education_educationlevel').value));	
	var county 			 = escape(encodeURI(document.getElementById('education_county').value));
	var town 			 = escape(encodeURI(document.getElementById('education_town').value));
	var start_day 		 = escape(encodeURI(document.getElementById('education_start-day').value));
	var start_month 	 = escape(encodeURI(document.getElementById('education_start-month').value));
	var start_year 		 = escape(encodeURI(document.getElementById('education_start-year').value));
	var end_day 		 = escape(encodeURI(document.getElementById('education_end-day').value));
	var end_month 		 = escape(encodeURI(document.getElementById('education_end-month').value));
	var end_year 		 = escape(encodeURI(document.getElementById('education_end-year').value));
	var grades			 = escape(encodeURI(document.getElementById('education_grades').value));
	
	// Validation
	var start = new Date(Date.UTC(start_year,start_month,start_day,0,0,0)).getTime() / 1000;
	var end = new Date(Date.UTC(end_year, end_month, end_day,0,0,0)).getTime() / 1000;
	
	if(institution.length == 0){
		alert('You must give an institution name');
	} else if(educationlevel.length == 0){
		alert('You must give an education level');
	} else if(start_day.length == 0){
		alert('You must select a start day');
	} else if(start_month.length == 0){
		alert('You must select a start month');
	} else if(start_year.length == 0){
		alert('You must select a start year');
	} else if(end_day.length == 0){
		alert('You must select a end day');
	} else if(end_month.length == 0){
		alert('You must select a end month');
	} else if(end_year.length == 0){
		alert('You must select a end year');
	} else if(start >= end ){
		alert('The end date must be later than start date');
	} else{
	
		var http = new XMLHttpRequest();
		
		var url = "/_cv_education.php";
		var params = "institution="+ institution +"&educationlevel="+ educationlevel +"&county="+ county +"&town="+ town +"&start_day="+ start_day +"&start_month="+ start_month +"&start_year="+ start_year +"&end_day="+ end_day +"&end_month="+ end_month +"&end_year="+ end_year +"&grades="+ grades;
		http.open("GET", url+"?"+params, true);
		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				alert(http.responseText);
				// Reload the employment list
				education_list();
			}
		}
		http.send(null);
		
	}

}


// Load the list
function education_list(){
	var http = new XMLHttpRequest();
	
	var url = "/_cv_educationlist.php";
	var params = "var=blah";
	http.open("GET", url+"?"+params, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById('education_list').innerHTML = http.responseText;
		}
	}
	http.send(null);
}


// Remove from the list
function remove_education(array_key){
	// Make a call to the PHP page that removes the employment records
var http = new XMLHttpRequest();
	
	var url = "/_cv_educationrmv.php";
	var params = "array_key="+ array_key;
	http.open("GET", url+"?"+params, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			alert(http.responseText);
			// Reload the employment list
			education_list();
		}
	}
	http.send(null);
}
