/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function genItin()
{
	$.get('../../Data/Itinerary/Itinerary.xml', function(xml){
		genItinerary(xml);
	});
}

function genItinerary(xml)
{
	var html = '';

	$('narrator', xml).each(function(){
		html += d ('name', $(this).attr('name'));
		$('x', this).each(function(i){
			html += (i%2 == 0) ? "<div class='wx'>" : "<div class='wx AlternateBG'>";

			html += "<div class='w2'>";
			html += h1 ($(this).find('day').text() + "ที่");
			html += h2 ($(this).find('date').text());
			//html += h2 (thaiDate ($(this).find('date').text()));
			html += h3 ($(this).find('time').text());
			html += "</div>";

			html += "<div class='w3'>";
			html += d ('assignment', "วาระงาน:")
			html += h4 ($(this).find('job').text());
			html += "</div>";

			html += "<div class='w3'>";
			html += d ('assignment', "ผู้นำ")
			html += h5 ($(this).find('leader').text());
			html += "</div>";

			html += "<div class='w3'>";
			html += d ('assignment', "สถานที่:")
			html += h6 ($(this).find('place').text());
			html += "</div></div>";
			html += d ('ruler', ' ');
		});
	});

	$('#table').append(html);
}

function thaiDate(amDate)
{
	var day, mo, month, year;
	var date = new Array();

	date = amDate.split('/');
	mo = date[0];
	day = date[1];
	year = date[2];

/*	switch (mo)
	{
		case '1':		month = 'มกราคม';	break;
		case '2':		month = 'กุมภาพันธ์';	break;
		case '3':		month = 'มีนาคม';		break;
		case '4':		month = 'เมษายน';		break;
		case '5':		month = 'พฤษภาคม';		break;
		case '6':		month = 'มิถุนายน';		break;

		case '7':		month = 'กรกาคม';		break;
		case '8':		month = 'สิงหาคม';		break;
		case '9':		month = 'กันยายน';		break;
		case '10':		month = 'ตุลาคม';		break;
		case '11':		month = 'พฤศจิกายน';	break;
		case '12':		month = 'ธันวาคม';		break;
	}
*/
	switch (mo)
	{
		case '1':		month = 'ม.ค.';		break;
		case '2':		month = 'ก.พ.';		break;
		case '3':		month = 'มี.ค.';	break;
		case '4':		month = 'เม.ย.';	break;
		case '5':		month = 'พ.ค.';		break;
		case '6':		month = 'มิ.ย.';	break;

		case '7':		month = 'ก.ค.';		break;
		case '8':		month = 'ส.ค.';		break;
		case '9':		month = 'ก.ย.';		break;
		case '10':		month = 'ต.ค.';		break;
		case '11':		month = 'พ.ย.';		break;
		case '12':		month = 'ธ.ค.';		break;
	}

	year = parseInt(year) + 543;
	
	return day + ' ' + month + ' ' + year;
}
