var totalItems = 0;
// The following are specified on the calling page
//var festival_info_URL = "xml/film_festivals_09.xml";


 $(document).ready(function(){
	$.ajax({
		type: "GET",
		url: festival_info_URL ,
		dataType: "xml",
		success: function(xml) {
			var title = $(xml).find('title').text();
			var last_updated = $(xml).find('last_updated').text();
			var textcontainer = $('#section_1');
			totalItems = $(xml).find('festival').length;
			var count = 0;
			var strText = '<p class="section_1_header"\>' + title + '<\/p\>';
			$(xml).find('festival').each(function(){
				if (count < itemsPerPage) {
					//strText += "<div class='itemNo'\>";
					var name = $(this).find('name').text();
					var date = $(this).find('date').text();
					var comment = $(this).find('comment').text();
					var location = $(this).find('location').text();
					var url = $(this).find('url').text();
					var entry_deadline = $(this).find('entry_deadline').text();
					strText += "<div class='blue_bold_large'\>" + name  + "<\/div\>";
					if (date && date.length) strText += "<div class='simple_text'\>To be held on: " + date  + "<\/div\>";
					if (location && location.length) strText += "<div class='simple_text'\>At: " + location  + "<\/div\>";
					if (comment && comment.length) strText += "<div class='simple_text'\>" + comment  + "<\/div\>";
					if (url && url.length) strText += "<div class='simple_text'\>Further details from: <a target='_new' href='" + url + "'>" + url + "</a><\/div\>";
					if (entry_deadline && entry_deadline.length) strText += "<div class='deadline_text'\>Please submit entry forms by: " + entry_deadline  + "<\/div\>";
				}
				count++;
			});
			strText += "<p style='text-align:center;font-style:italic;font-weight: 600;'\>Date information last checked: " + last_updated + "<\/p\><hr \/\><p \/\>";
			
			textcontainer.append(strText);
		}//,
		//failure: function() {(alert('oh no'))};
	});
});


function refresh(pageNo) {
	$.ajax({
		type: "GET",
		url: rule_URL,
		dataType: "xml",
		success: function(xml) {
			var div = document.getElementById("section_1");
			while (div.hasChildNodes()) {
				div.removeChild(div.lastChild);
			}
			var title = $(xml).find('title').text();
			var last_updated = $(xml).find('last_updated').text();
			var approved_by = $(xml).find('approved_by').text();
			var textcontainer = $('#section_1');
			totalItems = $(xml).find('competition').length;
			var count = 0;
			var strText = '<p style="width: 100%;text-align: center;" class="red_bold_large"\>' + rule_title + '<\/p\>';
			$(xml).find('competition').each(function(){
				if (count >= itemsPerPage*(pageNo -1) && count < itemsPerPage*pageNo) {
					var comp_name = $(this).find('comp_name').text();
					var name = $(this).find('name').text();
					var date = $(this).find('date').text();
					var comment = $(this).find('comment').text();
					var location = $(this).find('location').text();
					var url = $(this).find('url').text();
					var entry_deadline = $(this).find('entry_deadline').text();
					
					strText += "<div class='blue_bold_large'\>" + name  + "<\/div\>";
					if (date && date.length) strText += "<div class='simple_text'\>To be held on: " + date  + "<\/div\>";
					if (location &&location.length) strText += "<div class='simple_text'\>At: " + location  + "<\/div\>";
					if (comment && comment.length) strText += "<div class='simple_text'\>" + comment  + "<\/div\>";
					if (url && url.length) strText += "<div class='simple_text'\>Further details from: <a target='_new' href='" + url + "'>" + url + "</a><\/div\>";
					if (entry_deadline && entry_deadline.length) strText += "<div class='deadline_text'\>Please submit entry forms by: " + entry_deadline  + "<\/div\>";
				}
				count++;
			});
			strText += "<p style='text-align:center;font-style:italic;font-weight: 600;'\>Date information last checked: " + last_updated + "<\/p\>";
			
			textcontainer.append(strText);
		}//,
		//failure: function() {(alert('oh no'))};
	});
	};
