// Job Search

/*	SubSector load select */
// this function sets up the gateway we'll use and requests the items that will populate the first select box.
function body_onLoad() {
	objGateway1 = new gateway("serverpages/TRS4.cfm?");
	objGateway1.setListener('subsectorPacket_onReceive').setArguments( {type:'subsector-name'} ).request();

	objGateway2 = new gateway("serverpages/TRS4.cfm?");
	objGateway2.setListener('freetextPacket_onReceive').setArguments( {type:'freetext'} ).request();

	objGateway3 = new gateway("serverpages/TRS4.cfm?");
	objGateway3.setListener('levelPacket_onReceive').setArguments( {type:'job-level'} ).request();

	objGateway4 = new gateway("serverpages/TRS4.cfm?");
	objGateway4.setListener('featurePacket_onReceive').setArguments( {type:'key-feature'} ).request();

	//objGateway5 = new gateway("serverpages/TRS4.cfm?");
	//objGateway5.setListener('qualificationPacket_onReceive').setArguments( {type:'qualification'} ).request();

	objGateway7 = new gateway("serverpages/TRS4.cfm?");
	//objGateway7.setListener('listPacket_onReceive').setArguments( {type:'job-list'} ).request();

	//if ((objGateway7)) alert('okay'); else alert ('not');
}

/*	SubSector selection */
function subsectorPacket_onReceive(packet) {
	var select = document.getElementById('selectSubsector');
	if (select.selectedIndex && select.selectedIndex >= 0)
		var choice	= select.options[select.selectedIndex].value;
	else
		var choice = 0; 
	srsLoadSelect(select, packet, 'subsectorid', 'subsector', ':: Subsector::', 0, ':: Any Subsector ::', 0, choice);
}

/*	SubSector selected item & load basis Type */
function selectSubsector_onChange(field) {
	var choice = field.options[field.selectedIndex].value;
	
	objGateway1.setListener('subsectorPacket_onReceive').setArguments( {type:'subsector-name',SubsectorID:choice} ).request();
	objGateway2.setListener('freetextPacket_onReceive').setArguments( {type:'freetext',SubsectorID:choice} ).request();
	objGateway3.setListener('levelPacket_onReceive').setArguments( {type:'job-level',SubsectorID:choice} ).request();
	objGateway4.setListener('featurePacket_onReceive').setArguments( {type:'key-feature',SubsectorID:choice} ).request();
	//objGateway5.setListener('qualificationPacket_onReceive').setArguments( {type:'qualification',SubsectorID:choice} ).request();
	objGateway7.setListener('listPacket_onReceive').setArguments( {type:'job-list',SubsectorID:choice} ).request();
}

/*	Free Text Search */
function freetextPacket_onReceive(packet) {

}

/*	SubSector selected item & load basis Type */
function freeText_onChange(field) {
	var choice = field.value;
	
	objGateway1.setListener('subsectorPacket_onReceive').setArguments( {type:'subsector-name',FreeText:choice} ).request();
	objGateway2.setListener('freetextPacket_onReceive').setArguments( {type:'freetext',FreeText:choice} ).request();
	objGateway3.setListener('levelPacket_onReceive').setArguments( {type:'job-level',FreeText:choice} ).request();
	objGateway4.setListener('featurePacket_onReceive').setArguments( {type:'key-feature',FreeText:choice} ).request();
	//objGateway5.setListener('qualificationPacket_onReceive').setArguments( {type:'qualification',FreeText:choice} ).request();
	objGateway7.setListener('listPacket_onReceive').setArguments( {type:'job-list',FreeText:choice} ).request();
}

/*	Job Level selection */
function levelPacket_onReceive(packet) {
	var select = document.getElementById('selectJobLevel');
	if (select.selectedIndex && select.selectedIndex >= 0)
		var choice	= select.options[select.selectedIndex].value;
	else
		var choice = 0; 
	srsLoadSelect(select, packet, 'joblevelid', 'joblevel', ':: Job Level ::', 0, ':: Any Level ::', 0, choice);
}

/*	Job Level selected item & load Suitability */
function selectJobLevel_onChange(field) {
	var choice = field.options[field.selectedIndex].value;

	objGateway1.setListener('subsectorPacket_onReceive').setArguments( {type:'subsector-name',JobLevelID:choice} ).request();
	objGateway2.setListener('freetextPacket_onReceive').setArguments( {type:'freetext',JobLevelID:choice} ).request();
	objGateway3.setListener('levelPacket_onReceive').setArguments( {type:'job-level',JobLevelID:choice} ).request();
	objGateway4.setListener('featurePacket_onReceive').setArguments( {type:'key-feature',JobLevelID:choice} ).request();
	//objGateway5.setListener('qualificationPacket_onReceive').setArguments( {type:'qualification',JobLevelID:choice} ).request();
	objGateway7.setListener('listPacket_onReceive').setArguments( {type:'job-list',JobLevelID:choice} ).request();
}

/*	Key Feature selection */
function featurePacket_onReceive(packet) {
	var select = document.getElementById('selectKeyFeature');
	if (select.selectedIndex && select.selectedIndex >= 0)
		var choice	= select.options[select.selectedIndex].value;
	else
		var choice = 0; 
	srsLoadSelect(select, packet, 'keyfeatureid', 'keyfeature', ':: Key Feature ::', 0, ':: Any Feature ::', 0, choice);
}

/*	Key Feature selected item & load Suitability */
function selectKeyFeature_onChange(field) {
	var choice = field.options[field.selectedIndex].value;

	objGateway1.setListener('subsectorPacket_onReceive').setArguments( {type:'subsector-name',KeyFeatureID:choice} ).request();
	objGateway2.setListener('freetextPacket_onReceive').setArguments( {type:'freetext',KeyFeatureID:choice} ).request();
	objGateway3.setListener('levelPacket_onReceive').setArguments( {type:'job-level',KeyFeatureID:choice} ).request();
	objGateway4.setListener('featurePacket_onReceive').setArguments( {type:'key-feature',KeyFeatureID:choice} ).request();
	//objGateway5.setListener('qualificationPacket_onReceive').setArguments( {type:'qualification',KeyFeatureID:choice} ).request();
	objGateway7.setListener('listPacket_onReceive').setArguments( {type:'job-list',KeyFeatureID:choice} ).request();
}

/*	Qualification selection */
function qualificationPacket_onReceive(packet) {
	var select = document.getElementById('selectQualification');
	if (select.selectedIndex && select.selectedIndex >= 0)
		var choice	= select.options[select.selectedIndex].value;
	else
		var choice = 0; 
	srsLoadSelect(select, packet, 'qualificationid', 'qualification', ':: Qualification ::', 0, ':: Any Qualification ::', 0, choice);
}

/*	qualification selected item & load details */
function selectQualification_onChange(field) {
	var choice = field.options[field.selectedIndex].value;

	objGateway1.setListener('subsectorPacket_onReceive').setArguments( {type:'subsector-name',qualificationID:choice} ).request();
	objGateway2.setListener('freetextPacket_onReceive').setArguments( {type:'freetext',qualificationID:choice} ).request();
	objGateway3.setListener('levelPacket_onReceive').setArguments( {type:'job-level',qualificationID:choice} ).request();
	objGateway4.setListener('featurePacket_onReceive').setArguments( {type:'key-feature',qualificationID:choice} ).request();
	//objGateway5.setListener('qualificationPacket_onReceive').setArguments( {type:'qualification',qualificationID:choice} ).request();
	objGateway7.setListener('listPacket_onReceive').setArguments( {type:'job-list',qualificationID:choice} ).request();
}

/*	Jobs List */
function listPacket_onReceive(packet) {
	var results = '<table cellpadding="2" cellspacing="0" width="100%"><tr><td bgcolor="#4177b"><font color="#FFFFFF">Job Title</font></td><td  bgcolor="#4177bf"><font color="#FFFFFF">Job Level</font></td><td  bgcolor="#4177b"><font color="#FFFFFF">Subsector</font></td></tr>';
	for ( var i = 0 ; i < packet.jobtitle.length; i++ ) {
		results = results+ '<TR><TD><A HREF="careers_details_extra.cfm?JobID=' +packet.jobid[i]+ '">' +packet.jobtitle[i]+ '</A></TD><TD>'+packet.joblevel[i]+'</TD><TD>'+packet.subsectorname[i]+'</TD></TR>';
	}
	results = results + '</table>';
	document.getElementById('divResults').innerHTML = results;
	document.getElementById('tableResults').style.display = 'block';
}
