﻿$(document).ready(function(){

if((document.title.indexOf('<') !=-1))
	document.title =document.title.substr(0,document.title.indexOf('<'));
	
	 // This does the popup using the cluetip plugin.
    loadCueTip();

  
});

function doCourseSrch()
{
	var srchterm = jQuery.trim( $('#coursefind').val());
	var srchtype = jQuery.trim($('input[name=ctype]:checked').val());
	if(srchterm == '')
	{
		//$.prompt('Please provide a search term for Course Search');
		return false;
	}	
	if (srchtype == '')
	{
		//$.prompt('Please select your search type, Local or International');
		return false;
	}
	 

	if (srchtype.toLowerCase() != 'international')
	{
	 	srchtype = 'All';
	}
	else
	{
		// Set the international scope, the idxst=2 url parameter is to enable selection of the Advanced Search dropdown
		srchtype = 'International&idxst=2';
	}
	
	
	
	var res=location.protocol+ '//'+ location.host + '/courses/pages/coursesearchresults.aspx?wd='+srchterm +'&st='+srchtype;

	window.location = res;
	 
}


function dotreeviewpre(node)
{
//	$(node).treeview({collapsed: true, unique: true, prerendered: true});
	$(node).treeview({collapsed: true, unique: true});
	$(node).show();
}


function doGlobalSrch()
{
	var srchstr = jQuery.trim( $("#gsearchboxtxt").val());
	var srchtype = jQuery.trim($('input[name=rb_CourseSearch]:checked').val());

	if(srchstr == '')
	{
		//$.prompt('Please provide a search term for Global Search');
		return false;
	}
	
		window.location=location.protocol+ '//'+ location.host + '/search/results.aspx?k='+srchstr + '&wd=' + srchstr;
	
	return false;
}


function handleEnter(e, buttonid)
{
	if (e.which || e.keyCode) {
		if ((e.which == 13) || (e.keyCode == 13)) {
			document.getElementById(buttonid).click();
			return false;
		}
	} 
}

function convertToPageName(textToConvert) {
	// replace spaces with dash
	var converted = textToConvert.replace(/ /g, '-');
	// strip commas
	converted = converted.replace(/,/g, '');
	
	// If there are 3 dashes in the row then we can replace
	// them with 1
	converted = converted.replace('---', '-');

		
	return converted.toLowerCase();		
}

function updateCourseCentreLink(container) {
	var text = container.html();
	var link = '/visitors/pages/' + convertToPageName(text) + '.aspx';
	
	container.html('<a href="' + link + '">' + text  + '</a>');
}

function updateCareerCardLink(container) {
	var text = container.html();
    text = text.replace(/(&nbsp;)*/g,""); 
	
	var link = '/courses/careers/pages/' + convertToPageName(text) + '.aspx';
	
	container.html('<a href="' + link + '">' + text  + '</a>');
}

function updateCourseLocationLink(container) {
	var text = container.html();

	if (text.match(/,$/)) {
		// trim last comma
		text = text.substring(0, text.length - 1);
	}
	var locations = text.split(',');
	var item, link, result = '';
	
	try {
		for (var i=0; i<locations.length; i++) {
			item = locations[i];
			pagename =  convertToPageName($.trim(item));
			
			if (pagename == 'elgar-campus' || 
				pagename == 'nelson-campus' ||
				pagename == 'whitehorse-campus') {
				
				link = '/visitors/pages/' + pagename + '.aspx';
				result += '<a href="' + link + '">' + item + '</a>';
			}
			else {
				result += item;
			}					

			if (i < (locations.length - 1)) {
				result += ', ';
			} 					
		}
		
		container.html(result);
	}
	catch (err) {
	}

}

function changeToggle(id)
{
  identity=document.getElementById(id);
  image_identity=document.getElementById(id + "_image");
  if(identity.className == "toggleshow")
  {
    identity.className="toggle";
    image_identity.src="http://www.bhtafe.edu.au/PublishingImages/expand_collapse_plus.gif";
  }
else{
    identity.className="toggleshow";
	image_identity.src="http://www.bhtafe.edu.au/PublishingImages/expand_collapse_minus.gif";
	}
}

/**
* This script registers the cue tip to load on the page.
*/
function loadCueTip() {
    $('a.popupContent').cluetip({ splitTitle: '|' });
}


function fixupStudyAreaDisplay(container) {
	var text = $.trim(container.html());

if (text.match(/&nbsp;$/)) {
		// trim last space column
		text = text.substring(0, text.length - 6);
	}


	if (text.match(/;$/)) {
		// trim last semi column
		text = text.substring(0, text.length - 1);
	}
	
	// If in the study area its displaying
	// &amp;amp; we remove the second amp so its
	// &amp;
	text = text.replace('&amp;amp;', '&amp;');
	
	container.html(text);

}



