//function populateOptions(response, controlToPopulate, focuss, selectedVal) {
function populateOptions() {
	var response 			= arguments[0];
	var controlToPopulate 	= arguments[1];
	var focuss 				= arguments[2];
	var selectedVal 		= arguments[3];
//	alert(response);
		rows = response.split('%%');
		for (var i=0;i<rows.length;i++) {
//		alert(rows[i])
			if(rows[i].indexOf('|' != -1)) {
				elem = rows[i].split('|');
				selected = elem[0] == selectedVal ? true : false;
				$(controlToPopulate).options[$(controlToPopulate).options.length] = new Option(elem[1], elem[0], false, selected);
			} 
			if(focuss)
				$(controlToPopulate).focus();
		} 
}
function doChange() {
	var id 		= arguments[0];
	var which	= arguments[1];
	var campus	= arguments[2];
	switch (which) {
		case 1 : // manage specialisation combobox using selected campus id
			if($F('campus')) { // a valid option selected
				for (var q=$('specialisation').options.length;q>=0;q--)
					$('specialisation').options[q] = null;	 // null all of them
				for (var q=$('startingDate').options.length;q>=0;q--)
					$('startingDate').options[q] = null; // null all of them


				$('specialisation').options[$('specialisation').options.length] = new Option('Please wait...', ''); // create first option (Please wait...)	
//				$('startingDate').options[$('startingDate').options.length] = new Option('Please wait...', ''); // create first option (Please wait...)
				$('startingDate').options[$('startingDate').options.length] = new Option('Please Programme First', ''); // create first option (Please wait...)

				new Ajax.Updater(
							'divSpecialisation', 
							'/_getFormData.php?ACT=DO&LANG='+LANG+'&CAMPUS='+id+'&WHICH=5', {
								method: 'get'
							});	


			}else{  // empty option selected (first item)

				for (var q=$('specialisation').options.length;q>=0;q--) // loop options
					$('specialisation').options[q] = null;	 // null all of them
				for (var q=$('startingDate').options.length;q>=0;q--) // loop options
					$('startingDate').options[q] = null;		 // null all of them	
				$('specialisation').options[$('specialisation').options.length] = new Option('Select ESE Centre First', ''); // create first option (Select campus first)	
				$('startingDate').options[$('startingDate').options.length] = new Option('Select ESE Centre First', ''); // create first option (Select campus first)
				$('campus').focus();
			}
		break;

		case 2 :  // manage date combobox using selected specialisation id
			if($F('specialisation')) { // a valid option selected
				for (var q=$('startingDate').options.length;q>=0;q--) // loop options
					$('startingDate').options[q] = null; // null all of them

				$('startingDate').options[$('startingDate').options.length] = new Option('Please wait...', ''); // create first option (Please wait...)	

				new Ajax.Updater(
							'divStartingDate', 
							'/_getFormData.php?ACT=DO&LANG='+LANG+'&CAMPUS='+campus+'&SPEC='+id+'&WHICH=6', {
								method: 'get'
							});	
			}else{  // empty option selected (first item)
				for (var q=$('startingDate').options.length;q>=0;q--) // loop options
					$('startingDate').options[q] = null;	 // null all of them		
				$('startingDate').options[$('startingDate').options.length] = new Option('Select Programme First', ''); // create first option (Select specialisation area first)
				$('specialisation').focus();
			}
		break;
	}
}