﻿	var template = { "self": "<!--form id='{t}' name='{t}'-->\n{p}\n<!--<input type='button' name='Submit' value='{btnsubmit}' onclick='formValidation()'/>-->\n<!--/form-->",
					 "p": "{$}\n",
					 "p[*]": function(x) {
					 	var gottaHTML = "";
						if (x.Importance == 0){gottaHTML = jsondata.general.gottaHTML}				//必选项输入框后面添加红色的"*"项
					 	var inputType = x.InputType.toLowerCase();
						switch(inputType)
							{ case "password":
								//返回HTML片段
								return "<div id='div" + x.ID + "'>" +
										  "<table class='regTable' border='0' cellspacing='0' cellpadding='0'>" +
										    "<tr>" +
											  "<td class='regLabel'>" + x.Name + "</td>" +
											  "<td class='regInput'><input type='password' name='" + x.ID + "' id='" + x.ID + "' onBlur = pwdConsistency('" + x.ID  + "');itemValidation('" + x.ID  + "') Regex='" + x.Regex + "' Flag='" + x.Importance + "' /></td>" +
											  "<td>" + gottaHTML + "</td>" + 
											  "<td class='regTip' id='tip" + x.ID + "' >" + x.Tip + "</td>" + 
											"</tr>" +
										    "<tr>" +
											  "<td class='regLabel'>&nbsp;</td>" +
											  "<td class='regInput'><input type='password' name='" + x.ID + "2' id='" + x.ID + "2' onBlur = pwdConsistency('" + x.ID  + "'); Regex='" + x.Regex + "' Flag='" + x.Importance + "' InputType='" + inputType + "' /></td>" +
											  "<td>" + gottaHTML + "</td>" + 
											  "<td class='regTip' id='tip" + x.ID + "2' >&nbsp;</td>" +
											"</tr>" +
										  "</table>" +
										"</div>";
								break;
							  case "select":
								var i = 0;									//循环变量
								var str = "";								//创建Options变量HTML列表
								var jsonstr = "";
								var OptionsCount = x.Option.length;			//预置选项数量
								var OptionsFillFunc ="";					//通过Javascript动态填充列表项目
								if (OptionsCount == 1){
									//当数量为1时，表示列表内容通过Javascript函数(或AJAX)实现
									OptionsFillFunc = ";" + x.Option[0];
									eval("jsonstr =" + x.InitialFunc);
									for(i=0;i<jsonstr.Option.length;i++) {
										if(i==0){
											//定义首选项(第一个非空值将作为默认选定值；否则没有默认值)
											if (jsonstr.Option[0] != "") {
												str = "<option selected='selected' value='" + jsonstr.Option[i] + "'>" + jsonstr.Option[i] + "</option>";
											}
										}else{
											//定义首选项(非空值将作为选项值)
											if (jsonstr.Option[i] != "") {
												str += "<option value='" + jsonstr.Option[i] + "'>" + jsonstr.Option[i] + "</option>" ;
											}
										}
									}
								}else{
									//只有当预置选项超过一个的时候才将信息填充到选项列表中
									//将数组数值添加到列表中
									for(i=0;i<OptionsCount;i++) {
										if(i==0){
											//定义首选项(第一个非空值将作为默认选定值；否则没有默认值)
											if (x.Option[0] != "") {
												str = "<option selected='selected' value='" + x.Option[i] + "'>" + x.Option[i] + "</option>";
											}
										}else{
											//定义首选项(非空值将作为选项值)
											if (x.Option[i] != "") {
												str += "<option value='" + x.Option[i] + "'>" + x.Option[i] + "</option>" ;
											}
										}
									}
								}
								//返回HTML片段
								return "<div id='div" + x.ID + "'>" +
										  "<table class='regTable' border='0' cellspacing='0' cellpadding='0'>" +
										    "<tr>" + 
											  "<td class='regLabel'>" + x.Name + "</td>" +
											  "<td class='regInput'><select name='" + x.ID + "' id='" + x.ID + "' onchange=itemValidation('" + x.ID  + "')" + OptionsFillFunc + " Regex='" + x.Regex + "' Flag='" + x.Importance +  "' InputType='" + inputType + "' >" + str + "</select></td>" +
											  "<td>" + gottaHTML + "</td>" + 
											  "<td class='regTip' id='tip" + x.ID + "'>" + x.Tip + "</td>" + 
											"</tr>" +
										  "</table>" +
										"</div>";
								break;
							  default:
								//返回HTML片段
								return "<div id='div" + x.ID + "'>" + 
										   "<table class='regTable' border='0' cellspacing='0' cellpadding='0'>" + 
										     "<tr>" + 
											   "<td class='regLabel'>" + x.Name + "</td>" + 
											   "<td class='regInput'><input type='text' name='" + x.ID + "' id='" + x.ID + "' onBlur=itemValidation('" + x.ID  + "') Regex='" + x.Regex + "' Flag='" + x.Importance + "' InputType='" + inputType + "' /></td>" +
											   "<td>" + gottaHTML + "</td>" + 
											   "<td class='regTip' id='tip" + x.ID + "'>" + x.Tip + "</td>" + 
											 "</tr>" +
										   "</table>" + 
										 "</div>";
								break;
							};
						}
					}