// list menu show/hide onclick (mainly for course category pages)
function initMenus() {
	if (!document.getElementsByTagName) return;
	var elements = document.getElementsByTagName("LI");
	for (var i = 0; i < elements.length; i++) {
		var mclass = elements[i].className;
		if (mclass.indexOf("category") > -1) {
			var submenu = elements[i].childNodes;
			for (var j = 0; j < submenu.length; j++) {
				if (submenu[j].tagName == "A") {
					submenu[j].onclick = function() {
						var node = this.nextSibling;
						while (1) {
							if (node != null) {
								if (node.tagName == "OL") {
									var d = (node.style.display == "none")
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "treeopen" : "treeclosed";
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					}
					submenu[j].className = (mclass.indexOf("open") > -1) ? "treeopen" : "treeclosed";
				}
				
				if (submenu[j].tagName == "OL")
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
			}
		}
	}
}
window.onload = initMenus;

// PARSES QUERY STRING INTO VARIABLES
if (location.search.length != 0) {
	var get_vars = new Object();
	get_vars.varName = new Array();
	get_vars.varValue = new Array();
	var q_str = location.search.substring(1);
	var temp_var = q_str.split("&");
	for (x=0;x<temp_var.length;x++) {
	parts = temp_var[x].split("=");
	get_vars.varName[x] = parts[0];
	if (isNaN(parseFloat(parts[1]))) {
		get_vars.varValue[x] = '"' + parts[1] + '"';
	} else get_vars.varValue[x] = parts[1];
		eval(get_vars.varName[x] + "=" + get_vars.varValue[x]);
	}
}
var HOST = 'abcol.ac.uk';

// BEGIN STYLESWITCHER SCRIPTS
function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}
function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mtcmtauth', f.author.value, now, '/', HOST, '');
    setCookie('mtcmtmail', f.email.value, now, '/', HOST, '');
    setCookie('mtcmthome', f.url.value, now, '/', HOST, '');
}
function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', HOST);
    deleteCookie('mtcmthome', '/', HOST);
    deleteCookie('mtcmtauth', '/', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}
 var now = new Date();
 fixDate(now);
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
  
function setActiveStyleSheet(title) {
  setCookie('style', title, now, '/', HOST, '');
  var selfhref = self.location.href;
  if (selfhref.indexOf('#') > -1) {
     var selfhref_array = selfhref.split('#');
     self.location.replace(selfhref_array[0]+'?styleswitch');
  } else {
     self.location.replace(selfhref);
  }
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
var cookie = getCookie("style");
//if (hasFlash && !cookie) {
  	//setCookie('style', 'live', now, '/', HOST, '');
	//var cookie = getCookie("style");
//}

var currentstyle = cookie;
var title = cookie ? cookie : getPreferredStyleSheet();

  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
// END STYLE SWITCHER SCRIPTS

// COURSE SELECTOR SCRIPTS

var DomYes=document.getElementById?1:0;

function set_child_listbox(parentObject,childObject,childArray,spanToHide) {
	//Clear clild listbox
	for(var i=childObject.length;i>0;i--) {
		childObject.options[i] = null;
	} 

	childObject.options[0] = new Option("Select Value","");
	var selIndex = parentObject.options[parentObject.selectedIndex].value;
	if (selIndex == "") {
		childObject.disabled = true;
	} else {
		childObject.disabled = false;
		var childIndex = 1;
		for (i = 0; i < childArray.length; i++) {
			if (childArray[i][1] == selIndex) {
				childObject.options[childIndex] = new Option(childArray[i][2], childArray[i][0]);
				childIndex++;
			}
		}
	}

	//Select the first option
	childObject.selectedIndex = 0;
	childObject.onchange();

	//Hide a dependent block
	if (spanToHide != "") {
		if (DomYes) {
  			document.getElementById(spanToHide).style.display="none";
		} else {
			document.all[spanToHide].style.display="none";
		}
	}
}

function reload_page() {
	var sel_index = document.directory_items_statesSearch.s_category_id.options[document.directory_items_statesSearch.s_category_id.selectedIndex].value;
	var sel_subindex = document.directory_items_statesSearch.s_subcategory_id.options[document.directory_items_statesSearch.s_subcategory_id.selectedIndex].value;
	var sel_item = document.directory_items_statesSearch.s_item_id.options[document.directory_items_statesSearch.s_item_id.selectedIndex].value;
	if (sel_item != "") {
		document.location.href = document.location.pathname + "?" + "s_category_id=" + sel_index+"&s_subcategory_id=" + sel_subindex+"&s_item_id=" + sel_item;
	}
}

/*function disable_child_listbox() {

//Disable second listbox
if (document.directory_items_statesSearch.s_category_id.selectedIndex == "") {
document.directory_items_statesSearch.s_subcategory_id.disabled = true;
} else if (document.directory_items_statesSearch.s_subcategory_id.length == 1) {
document.directory_items_statesSearch.s_category_id.onchange();
}

//Disable third listbox
if (document.directory_items_statesSearch.s_subcategory_id.selectedIndex == "") {
document.directory_items_statesSearch.s_item_id.disabled = true;
}
}

window.onload = disable_child_listbox;*/



var SubCategory = new Array(
	new Array(10,1,"Accessories"),
	new Array(11,1,"Auto Wrecking"),
	new Array(37,5,"Bars, Pubs, and Clubs"),
	new Array(32,4,"Colleges and Universities"),
	new Array(25,3,"Communications and Networking"),
	new Array(26,3,"Computer Graphics"),
	new Array(27,3,"Computer Rental"),
	new Array(28,3,"Computer Service and Repair"),
	new Array(29,3,"Computer Training"),
	new Array(38,5,"Dance"),
	new Array(12,1,"Dealers"),
	new Array(30,3,"Desktop Publishing"),
	new Array(39,5,"Entertainers"),
	new Array(33,4,"K-12"),
	new Array(34,4,"Language"),
	new Array(13,1,"Motorcycles"),
	new Array(40,5,"Movies and Film"),
	new Array(41,5,"Museums and Galleries"),
	new Array(42,5,"Music"),
	new Array(35,4,"Preschools"),
	new Array(14,1,"Racing"),
	new Array(15,1,"Rental"),
	new Array(31,3,"Software"),
	new Array(43,5,"Tickets"),
	new Array(16,1,"Tires"),
	new Array(36,4,"Tutoring"),
	new Array(44,5,"Video")
);



var Items = new Array(
	new Array(2,31,"IBM"),
	new Array(4,31,"Microsoft"),
	new Array(3,31,"Oracle"),
	new Array(5,31,"Sun Microsystems"),
	new Array(1,31,"YesSoftware")
);

	var categories = new Array('Art &amp; Design', 'Business Management', 'Care', 'Communication', 'Computing &amp; IT', 'Engineering &amp; Construction', 'Hairdressing, Beauty &amp; Complimentary Therapies', 'Highers (SQA)', 'Hospitality', 'Music &amp; Performing Arts', 'Science', 'Small Animal Care', 'Social Science', 'Sport &amp; Fitness', 'Student Development &amp; ACCESS Centre (Assisted Study)', 'TV, Radio &amp; Sound Engineering', 'Travel &amp; Tourism');
function courseForm(){
	
	
	document.write("<form method='post' action='?ccsForm=directory_items_statesSearch' name='directory_items_statesSearch'>");
	document.write("<fieldset>");
	document.write("<label for='Course'>Course:<\/label>");
	document.write("<select name='s_category_id' onChange='set_child_listbox(this,document.directory_items_statesSearch.s_subcategory_id,SubCategory,'Items');' style='width: 150px;'>");
	document.write("<option selected='selected' value=''>Select Course<\/option>");
	for (i=0; i<categories.length; i++) {
			document.write("<option value="+i+" style='width:160px;'>"+categories[i]+"<\/option>");
	}
							
	document.write("<\/select>");
	document.write("<label for='Qualifications'>Qualification:<\/label>");
	document.write("<select name='s_subcategory_id' onChange='set_child_listbox(this,document.directory_items_statesSearch.s_item_id,Items,Items);' style='width: 150px;'>");
	document.write("<option selected value=''>Select Qualification<\/option>");
	document.write("<\/select>");
	document.write("<label class='study'>Study Method:<\/label>");
	document.write("<select name='s_item_id' onChange='reload_page();' style='width: 150px;'>");
	document.write("<option selected='selected'>Select Method<\/option>");
	document.write("<\/select>");
	document.write("<\/fieldset>");
	document.write("<\/form>");
}

// BEGIN FONT SELECTOR FUNCTIONS
function renderReadability () {
	document.write('<h2>site layout controls<\/h2>');
	document.write('<div class="box">');
	document.write('<form><label for="font">change font:<\/label><select name="fontfamily" style="width: 90px;" onChange="changeFontFamily(this.options[selectedIndex].value);">');
	var typefaces = new Array('Trebuchet', 'Arial', 'Verdana', 'Lucida Grande', 'Helvetica', 'Gill Sans', 'Georgia', 'Times');
	for (i=0; i<typefaces.length; i++) {
		if (fontfamily == typefaces[i]) {
			var notcustom = true;
			document.write('<option value="'+ typefaces[i]+'" selected="selected">'+typefaces[i]+'<\/option>');
		} else {
			document.write('<option value="'+ typefaces[i]+'">'+typefaces[i]+'<\/option>');
		}
	}
	if (!notcustom) {
		document.write('<option value="'+ fontfamily+'" selected="selected">'+fontfamily+'<\/option>');
	}
	document.write('<\/select><br />');
	document.write('<label for="size">change size:<\/label><select name="fontsize" onChange="changeFontSize(this.options[selectedIndex].value);">');
	for ( var x=0.8; x <= 2.1; x+=0.1) {
		if (Number(Math.round(10*x)/10) == Number(fontsize)) {
			document.write('<option value="'+Math.round(10*x)/10+'" selected="selected">'+Math.round(10*x)/10+'<\/option>');
		} else {
			document.write('<option value="'+Math.round(10*x)/10+'">'+Math.round(10*x)/10+'<\/option>');
		}
	}
	document.write('<\/select><\/form>');
	document.write('<\/div>');
}

var fontfamily = getCookie('fontfamily');
var fontsize = getCookie('fontsize');

if (!fontfamily) {
	var fontfamily = 'Trebuchet';
}
if (!fontsize) {
	var fontsize = 0.8;
}

function changeFontFamily (fontfamily) {
	setCookie('fontfamily', fontfamily.replace(/%20/g,unescape('%20')), now, '/', HOST, '');
	self.location.href = self.location.href;
}
function changeFontSize (fontsize) {
  setCookie('fontsize', fontsize, now, '/', HOST, '');
  self.location.href = self.location.href;
}

var fontfamilyadjusted;

	if (fontfamily == 'Times') {
		fontfamilyadjusted = '"Times New Roman", Times';
	} else if (fontfamily == 'Trebuchet') {
		fontfamilyadjusted = '"Trebuchet MS", Trebuchet';
	} else {
		fontfamilyadjusted = '"'+fontfamily+'"';
}
document.write('<style type="text/css">');
document.write('#content p,#content h2,#content h3,#content ul,#content form,table,#content ol#courseList,.category ol,#courseList .category ol{font-family:'+fontfamilyadjusted+'; font-size:'+fontsize+'em; line-height: 1.6em}');
document.write('<\/style>');


function select_course() {
	var form = MM_findObj('courseselect');
	var list = form.subjectarea
	var course = list.options[list.selectedIndex].value
	location = "coursedetails.cfm?group1=" + form.group1.value + "&subject=" + course;  
}
