// input checkbox区：$("div#fieldsbox) $("div#fieldsbox_id") id与 接收站配置项的value相对应 selectctrl.options[selectctrl.selectedIndex].value
// 新建区：$("div#newdatasbox) $("div#newdatasbox_id")  id与 接收站配置项的value相对应 selectctrl.options[selectctrl.selectedIndex].value

//编辑区  $("div#editdatasbox)
  //每个编辑块都用li包裹起来，外面的ul的id为blockul和editblockul

  //注意：有两个配置，一个是接收中对控件的配置，每个键值对中值以{}括起来表示 ，该字段需要填充  一个是发送对控件的配置
var defaulttextareawidth="98%";
var defaulttextareaheight="30px";//如不是百分比，则px必须加上
var e6d22ba8earr=[];//
var currentoptionval=0;//当前被选中的接收配置 select#conode的当前选择项
var configarr_flip=[];



function ebb3f01e2(data)
{
	newli=$("div.newinputboxdiv2:visible li.newinputli:first").clone(true);
	$("input.singlenewpostbutt",newli).attr("class","singleeditpostbutt");
	//$("input.singlenewpostbutt",newli).attr("class","singleeditpostbutt").attr("onclick",singlpost);//用attr不能绑定函数，只能内联语句
	$("input:last",newli).after("<input type=\"hidden\" name=\"cid\" value=\""+data.aid+"\"/>");	
	var record=[];
	var lilist=[];
	var j=0;
	for(var i in data){ 
		j++;
		record=data[i];
		if(record){
			$("textarea",newli).each(function(){
				ctrlkeyarr=$(this).attr("name").split("_");
				$(this).get(0).value="";
				if((ctrlkeyarr[0] in configarr_flip) && record[configarr_flip[ctrlkeyarr[0]]]){		
					$(this).get(0).value=record[configarr_flip[ctrlkeyarr[0]]];
				}
				lilist[i]=newli.clone(true);
			});	
		}
	}
	for(var i in lilist){
		$("ul#editinputul").append(lilist[i]);
	}
}






$(function(){
	

	//$("#layout").change();
	
		
		
		$("#newpostallreset").click(function() {
			var i=0;
			$("div#newinputbox form").each(function(){
				if($(this).find(":checkbox.newinputcheck").attr("checked"))
				{this.reset();i++;}
			});
			if(i==0) alert("请至少选中一个表单");
		});

		//$(".allnewpostbutt,.alleditpostbutt").click(function(){mutilepost.call(this);});


		//$(".singlenewpostbutt,.singleeditpostbutt").click(function(){singlpost.call(this);});


		$("#editpostallreset").click(function() {
			var i=0;
			$("div#editinputbox form").each(function(){
				if($(this).find(":checkbox.newinputcheck").attr("checked"))
				{this.reset();i++;}
			});
			if(i==0) alert("请至少选中一个表单");
		});

		$("#editpostall").click(function() {
			var i=0;
			$("div#editinputbox form").each(function(){
				//this.submit(); 直接用提交函数不好，最好用个过渡
				if($(this).find(":checkbox.newinputcheck").attr("checked"))
				{publishrecord(this);i++;}
				
			});
			if(i==0) alert("请至少选中一个表单");
		});

		$("#newallcheck").click(function() {
			$("div#newinputbox :checkbox.newinputcheck").attr("checked",this.checked);
		});

		$("#editallcheck").click(function() {
			$("div#editinputbox :checkbox.newinputcheck").attr("checked",this.checked);
		});




/*
$("#conode").change(function(){
	currentoptionval=this.options[this.selectedIndex].value;
	configarr=$(this.options[this.selectedIndex]).attr("configtext").split("&");
	configarr_flip=[];
	for(var i in configarr){
		var item=configarr[i].split("=");
		if(item[1].indexOf("{")===0)
		configarr_flip[item[0]]=item[1].replace(/^\{|\}$/g,'');
	}
	var e6d22ba8estr="";

	if(!e6d22ba8earr || !e6d22ba8earr[currentoptionval])
	{
		if(!e6d22ba8earr) e6d22ba8earr=[];
		e6d22ba8earr[currentoptionval]=[];		
		for(var i in configarr_flip){
			e6d22ba8earr[currentoptionval][i]=[1,0,0];
		}
	}
	var ctrltemplate_checkbox="<li  class=\"checkboxli\"><input onchange=\"fieldchange(this)\" class=\"showfieldbox\" ischecked type=\"checkbox\" name=\"ctrlname\" value=\"1\"/>ctrlname</li>";

	var ctrltemplate_newinput="<tr style=\"display:table-row;\" name=\"inputtr_ctrlname\" class=\"inputtr\"><td class=\"newinputtd_key\" >ctrlname：</td><td class=\"newinputtd_value\"><div name=\"ctrlname_textareacontainer\" class=\"textareacontainer\" style=\"position:relative;width:95%;height:98%;\"><textarea class=\"ctrltextarea\" name=\"ctrlname_textarea\"></textarea><div class=\"drag\">55</div></div></td></tr>";

	//checkboxlist重新载取  //字段显示的checkbox的list重新载取 最外层是div#fieldsbox，往里是div#fieldsbox_id.fieldsboxdiv，再往里是ul.fieldsul ,li.checkboxli,input
	
	$("div[id^='fieldsbox_']").hide();
	if($("#fieldsbox_"+currentoptionval).length>0){
		$("div#fieldsbox_"+currentoptionval).show();
	}else{		
		var ctrlliststr="";
		for(var i in e6d22ba8earr[currentoptionval]){
			ctrlliststr += ctrltemplate_checkbox.replace(/ctrlname/gi,i).replace("ischecked",parseInt(e6d22ba8earr[currentoptionval][i][0])?"checked=1":"");	
		}		
		ctrlliststr="<div class=\"fieldsboxdiv\" id=\"fieldsbox_"+currentoptionval+"\"><ul class=\"fieldsul\">"+ctrlliststr+"</ul></div>"
		$(ctrlliststr).appendTo("div#fieldsbox");
	}

	//新建框的list重新载取 最外层是div#newinputbox，往里是div#newinputbox_id .newinputboxdiv2，再往里是ul.newinputul ,li.newinputli,然后是form name="newinputform_id"   table#newinputtable_id.newinputtable,tr
	$("div[id^='newinputbox_']").hide();
	if($("div#newinputbox_"+currentoptionval).length>0){
		$("div#newinputbox_"+currentoptionval).show();
	}else{
		var newinputlist="";
		for(var i in e6d22ba8earr[currentoptionval]){
			//生成新建框的list
			newinputlist += ctrltemplate_newinput.replace(/ctrlname/gi,i).replace(
			/width:([^;"]*)([";])/,("width:"+ (parseInt(e6d22ba8earr[currentoptionval][i][1]) ? (e6d22ba8earr[currentoptionval][i][1]+"px") : "$1")+"$2")).replace(/height:([^;"]*)([";])/,("height:"+ (parseInt(e6d22ba8earr[currentoptionval][i][2])?(e6d22ba8earr[currentoptionval][i][2]+"px"):"$1")+"$2")
			).replace(/display:"([^;"]*)([";])/,parseInt(e6d22ba8earr[currentoptionval][i][0]) ? "display:table-row;" : "display:none;");
		}
		newinputlist+="<tr class=\"inputbutt_tr\"><td class=\"newinput_buttrow\" colspan=\"2\"><div style=\"float:right;\"><input type=\"checkbox\" value=\""+currentoptionval+"\" class=\"newinputcheck\" name=\"newinputcheck\" id=\"newinputcheck_"+currentoptionval+"\" />选中</div>&nbsp;&nbsp;<input type=\"reset\" value=\"重置\" onclick=\"this.form.reset();\" class=\"newresetbutt\" name=\"resetbutt\" />&nbsp;&nbsp;<input type=\"button\" value=\"发布\" onclick=\"singlpost.call(this,'publish');\" class=\"singlenewpostbutt\" name=\"postbutt_"+currentoptionval+"\" />&nbsp;&nbsp;<input type=\"button\" value=\"保存\" onclick=\"singlpost.call(this,'tempsave');\" class=\"singlenewpostbutt\" name=\"savesinglebutt_"+currentoptionval+"\" /></td></tr>";

		newinputlist= "<li class='newinputli'><form><table class=\"newinputtable\" >"+newinputlist+"</table></form></li>";
		
		var i=1;
		var ef6078293=parseInt($("#ef6078293").val());
		var newinputlist2=newinputlist;
		while(i<ef6078293){
			newinputlist2+=newinputlist;
			i++;
		}
		
		$("<div class=\"newinputboxdiv2\" id=\"newinputbox_"+currentoptionval+"\" ><ul class='blockul'>"+newinputlist2+"</ul></div>").appendTo($("div#newinputbox"));
		draginit(document);
		newinputlist2=newinputlist=null;
	}
	$("#layout").change();
	$("#receivesiteurl").val($(this.options[this.selectedIndex]).attr("receivesiteurl"));
	
});

*/


//draginit(document);
});


function savedrag(){
	/*
	var namearr=$(textarea,this.obj).attr("name").split("_");
	e6d22ba8earr[currentoptionval][namearr[0]][0];
	*/
	
	var ctrlname=$("textarea",this).attr("name").split("_");
	var width=parseInt($(this).css("width"));
	var height=parseInt($(this).css("height"));
	//$("div[name='"+$(this).attr("name")+"']").css("width",width).css("height",height);
	//e6d22ba8earr[currentoptionval][ctrlname][0]为是否显示
	e6d22ba8earr[currentoptionval][ctrlname[0]][1] = width;
	e6d22ba8earr[currentoptionval][ctrlname[0]][2] = height;
}

function autoadjustsize(){
	var outerheight=document.getElementById("editright").clientHeight;
	var maxtopheight=parseInt(outerheight*0.4);
	var topheight=document.getElementById("newinputbox").offsetHeight;
	if(topheight>maxtopheight){
		$("#newinputbox").css("height",maxtopheight+"px");
		$("#editinputbox").css("height",(outerheight-100-maxtopheight)+"px");
	}else	
	$("#editinputbox").css("height",(outerheight-100-topheight)+"px");	
}

function handleadjustheight(){
	var outerheight=document.getElementById("editright").clientHeight;
	var maxtopheight=parseInt(outerheight*0.4);
	var topheight=document.getElementById("newinputbox").offsetHeight;
	if(topheight>maxtopheight){
		$("#newinputbox").css("height",maxtopheight+"px");
		$("#editinputbox").css("height",(outerheight-100-maxtopheight)+"px");
	}else	
	$("#editinputbox").css("height",(outerheight-100-topheight)+"px");	
}