/**
 * Encapsulate the survey entity type. See the survey database table
 */ 
  
var Survey = {
			
	entityName: Entity.SURVEY,

	create: function(context){
	},

	edit: function(context, entityID){
	},

	view: function(context, entityID) {
		try {
			Action.refreshPanel(Context.SURVEYS_ACTIONS);
		} catch(err) {;}
		try {
			Note.refreshPanel(Context.SURVEYS_NOTES);
		} catch(err) {;}
		
		// Actions: load the actions div which be default is not visible
		var filter = new ListFilter(this.entityName, entityID);
		$(Context.SURVEYS_ACTIONS + Service.SCOPE_SEPARATOR + 'instanceID').value = entityID;
		var target = Context.SURVEYS_ACTIONS + Service.SCOPE_SEPARATOR + 'lister' + Service.SCOPE_SEPARATOR + Entity.ACTION;
		var eventHandler = 'Entity.view(\'' + Context.SURVEYS_ACTIONS + '\',\'' + Entity.ACTION + '\',\'@id\')';
		Service.lister(target, Context.SURVEYS_ACTIONS, Entity.ACTION, null, eventHandler, '', false, filter);

		// Notes: load the notes div which be default is not visible
		var filter = new ListFilter(this.entityName, entityID);
		$(Context.SURVEYS_NOTES + Service.SCOPE_SEPARATOR + 'instanceID').value = entityID;
		var target = Context.SURVEYS_NOTES + Service.SCOPE_SEPARATOR + 'lister' + Service.SCOPE_SEPARATOR + Entity.ACTION;
		var eventHandler = 'Entity.view(\'' + Context.SURVEYS_NOTES + '\',\'' + Entity.ACTION + '\',\'@id\')';
		Service.lister(target, Context.SURVEYS_NOTES, Entity.ACTION, null, eventHandler, '', false, filter);
		
	},
	
	
	closeEditor: function(context) {
	},

	closeViewer: function(context) {
		$(Context.SURVEYS_ACTIONS + Service.SCOPE_SEPARATOR + 'instanceID').value = '';
		$(Context.SURVEYS_NOTES + Service.SCOPE_SEPARATOR + 'instanceID').value = '';
		try {
			Action.refreshPanel(Context.SURVEYS_ACTIONS);
		} catch(err) {;}
		try {
			Note.refreshPanel(Context.SURVEYS_NOTES);
		} catch(err) {;}
	},
	
	validate: function(context){
		var message = '';
		var textMessage = '';
		// Must have values in all descriptor text fields
		var textInputElements = $(context + Service.SCOPE_SEPARATOR + this.entityName + Service.SCOPE_SEPARATOR + 'form').getInputs('text');
		for (i = 0; i < textInputElements.length; i++) {
			// Ignore the directory because it may not be set
			if ($(textInputElements[i].id.endsWith(Service.SCOPE_SEPARATOR + 'directory'))) continue;
			if ($(textInputElements[i]).value.length == 0) textMessage += $(textInputElements[i].id).previous('label').innerHTML.replace(':','') + '\n';
		}
		if(textMessage) message += 'Please enter a value in:\n' + textMessage;
		return message;
	}
	
}
