var optionTest;
optionTest = true;

// logic for the student enquiry form

/* used to be called during onLoad in the custom enquiries template, but no one
 * remembers why.
 * doing so caused a script error to occur when the form was submitted, because
 * the custom template was used on the reply page AND the form page, and there
 * are page elements referenced here that aren't present in the reply page.

function init_student_enquiry()
{ 
var previous;
previous="";
    document.enquire.reset();
	document.current.reset();
	document.previous.reset();
	document.noneoftheabove.reset();
	document.someoneelse.reset();
	document.enquire.first.selectedIndex = 0;
	document.enquire.second.selectedIndex = 0;
	document.enquire.third.selectedIndex = 0;
	document.enquire.qualification1.selectedIndex=0;
	document.enquire.qualification2.selectedIndex=0;
	document.enquire.program_info_required.selectedIndex=0;
	document.enquire.program_info_required.value="";
	optionTest = true;
	lgth = document.enquire.second.options.length - 1;
	document.enquire.second.options[lgth] = null;
	if (document.enquire.second.options[lgth]) optionTest = false;
}
*/

function populate_qualification()
{ 
	if (!optionTest) return;
	var box = document.enquire.qualification1;
	var box2 = document.enquire.qualification2;
	box2.options.length = 1;
	var level = box.options[box.selectedIndex].value;
	if (!level) return;
	var list = qual[level];
	for(i=0;i<list.length;i+=2)
	{
		box2.options[i/2] = new Option(list[i],list[i+1]);
	}
}

function populate_discipline()
{ 
	if (!optionTest) return;
	var box = document.enquire.first;
	var box2 = document.enquire.second;
	box2.options.length = 1;
	var box3 = document.enquire.third;
	box3.options.length = 0;
	box3.options[0] = new Option('Select area of study first','');
	var level = box.options[box.selectedIndex].value;
	if (!level) return;
	var list = discipline[level];
	for(i=0;i<list.length;i+=2)
	{
		box2.options[i/2] = new Option(list[i],list[i+1]);
	}
}

function populate_program()
{ 
	if (!optionTest) return;
	var box = document.enquire.first;
	var box2 = document.enquire.second;
	var box3 = document.enquire.third;
	box3.options.length = 0;
	box3.options[0] = new Option('Select area of study first','');
	var level = box.options[box.selectedIndex].value;
	var discipline = box2.options[box2.selectedIndex].value;
	if (!discipline) return;
	var list = programs[level][discipline];
	for(i=0;i<list.length;i++)
	{
		box3.options[i] = new Option(list[i], list[i]);
	}
}


/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function do_hide(whichID) {
 elem = document.getElementById(whichID);
 elem.style.display="none";
}
function do_show(whichID) {
 elem = document.getElementById(whichID);
 elem.style.display="block";
}


/* write out search term */                    
function search_term(form){
  var text;
  var box;
  box = document.enquire.third;
  text = box.options[box.selectedIndex].value;
  if( text )  {
    progam_display_indexof(text);
  } else {
      alert( 'Error: no text selected?' );
  }
}


function progam_display_indexof(text) {
  var field = document.enquire.program_info_required;
  if (field.value.indexOf(text) >= 0) {
    alert('Item already selected');
  } else {
    field.value += text + "\n";
  }
}

//-->
	
	

/* put student ID into subject field */    
function studentID() {
var text;
text = "Student ID " + document.current.studentnum.value + ". Enquiring about: ";
boxes = document.current.enquiring_about.length;
for (var i=0; i < boxes; i++){
	if (document.current.enquiring_about[i].checked) {
      text = text + document.current.enquiring_about[i].value + ", ";
		}
   }
document.current.subject.value = text;
}





/*** sets student type */
var mycontent=new Array()
mycontent[0]=' <img src="../images/tick.gif"> I am a current student <a href="#" onClick="expandcontent(this, \'sc1\'); do_hide(\'stu_type\')" >[change student type]</a>'
mycontent[1]=' <img src="../images/tick.gif"> I am a prospective student <a href="#" onClick="expandcontent(this, \'sc1\') ; do_hide(\'stu_type\')">[change student type]</a>'
mycontent[2]=' <img src="../images/tick.gif"> I am a previous student <a href="#" onClick="expandcontent(this, \'sc1\'); do_hide(\'stu_type\')">[change student type]</a>'
mycontent[3]=' <img src="../images/tick.gif"> I am making an enquiry on behalf of someone else <a href="#" onClick="expandcontent(this, \'sc1\'); do_hide(\'stu_type\')">[change student type]</a>'
mycontent[4]=' <img src="../images/tick.gif"> I am none of the above <a href="#" onClick="expandcontent(this, \'sc1\'); do_hide(\'stu_type\')">[change student type]</a>'





