/**
 * Encapsulate the QACase entity type. See the ea_type database table
 */ 
  
var Qacase = {
			
	entityName: Entity.QACASE,

	handleEvent: function(event, context) {
		var element = Event.element(event);
		elementID = element.id;
		if (element.id.endsWith(Service.SCOPE_SEPARATOR + 'save')) {
			Qacase.save(context, Entity.QACASE);
			return;
		}	
		else if (element.id.endsWith(Service.SCOPE_SEPARATOR + 'cancel')) {
			Entity.closeEditor(context, Entity.QACASE);
			return;
		}	
		else if (element.id.endsWith('search') || element.id.endsWith('clear')) {
			QAService.caseSearch(Context.QACASES, event);				
		}
		else{
			QAService.handleEvent(event,Context.QACASES);
			return;
		}
	},
	
	/**
	 * Create a new case study.
	 */
	create: function(context,entity){
		QAService.caseViewer(context, entity, "");
	},

	edit: function(context, entityID){
	},

	save: function(context, entity){
		//define variables
		data = "";
		entityID ="";
		idPrefix = context+Service.SCOPE_SEPARATOR+entity+Service.SCOPE_SEPARATOR;		
		
		//get the form data
		data = Entity.serialiseFormData(idPrefix+"form");
		
		//see if we can find the entity id
		try{
			entityID = $(idPrefix+"id").value;
		}catch(err){entityID="";}
				
		QAService.saveQACase(context,entity,entityID,data);
	},
	view: function(context, entityID) {
	},
		
	closeEditor: function(context) {
	},

	closeViewer: function(context) {
		try {
			var target = context + Service.SCOPE_SEPARATOR + this.entityName;
			$(target).update('');
			var target = context + Service.SCOPE_SEPARATOR + Service.BUTTONS + Service.SCOPE_SEPARATOR + this.entityName;
			$(target).update('');			
		} catch(err) {;}
	}
	
}
