
/* - all-course-functions_min.js - */
$(document).ready(function(){

$('ul.tabs li a').click(function () {location.hash = $(this).attr('href');}); 

if ($("#azdiv")[0]) { 
		azList();
}

if ($("#azdivFull")[0]) { 
	azListFull();
}


/////////// POST GRAD fees page function //////////

		if ($("#showFees")[0]){
			showFees();
		}
		
		function showFees() {
				$.ajax({ url : "fees-pg.html", dataType: "text", success : function (data) {
						$("#showFees").html(data);
					}
				});
			
		}
		
/////////// POST GRAD fees page function //////////



/////////// A-Z small list function //////////
		function azList() {	
			$.ajax({
					type: "GET",
					url:"/040711.xml",
					dataType: "xml",
					success: function(d)
					{
				$('body .azdiv').append('<h3><span class="aztitle">A - Z course list</span></h3>');
				$('body .azdiv').append('<div id="azList-nav"><div class="hidden" style="display:block; visibility:hidden; position:relative; top:0; left:0; width:20px;">0</div></div>');
				$('body .azdiv').append('<br /><ul id="azList" class="azList" style="overflow: hidden; height: 218px;">');
				$(d).find('narrative').each(function(){
					var description = $(this).find('Course_Name').text();
					var course_url = $(this).find('Course_URL').text().replace(/ /g,'');
					var level = $(this).find('Course_Level').text();

					var area = $(this).find('Subject_Area').text().replace(/ /g,'');
					
					if ( area === 'busi'){
						network = 'business-and-leisure';
					}
					else if ( area === 'outd'){
						network = 'business-and-leisure';
					}
					else if ( area === 'spor'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'tour'){
						network = 'business-and-leisure';
					}
					else if ( area === 'mana'){
						network = 'business-and-leisure';
					}
					else if ( area === 'hosp'){
						network = 'business-and-leisure';
					}
					else if ( area === 'huma'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'arts'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'arta'){
						network = 'creative-and-cultural-industries';
					}
					else if ( area === 'soci'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'heal'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'beau'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'soca'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'chil'){
						network = 'education-and-childcare';
					}
					else if ( area === 'educ'){
						network = 'education-and-childcare';
					}
					else if ( area === 'lang'){
						network = 'education-and-childcare';
					}
					else if ( area === 'gael'){
						network = 'gaelic-medium-studies';
					}
					else if ( area === 'cult'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'crea'){
						network = 'creative-and-cultural-industries';
					}
					else if ( area === 'engi'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'ener'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'cons'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'coun'){
						network = 'science-and-environment';
					}
					else if ( area === 'envi'){
						network = 'science-and-environment';
					}
					else if ( area === 'scie'){
						network = 'science-and-environment';
					}
					else if ( area === 'comp'){
						network = 'computing-and-it';
					}

					var network = network;

					var html = '<li><a href="/en/courses/'+network+'/'+course_url+'">' + description + '</a>' +level+ '</li>';

				$('ul.azList').append($(html));
				});



				$('.azList').listnav({ 
					initLetter: 'a',
					cookieName: 'az-course',
					includeAll: false, 
					includeOther: false, 
					flagDisabled: true, 
					noMatchText: 'There are no matching entries, please click another letter.', 
					showCounts: false,
					includeNums: false
					//prefixes: ['the', 'The'] 
				});
				
				
				var mylist = $('ul.azList');
				var listitems = mylist.children('li').get();
				listitems.sort(function(a, b) {
				   var compA = $(a).text().toUpperCase();
				   var compB = $(b).text().toUpperCase();
				   return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
				})
				$.each(listitems, function(idx, itm) { mylist.append(itm); });


				$('body .azdiv').append('<br /><p align="right" style="color:#ef8400 !important;"><strong><a href="/courses/a-z-course-list-full" title="Full A-Z Course list">See full list</a></strong></p>');
				}
			});
		};
/////////// A-Z small list function //////////

/////////// A-Z full list function //////////
		function azListFull() {	
			$.ajax({
					type: "GET",
					url:"/040711.xml",
					dataType: "xml",
					success: function(d)
					{
				$('body .azdivFull').append('<h3><span class="aztitle">A - Z course list</span></h3>');
				$('body .azdivFull').append('<div id="azListFull-nav"><div class="hidden" style="display:block; visibility:hidden; position:relative; top:0; left:0; width:20px;">0</div></div>');
				$('body .azdivFull').append('<br /><ul id="azListFull" class="azListFull" style="overflow: hidden;">');
				$(d).find('narrative').each(function(){
					var description = $(this).find('Course_Name').text();
					var course_url = $(this).find('Course_URL').text().replace(/ /g,'');
					var level = $(this).find('Course_Level').text();
					var area = $(this).find('Subject_Area').text().replace(/ /g,'');
					var summary = $(this).find('Summary').text();
					summary = truncate(summary, 30);

					if ( area === 'busi'){
						network = 'business-and-leisure';
					}
					else if ( area === 'outd'){
						network = 'business-and-leisure';
					}
					else if ( area === 'spor'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'tour'){
						network = 'business-and-leisure';
					}
					else if ( area === 'mana'){
						network = 'business-and-leisure';
					}
					else if ( area === 'hosp'){
						network = 'business-and-leisure';
					}
					else if ( area === 'huma'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'arts'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'arta'){
						network = 'creative-and-cultural-industries';
					}
					else if ( area === 'soci'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'heal'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'beau'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'soca'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'chil'){
						network = 'education-and-childcare';
					}
					else if ( area === 'educ'){
						network = 'education-and-childcare';
					}
					else if ( area === 'lang'){
						network = 'education-and-childcare';
					}
					else if ( area === 'gael'){
						network = 'gaelic-medium-studies';
					}
					else if ( area === 'cult'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'crea'){
						network = 'creative-and-cultural-industries';
					}
					else if ( area === 'engi'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'ener'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'cons'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'coun'){
						network = 'science-and-environment';
					}
					else if ( area === 'envi'){
						network = 'science-and-environment';
					}
					else if ( area === 'scie'){
						network = 'science-and-environment';
					}
					else if ( area === 'comp'){
						network = 'computing-and-it';
					}

					var network = network;
					//var html = '<li><a href="/whc/whcuhi/courses/'+network+'/'+url+'">' + description + '</a>' +level+ '</li>';
					var html = '<li><h3 class="toggle">' + description + '</a></h3>' +level+ '<div class="toggle_container_full"><p>' + summary + '</p> \n <p><a href="'+network+'/'+course_url+'">Full course details ...</a></p></div></li>';
					
					

					$('ul.azListFull').append($(html));
					});
					$('.azListFull').listnav({ 
						initLetter: 'a', 
						cookieName: 'az-course',
						includeAll: false, 
						includeOther: false, 
						flagDisabled: true, 
						noMatchText: 'There are no matching entries, please click another letter.', 
						showCounts: false,
						includeNums: false
						//prefixes: ['the', 'The'] 
					});

				var mylist = $('ul.azListFull');
				var listitems = mylist.children('li').get();
				listitems.sort(function(a, b) {
				   var compA = $(a).text().toUpperCase();
				   var compB = $(b).text().toUpperCase();
				   return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
				})
				$.each(listitems, function(idx, itm) { mylist.append(itm); });


				$(".toggle_container_full").hide();
		
				$("h3.toggle").click(function(){
					$(this).toggleClass("active").next().slideToggle("slow");
				});
		
				}
			});
		};
/////////// A-Z full list function //////////


/////////// Course page function //////////

	var url = window.location.pathname;
	
	var afterHash = window.location.hash;
	
	if ( afterHash === ''){
		var myVar = url.toLowerCase().substring(url.lastIndexOf('/') + 1);
	}
	else if ( afterHash !== '') {
		var myVar = url.toLowerCase().substring(url.lastIndexOf('/') + 1).replace(afterHash,'');
	}

	var pageName = $(document).attr('title');


$('ul.tabs li a').click(function () {location.hash = $(this).attr('href');}); 


if ($("#special")[0]) {
	searchThisCourse();
}


	function searchThisCourse() {		
		
		$.ajax({
			type: "GET",
			url:"/040711.xml",
			dataType: "xml",
			success: function(xml) {
				loadThisCourse(xml) 
				}
		});
	}


	function loadThisCourse (xml) {
		
		$(xml).find('narrative[url='+ myVar +']').each(function () {

				var name = $(this).find('Course_Name').text();
				$('<h1>').html(name+'</h1>').appendTo('#header');

		// *** SUMMARY TAB *** //
				var summary = $(this).find('Summary').text();
				var Embed_Video = $(this).find('Embed_Video').text();
				
		// *** GAELIC *** //
		
					var specText;
					var specFeat;
					var entryText;
					var studyText;
					var whereText;
					var startText;
					var feesText;
					var fundingText;
					var careerText;
					
					var furtherText;
					var accRout;
					var durationText;
					var disclaimer;

				
				var courseCode = $(this).find('Course_Code_Extra').text().replace(/ /g,'');

				if (courseCode === 'UQ530G' || courseCode === 'UQ532G' || courseCode === 'UQW53G' || courseCode === 'UQ505G' || courseCode === 'UQP53G' ){
					specText = "Dè tha sònraichte mu dheidhinn a' chùrsa seo?";				
					specFeat = "Feartan sònraichte";
					entryText = "Feumalachdan inntrigidh";
					studyText = "Modhan ionnsachaidh";
					whereText = "Gheibhear an cùrsa seo aig";
					startText = "Tha an cùrsa ri fhaotainn";
					feesText = "Cìsean";
					fundingText = "Maoineachadh";
					careerText = "Cothroman cosnaidh";

					furtherText= "An urrainn dhomh adhartas a dh?anamh do ionnsachadh a bharrachd?";
					accRout = "Slighean a-steach";
					durationText= "Dè cho fad 's a mhaireas a' chùrsa agam?";
					
					contactText = "Cuir fios thugainn";
					applyText = "Cuir iarrtas a-steach";
					applyCourseText = "Cuir iarrtas a-steach airson a' chùrsa seo";
					infoText = "Loidhne fiosrachaidh";
					ucasText = "Còdan UCAS";
					disclaimer = "Nota chudromach: tha susbaint a' chùrsa airson eisimpleir a-mhàin agus chan eil e a' riochdachadh liosta iomlan, a thaobh ainm no gnè, de mhodalan a bhithear ag ionnsachadh air a' chùrsa seo, agus faodaidh eadar-dhealachaidhean a bhith ann a thaobh càite a bheilear ag ionnsachadh. Faodaidh susbaint a' chùrsa atharrachadh aig àm sam bith, gun rabhadh.";
					//triggerClass = "<h2 class='triggerGD'>";
				}
				else {
					specText="What is special about this course?";
					specFeat="Special features";
					entryText="Entry requirements";
					studyText="Study options";
					whereText="Where will I study my course?";
					startText="Start date";
					feesText="How much will my course cost?";
					fundingText="What funding can I apply for?";
					careerText="What can I do on completion of my course?";
					furtherText="Can I progress into further study?";
					accRout="Access routes";
					durationText="How long will my course last?";
					contactText="Contact us";
					applyText="Apply";
					applyCourseText="Apply for this course";
					infoText="UHI information line";
					ucasText="UCAS code";
					disclaimer="Important note: course content is indicative only and does not represent a definitive list, in name or in nature, of modules that will be studied in this course, and may vary depending on location of study. Course content is subject to change at any time, without prior notice.";

					//triggerClass = "<h2 class='trigger'>";
				}
		
		// *** GAELIC *** //
				
				$('<h2>').html(specText+'</h2>').appendTo('#special');
				//$('<p>').html(Embed_Video+summary+'</p>').appendTo('#special');
				$('#special').append(Embed_Video+summary);
				
				$('#Apply').remove();
				$('#wysiwygTab-selector-5').remove();
				$('#wysiwygTab-selector-5').hide();

				var Features = $.trim($(this).find('Features').text());

				if ( Features === '&nbsp;'){
					Features = '';
					$('#features').remove();
				}
				else if ( Features === ''){
					$('#features').remove();
				}
				else{
					$('<h2>').html(specFeat+'</h2>').appendTo('#features');
					$('#features').append(Features);
				}



				var Entry_Req = $(this).find('Entry_Req').text();
				
				$('<h2>').html(entryText+'</h2>').appendTo('#entry');
				$('#entry').append(Entry_Req);

				var Access_Rt = $.trim($(this).find('Access_Rt').text());

				if ( Access_Rt === '&nbsp;'){
					Access_Rt = '';
				}
				else if ( Access_Rt === ''){
					var accRout = '';
				}
				else{
					$('<h2>').html(accRout+'</h2>').appendTo('#routes');
					$('<p>').html(Access_Rt+'</p>').appendTo('#routes');
				}
				
		// *** SUMMARY TAB *** //

		// *** CONTENT TAB *** //
				var Title_Y1 = $.trim($(this).find('Title_Y1').text());
				var Cont_Y1 = $.trim($(this).find('Content_Y1').text());
				var Title_Y2 = $.trim($(this).find('Title_Y2').text());
				var Cont_Y2 = $.trim($(this).find('Content_Y2').text());
				var Title_Y3 = $.trim($(this).find('Title_Y3').text());
				var Cont_Y3 = $.trim($(this).find('Content_Y3').text());
				var Title_Y4 = $.trim($(this).find('Title_Y4').text());
				var Cont_Y4 = $.trim($(this).find('Content_Y4').text());

				
				if ( Cont_Y1 !== '' && Cont_Y2 === '' && Cont_Y3 === '' && Cont_Y4 === ''){
					Title_Y4 == '';
					Title_Y3 == '';
					Title_Y2 == '';
					$('#y1').append('<h2 class="trigger">' + Title_Y1 + '</h2>');
					$('#y1').append('<div class="toggle_container">' + Cont_Y1 + '</div>');
				}
				
				else if ( Cont_Y1 !== '' && Cont_Y2 !== '' && Cont_Y3 === '' && Cont_Y4 === ''){
					Title_Y4 == '';
					Title_Y3 == '';
					$('#y1').append('<h2 class="trigger">' + Title_Y1 + '</h2>');
					$('#y1').append('<div class="toggle_container">' + Cont_Y1 + '</div>');
					$('#y2').append('<h2 class="trigger">' + Title_Y2 + '</h2>');
					$('#y2').append('<div class="toggle_container">' + Cont_Y2 + '</div>');
				}
				else if ( Cont_Y1 !== '' && Cont_Y2 !== '' && Cont_Y3 !== '' && Cont_Y4 === ''){
					Title_Y4 == '';
					$('#y1').append('<h2 class="trigger">' + Title_Y1 + '</h2>');
					$('#y1').append('<div class="toggle_container">' + Cont_Y1 + '</div>');
					$('#y2').append('<h2 class="trigger">' + Title_Y2 + '</h2>');
					$('#y2').append('<div class="toggle_container">' + Cont_Y2 + '</div>');
					$('#y3').append('<h2 class="trigger">' + Title_Y3 + '</h2>');
					$('#y3').append('<div class="toggle_container">' + Cont_Y3 +'</div>');
				}
				else if ( Cont_Y1 !== '' && Cont_Y2 !== '' && Cont_Y3 !== '' && Cont_Y4 !== ''){
					$('#y1').append('<h2 class="trigger">' + Title_Y1 + '</h2>');
					$('#y1').append('<div class="toggle_container">' + Cont_Y1 + '</div>');
					$('#y2').append('<h2 class="trigger">' + Title_Y2 + '</h2>');
					$('#y2').append('<div class="toggle_container">' + Cont_Y2 + '</div>');
					$('#y3').append('<h2 class="trigger">' + Title_Y3 + '</h2>');
					$('#y3').append('<div class="toggle_container">' + Cont_Y3 +'</div>');
					$('#y4').append('<h2 class="trigger">' + Title_Y4 + '</h2>');
					$('#y4').append('<div class="toggle_container">' + Cont_Y4 +'</div>');
				}
				else if ( Cont_Y1 === '' && Cont_Y2 === '' && Cont_Y3 === '' && Cont_Y4 !== ''){
					Title_Y3 == '';
					Title_Y2 == '';
					Title_Y1 == '';
					$('#y4').append('<h2 class="trigger">' + Title_Y4 + '</h2>');
					$('#y4').append('<div class="toggle_container">' + Cont_Y4 +'</div>');
				}


		// *** CONTENT TAB *** //

		// *** STUDY MODE TAB *** //
				//var Study_Options = $(this).find('Study_Options').text();
				var Study_Options = $(this).find('Study_Options').text()
				.replace('(structured)', '(structured) <strong><a id="struct" href="structured.txt" title="What does this mean?"> ? </a></strong>')
				.replace('(unstructured)', '(unstructured) <strong><a id="unstruct" href="unstructured.txt" title="What does this mean?"> ? </a></strong>');

				var Study_Descr = $(this).find('Study_Description').text();
				var Study_VC = $(this).find('Study_VC').text();
				var Study_OL = $(this).find('Study_OL').text();
				var Study_FF = $(this).find('Study_FF').text();

				$('#study-opt').append('<h2>' + studyText + '</h2>');
				$('#study-opt').append(Study_Options);
				$('#study-opt').append(Study_Descr, Study_VC, Study_OL, Study_FF);

				var Location = $.trim($(this).find('Location').text());

				$("#study-opt:contains(structured)").add('<strong><a id="studyOptions" href="studyOptions.txt" title="What does this mean?"> ? </a></strong>');


				if ( Location === '<ul></ul>'){
					Location = '';
					$('#Location').remove();
				}
				else if ( Location === '&nbsp;'){
					Location = '';
					$('#Location').remove();
				}
				else if ( Location === ''){
					$('#Location').remove();
				}
				else {
					$('#Location').append('<h2>'+whereText+'</h2>');
					$('#Location').append(Location);
				}
				
				var Duration = $.trim($(this).find('Duration').text());
				
				if ( Duration === '<ul></ul>'){
					Duration = '';
					$('#Duration').remove();
				}
				else if ( Duration === '&nbsp;'){
					Duration = '';
					$('#Duration').remove();
				}
				else if ( Duration === ''){
					$('#Duration').remove();
				}
				else {
					$('#Duration').append('<h2>'+durationText+'</h2>');
					$('#Duration').append(Duration);
				}
				
				var Crs_Start = $.trim($(this).find('Crs_Start').text());

				if ( Crs_Start === '<ul></ul>'){
					Crs_Start = '';
					$('#Start').remove();
				}
				else if ( Crs_Start === '&nbsp;'){
					Crs_Start = '';
					$('#Start').remove();
				}
				else if ( Crs_Start === ''){
					$('#Start').remove();
				}
				else {
					$('#Start').append('<h2>'+startText+'</h2>');
					$('#Start').append(Crs_Start);
				}

		// *** STUDY MODE TAB *** //


		// *** FEES TAB *** //

			var level = $.trim($(this).find('Course_Level').text());

				//    MA Health and Wellbeing || MSc Infection Control || MSc Medical Device Decontamination || MA Professional Development || MLitt History of the Highlands and Islands || MA Material Culture and the Environment
				if (courseCode === 'UB992' || courseCode === 'UB990' || courseCode === 'UB991' || courseCode === 'U93X4' || courseCode === 'UV200' || courseCode === 'U93Q7'){
						getFees01();
					}
				//    MLitt Highlands and Islands Literature || MLitt Orkney and Shetland Studies
				else if (courseCode === 'UQ500' || courseCode === 'UQ323'){
						getFees02();
					}
				//    MA Archaeological Practice || MSc Shallow Geophysics
				else if (courseCode === 'UV460' || courseCode === 'UF660'){
						getFees03();
					}
				//    MSc Interpretation: Management and Practice
				else if (courseCode === 'UN210'){
						getFees04();
					}
				//    MSc Leadership and Management
				else if (courseCode === 'UN291'){
						getFees05();
					}
				//    MSc Managing Sustainable Rural Development || MSc Managing Sustainable Mountain Development || MSc Sustainable Energy Solutions || MSc Developing Low Carbon Communities
				else if (courseCode === 'U93N2' || courseCode === 'U91L7' || courseCode === 'UF854' || courseCode === 'UF853'){
						getFees06();
					}
				//    PgCert Enterprise and e-Marketing
				else if (courseCode === 'UN590'){
						getFees07();
					}
				//    PgCert Restorative Practice || PgCert Socio-legal Issues of Childhood
				else if (courseCode === 'UM9X9' || courseCode === 'UM9L3'){
						getFees08();
					}
                                //    MTh Theological studies
				else if (courseCode === 'UV611'){
						getFees09();
					}
                                //    PgCert Entrepreneurial Leadership
				else if (courseCode === 'UN2N8'){
						getFees10();
					}
                                //    PgCert Health Leadership and Management
				else if (courseCode === 'UN215'){
						getFees11();
					}



				//    All degrees including Gaelic with education MA (Hons)
				else if (level === 'BA' || level === 'BA (Hons)' || level === 'BSc' || level === 'BSc (Hons)' || level === 'BEng' || level === 'BEng (Hons)' || courseCode === 'UQ533'){
						getFeesDegrees();
				}
				//    All HNC and HND courses
				else if (level === 'HNC' || level === 'HND'){
					getFeesHN();
				}
				//    All PDA courses
				else if (level === 'PDA'){
					getFeesPDA();
				}

				else { 
					var fees =  $.trim($(this).find('Fees').text()); 
						if ( fees === '&nbsp;'){
							fees = '';
							$('#Fees').remove();
						}
						else if ( fees === ''){
							$('#Fees').remove();
						}
						else {
							$('#Fees').append('<h2>'+feesText+'</h2>');
							$('#Fees').append(fees);
						}
				}

		function getFees01() {
				$.ajax({ url : "fees-01.html", dataType: "text", success : function (data) {
						$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees02() {
				$.ajax({ url : "fees-02.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees03() {
				$.ajax({ url : "fees-03.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees04() {
				$.ajax({ url : "fees-04.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees05() {
				$.ajax({ url : "fees-05.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees06() {
				$.ajax({ url : "fees-06.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees07() {
				$.ajax({ url : "fees-07.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}					
		function getFees08() {
				$.ajax({ url : "fees-08.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}
		function getFees09() {
				$.ajax({ url : "fees-09.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}		
		function getFees10() {
				$.ajax({ url : "fees-10.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}
		function getFees11() {
				$.ajax({ url : "fees-11.html", dataType: "text", success : function (data) {
					$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}

		function getFeesDegrees() {
				$.ajax({ url : "fees-degrees.html", dataType: "text", success : function (data) {
							$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}
		function getFeesHN() {
				$.ajax({ url : "fees-hn.html", dataType: "text", success : function (data) {
							$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}
		function getFeesPDA() {
				$.ajax({ url : "fees-pda.html", dataType: "text", success : function (data) {
							$('#Fees').append('<h2>'+feesText+'</h2>');
						$('#Fees').append(data);
					}
				});
		}
		
		
		


// *** FEES TAB *** //

		// *** FUNDING TAB *** //
				var funding =  $.trim($(this).find('Funding').text());

				$('#Funding').append('<h2>'+fundingText+'</h2>');
				$('#Funding').append(funding);

		// *** FUNDING TAB *** //





		// *** CAREER TAB *** //
				var career = $.trim($(this).find('Career').text());

				if ( career === '&nbsp;'){
					$('#Career').remove();
					$('#wysiwygTab-selector-4').remove();
					career = '';
				}
				else if ( career === ''){
					$('#Career').remove();
					$('#wysiwygTab-selector-4').remove();
				}
				else {
					$('#Career').append('<h2>'+careerText+'</h2>');
					$('#Career').append('<p>'+career+'</p>');
				}


				var further =  $.trim($(this).find('Further').text());

				if ( further === '&nbsp;'){
					$('#Further').remove();
					further = '';
				}
				else if ( further === ''){
					$('#Further').remove();
				}
				else {
					$('#Further').append('<h2>'+furtherText+'</h2>');
					$('#Further').append('<p>'+further+'</p>');
				}

				var progression = $(this).find('Progression').text();
				var prog_img = $(this).find('Progress_Image').text();	

				$('<p>').html(progression+prog_img+'</p>').appendTo('#Prog');

		// *** CAREER TAB *** //

		// *** APPLY TAB *** //
				//var Apply = $.trim($(this).find('Apply').text());

				//if ( Apply === '<UL></UL>'){
				//	Apply = '';
				//	$('#Apply').remove();
				//	$('#wysiwygTab-selector-5').remove();
				//}
				//else if ( Apply === ''){
				//	$('#Apply').remove();
				//	$('#wysiwygTab-selector-5').remove();
				//}
				//else {
				//	$('#Apply').append('<p>'+Apply+'</p>');
				//	$("#Apply p a").wrap("<li></li>");
				//	$('#Apply br').remove();
				//}
				
		// *** APPLY TAB *** //

		// *** RHS TABS *** //
				//var Ctc_Name = $.trim($(this).find('Ctc_Name').text());
				//var Ctc_Email = $(this).find('Ctc_Email').text().replace(/ /g,'');
				//var Ctc_Loc = $(this).find('Ctc_Loc').text();
				//var Ctc_Tel = $(this).find('Ctc_Tel').text();
				
				//if ( Ctc_Name != ''){
				//	$('.Enquiry').append('<h3>Staff</h3><p><a href="mailto:'+Ctc_Email+'">'+Ctc_Name+'</a><br/>'+Ctc_Loc+'<br/>'+Ctc_Tel+'</p>');
				//}
                //else { $('.Enquiry').append('<h3>Contact us</h3><p><a href="mailto:info@uhi.ac.uk" title="Contact the UHI Information Line">UHI Information Line</a><br/>0845 272 3600</p>');}
				
				$('.Enquiry').append('<h3>'+contactText+'</h3><p><a href="mailto:info@uhi.ac.uk" title="Contact the UHI Information Line">'+infoText+'</a><br/>0845 272 3600</p>');
				
				var code = $(this).find('UCAS_Code').text().replace(/ /g,'');
				
				if ( code == '<p>N/A</p>'){
					$('div.staff').remove();
				}
				else if ( code == 'N/A'){
					$('div.staff').remove();
				}
				else if ( code == ''){
					$('div.staff').remove();
				}
				else {
					//var codeText= "UCAS code";
					$('.staff').append('<h3>'+ucasText+'</h3>');
					$('.staff').append('<p>'+code+'</p>');
				}

				//if (courseCode === 'UX343'){
				//	$('<div id="right-box" class="ApplyBox"><h3>Apply</h3><p><a href="http://www.strath.ac.uk/forms/pdu/charteredteacher/" title="Apply for this course through the University of Strathclyde" target="_blank">Apply for this course through the University of Strathclyde</a></p></div>').insertAfter('.Enquiry');					
				//}
				//if (courseCode === 'UF660'){
				//	$('<div id="right-box" class="ApplyBox"><h3>Apply</h3><p><a href="/apply" title="Apply for this course">Apply to start this course in 2012 - 2013</a><br />(applications for 2011 are now closed)</p></div>').insertAfter('.Enquiry');
				//}
				//else if (courseCode === 'UQ320'){
				//	$('<div id="right-box" class="ApplyBox"><h3>Apply</h3><p><a href="/apply" title="Apply for this course">Apply to start this course in 2012 - 2013</a><br />(applications for 2011 are now closed)</p></div>').insertAfter('.Enquiry');
				//}
				//else{
					$('<div id="right-box" class="ApplyBox"><h3>'+applyText+'</h3><p><a href="/apply" title="Apply for this course">'+applyCourseText+'</a></p></div>').insertAfter('.Enquiry');
				//}


				//var Enquiry = $(this).find('Enquiry').text();

				//if ( Enquiry != ''){
					//var enquiryText= "Make an enquiry";
					//$('.Enquiry').append('<h2>'+enquiryText+'</h2>');
				//	$('.Enquiry').append('<p>'+Enquiry+'</p>');
				//}
				//else{
				//	$('div.Enquiry').remove();
				//}

				var Quote = $.trim($(this).find('Quote').text());

				if ( Quote != ''){
					QuoteTrim = truncate(Quote, 20);
					$('.Quote').append('<p>'+QuoteTrim+'</p><a id="profileFull" href="#inline1" title="Student profile">Read more</a>');
					$('.Quote').append('<div style="display: none;"><div id="inline1" style="width:400px;height:100px;overflow:auto;"><p>'+Quote+'</p></div></div>');
				}
				else{
					$('div.Quote').remove();
					$('div.profilePic').remove();
				}
				
				
				var facebook = $.trim($(this).find('Facebook_URL').text());
				

                                if (facebook !== '' && Quote == ''){
					$('<br /><a href="'+facebook+'" title="Find us on facebook" target="_blank"><img src="facebook.jpg" alt="find us on facebook" title="Find us on facebook" /></a>').insertAfter('.ApplyBox');
				}
				else if (facebook !== ''){
					$('<br /><a href="'+facebook+'" title="Find us on facebook" target="_blank"><img src="facebook.jpg" alt="find us on facebook" title="Find us on facebook" /></a>').insertAfter('.Quote');
				}
		// *** RHS TABS *** //

		// *** DISCLAIMER *** //
				//$('<p>Disclaimer info....</p>').insertAfter('.pane-break');
				$('.pane-container').after('<p><em>'+ disclaimer +'</em></p>');
		
		// *** DISCLAIMER *** //


		$("div.toggle_container").hide(); 
		
		$("h2.trigger").click(function(){
			$(this).toggleClass("active").next().slideToggle("slow");
		});

		$(".toggle_container p").wrap("<strong></strong>");


				var UCAS_Code = $(this).find('UCAS_Code').text();
				var Keywords = $(this).find('Keywords').text();
				var Entry_Year = $(this).find('Entry_Year').text();
				var Summary2 = $(this).find('Summary2').text();
				var Quote_by = $(this).find('Quote_by').text();
				var Cont_Summ = $(this).find('Cont_Summ').text();
				var Info_Line = $(this).find('Info_Line').text();

			$("#profileFull").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});


			$("#structured").fancybox({'titlePosition': 'inside'});
			$("#unstructured").fancybox({'titlePosition': 'inside'});
			$("#struct").fancybox({'titlePosition': 'inside'});
			$("#unstruct").fancybox({'titlePosition': 'inside'});
			});
		}

///////////////////////////////////////////////////////////////////////

	$("#main_body").empty().html('<h2 align="center">Loading course list.<br /> <br /><img src="loadingIcon.gif" /></h2>');

	var keyword = '';
	var pub = '';

	var i = 0;
	
    if (url.indexOf('business-and-leisure') > -1) {
		  var area = "busi";
		  var area1 = "outd";
		  var area2 = "tour";
		  var area3 = "mana";
		  var area4 = "hosp";
	}
    else if (url.indexOf('arts-humanities-and-social-sciences') > -1) {
		  var area = "huma";
		  var area1 = "arts";
		  var area2 = "soci";
		  var area3 = "cult";
	}
    else if (url.indexOf('health-and-wellbeing') > -1) {
		  var area = "heal";
		  var area1 = "beau";
		  var area2 = "spor";
		  var area3 = "soca";
	}
    else if (url.indexOf('education-and-childcare') > -1) {
		  var area = "chil";
		  var area1 = "educ";
		  var area2 = "lang";
	}
    else if (url.indexOf('gaelic-medium-studies') > -1) {
		  var area = "gael";
	}
    else if (url.indexOf('creative-and-cultural-industries') > -1) {
		  var area = "crea";
		  var area1 = "arta";
	}
    else if (url.indexOf('energy-engineering-and-construction') > -1) {
		  var area = "engi";
		  var area1 = "ener";
		  var area2 = "cons";
	}
    else if (url.indexOf('science-and-environment') > -1) {
		  var area = "coun";
		  var area1 = "envi";
		  var area2 = "scie";
	}
    else if (url.indexOf('computing-and-it') > -1) {
		  var area = "comp";
	}
	else if (url.indexOf('NEW') > -1){
		  var area='';
	  }


if ($("#main_body")[0]) { 
	searchThisLanding();
}

	function searchThisLanding() {				
		$.ajax({
			type: "GET",
			url:"/040711.xml",
			dataType: "xml",
			success: function(xml) { loadLandingPublication(xml) }
		});
	}

	function loadLandingPublication (xml) {
		i = 0;
		var row;
		var searchExp = " ";

	if ( area !== ''){
		$(xml).find('narrative[area='+ area +'], [area='+ area1 +'], [area='+ area2 +'], [area='+ area3 +'], [area='+ area4 +']').each(function () {
			var name = $.trim($(this).find('Course_Name').text());
			var url = $(this).find('Course_URL').text().replace(/ /g,'');
			var network = $(this).find('Subject_Network').text().replace(/ /g,'');
			var code = $(this).find('Course_Code').text();
			var level = $(this).find('Course_Level').text();
			var summary = $(this).find('Summary').text();
			var start = $(this).find('Crs_Start').text();
			var mode = $(this).find('Study_Options').text();
			var fee = $(this).find('Course_Fee').text();
			var contact = $(this).find('Ctc_Name').text();
			var type = $(this).find('Course_Type').text();
			var everything = $(this).find('*').text();
			var location = $(this).find('Location_Search').text();
			var ucas = $(this).find('UCAS_Code').text().replace(/ /g,'');

			summary = truncate(summary, 30);

			var exp = new RegExp(keyword,"gi");
			
			searchExp = everything.match(exp);
			if ( searchExp != null ) {
				i++;
				pub += '<tr' + row + '"> \n <td valign="top" ><h3 class="trigger2">' + name + '</h3><div class="toggle_contain">' + summary + ' \n <p><a href="'+url+'">Full course details ...</a></p></div></td> \n';
				pub += '<td valign="top" >' +level+ '</td> \n <td valign="top" >' +start+ '</td> \n <td valign="top" >' +mode+ '</td> \n </tr>' + '\n';
			}
		});
	}
	else if ( area === ''){
		$(xml).find('narrative').each(function () {
			var name = $.trim($(this).find('Course_Name').text());
			var url = $(this).find('Course_URL').text().replace(/ /g,'');
			var network = $(this).find('Subject_Network').text().replace(/ /g,'');
			var code = $(this).find('Course_Code').text();
			var summary = $(this).find('Summary').text();
			var start = $(this).find('Crs_Start').text();
			var mode = $(this).find('Study_Options').text();
			var fee = $(this).find('Course_Fee').text();
			var contact = $(this).find('Ctc_Name').text();
			var type = $(this).find('Course_Type').text();
			var everything = $(this).find('*').text();
			var location = $(this).find('Location_Search').text();
			var summary_main = $(this).find('summary_main').text();
			var ucas = $(this).find('UCAS_Code').text().replace(/ /g,'');

			summary = truncate(summary, 30);

			var exp = new RegExp(keyword,"gi");
			
			searchExp = everything.match(exp);
			if ( searchExp != null ) {
				i++;
				pub += '<tr' + row + '"> \n <td valign="top" ><h3 class="trigger2">' + name + '</h3><div class="toggle_contain">' + summary + ' \n <p><a href="'+url+'">Full course details ...</a></p></div></td> \n';
				pub += '<td valign="top" >' +level+ '</td> \n <td valign="top" >' +start+ '</td> \n <td valign="top" >' +mode+ '</td> \n </tr>' + '\n';
			}
		});
	}
		if ( i == 0 ) {
			pub += '<div class="error">' + '\n' + 'No Result was Found' + '\n' +'</div>' + '\n';			
			$('#main_body').html( pub );
		}
		else {
			showResult ( pub );
			pager();
		}
	}
	
function showResult (resultSet) {

		pub = '<div class="messcode">There are <strong>' + i + '</strong> courses available in this section';
		pub += '<div class="pager"><strong>Displaying page <span class="currentPage"></span> of <span class="totalPages"></span></strong></div>';
		pub += '<div class="pager"><strong><a href="#" alt="Previous" class="prevPage"><< Prev</a> &nbsp; &nbsp;<a href="#" alt="Next" class="nextPage">Next >></a></strong></div></div><br />';
		pub += '<table class="tablesorter" id="resultTable"  width="960px">' + '\n';
		pub += '<thead><tr>' + '\n';
		pub += '<th width="360px">Course Title</th>' + '\n';
		pub += '<th width="200px">Course Level</th>' + '\n';
		pub += '<th width="200px">Start Date</th>' + '\n';
		pub += '<th width="200px">Attendance</th>' + '\n';
		pub += '</tr></thead>' + '\n';
		pub += '<tbody>' + '\n';
		pub += resultSet;
		pub += '</tbody>' + '\n';
		pub += '</table>' + '\n';

		$('#main_body').html(pub)

		$(".toggle_contain").hide(); 

		$("h3.trigger2").click(function(){
			$(this).toggleClass("active").next().slideToggle("slow");
		});

		$('tbody tr').addClass('visible');

        $("#resultTable").tablesorter(); 

		$('.visible:even').addClass('odd');

	}


////////////////////////////////////////////////////////////////////

$("#main_body_results").empty().html('<h2 align="center">Loading course list.<br /> <br /><img src="loadingIcon.gif" /></h2>');

	//var catType = '';
	var pub = '';

	var i = 0;

    var str = $("form").serialize();

if ($("#main_body_results")[0]) { 
	searchThis();
	var keyword = getUrlVars()["term"].replace(/[+]/g,' ');
	var searchedFor = $.trim(keyword); //trim white space
}

	function getUrlVars()
	{
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}


	function searchThis() {				
		$.ajax({
			type: "GET",
			url:"/040711.xml",
			dataType: "xml",
			success: function(xml) { loadPublication(xml) }
		});
	}


	function loadPublication (xml) {
		i = 0;
		var row;
		var searchExp = "";

		$(xml).find('narrative').each(function () {
			var name = $.trim($(this).find('Course_Name').text());
			var url = $(this).find('Course_URL').text().replace(/ /g,'');
			var code = $(this).find('Course_Code').text();
			var level = $(this).find('Course_Level').text();
			var summary = $(this).find('Summary').text();
			var start = $(this).find('Crs_Start').text();
			var mode = $(this).find('Study_Options').text();
			var fee = $(this).find('Course_Fee').text();
			var contact = $(this).find('Ctc_Name').text();
			var type = $(this).find('Course_Type').text();
			var everything = $(this).find('*').text();
			var location = $(this).find('Location_Search').text();
			var keywords = $(this).find('Keywords').text().replace(/ /g,'');

			var area = $(this).find('Subject_Area').text().replace(/ /g,'');

					if ( area === 'busi'){
						network = 'business-and-leisure';
					}
					else if ( area === 'outd'){
						network = 'business-and-leisure';
					}
					else if ( area === 'spor'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'tour'){
						network = 'business-and-leisure';
					}
					else if ( area === 'mana'){
						network = 'business-and-leisure';
					}
					else if ( area === 'hosp'){
						network = 'business-and-leisure';
					}
					else if ( area === 'huma'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'arts'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'arta'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'soci'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'heal'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'beau'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'soca'){
						network = 'health-and-wellbeing';
					}
					else if ( area === 'chil'){
						network = 'education-and-childcare';
					}
					else if ( area === 'educ'){
						network = 'education-and-childcare';
					}
					else if ( area === 'lang'){
						network = 'education-and-childcare';
					}
					else if ( area === 'gael'){
						network = 'gaelic-medium-studies';
					}
					else if ( area === 'cult'){
						network = 'arts-humanities-and-social-sciences';
					}
					else if ( area === 'crea'){
						network = 'creative-and-cultural-industries';
					}
					else if ( area === 'engi'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'ener'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'cons'){
						network = 'energy-engineering-and-construction';
					}
					else if ( area === 'coun'){
						network = 'science-and-environment';
					}
					else if ( area === 'envi'){
						network = 'science-and-environment';
					}
					else if ( area === 'scie'){
						network = 'science-and-environment';
					}
					else if ( area === 'comp'){
						network = 'computing-and-it';
					}

					var network = network;

			summary = truncate(summary, 30);

			keyword	=	$.trim(keyword); //trim white space
		    keyword = keyword.replace(/ /gi, '.*'); 

			var exp = new RegExp(keyword,"gi");			
			
			searchExp = name.match(exp) || keywords.match(exp) || level.match(exp);
			if ( searchExp != null ) {
				i++;
				pub += '<tr' + row + '"> \n <td valign="top" ><h3 class="trigger">' + name + '</h3><div class="toggle_contain">' + summary + ' \n <p><a href="'+network+'/'+url+'">Full course details ...</a></p></div></td> \n';
				pub += '<td valign="top" >' +level+ '</td> \n <td valign="top" >' +start+ '</td> \n <td valign="top" >' +mode+ '</td> \n </tr>' + '\n';
			}
		});



		if ( i == 0 ) {
			pub += '<div class="error">' + '\n' + 'No Result was Found' + '\n' +'</div>' + '\n';			
			$('#main_body_results').html( pub );
		}
		else {
			showResultSearch ( pub );
			pager();
		}
	}
	
function showResultSearch (resultSet) {
		pub = '<div class="messcode">Your search for <strong>"' + searchedFor + '"</strong> has found <strong>' + i + '</strong> courses';
		pub += '<div class="pager"><strong>Displaying page <span class="currentPage"></span> of <span class="totalPages"></span></strong></div>';
		pub += '<div class="pager"><strong><a href="#" alt="Previous" class="prevPage"><< Prev</a> &nbsp; &nbsp;<a href="#" alt="Next" class="nextPage">Next >></a></strong></div></div><br />';
		pub += '<table class="tablesorter" id="resultTable"  width="960px">' + '\n';
		pub += '<thead align="left"><tr>' + '\n';
		pub += '<th width="360px">Course Title</th>' + '\n';
		pub += '<th width="200px">Course Level</th>' + '\n';
		pub += '<th width="200px">Start Date</th>' + '\n';
		pub += '<th width="200px">Attendance</th>' + '\n';
		pub += '</tr></thead>' + '\n';
		pub += '<tbody>' + '\n';
		pub += resultSet;
		pub += '</tbody>' + '\n';
		pub += '</table>' + '\n';

		$('#main_body_results').html(pub)

		$(".toggle_contain").hide(); 

		$("h3.trigger").click(function(){
			$(this).toggleClass("active").next().slideToggle("slow");
		});

		$('tbody tr').addClass('visible');

        $("#resultTable").tablesorter(); 

		$('.visible:even').addClass('odd');

}



$(".defaultText").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
});
    
$(".defaultText").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
});
    
$(".defaultText").blur();

function zebraRows(selector, className)
	{
		$(selector).removeClass(className).addClass(className);
	}
	function pager(){
		$('#resultTable').paginateTable();
}


/////////// TRUNCATE FUNCTION //////////
function truncate (text, limit, append) {
    if (typeof text !== 'string'){
        return '';}
    if (typeof append == 'undefined'){
        append = '...';}
    var parts = text.split(' ');
    if (parts.length > limit) {
        for (var i = parts.length - 1; i > -1; --i) {
            if (i+1 > limit) {
                parts.length = i;
            }
        }
        parts.push(append);
    }
    return parts.join(' ');
}

/////////// TRUNCATE FUNCTION //////////

});


