/**
* Methods and fields for making calls on AP services
*/

var APService = {
	
	// AP SERVICES -------------------------------------------------------	
	
	AP_APPLICANT_FILTER: 'ap.applicant.filter',
	AP_TASK_ASSIGN: 'ap.task.assign',
	AP_TASK_VIEWER: 'ap.task.viewer',
	AP_TASK_LISTER: 'ap.task.lister',
	AP_TASK_FILTER: 'ap.task.filter',
	AP_FORM_VIEWER: 'ap.form.viewer',
	AP_ASSESSOR_ASSIGN: 'ap.assessor.assign',
	AP_REGISTRATION_VIEWER: 'ap.registration.viewer',
	AP_EXTERNAL_USER_LISTER: 'ap.external.user.lister',
	AP_APPLICANT_LISTER: 'ap.applicant.lister',
	AP_APPLICANT_ASSIGN: 'ap.applicant.assign',
	AP_APPLICANT_PREAPEL_VIEWER: 'ap.applicant.preapel.viewer',
	AP_APPLICANT_APEL_VIEWER: 'ap.applicant.apel.viewer',
	AP_FORM_GETSTATEMENT: 'ap.form.getstatement',
	AP_CIBSE_USER_LISTER: 'ap.cibse.user.lister',
	AP_EXTERNAL_USER_VIEWER: 'ap.external.user.viewer',
	AP_APPLICANT_VIEWER: 'ap.applicant.viewer',
	AP_CIBSE_USER_VIEWER: 'ap.cibse.user.viewer',
	AP_TASK_SAVE: 'ap.task.save',
	AP_TASK_SAVESTATUS: 'ap.task.savestatus',
	AP_TASK_COMPLETE: 'ap.task.complete',
	AP_TASK_OPTIONOUTCOME: 'ap.task.optionoutcome',
	AP_TASK_APPROVE: 'ap.task.approve',
	AP_TASK_FAIL: 'ap.task.fail',
	AP_TASK_RESUBMIT: 'ap.task.resubmit',
	AP_FILE_CHECK: 'ap.file.check',
	AP_FILE_DOWNLOAD: 'ap.file.download',
	AP_FILE_REPLACE_PI: 'ap.file.replace.pi',
	AP_FILE_DOWNLOAD_FORM: 'ap.file.download.form',
	AP_APPLICANT_SAVE_COMMENTS: 'ap.applicant.save.comments',
	AP_APPLICANT_AUTOSAVE_COMMENTS: 'ap.applicant.autosave.comments',
	
	/**
	 * Handle AP events. Invoked from workbench.js
	 * @param {Object} event The event we are handling
	 * @param String context The AP interface framework context (see Context.js)
	 */
	handleEvent: function(event, context) {
		var element = Event.element(event);
		var parts=element.id.split("-");
		if(parts[parts.length-2]=="download_form"){
			APService.downloadForm(parts[parts.length-1]);
			Event.stop(event);
		}
		else if(event.type=="mouseup"){
			//L.D Replace Pi File - Set form values back
			if(parts[parts.length-2]=="replacement_pi_submit"){
				var form=$(element).up('form');
				form.target="aptasks-aPFormViewer-upload_target";
				$('aptasks-aPFormViewer-replacement_pi_service').name="";
				$('aptasks-aPFormViewer-replacement_pi_context').name=""
				form.target=""; 
				form.method="";  
				form.enctype="";
				form.action="javascript:void(0)";
				
			}
		}
		else if(event.type=="mousedown"){
			//L.D Replace Pi File - Make form post files, target is hidden iFrame.
			if (parts[parts.length-2]=="replacement_pi_submit"){
				var form=$(element).up('form');
				form.target="aptasks-aPFormViewer-upload_target";
				$('aptasks-aPFormViewer-replacement_pi_service').name="service";
				$('aptasks-aPFormViewer-replacement_pi_context').name="context";
				form.method="post";  
				form.encoding=form.enctype="multipart/form-data";
				form.action=Service.URL;
				form.submit();
				Event.stop(event);
			}
		}
		else if(parts[parts.length-2]=="replacement_pi_submit"){
			//L.D Replace Pi File - Just in case stop all events on submit button
			Event.stop(event);
		}
		else if (element.id.startsWith('apexternal-task-')) {
			// Get the task ID so we can view the task
			var taskID = Names.getInstanceID(element.id);
			var target = 'apexternal-task';
			APService.taskViewer(context, target, taskID);
		} else if (element.id.startsWith('aptasks-task-')) {
			// Get the task ID so we can view the task
			var taskID = Names.getInstanceID(element.id);
			var target = 'aptasks-task';
			
			APService.taskViewer(context, target, taskID);
		} else if (element.id.startsWith('aptasks-aPTaskViewer-')){
			var sectionSave=element.id;
			sectionSave=sectionSave.split("-");
			sectionSave=sectionSave[sectionSave.length-2];
			if (element.id.endsWith('-approve')) {
				try {
					var msg=this.apelCheckStatusOfConfirmed();
					if(msg==""){
						APService.approveAPEL(context);	
					}else{
						alert(msg);
					}								
				} catch(err) {;}									
			} else if (element.id.endsWith('-fail')) {
				//L.D need to stop this if apel form is not checked
				try {
					var msg=this.apelCheckStatusOfConfirmed();
					if(msg==""){
						APService.failAPEL(context);
					}else{
						alert(msg);
					}			
				} catch(err) {;}
			} else if (element.id.endsWith('-resubmit')) {
				APService.resubmitAPEL(context);
			} else if (element.id.endsWith('-save')||sectionSave=="save") {
				if(context==Context.APTASKS){
					APService.saveTask(context);					
				} else if(context==Context.APAPPLICANTS) {
					APService.saveComments(context);
				}
				
			} else if(element.id.endsWith('-savetaskstatus')) {
				APService.saveTaskStatus(context);	
			}else if (element.id.endsWith('-complete')) {
				APService.completeTask(context);
			}
		} else if (element.id.startsWith('apexternal-aPTaskViewer-')) {
			if (element.id.endsWith('-approve')) {
				try {
					var msg=this.apelCheckStatusOfExternalConfirmed();
					if(msg==""){
						APService.approveAPEL(context);	
					}else{
						alert(msg);
					}								
				} catch(err) {;}
			} else if (element.id.endsWith('-fail')) {
				//L.D need to stop this if apel form is not checked
				try {
					var msg=this.apelCheckStatusOfExternalConfirmed();
					if(msg==""){
						APService.failAPEL(context);
					}else{
						alert(msg);
					}			
				} catch(err) {;}
			} else if (element.id.endsWith('-resubmit')) {
				APService.resubmitAPEL(context);
			} else if (element.id.endsWith('-save')) {
				APService.saveTask(context);			
			} else if (element.id.endsWith('-complete')) {
				APService.completeTask(context);
			}
		} else if (element.id.endsWith('-file')) {
			APService.fileCheck(element.id);
		}		
	},
	
	/**
	 * Invoked when an AJAX request which does not expect content to be delivered in
	 * the response succeeds
	 * @param {Object} xhrObject
	 */		
	success: function(xhrObject) {
		document.body.style.cursor = "";
		var gotError = false;
		var xmlObject = XML.getXMLObject(xhrObject);
		// Look for an error
		var root = xmlObject.getElementsByTagName('error')[0];
		var message = "";
		if (root != undefined) {
			gotError = true;
			message = root.getElementsByTagName('message')[0].firstChild.data;
			alert(message);			
			return;
		} else {
			root = xmlObject.getElementsByTagName('success')[0];
			try {
				message = root.getElementsByTagName('message')[0].firstChild.data;
			} catch(err) {;};
		}

		var service = root.getElementsByTagName('service')[0].firstChild.data;
		if (message.length > 0 && !gotError && service != APService.AP_FILE_CHECK) {
			alert(message);
		}
		
		if (service == APService.AP_TASK_COMPLETE 
			|| service == APService.AP_TASK_APPROVE 
			|| service == APService.AP_TASK_FAIL 
			|| service == APService.AP_TASK_RESUBMIT) {
			var context = root.getElementsByTagName('context')[0].firstChild.data;
			APService.refreshTaskList(context);
		} else if (service == APService.AP_TASK_SAVE || service == APService.AP_ASSESSOR_ASSIGN) {
			var taskID = $('aptasks-aPTaskViewer-task-id').value;
			var target = 'aptasks-task';			
			APService.taskViewer(Context.APTASKS, target, taskID);
			APService.refreshTaskList(context.APTASKS);
		} else if (service == APService.AP_TASK_ASSIGN) {
			var context = root.getElementsByTagName('context')[0].firstChild.data;
			APService.refreshTaskList(context);
		} else if (service == APService.AP_APPLICANT_ASSIGN) {
			var context = root.getElementsByTagName('context')[0].firstChild.data;
			APService.applicantViewer(Context.APAPPLICANTS);
		} else if (service == APService.AP_FILE_CHECK) {
			APService.fileDownload(message);
		}		
	},

	/**
	 * Invoked when an AJAX request that expects content in the response succeeds
	 * @param {Object} xhrObject Success XML - see Service.php
	 */
	contentSuccess: function(xhrObject) {
		document.body.style.cursor = "";
		var xmlObject = XML.getXMLObject(xhrObject);
		// Look for an error
		var error = xmlObject.getElementsByTagName('error')[0];
		if (error != undefined) {
			var message = error.getElementsByTagName('message')[0].firstChild.data;
			alert(message);
			return;
		}
		var root = xmlObject.getElementsByTagName('success')[0];
		var service = root.getElementsByTagName('service')[0].firstChild.data;
	    var context = root.getElementsByTagName('context')[0].firstChild.data;
		var target = root.getElementsByTagName('target')[0].firstChild.data;
		var content = root.getElementsByTagName('content')[0].firstChild.data;
		$(target).update(content);

		if (service == APService.AP_APPLICANT_VIEWER) {
			// Show the user Pre-APEL if any
			var applicantID = $('apapplicants-aPApplicantViewer-user-id').value;
			var target = 'apapplicants-preapel';
			APService.applicantPreAPELViewer(Context.APAPPLICANTS, target, applicantID);
			
		}
		if (service == APService.AP_APPLICANT_PREAPEL_VIEWER) {
			// We've come back from display of Pre-APEL form so now we need the APEL
			var applicantID = $('apapplicants-aPApplicantViewer-user-id').value;
			var target = 'apapplicants-apel';
			APService.applicantAPELViewer(Context.APAPPLICANTS, target, applicantID);
		}
		if (service == APService.AP_TASK_VIEWER) {
			var taskID = root.getElementsByTagName('entityID')[0].firstChild.data;
			if (context == Context.APEXTERNAL) {
				// External user tasks are always associated with a form
				target = 'apexternal-apel';
				APService.formViewer(context, target, taskID);
			}			
			if (context == Context.APTASKS) {
				var taskTypeIdentifier = root.getElementsByTagName('data')[0].firstChild.data;
				switch(taskTypeIdentifier) {
					/*
					 * The task below is the registration task so we need to display registration data
					 * which is stored in the task instance's data field.
					 * We use the form target (see below)
					 */
					case 'ap_task_1':
						target = 'aptasks-apel';
						APService.registrationDataViewer(context, target, taskID);
						break;
					/*
					 * The set of tasks defined by the following block of
					 * task identifiers are the ones concerned with making
					 * a decision about a Pre-APEL or APEL submission. This is
					 * why we call the formViewer service
					 */
					case 'ap_task_3':
					case 'ap_task_4':
					case 'ap_task_5':
					case 'ap_task_6':
					case 'ap_task_8':
					case 'ap_task_10':
					case 'ap_task_11':
						target = 'aptasks-apel';
						APService.formViewer(context, target, taskID);
						break;
					default:
						Entity.closeViewer(context, Entity.APEL);
						break;
				}
			}	
		}
	},

	/**
	 * Controls the initial state of an APEL sub-tab
	 * Called by tabSelect() in workbench.js
	 * @param String context The AP interface framework context (see Context.js)
	 */
	controller: function(context) {
		switch(context) {
			case Context.AP:
				break;
			case Context.APEXTERNAL:
				// List the task belonging to an external user
				APService.refreshTaskList(context);
				break;
			case Context.APCIBSEUSERS:
				// List the CIBSE users
				var selected = '';
				var idField = 'apcibseusers-aPCIBSEUserViewer-user-id';
				try {
					selected = $(idField).value;
				} catch(err) {;}
				APService.cibseUserLister(context, selected);
				break;
			case Context.APEXTERNALUSERS:
				// List the external users
				var selected = '';
				var idField = 'apexternalusers-aPExternalUserViewer-user-id';
				try {
					selected = $(idField).value;
				} catch(err) {;}
				APService.externalUserLister(context, selected);
				break;
			case Context.APELLOOKUP:
			case Context.PREAPELLOOKUP:
			case Context.APELOLD:
			case Context.LOOKUP:
			case Context.APAPPLICANTS:
				// List the external users
				var selected = '';
				var idField = context+'-aPApplicantViewer-user-id';
				try {
					selected = $(idField).value;
				} catch(err) {;}
				APService.applicantLister(context, selected);
				break;
			case Context.APTASKS:
				// List the external users
				APService.refreshTaskList(context);
				break;
			default:
				return;
		}

		// APEL
		try {
			// Request a filter for the NAU task list. It goes in the searcher div
			var target = Context.APTASKS + Service.SCOPE_SEPARATOR + "filter" + Service.SCOPE_SEPARATOR + Entity.TASK;
			APService.taskFilter(Context.APTASKS, target);
		} catch(err) {;}	
				
		try {
			// Request a filter for the NAU task list. It goes in the searcher div
			var target = Context.APEXTERNAL + Service.SCOPE_SEPARATOR + "filter" + Service.SCOPE_SEPARATOR + Entity.TASK;
			APService.taskFilter(Context.APEXTERNAL, target);
		} catch(err) {;}			

		try {
			// Request a filter interface for the applicants list
			var target = Context.APAPPLICANTS + Service.SCOPE_SEPARATOR + Service.SEARCHER + Service.SCOPE_SEPARATOR + Entity.USER;
			APService.applicantFilter(Context.APAPPLICANTS, target);
		} catch(err) {;}
	},
	
	/**
	 * Make a trip to the server to check for the existence of a requested file
	 * 
	 * @param integer downloadID identifer for pre-APEL/APEL and the file ID
	 */
  	fileCheck: function(downloadID) {
		var message = '';
		var pars = 'service=' + APService.AP_FILE_CHECK;
		pars += '&' + 'context=' + Context.APTASK;
		pars += '&' + 'downloadID=' + downloadID;
		
    	var onSuccessFunction = 'APService.success';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Download a pre-AEL or APEL file
	 * 
	 * @param integer downloadID identifer for pre-APEL/APEL and the file ID
	 */
 	fileDownload: function(downloadID) {
		var pars = 'service=' + APService.AP_FILE_DOWNLOAD;
		pars += '&' + 'context=' + Context.APTASK;
		pars += '&' + 'downloadID=' + downloadID;
		document.location = Service.URL + '?' + pars;
	},
	
	downloadForm: function(apelID){
		var message = '';
		var pars = 'service=' + APService.AP_FILE_DOWNLOAD_FORM;
		pars += '&' + 'context=' + Context.APTASKS;
		pars += '&' + 'apelID=' + apelID;
		document.location = Service.URL + '?' + pars;
    	//var onSuccessFunction = 'APService.success';
		//var onFailureFunction = 'Service.failure';
		//new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},


	/**
	 * Get the ID of a selected task instance in an AP context
	 * @param String context The AP interface framework context (see Context.js)
	 */
	getTaskID: function(context){
		var idElement = context + Service.SCOPE_SEPARATOR + Widget.AP_TASK_VIEWER + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'id';
		return $F(idElement);
	},

	/**
	 * Make a request on the AP_ASSESSOR_ASSIGN service
	 * Assign an assessor and generate task 8 or 10 which are assigned to that assessor
	 * @param String context The AP interface framework context (see Context.js)
	 * @param Number taskID The ID of the task
	 */
	selectAssessor: function(context, taskID) {
		// Get the assessor
   		var message = 'You are about to assign an Assessor to this Applicant\'s APEL submission.';
 		var answer = confirm(message);
		if (answer) {
			var elementID = Context.APTASKS + Service.SCOPE_SEPARATOR + Widget.AP_TASK_VIEWER + Service.SCOPE_SEPARATOR + 'assignassessor';
			var assessorID = $(elementID).options[$(elementID).options.selectedIndex].value;
			if (assessorID == 0) {
				alert('Please select an Assessor');
				return;
			}
			var pars = 'service=' + APService.AP_ASSESSOR_ASSIGN;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + taskID;
			pars += '&' + 'instanceID=' + assessorID;
			
			var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {
				parameters: pars,
				onSuccess: eval(onSuccessFunction),
				onFailure: eval(onFailureFunction)
			});
		} else {
			var taskID = $('aptasks-aPTaskViewer-task-id').value;
			var target = 'aptasks-task';			
			APService.taskViewer(Context.APTASKS, target, taskID);			
		}
	},
	
	/**
	 * Make a request on the AP_APPLICANT_ASSIGN service
	 * Assign an applicant and current task to another administrative user.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param Number applicantID The ID of the applicant
	 */
	assignApplicant: function(context, applicantID) {
		// Get the assignee
   		var message = 'You are about to assign this Applicant to another user. Click OK to continue.';
 		var answer = confirm(message);
		
		if (answer) {
			var elementID = Context.APAPPLICANTS + Service.SCOPE_SEPARATOR + Widget.AP_APPLICANT_VIEWER + Service.SCOPE_SEPARATOR + Entity.USER + Service.SCOPE_SEPARATOR + 'assign';
			var assigneeID = $(elementID).options[$(elementID).options.selectedIndex].value;
			if (assigneeID == 0) {
				alert('Please select a user');
				return;
			}
			var pars = 'service=' + APService.AP_APPLICANT_ASSIGN;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + applicantID;
			pars += '&' + 'instanceID=' + assigneeID;
			
			var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {
				parameters: pars,
				onSuccess: eval(onSuccessFunction),
				onFailure: eval(onFailureFunction)
			});
		} else {
			APService.applicantViewer(Context.APAPPLICANTS);			
		}
		
	},
	/**
	 * get the selected statement version
	 */
	getStatement: function (context,type,title) {
		var optionValue = $(context+'_'+type+'_select').value;
		var pars = 'service='+APService.AP_FORM_GETSTATEMENT;
		pars += '&' + 'optionvalue=' + optionValue;
		pars += '&' + 'target=' + context+'_'+type+'_data';
		pars += '&' + 'context=' + context;
		pars += '&' + 'title=' + title;
		var onSuccessFunction =	'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   
	},
	
	assignApplicantAssessor: function(context, applicantID) {
		// Get the assignee
   		var message = 'You are about to assign this Applicant to an assessor. Click OK to continue.';
 		var answer = confirm(message);
		
		if (answer) {
			var elementID = Context.APAPPLICANTS + Service.SCOPE_SEPARATOR + Widget.AP_APPLICANT_VIEWER + Service.SCOPE_SEPARATOR + Entity.USER + Service.SCOPE_SEPARATOR + 'assign';
			var assigneeID = $(elementID).options[$(elementID).options.selectedIndex].value;
			if (assigneeID == 0) {
				alert('Please select an assessor');
				return;
			}
			var pars = 'service=' + APService.AP_APPLICANT_ASSIGN;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + applicantID;
			pars += '&' + 'instanceID=' + assigneeID;
			
			var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {
				parameters: pars,
				onSuccess: eval(onSuccessFunction),
				onFailure: eval(onFailureFunction)
			});
		} else {
			APService.applicantViewer(Context.APAPPLICANTS);			
		}
		
	},

	/**
	 * Make a request on the AP_TASK_ASSIGN service
	 * Assign a task to another administrative user.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param Number taskID The ID of the task stored in a hidden field
	 */
	assignTask: function(context, taskID) {
		// Get the assignee
  		var message = 'You are about to assign this Task to another user. You will no longer see the task in your list. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {
			var elementID = Context.APTASKS + Service.SCOPE_SEPARATOR + Widget.AP_TASK_VIEWER + Service.SCOPE_SEPARATOR + 'assign';
			var assigneeID = $(elementID).options[$(elementID).options.selectedIndex].value;
			if (assigneeID == 0) {
				alert('Please select a user');
				return;
			}
			var pars = 'service=' + APService.AP_TASK_ASSIGN;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + taskID;
			pars += '&' + 'instanceID=' + assigneeID;
			
			var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {
				parameters: pars,
				onSuccess: eval(onSuccessFunction),
				onFailure: eval(onFailureFunction)
			});
		} else {
			var taskID = $('aptasks-aPTaskViewer-task-id').value;
			var target = 'aptasks-task';			
			APService.taskViewer(Context.APTASKS, target, taskID);			
		}
	},
	
	/**
	 * Make a request on the AP_TASK_SAVE service
	 * Saves the state of a task. This means any comments as well as task-specific
	 * data, if any, will be saved.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	saveTask: function(context) {
  		var message = 'You are about to save this Task. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {	
 	 		var formID = context + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'form';
	 		var pars = 'service=' + APService.AP_TASK_SAVE;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + APService.getTaskID(context);
			var data = $(formID).serialize();			
			pars += '&' + data;
	   		var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
		}	
	},
	
	/**
	 * returns the correct schemes/channels for the selected action
	 */
	selectTaskOutcome: function(context,taskID,applicantID) {
		var optionValue = $(context+'-aPTaskViewer-actions').value;
		var pars = 'service='+ APService.AP_TASK_OPTIONOUTCOME;
		pars += '&' + 'optionvalue=' + optionValue;
		pars += '&' + 'context=' + context;
		pars += '&' + 'taskid=' + taskID;
		pars += '&' + 'applicantid=' + applicantID;
		var onSuccessFunction =	'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   
	},

	/**
	 * save the scheme application status
	 */
	 saveTaskStatus: function(context) {
		var formID = context + Service.SCOPE_SEPARATOR + "task" + Service.SCOPE_SEPARATOR + 'form';
		
		var optionValue = $(context+'-aPTaskViewer-actions').value;
		var pars = 'service='+ APService.AP_TASK_SAVESTATUS;
		pars += '&' + 'optionvalue=' + optionValue;
		pars += '&' + 'context=' + context;
		pars += '&' + 'entityID=' + APService.getTaskID(context);
		var data = $(formID).serialize();	
		pars += '&' + data;
		var onSuccessFunction =	'APService.Success';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   
		
		
	},
	/**
	 * Save Applicant tasks
	 */
	saveComments: function(context) {
		var message = 'You are about to save your Comments. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {	
 	 		var formID = context + Service.SCOPE_SEPARATOR + "comments" + Service.SCOPE_SEPARATOR + 'form';
	 		var pars = 'service=' + APService.AP_APPLICANT_SAVE_COMMENTS;
			pars += '&' + 'context=' + context;
			pars += '&' + 'applicantID=' + $('apapplicants-aPApplicantViewer-user-id').value ;
			var data = $(formID).serialize();			
			pars += '&' + data;
	   		var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
		}	
	},

	/**
	 * Save Applicant tasks
	 */
	autoSaveComments: function(context) {
	 	var formID = context + Service.SCOPE_SEPARATOR + "comments" + Service.SCOPE_SEPARATOR + 'form';
 		var pars = 'service=' + APService.AP_APPLICANT_AUTOSAVE_COMMENTS;
		pars += '&' + 'context=' + context;
		pars += '&' + 'applicantID=' + $('apapplicants-aPApplicantViewer-user-id').value ;
		var data = $(formID).serialize();			
		pars += '&' + data;
   		var onSuccessFunction = 'APService.success';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},
	
	/**
	 * Make a request on the AP_TASK_COMPLETE service
	 * Assigns a non-APEL task as complete.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	completeTask: function(context) {		
    	var message = 'You are about to assign this Task as completed. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {
 	 		var formID = context + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'form';
			
	 		var pars = 'service=' + APService.AP_TASK_COMPLETE;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + APService.getTaskID(context);
			var data = $(formID).serialize();				
			pars += '&' + data;
	
	   		var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
		}	
	},

	/**
	 * Make a request on the AP_TASK_RESUBMIT service
	 * 
	 * @param String context The AP interface framework context (see Context.js)
	 */
	resubmitAPEL: function(context) {
  		var message = 'You are about to request form re-submission. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {
 	 		var formID = context + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'form';
			
	 		var pars = 'service=' + APService.AP_TASK_RESUBMIT;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + APService.getTaskID(context);
			var data = $(formID).serialize();				
			pars += '&' + data;
			
	   		var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
		}	
	},

	/**
	 * Make a request on the AP_TASK_APPROVE service
	 * Assigns a APEL as approved and the task as complete.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	approveAPEL: function(context) {
   		var message = 'You are about to approve an APEL submission. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {
 	 		var formID = context + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'form';
			
	 		var pars = 'service=' + APService.AP_TASK_APPROVE;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + APService.getTaskID(context);
			var data = $(formID).serialize();				
			pars += '&' + data;
			
	   		var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
		}	
	},
	
	/**
	 * Make a request on the AP_TASK_FAIL service
	 * Assigns a APEL as failed and the task as complete.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	failAPEL: function(context) {		
    	var message = 'You are about to fail an APEL submission. Click OK to continue.';
 		var answer = confirm(message);
		if (answer) {
 	 		var formID = context + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'form';
			
	 		var pars = 'service=' + APService.AP_TASK_FAIL;
			pars += '&' + 'context=' + context;
			pars += '&' + 'entityID=' + APService.getTaskID(context);
			var data = $(formID).serialize();				
			pars += '&' + data;
			
	   		var onSuccessFunction = 'APService.success';
			var onFailureFunction = 'Service.failure';
			new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
		}	
	},

	/**
	 * Make a request on the AP_APPLICANT_VIEWER service
	 * Delivers data for a selected applicant in the AP_APPLICANT_VIEWER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	applicantViewer: function(context,userID) {
		// Get the user ID
		if(userID == undefined || userID == null || userID == ""){
			var elementID = Context.APAPPLICANTS + Service.SCOPE_SEPARATOR + 'aPUserLister-select';	
			var optionID = $(elementID).options[$(elementID).options.selectedIndex].value;
			userID = Names.getInstanceID(optionID);
		}
		
 		var pars = 'service=' + APService.AP_APPLICANT_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + 'apapplicants-user';
		pars += '&' + 'widget=' + Widget.AP_APPLICANT_VIEWER;
		pars += '&' + 'entityID=' + userID;

   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_CIBSE_USER_VIEWER service
	 * Delivers data for a selected CIBSE administrative user
	 * in the AP_CIBSE_USER_VIEWER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	cibseUserViewer: function(context) {
		// Get the user ID
		var elementID = Context.APCIBSEUSERS + Service.SCOPE_SEPARATOR + 'aPUserLister-select';	
		var optionID = $(elementID).options[$(elementID).options.selectedIndex].value;
		var userID = Names.getInstanceID(optionID);

		var pars = 'service=' + APService.AP_CIBSE_USER_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + 'apcibseusers-user';
		pars += '&' + 'widget=' + Widget.AP_CIBSE_USER_VIEWER;
		pars += '&' + 'entityID=' + userID;
		
   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_EXTERNAL_USER_VIEWER service
	 * Delivers data for a selected external administrative user (referee or assessor)
	 * in the AP_EXTERNAL_USER_VIEWER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	externalUserViewer: function(context, applicantID) {
		// Get the user ID
		if (context == null) {
			context = Context.APEXTERNALUSERS;
		}
		var elementID = Context.APEXTERNALUSERS + Service.SCOPE_SEPARATOR + 'aPUserLister-select';	
		var optionID = $(elementID).options[$(elementID).options.selectedIndex].value;
		var userID = Names.getInstanceID(optionID);

		var pars = 'service=' + APService.AP_EXTERNAL_USER_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + 'apexternalusers-user';
		pars += '&' + 'widget=' + Widget.AP_EXTERNAL_USER_VIEWER;
		pars += '&' + 'entityID=' + userID;
		if (applicantID != undefined && applicantID != null) {
			pars += '&' + 'instanceID=' + applicantID;
		}		
   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_APPLICANT_LISTER service
	 * Delivers a list of applicants in the AP_USER_LISTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param {Object} selected Defines the currently selected user
	 * @param String filterID Defines the currently selected filter option
	 */
	applicantLister: function(context, selected, filterID) {
 		var pars = 'service=' + APService.AP_APPLICANT_LISTER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + context+'-lister-user';
		pars += '&' + 'widget=' + Widget.AP_USER_LISTER;
		if (selected != undefined && selected != null && selected.length > 0) {
			pars += '&' + 'entityID=' + selected;
		}
 		
 		switch(context){
 			case Context.LOOKUP:
 			case Context.APELLOOKUP:
 				pars += '&' + 'filterID=14';
 				pars += "&eventHandler=ASService.handleGotoEvent('"+context+"-aPUserLister-select','"+context+"',false)";
 				break;
			case Context.PREAPELLOOKUP:
				pars += '&' + 'filterID=15';
 				pars += "&eventHandler=ASService.handleGotoEvent('"+context+"-aPUserLister-select','"+context+"',false)";
				break;
			default:
				if (filterID != undefined && filterID != null) {
					pars += '&' + 'filterID=' + filterID;
				}
				break;
 		}
 		

 		try{
			if(context == Context.APELLOOKUP || context == Context.PREAPELLOOKUP){
				var nameID = context+Service.SCOPE_SEPARATOR+"searcher"+Service.SCOPE_SEPARATOR+Entity.ASAPPLICANT+Service.SCOPE_SEPARATOR+"name";
				var name = $(nameID).value;
				pars += "&name="+name;
			}
 		}catch(err){;}
		
  		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_EXTERNAL_USER_LISTER service
	 * Delivers a list of external administrative users in the AP_USER_LISTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param {Object} selected Defines the currently selected user
	 */
	externalUserLister: function(context, selected) {
		var pars = 'service=' + APService.AP_EXTERNAL_USER_LISTER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + 'apexternalusers-lister-user';
		pars += '&' + 'widget=' + Widget.AP_USER_LISTER;
		if (selected != undefined && selected != null && selected.length > 0) {
			pars += '&' + 'entityID=' + selected;
		}
		
   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_CIBSE_USER_LISTER service
	 * Delivers a list of CIBSE administrative users in the AP_USER_LISTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param {Object} selected Defines the currently selected user
	 */
	cibseUserLister: function(context, selected) {
		var pars = 'service=' + APService.AP_CIBSE_USER_LISTER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + 'apcibseusers-lister-user';
		pars += '&' + 'widget=' + Widget.AP_USER_LISTER;
		if (selected != undefined && selected != null && selected.length > 0) {
			pars += '&' + 'entityID=' + selected;
		}
		
   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Force a refresh of a list of users
	 * Delivers a refreshed list of users in the AP_USER_LISTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	refreshUserList: function(context) {	
		switch(context) {
			case Context.APAPPLICANTS:
				// Do we have a filter option
				var filterID = null;
				try {
					var elementID = context + Service.SCOPE_SEPARATOR + Widget.AP_APPLICANT_FILTER + Service.SCOPE_SEPARATOR + Entity.USER + Service.SCOPE_SEPARATOR + 'filter';
					filterID = $(elementID).options.selectedIndex;			
				} catch(err) {;}
				APService.applicantLister(context, "", filterID);
				break;
			case Context.APEXTERNALUSERS:
				APService.externalUserLister(context);
				break;
			case Context.APCIBSEUSERS:
				APService.cibseUserLister(context);
				break;
		}
		Entity.closeViewer(context, Entity.USER);
		var target = 'apapplicants-preapel';
		$(target).update('');
		target = 'apapplicants-apel';
		$(target).update('');
	},

	/**
	 * Make a request on the AP_TASK_LISTER service
	 * Delivers a list of tasks in the AP_TASK_LISTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String}target Defines the target DOM objects for the list widget
	 * @param target filterID Defines the currently selected task list filter
	 */
	taskLister: function(context, target, filterID) {
		var pars = 'service=' + APService.AP_TASK_LISTER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_TASK_LISTER;
		if (filterID != undefined && filterID != null) {
			pars += '&' + 'filterID=' + filterID;
		}
				
   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},
	
	/**
	 * Make a request on the AP_TASK_FILTER service
	 * Delivers a set of task list filter options in the AP_TASK_FILTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String}target Defines the target DOM objects for the filter
	 */
	taskFilter: function(context, target) {
		var pars = 'service=' + APService.AP_TASK_FILTER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_TASK_FILTER;
		
		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});
	},

	/**
	 * Force a refresh of a list of tasks
	 * Delivers a refreshed list of tasks in the AP_TASK_LISTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 */
	refreshTaskList: function(context) {
		// Get the current filter value
		var filterID = null;
		try {
			var elementID = context + Service.SCOPE_SEPARATOR + Widget.AP_TASK_FILTER + Service.SCOPE_SEPARATOR + Entity.TASK + Service.SCOPE_SEPARATOR + 'filter';
			filterID = $(elementID).options.selectedIndex;			
		} catch(err) {;}

		switch(context) {
			case Context.APTASKS:
				var target = 'aptasks-lister-task';
				APService.taskLister(context, target, filterID);
				break;
			case Context.APEXTERNAL:
				var target = 'apexternal-lister-task';
				APService.taskLister(context, target, filterID);
				break;
		}
		Entity.closeViewer(context, Entity.TASK);
		Entity.closeViewer(context, Entity.APEL);
	},

	/**
	 * Make a request on the AP_TASK_VIEWER service
	 * Delivers data for a selected task in the AP_TASK_VIEWER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String target The ID of the DOM object for the viewer
	 * @param Number taskID The ID of the task stored in a hidden field
	 */
	taskViewer: function(context, target, taskID) {
 		var pars = 'service=' + APService.AP_TASK_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_TASK_VIEWER;
		pars += '&' + 'entityID=' + taskID;
		
   		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},


	/**
	 * Make a request on the AP_FORM_VIEWER service
	 * Delivers data for a task's Pre-APEL or ALEL form in the AP_FORM_VIEWER widget.
	 * Invoked automatically when viewing these tasks:
	 * ap_task_3, ap_task_5, ap_task_6, ap_task_8, ap_task_10, ap_task_11
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String target The ID of the DOM object for the viewer
	 * @param Number taskID The ID of the task stored in a hidden field.
	 */
	formViewer: function(context, target, taskID) {
		
  		var pars = 'service=' + APService.AP_FORM_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_FORM_VIEWER;
		pars += '&' + 'entityID=' + taskID;

  		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_APPLICANT_PREAPEL_VIEWER service
	 * Delivers data for an applicant's Pre-APEL form in the AP_FORM_VIEWER widget.
	 * Invoked automatically when viewing applicants
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String target The ID of the DOM object for the viewer
	 * @param Number applicantID The ID of the applicant stored in a hidden field.
	 */
	applicantPreAPELViewer: function(context, target, applicantID) {
		
  		var pars = 'service=' + APService.AP_APPLICANT_PREAPEL_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_FORM_VIEWER;
		pars += '&' + 'entityID=' + applicantID;
	
  		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},

	/**
	 * Make a request on the AP_APPLICANT_FILTER service
	 * Delivers a set of applicant list filter options in the AP_APPLICANT_FILTER widget.
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String}target Defines the target DOM objects for the filter
	 */
	applicantFilter: function(context, target) {
		var pars = 'service=' + APService.AP_APPLICANT_FILTER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_APPLICANT_FILTER;
		
		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});
	},
	
	/**
	 * Make a request on the AP_APPLICANT_APEL_VIEWER service
	 * Delivers data for an applicant's APEL form in the AP_FORM_VIEWER widget.
	 * Invoked automatically when viewing applicants
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String target The ID of the DOM object for the viewer
	 * @param Number applicantID The ID of the applicant stored in a hidden field.
	 */
	applicantAPELViewer: function(context, target, applicantID) {
		
  		var pars = 'service=' + APService.AP_APPLICANT_APEL_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_FORM_VIEWER;
		pars += '&' + 'entityID=' + applicantID;
	
  		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},
	
	/**
	 * Make a request on the AP_REGISTRATION_VIEWER service
	 * Delivers data for a ap_task_1 type's registration in the AP_REGISTRATION_VIEWER widget.
	 * Invoked automatically when viewing these tasks:
	 * ap_task_1
	 * @param String context The AP interface framework context (see Context.js)
	 * @param String target The ID of the DOM object for the viewer
	 * @param Number taskID The ID of the task stored in a hidden field.
	 */
	registrationDataViewer: function(context, target, taskID) {
		
  		var pars = 'service=' + APService.AP_REGISTRATION_VIEWER;
		pars += '&' + 'context=' + context;
		pars += '&' + 'target=' + target;
		pars += '&' + 'widget=' + Widget.AP_REGISTRATION_VIEWER;
		pars += '&' + 'entityID=' + taskID;

  		var onSuccessFunction = 'APService.contentSuccess';
		var onFailureFunction = 'Service.failure';
		new Ajax.Request(Service.URL, {parameters:pars, onSuccess:eval(onSuccessFunction), onFailure:eval(onFailureFunction)});   	
	},
	
	toggleDiv: function(element) {
		var img=$(element).firstDescendant();
		var div=element.parentNode;
		div=$(div).next('div');
		if(div.style.display=="none"){
			div.style.display="block";
			img.src="images/node_minus.gif";
			img.title="Close";
		}
		else{
			div.style.display="none";
			img.src="images/node_plus.gif";
			img.title="Open";
		}
	},
	
	apelCheckStatusOfConfirmed: function(){
		var msg="";
		var elements=$$('#aptasks-task-form input[$confirmed]');
		for(var i=0;i<elements.length;i++){
			if(elements[i].id.indexOf("aptasks-aPFormViewer")==-1 || elements[i].type!="checkbox") continue;
			if(elements[i].checked) continue;
			msg+="Please check the "+$(elements[i].id+'-section-name').value+" checkbox \n";
		}
		return msg
	},
	
	apelCheckStatusOfExternalConfirmed: function(){
		var msg="";
		var elements=$$('#apexternal-task-form input[$confirmed]');
		for(var i=0;i<elements.length;i++){
			if(elements[i].id.indexOf("apexternal-aPFormViewer")==-1 || elements[i].type!="checkbox") continue;
			if(elements[i].checked) continue;
			msg+="Please check the "+$(elements[i].id+'-section-name').value+" checkbox \n";
		}
		return msg
	},

	highLightHeading: function(element){
		try {
			var heading=$(element).parentNode.parentNode.previous('h3');
			var par=$(element).parentNode.parentNode.previous('p');
			if(element.checked){
				heading.removeClassName("active");
				heading.addClassName("de-active");
				par.removeClassName("active");
				par.addClassName("de-active");
			}else{
				heading.removeClassName("de-active");
				heading.addClassName("active");
				par.removeClassName("de-active");
				par.addClassName("active");
			}
		} catch(err){;}
	},
	
	displayReplacePiDiv: function(id){
		if($(id).style.display=="block")
			$(id).style.display="none";
		else $(id).style.display="block";
	}
	

	
	
}
