var pgm_Model = Backbone.Model.extend({
   defaults: {
      name: ""
   }
});

var pgm_Collection = Backbone.Collection.extend({
   model: pgm_Model
});

/*
var tmp_str = "";

var pgm_ModelView = Backbone.View.extend({
    template: Handlebars.compile($("#pgmTemplate").html()),

    render: function () {
        var pgm111_tmp = this.template;

        if(this.model.attributes.cont === 1) {
            tmp_str = pgm111_tmp(this.model.toJSON());

            $('#'+active_pgm+' td').last().append(tmp_str);
        } else {
            $(this.el).html(pgm111_tmp(this.model.toJSON()));
        }

        return this;
    }
});
*/

var pgm_ModelsView = Backbone.View.extend({
   template: Handlebars.compile($("#pgmTemplate").html()),
   attr_template: Handlebars.compile($("#make_attrTemplate").html()),
   func_template: Handlebars.compile($("#make_funcTemplate").html()),

   initialize: function (col) {
      this.collection = new pgm_Collection(col);
   },

   render: function (sel) {
		//var start_time = new Date;
		//console.log("[0.000] Start Time : "+start_time);
      var that = this;
      var mytab = this.collection.models[0].attributes.elements[0].tab;
      var real_pgm = ap.render_pgm;
      type_history[0] = null;
      type_history[1] = null;
      variable_order[ap.render_pgm] = 0;

      debug_mode.flag && console.log(" pgm_view.collection.models[0].attributes.elements[0].tab render_pgm:" + ap.render_pgm + " mytab.length:" + mytab.length);
      
		if (active_base == "tab_function_base" || active_base == "tab_install_wizard") {
			for (var idx = 0; idx < pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab.length; idx++) {
				if (pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key) {
					real_pgm = pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab[idx].key.split('_')[0];
					break;
				}
			}
		}
		debug_mode.flag && console.log("ap.render_pgm : "+ap.render_pgm+" real_pgm : "+real_pgm);

      _.each(this.collection.models[0].attributes.elements, function (items) {
         _.each(items.tab, function (item, i) {
            if (item.preload) {
               no_margin_flag = false;
            }
         }, this);
      }, this);

      _.each(this.collection.models[0].attributes.elements, function (items) {
			var tbl_name = null;

         _.each(items.tab, function (item, i) {
            if (sel) {
					if(i == 0) {
						var attr_pgm = item.key.split("_");
						$("#" + ap.render_pgm + "_attrs").append("<div style='text-align:center'><input type='button' value='"+langs.getText("common","btn_chkall")+"' class='btn_checkall_attr'><input type='button' name='"+attr_pgm[0]+"' value='"+langs.getText("common","btn_save")+"' class='btn_save_attr' style='margin-left:10px'><input type='button' name='"+attr_pgm[0]+"' value='"+langs.getText("common","btn_init")+"' class='btn_init_attr' style='margin-left:10px'></div>");
					}
               that.render_attrs(item);
               if(item.table && item.title) {
						$("#" + ap.render_pgm + "_attrs div input:checkbox:last").addClass("mktbl");
						tbl_name = item.key;
               } else if((item.th || item.tr || item.struct) && item.title) {
						$("#" + ap.render_pgm + "_attrs div input:checkbox:last").addClass("tbl_tr");
						$("#" + ap.render_pgm + "_attrs div input:checkbox:last").attr("name",tbl_name);
						$("#" + ap.render_pgm + "_attrs div input:checkbox:last").attr("disabled","disabled");
               }
            } else {
					if ((active_base == "tab_function_base") && (pgm_models[ap.active_pgm].elements.length > 1) && (i == 0)) {
						if($('#'+ap.render_pgm).index() == 0) {
							$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						} else if($('#'+ap.render_pgm).index() == pgm_models[ap.active_pgm].elements.length - 1) {
							$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_prev' value=' "+langs.getText("common","btn_prev")+" '><br></div>");
						} else {
							$('#'+ap.render_pgm).append("<div class='top_button'><input type='button' class='btn-image btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn-image btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						}
					}

					if ((active_base == "tab_install_wizard") && (i == 0)) {
						if($('#'+ap.render_pgm).index() == 0) {
							$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						} else if($('#'+ap.render_pgm).index() == (info.NO_OF_INSTALL_WIZARD_STEP - 1)) {
							$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn_finish auth_write' value=' "+langs.getText("common","btn_finish")+" '><br></div>");
						} else {
							$('#'+ap.render_pgm).append("<div class='button'><input type='button' class='btn_prev' value=' "+langs.getText("common","btn_prev")+" '><input type='button' class='btn_next' value=' "+langs.getText("common","btn_next")+" '><br></div>");
						}
					}

               if (item.table) {
                  if (item.table[0] && item.table[0].tbl_show_flag) {
                     if (item.table[0].value == "1") {
                        tbl_render_flag = true;
                        $("#" + ap.render_pgm).append("<div style='display:none'><input type='hidden' name='" + item.table[0].name + "' value='" + item.table[0].value + "'></div>");
                     } else {
                        tbl_render_flag = false;
                     }
                  }
               }
               
               if (item.edit_table) {
						if (!hidden_flags[ap.render_pgm]) {
							render_editTable();
						}
               } else {
						that.renderModel(item);
               }
            }
         }, this);
      }, this);

      if(sel && ($("#" + ap.render_pgm + "_attrs div").length == 1)) {
			$("#" + ap.render_pgm + "_attrs .btn_checkall_attr").hide();
			$("#" + ap.render_pgm + "_attrs .btn_save_attr").css("margin-left","0");
			$("#"+ap.render_pgm+"_attrs").append("<div class='all_attr' style='margin-bottom:0px'>"+ langs.getText("common","no_attr") + "</div>");
			$("#" + ap.render_pgm + "_attrs div:last").css("background-color", "#D9EDF7");
      }

      if (active_base == "tab_pgm_base" || active_base == "tab_function_base" || active_base == "tab_maintenance" || active_base == "tab_stn_base") {
			$('#' + ap.render_pgm).css('height', $('.row-fluid .custom_span_pgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('padding-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')));
      } else if (active_base == "tab_install_wizard") {
			$('#' + ap.render_pgm).css('height', $('.row-fluid .custom_span_iwpgm ').height() - $('#' + active_base + ' .nav-tabs-main').height() - eval($('#' + active_base + ' .nav-tabs-main').css('margin-top').replace('px', '')) - eval($('#' + active_base + ' .nav-tabs-main').css('margin-bottom').replace('px', '')) - eval($('#' + active_base + ' .tab-pane-main').css('padding-bottom').replace('px', '')));
      }
      if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && (pgm_models[ap.active_pgm].elements.length > 1)) {
			$('#' + ap.render_pgm).css('height', $('#' + ap.render_pgm).height() - $('#' + ap.active_pgm+' .nav-tabs-sub').height() + eval($('#' + ap.active_pgm+' .tab-pane-sub').css('padding-top').replace('px', '')) + eval($('#' + ap.active_pgm+' .tab-pane-sub').css('padding-bottom').replace('px', '')) - eval($('#' + ap.active_pgm+' .tab-content-sub').css('margin-bottom').replace('px', '')) - eval($('#' + ap.active_pgm+' .nav-tabs-sub').css('border-bottom-width').replace('px', '')) - eval($('#' + ap.active_pgm+' .tab-content-sub').css('border-bottom-width').replace('px', '')));
      }
      if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && (pgm_models[ap.active_pgm].elements.length > 1)) {
			$('#' + ap.render_pgm + ' .button').css('right', 40 - $('#' + ap.render_pgm).scrollLeft());
         $('#' + ap.render_pgm + ' .btn_scroll').css('top', 170 + $('#' + ap.render_pgm).scrollTop()).css('right', 40 - $('#' + ap.render_pgm).scrollLeft());
      }

      $('.tab-pane-main, .fav_list, .fav_edit').scroll(function () {
			if((active_base == "tab_function_base") && (ap.active_pgm != "favorite_func") && (pgm_models[ap.active_pgm].elements.length > 1)) {
				$('#' + ap.render_pgm + ' .button').css('top', $('#' + ap.active_pgm+' .tab-content-sub').scrollTop()).css('right', 40 - $('#' + ap.active_pgm+' .tab-content-sub').scrollLeft());
				$('#' + ap.render_pgm + ' .btn_scroll').css('top', 100 + $('#' + ap.active_pgm+' .tab-content-sub').scrollTop()).css('right', 40 - $('#' + ap.active_pgm+' .tab-content-sub').scrollLeft());
			} else {
				$('#' + ap.render_pgm + ' .button').css('top', $('#' + ap.render_pgm).scrollTop()).css('right', 20 - $('#' + ap.render_pgm).scrollLeft());
				$('#' + ap.render_pgm + ' .btn_scroll').css('top', 100 + $('#' + ap.render_pgm).scrollTop()).css('right', 20 - $('#' + ap.render_pgm).scrollLeft());
         }
      });

      if ($("#" + ap.render_pgm + " input[name='CHKFLAG']").val() == "1") {
         $('#' + ap.render_pgm + ' .btn_checkall').attr('value', langs.getText("common","btn_unchkall"));
         $('#' + ap.render_pgm + ' .chk_checkall').attr('checked', 'checked');
      }

      $('#' + ap.render_pgm + ' .btn_selectall').attr('value', langs.getText("common","btn_unselectall"));
      _.each($('#' + ap.render_pgm + ' .chk_selectall'), function (item) {
         //debug_mode.flag && console.log(item);
         if (!item.checked && !item.disabled) {
            $('#' + ap.render_pgm + ' .btn_selectall').attr('value', langs.getText("common","btn_selectall"));
            return false;
         }
      });

      if (!sel) {
         $("#" + ap.render_pgm).append("<br>");
      }

      if ($("#" + ap.render_pgm + " .preload").length) {
         $("#" + ap.render_pgm + " .preload input:eq(1)").focus();
      } else {
         $('#' + ap.render_pgm).scrollTop(0);
      }

      if ($('#'+ap.render_pgm).children().not('.preload').children().find('.error').length) {
			$('#'+ap.render_pgm).children().not('.preload').children().find('.error:eq(0)').prev().focus();
      }

		if (active_base != "tab_user_guide") {
			if ((info.AUTH == 1) || ((pgm_info[real_pgm.replace("pgm","")]) && (pgm_info[real_pgm.replace("pgm","")].auth == 1))) {
				$("#" + ap.render_pgm + " .auth_write").attr('disabled','disabled').css('cursor','default');
			}
      }

      tbl_render_flag = true;
      no_margin_flag = true;
      $('.loadingPane').hide();
		//var end_time = new Date;
		//console.log("["+((end_time.getTime() - start_time.getTime())/1000)+"] End Time : "+end_time);
   },

   renderModel: function (item) {
      var pgm_tmp = this.template;

      pgm_tmp(eval(item));
   },
   render_attrs: function (item) {
      var pgm_attr_tmp = this.attr_template;
      //debug_mode.flag && console.log("item.length:"+item.table.length);
      //debug_mode.flag && console.log("render_pgm : " + ap.render_pgm);
      $("#" + ap.render_pgm + "_attrs").append(pgm_attr_tmp(eval(item)));
      if ((item.table || item.th) && item.title) {
         $("#" + ap.render_pgm + "_attrs div:last").css("background-color", "#D9EDF7");
      } else {
         if (($("#" + ap.render_pgm + "_attrs div").length % 2) == 0) {
            if ($("#" + ap.render_pgm + "_attrs div:last").css("background-color") != "rgb(217, 237, 247)") {
               $("#" + ap.render_pgm + "_attrs div:last").css("background-color", "#eaeaea");
            }
         }
      }
   },
   render_item: function (id) {
      var make_func_tmp = this.func_template;
      // debug_mode.flag && console.log("this.collection.models.length:"+this.collection.models.length);
      debug_mode.flag && console.log(" this.collection.models[0].attributes.elements[0].tab.length:" + this.collection.models[0].attributes.elements[0].tab.length + " id:" + id);

      for (var i in this.collection.models[0].attributes.elements[0].tab) {
         var model = this.collection.models[0].attributes.elements[0].tab[i];
         tcol = model;
         //debug_mode.flag && console.log("model.key:"+model.key+" active_pgm:"+ap.active_pgm+" active_tab:"+active_tab);
         if (model.key == id) {
            debug_mode.flag && console.log("key:" + model.key + " added!! render_pgm:" + ap.render_pgm + " active_tab:" + active_tab);
            make_func_tmp(eval(model));
            break;
         }
      }

      debug_mode.flag && console.log(" render_item:" + id);
   }
});

function render_editTable () {
	var table_headers = new Array();
	var table_data = new Array();
	var tmp_row_data = null;
	var set_column_config = new Array();
	var data_index = 0;
   var real_pgm = ap.render_pgm;
	var first_render = 0;
	var model_tab = pgm_views[ap.render_pgm].collection.models[0].attributes.elements[0].tab;
	
	if (!((info.NCODE=="GBR")||(info.NCODE=="ITA")||(info.NCODE=="KOR")||(info.NCODE=="ISR")||(info.NCODE=="DEU")||(info.NCODE=="USA")||(info.NCODE=="TUR")||(info.NCODE=="POL")||(info.NCODE=="AUS")||(info.NCODE=="TST")||(info.NCODE=="CYP"))) {
		chkall_flag = true;
	} else {
		chkall_flag = false;
	}

   if (active_base == "tab_function_base" || active_base == "tab_install_wizard") {
      for (var idx = 0; idx < model_tab.length; idx++) {
			if (model_tab[idx].key) {
				real_pgm = model_tab[idx].key.split('_')[0];
				break;
			}
		}
   }

   for (var idx = 0; idx < model_tab.length; idx++) {
		if (model_tab[idx].edit_table) {
			data_index = idx;
			
			if (model_tab[idx].edit_table.length) {
				for (var idx_2 = 0; idx_2 < model_tab[idx].edit_table.length; idx_2++) {
					var tmp_html = "";
					var model_th = model_tab[idx].edit_table[idx_2];
				
					if (model_th.label) {
						tmp_html = model_th.label;
					} else if (model_th.br) {
						for(var i=0; i<model_th.br; i++) {
							tmp_html += "<br>";
						}
					}
					
					if (model_th.cont) {
						table_headers[table_headers.length-1] += tmp_html;
					} else {
						table_headers.push($.trim(tmp_html))
					}
				}
			}
			
			if (model_tab[idx].variable_data && model_tab[idx].variable_data.length) {
				for (var idx_3 = 0; idx_3 < model_tab[idx].variable_data.length; idx_3++) {
					var model_tr = model_tab[idx].variable_data[idx_3].tr;
					tmp_row_data = new Array();
					
					if (model_tr && model_tr.length) {
						for (var idx_4 = 0; idx_4 < model_tr.length; idx_4++) {
							var tmp_html = "";
							var model_td = model_tr[idx_4];
							
							if (model_td.label) {
								if(model_td.name) {
									tmp_html = model_td.value;
								} else {
									tmp_html = model_td.label;
								}
							} else if (model_td.select) {
								for (var i=0; i<model_td.select.length; i++) {
									if (model_td.value == model_td.select[i].value) {
										tmp_html = model_td.select[i].option;
									}
								}
							} else if (model_td.textfield) {
								tmp_html = model_td.value;
							} else if (model_td.br) {
								for(var i=0; i<model_td.br; i++) {
									tmp_html += "<br>";
								}
							}
							
							if (model_td.cont) {
								tmp_row_data[tmp_row_data.length-1] += tmp_html;
							} else {
								tmp_row_data.push($.trim(tmp_html));
							}
						}
						table_data.push(tmp_row_data);
					}
				}
			}
			break;
		}
	}

   if (column_config[real_pgm]) {
		set_column_config = column_config[real_pgm];
   } else {
		var tmp_object = new Object;
		for (var i=0; i<table_headers.length; i++) {
			set_column_config.push(tmp_object);
		}
   }

	$('#'+ap.render_pgm).append('<div name=spreadsheet_table></div>')
	$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable({
		data: table_data,
		currentRowClassName: 'currentRow',
		currentColClassName: 'currentCol',
		colHeaders: table_headers,
		columns: set_column_config,
		outsideChkboxPlugin: true,
		manualColumnResize: true,
		manualRowResize: true,
    	afterChange: function (changes, source) {
         if (source != "loadData") {
            _.each(changes, function (changed_cell) {
               $($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', changed_cell[0], changed_cell[1])).siblings('th').find('input:checkbox')[0].checked = true;
            });
				
            if ((info.PHASE >= 2.2)&& (ap.render_pgm == "pgm1010")) {
					for(var h=0; h<changes.length; h++) {
						var row = changes[h][0];
						var col = changes[h][1];
						var oldValue = changes[h][2];
						var newValue = changes[h][3];
						if (oldValue != newValue) {
							if (col == 1) {
								var instance = this;       
								var cellProperties, options;
								cellProperties = instance.getCellMeta(row, 2);
								setAutocompleteSource.call(instance, row, newValue);
								$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+4, "", "loadData");
								for (var j=2; j<9; j++) {
									$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+j)).removeClass("htDimmed");
								}
							} else if (col == 2) {
								for (var i=1; i<8; i++) {
									$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+i).readOnly = false;
									$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+i)).removeClass("htDimmed");
								}
								
								if (newValue == g_ucs.option) {
									$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "", "loadData");
									for (var j=1; j<8; j++) {
										if (j!=6) {
											$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+j).readOnly = true;
											$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+j)).addClass("htDimmed");
										}
									}
								} else if (newValue == g_vmex.option) {
									$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "", "loadData");
									for (var j=1; j<8; j++) {
										if (j!=4 && j!=5) {
											$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+j).readOnly = true;
											$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+j)).addClass("htDimmed");
										} else {
											$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+j).readOnly = false;
											$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+j)).removeClass("htDimmed");
										}
									}
								} else {
									for (var i in g_stnid) {
										if (newValue == g_stnid[i].option) {
											if (g_stnid[i].value == 118 || g_stnid[i].value == 114 || g_stnid[i].value == 119 || g_stnid[i].value == 100 || g_stnid[i].value == 7) {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "8", "loadData");
											} else if (g_stnid[i].value == 120 || g_stnid[i].value == 116 || g_stnid[i].value == 1731) { 
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "32", "loadData");
											} else if (g_stnid[i].value == 208 || g_stnid[i].value == 42 || g_stnid[i].value == 104 || g_stnid[i].value == 101) {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "24", "loadData");
											} else if (g_stnid[i].value == 134 || g_stnid[i].value == 83 || g_stnid[i].value == 1730 || g_stnid[i].value == 10) {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "16", "loadData");
											} else if (g_stnid[i].value == 41) {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "30", "loadData");
											} else if (g_stnid[i].value == 0) {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "", "loadData");
												rdOnly = false;
											} else if (g_stnid[i].value == 168) {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "48", "loadData");
											} else {
												$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+3, "1", "loadData");
											}
											break;
										}
									}
										
									for (var j=4; j<8; j++) {
										$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+j).readOnly = true;
										$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+j)).addClass("htDimmed");
									} 
								}
							} else if (col == 3) {
								if ($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getDataAtCell',row,col)==langs.getText("common","opt_yes")) {
									$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('setDataAtCell', row, col+1, "", "loadData");
									$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+1).readOnly = true;
									$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+1)).addClass("htDimmed");
								} else if (($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getDataAtCell',row,col)==langs.getText("common","opt_no")) && (oldValue!=langs.getText("common","opt_no"))) {
									$('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCellMeta', row, col+1).readOnly = false;
									$($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getCell', row, col+1)).removeClass("htDimmed");
								}
							}
						}
					}
				}
			}
    	},
    	beforeChange: function(changes, source) {
    	   for (i = 0; i < changes.length; i++) {
      		var meta = this.getCellMeta(changes[i][0], changes[i][1]);
      		var data = changes[i][3];
            if (meta.maxLength) {
					if (chkKoreanLength(data) > meta.maxLength) {
						changes[i][3] = chkKoreanOfLength(data, meta.maxLength);
						//meta.overlen=true;
         		}
         	}
	      }
    	},
		cells: function (row, col, prop) {
			//debug_mode.flag && console.log("row : "+row+", col : "+col+", prop : "+prop);
			var tmp_variable_data = pgm_views[real_pgm].collection.models[0].attributes.elements[0].tab[data_index].variable_data;
			if (tmp_variable_data && tmp_variable_data[row+1] && tmp_variable_data[row+1].tr[col]) {
				var cellProperties = {};
				cellProperties.readOnly = false;
				cellProperties.valid = true;
				cellProperties.modified = false;
				cellProperties.comment = "";
				cellProperties.hasHTML = false;
				
				if (this.readOnly) {
					cellProperties.readOnly = true;
				}
/*				
				if (this.overlen==true) {
					cellProperties.valid = false;
					cellProperties.comment = langs.getText("error_msg","over_cnt");
				}
*/				
				if (real_pgm == "pgm446") {
					if ((col == 1) || (col == 2)) {
						if ($.trim(tmp_variable_data[row+1].tr[col].value).length != 0) {
							cellProperties.readOnly = true;
						}
					}
				}
				
				if (real_pgm == "pgm105") {
					if (col == 2) {
						if ($.trim(tmp_variable_data[row+1].tr[col].value).length != 0) {
							cellProperties.hasHTML = true;
						}
					}
				}
				if (this.type == "dropdown") {
					if ($.inArray($('#'+ap.render_pgm+' [name=spreadsheet_table]').handsontable('getData')[row][col], this.source) < 0) {
					if((info.PHASE >= 2.2) && !(real_pgm == "pgm1010" && col == 2)) {  //select source of col 2(device id) is dynamically updated later in afterChange.
						   cellProperties.valid = false;
					   }
					}
				}
				
				if (tmp_variable_data[row+1].tr[col].error) {
					if (tmp_variable_data[row+1].tr[col].error == "DA") {
						cellProperties.readOnly = true;
					} else {
						cellProperties.valid = false;
						cellProperties.comment = langs.getText("error_msg",tmp_variable_data[row+1].tr[col].error);
					}
				} else if (tmp_variable_data[row+1].tr[col].message) {
					cellProperties.comment = langs.getText("hover",tmp_variable_data[row+1].tr[col].message);
				}

				return cellProperties;
			}
		}
	});
}

function setAutocompleteSource(row, value) {
  var instance = this;
  var options = optionsMap[value];
  var cellProperties = instance.getCellMeta(row, 2);
  cellProperties.source = options;
  instance.getData()[row][2] = options[0];
}	
