// Read XML file
var url = "vitae.xml";
var http = new JKL.ParseXML( url );
var data = http.parse();

// Sorting
function sortbyYear(a,b) { return b.year - a.year };
function sortbyMonth(a,b) { return b.month - a.month };
function sortbyOrder(a,b) { return a.authors.order - b.authors.order };
data.resume.paper.sort(sortbyOrder);
data.resume.paper.sort(sortbyYear);
data.resume.presen.sort(sortbyOrder);
data.resume.presen.sort(sortbyMonth);
data.resume.presen.sort(sortbyYear);

// document.getElementById
function $(tagId) {
	return document.getElementById(tagId);
}

function getCV() {
	var text = "";
	var textj = "";
	if ( $('typeof').value == 'paper' ) { // Paper !
		text += '<h2>Referred Papers</h2><ul>';
		for (i in data.resume.paper) {
			if (data.resume.paper[i].lang == 'eng') {
				text += '<li>';
				for (j in data.resume.paper[i].authors.author) {
					if (j == data.resume.paper[i].authors.order-1) { // This is mine!
						text += '<span class="udl">' + data.resume.paper[i].authors.author[j] + '</span>';
					} else {
						text += data.resume.paper[i].authors.author[j];
					}
					text += ', ';
				}
				text += data.resume.paper[i].year + ': ';
				text += data.resume.paper[i].title + ', ';
				text += '<span class="it">' + data.resume.paper[i].journal + '</span>, ';
				if (data.resume.paper[i].issue != undefined) {
					text += '<span class="bd">' + data.resume.paper[i].issue + '</span>, ';
				}
				text += data.resume.paper[i].page + '.</li>';
			} else { // Japanese
				textj += '<li>';
				for (j in data.resume.paper[i].authors.author) {
					if (j == data.resume.paper[i].authors.order-1) { // This is mine!
						textj += '<span class="udl">' + data.resume.paper[i].authors.author[j] + '</span>';
					} else {
						textj += data.resume.paper[i].authors.author[j];
					}
					textj += ', ';
				}
				textj += data.resume.paper[i].year + ': ';
				textj += data.resume.paper[i].title + ', ';
				textj += '<span class="it">' + data.resume.paper[i].journal + '</span>, ';
				if (data.resume.paper[i].issue != undefined) {
					textj += '<span class="bd">' + data.resume.paper[i].issue + '</span>, ';
				}
				textj += data.resume.paper[i].page + '.</li>';
			}
		}
		text += textj + '</ul>';
	} else if ( $('typeof').value == 'education' ) { // Education!
		text += '<h2>Education</h2><ul>';
		for (i in data.resume.education) {
			text += '<li>';
			text += data.resume.education[i].degree+' in '+data.resume.education[i].major+' ['+data.resume.education[i].year+', '+data.resume.education[i].univ+']';
			text += '</li>';
		}
		text += '</ul>';
		text += '<h2>Research Experiences</h2><ul>';
		for (i in data.resume.research) {
			text += '<li>';
			text += data.resume.research[i].title+' ['+data.resume.research[i].year+', '+data.resume.research[i].affiliation+']';
			text += '</li>';
		}
		text += '</ul>';
	} else if ( $('typeof').value == 'presen' ) { // Presentation !
		text += '<h2>Presentations - after 2003</h2><ul>';
		for (i in data.resume.presen) {
			if (data.resume.presen[i].lang == 'eng' && data.resume.presen[i].year > 2002) {
				text += '<li>';
				for (j in data.resume.presen[i].authors.author) {
					if (j == data.resume.presen[i].authors.order-1) { // This is mine!
						text += '<span class="udl">' + data.resume.presen[i].authors.author[j] + '</span>';
					} else {
						text += data.resume.presen[i].authors.author[j];
					}
					text += ', ';
				}
				text += data.resume.presen[i].year + ': ';
				text += data.resume.presen[i].title + ', ';
				text += '[<span class="it">' + data.resume.presen[i].confname + '</span>], ';
				text += '(<span class="itb">' + data.resume.presen[i].type + ' Presentation</span>).</li>';
			}
		}
		text += '</ul>';
	}
	$('vitae').innerHTML = text;
}
