//dojo.declare("com.mgh.GenderView",[com.mgh.AgeGroupView],{
// jlp8 modified 09/24/2010. Centers view is the base class for all views.
dojo.declare("com.mgh.GenderView", null, {
	constructor : function(){
		this.renderLayer = '#gender';
	},
	/* original 
	RenderInitialView : function(){
		this.model = new Array();
		this.model[0] = new com.mgh.Gender('51881','Female');
		this.model[1] = new com.mgh.Gender('51883','Male');
		
		this.RenderListView();
	},*/
	
	/* jlp8 modified 09/01/2009 */
	RenderInitialView : function(){
		this.model = new Array();
		this.model[0] = new com.mgh.Gender('51881','Female');
		this.model[1] = new com.mgh.Gender('51883','Male');
		
		if (applicationState.getApplicationComponentState('gender')){
			var id = applicationState.model.gender;
			this.RenderSelectedView(id, 'Gender', 'Gender');
		} else {
			this.RenderListView('','','Gender');
		}
	},
	
	
	RenderListView : function(id,name,type){
		this.RenderListViewFromExistingModel();
	},
		
	RenderListViewFromExistingModel : function(){
		var output = "";
		try {
			for (var i = 0; i < this.model.length; i++){
				output += "<li>" + this.model[i].Format() + "</li>";
			}
			//output = dojo.string.substitute(this.listLayout,[output]);			
			output = "<ul>" + output + "</ul>";
		} catch(e) {
			output = "<ul><li><a href=\"#\" onclick=\"dojo.publish('genderClicked',['51881','Female','Gender'])\">Female</a></li><li><a href=\"#\" onclick=\"dojo.publish('genderClicked',['51883','Male','Gender'])\">Male</a></li></ul>";			
		}
		jQuery(this.renderLayer).html(output);
	},
	
	RenderSelectedView : function(id,name,type){
		try {
			for (var i=0; i < this.model.length; i++){
				if(this.model[i].id == id){			
					selected = this.model[i].SelectedFormat();	
					break;
				}
			}
		} catch(e) {
			if(id == '51881') {
				selected = "<p class=\"title\">Female</p><a href=\"#\" class=\"goBack\" id=\"51881\" onclick=\"dojo.publish('showAllGenders',['','','Gender'])\">Show all</a>";
			} 
			else {
				selected = "<p class=\"title\">Male</p><a href=\"#\" class=\"goBack\" id=\"51883\" onclick=\"dojo.publish('showAllGenders',['','','Gender'])\">Show all</a>";
			}
		}
		jQuery(this.renderLayer).html(selected);
	}	
});
