// JavaScript source code
function addLoadListener(fn)
{
  	if (typeof window.addEventListener != 'undefined')
  	{
    	window.addEventListener('load', fn, false);
  	}
  	else if (typeof document.addEventListener != 'undefined')
  	{
    	document.addEventListener('load', fn, false);
  	}
  	else if (typeof window.attachEvent != 'undefined')
  	{
    	window.attachEvent('onload', fn);
  	}
  	else
  	{
    	var oldfn = window.onload;
    	if (typeof window.onload != 'function')
    	{
      	window.onload = fn;
   		}
    	else
    	{
      	window.onload = function()
      	{
        	oldfn();
        	fn();
      	};
    	}
  	}
}

addLoadListener(init);

function readCookie(name) {

	if (document.cookie == '') { 
	return false;
	} else { 
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);
	if(firstChar != -1)  {
	firstChar += name.length + 1;
	lastChar = theBigCookie.indexOf(';', firstChar);
	if(lastChar == -1) lastChar = theBigCookie.length;
	return unescape(theBigCookie.substring(firstChar, lastChar));
	} else {
	return false
	}
    }
}

function init() {
	if (document.getElementById('context')) {
		hideItem("context_alt");
		showItem("context");
	}
	if (cookie_string = readCookie("infoFor_cookie")) {
		user_pref = cookie_string;
		displayOptions(user_pref);
		document.getElementById('context_header').innerHTML=user_pref;
	}

  	document.cookie="furtherInfoFor_cookie=" + escape("pacific");
  	displayFurtherInfo("pacific")
	
	return true;
}	

function hideItem(id) 
{
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showItem(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function displayOptions(selection)
{
	switch (selection) {
            case "Prospective Undergraduates":
				hideItem("context_start");
				hideItem("postgrade");
				hideItem("intl");
				hideItem("alumni");
				hideItem("parents");
				showItem("undergrade");
				displayFurtherInfo("default");
                break;
            case "Prospective Postgraduates":
				hideItem("context_start");
				hideItem("undergrade");
				hideItem("intl");
				hideItem("alumni");
				hideItem("parents");
				showItem("postgrade");
				displayFurtherInfo("default");
                break;
            case "International Students":
				hideItem("context_start");
				hideItem("postgrade");
				hideItem("undergrade");
				hideItem("alumni");
				hideItem("parents");
				showItem("intl");
				displayFurtherInfo("default");
                break;
            case "Alumni":
				hideItem("context_start");
				hideItem("postgrade");
				hideItem("undergrade");
				hideItem("intl");
				hideItem("parents");
				showItem("alumni");
				displayFurtherInfo("default");
                break;
            case "Parents and Friends":
				hideItem("context_start");
				hideItem("postgrade");
				hideItem("undergrade");
				hideItem("intl");
				hideItem("alumni");
				showItem("parents");
				displayFurtherInfo("hide");
                break;
	}
}

function displayFurtherInfo(selection)
{
	switch (selection) {
            case "default":
				hideItem("mature");
				hideItem("mature_choice");
				hideItem("maori");
				hideItem("maori_choice");
				hideItem("pacific");
				hideItem("pacific_choice");
				showItem("further");
				showItem("choice");
                break;
	   case "mature":
				hideItem("further");
				hideItem("choice");
				hideItem("maori");
				hideItem("maori_choice");
				hideItem("pacific");
				hideItem("pacific_choice");
				showItem("mature");
				showItem("mature_choice");
                break;
	   case "maori":
				hideItem("further");
				hideItem("choice");
				hideItem("mature");
				hideItem("mature_choice");
				hideItem("pacific");
				hideItem("pacific_choice");
				showItem("maori");
				showItem("maori_choice");
                break;
	  case "pacific":
				hideItem("further");
				hideItem("choice");
				hideItem("maori");
				hideItem("maori_choice");
				hideItem("mature");
				hideItem("mature_choice");
				showItem("pacific");
				showItem("pacific_choice");
                break;
		
	}
}
