//eColumnMenu.js
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
var bisMobile=(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM);

function ColumnMenu_Esc()
{
	var event = arguments[0]||window.event; 
	var keyCode=event.which || event.keyCode;
	if(keyCode==27){cancelColumnMenu();}
};
function showColumnMenu(obj)
{		
	var box=document.getElementById("column_menu");	
	if(!box){return;}	
	if(typeof(sortmenu_close)=="function")
	{
		sortmenu_close();
	}
	//if (!$(box).is(":hidden"))
	if(box.style.display.length==0)
	{
		//var evt=getEvent();
		//if (evt.stopPropagation){evt.stopPropagation();}else{event.cancelBubble = true;}
		//if (evt.preventDefault){evt.preventDefault();}else{evt.cancelBubble = true;}
		cancelColumnMenu();
		return;
	}
	var Rect = obj.getBoundingClientRect();
	box.style.left="-2000px";
	box.style.top="-2000px";
	showObject(box);
	
	box.style.left=(new eScroll().left +　Rect.right - box.offsetWidth) + "px";
	box.style.top=(new eScroll().top +　Rect.bottom - 1) + "px";

	
	if (window.addEventListener)
	{
		/*
		if(bisMobile)
		{
			document.addEventListener("touchstart",cancelColumnMenu, false);
		}
		else
		{
			document.addEventListener("mouseup",cancelColumnMenu, false);
			document.addEventListener("keyup",ColumnMenu_Esc, true);
		}
		*/
		document.addEventListener("mouseup",cancelColumnMenu, false);
		document.addEventListener("keyup",ColumnMenu_Esc, true);
	}
	else
	{
		document.attachEvent("onmouseup",cancelColumnMenu);
		document.attachEvent("onkeyup",ColumnMenu_Esc);
	}
	//if(document.ontouchstart){alert(3); }
	//if(document.touchstart){alert(43); }
};
function getEvent()
{
	var evt;
	if(window.event)
	{
		evt=window.event;
	}
	else
	{
		var o = arguments.callee;
		var e;
		while(o != null)
		{
			e = o.arguments[0];
			if(e && (e.constructor == Event || e.constructor == MouseEvent))
			{
				evt=e;
				break;
			}
			o = o.caller;
		}
	}
	return evt;
};
function cancelColumnMenu()
{
	
	hideObject("column_menu");
	if (document.addEventListener)
	{
		/*
		if(bisMobile)
		{
			document.removeEventListener('touchstart', cancelColumnMenu, false);
		}
		else
		{
			document.removeEventListener('mouseup', cancelColumnMenu, false);
			document.removeEventListener('keyup', ColumnMenu_Esc, true);
		}
		*/
		document.removeEventListener('mouseup', cancelColumnMenu, false);
			document.removeEventListener('keyup', ColumnMenu_Esc, true);
	}
	else
	{
		document.detachEvent("onmouseup",cancelColumnMenu);
		document.detachEvent("onkeyup",ColumnMenu_Esc);
	}
	
	//alert(document.ontouchstart);
	//alert(3);
};
function showColumn(obj,ajax)
{
	var value=0;
	var ct=$(obj).parent().find(".cur").length;	
	if(ct==1 && obj.className=="cur")
	{
		alert("不能全部取消!");
		return;
	}
	if(obj.className=="cur")
	{
		obj.className="";		
	}
	else
	{
		obj.className="cur";
		value=1;
	}
	hideObject("column_menu");
	
	
	var modelitemid=obj.getAttribute("CellID");


	var url="?";	
	if(typeof(AppItem)=="string" && AppItem.length > 0){url+="AppItem=" + AppItem;}
	if(typeof(ModelID)=="string" && ModelID.length > 0){url+="ModelID=" + ModelID;}
	
	url+="&act=showcolumn&modelitemid=" + modelitemid + "&value=" + value + "&t=" + now();

	//$.ajax({type:"GET",async:false,url:_url,dataType:"html"});	
	if(ajax)
	{
		//document.title=ajax;
		$.ajax({
			   type:"GET",
			   async:false,
			   url:url,
			   dataType:"html",
			   success:function(data)
			   {
				   //var page=$("#page").val();
				   //Search(page);
				   Search();
			   }
		});	
	}
	else
	{
			$.ajax({type:"GET",async:false,url:url,dataType:"html",success:function(data)
			{
				document.location.assign(document.location.href.replace("#",""));
			}
			});
		
	}
};

//selInput.js
function set_selText(obj)
{
	var span=obj.parentNode.parentNode;
	var input =span.getElementsByTagName("input")[0];
	input.value=obj.innerHTML;
	
	var ul = obj.parentNode;	
	ul.style.display="none";
	ul.parentNode.style.zIndex=1;
	
	if(event.cancelBubble){event.cancelBubble=true;event.returnValue=false;}
	else{event.stopPropagation();event.preventDefault();}
};
function show_selText(obj)
{
	var src = getsrcElement(); 
	var ul =obj.getElementsByTagName("ul")[0];
	if(src.tagName == "INPUT" && ul.style.display != "none"){obj.style.zIndex=1;ul.style.display="none";return;}
	
	if(src.tagName != "SPAN"){return;}
	
	
	if(ul.style.display=="none")
	{
		ul.style.display="";
		obj.style.zIndex=1000;
		//ul.parentNode.style.zIndex=10000+parseInt(ul.parentNode.style.zIndex);
		//alert(obj.className + "::" + obj.style.zIndex);
	}
	else
	{
		ul.style.display="none";
		obj.style.zIndex=1;
	}
};
function getsrcElement()
{
	var evt,src;
	if(window.event)
	{
		evt=window.event;
		src = evt.srcElement;
	}
	else
	{
		var o = arguments.callee;
		var e;
		while(o != null)
		{
			e = o.arguments[0];
			if(e && (e.constructor == Event || e.constructor == MouseEvent))
			{
				evt=e;src=evt.target; 
				break;
			}
			o = o.caller;
		}
	}
	return src;	
};

//eEditer.js
//编码
function HtmlEncode(str)
{
	if(str.length == 0) return "";
	 var s = str.replace(/ /g,"&nbsp;");
	 s = s.replace(/\n/g,"<br>");
     s = s.replace(/\'/g,"&#39;");
     s = s.replace(/\"/g,"&quot;");
     return s;  
};
function eediter_setjson(ul)
{
	var json='[';
	ul.find("li").each(function(index, element){
		if(index>0){json+=',';}
		
		json+='{"type":"' + $(this).attr("data-type") + '","body":"' ;
		
		if( $(this).attr("data-type")=="text")
		{
			json+=HtmlEncode($(this).find("textarea:eq(0)").val());//.encode() ;
			//json+=decodeURIComponent($(this).find("textarea:eq(0)").val());			
		}
		else if($(this).attr("data-type")=="image")
		{
			json+= $(this).find("img:eq(0)").attr("src") ;
		}
		else
		{
			json+= $(this).find("span:eq(0)").attr("src") ;
		}
		
		json+= '"}';
    });
	json+=']';	
	var txtid=ul.parent().attr("id").replace("_body","");
	ul.parent().find("#" + txtid).val(json);
};

function eediter_del(obj)
{
	var _back=confirm('确认要删除吗？');
	if(!_back){return;};
	var type=$(obj).parent().attr("data-type");
	if(type=="image")
	{
		var img=$(obj).parent().find("img:eq(0)").attr("src");
		if(img.toLowerCase().indexOf("/temp/") > -1)
		{
			var url=$(obj).parent().parent().parent().attr("vpath") + "Plugins/ProUpload.aspx?act=del&file=" + img;
			$.ajax({
				type: "GET", async: true,
				url: url,
				dataType: "html",
				success: function (data) {}
			 });		
		}
	}
	
	var ul=$(obj).parent().parent()
	$(obj).parent().remove();
	eediter_setjson(ul);
};
function eediter_add(type)
{
	var html='<li data-type="text">';
    html+='<textarea onblur="eediter_setjson($(this).parent().parent());"></textarea>';
	html+='<a class="del" href="javascript:;" onclick="eediter_del(this);"></a>';
    html+='</li>';	
	//$(".eediter ul").append(html);	
	//$('.eediter li').arrangeable();
	var src = getsrcElement();	
	var ul=$(src).parent().parent().find("ul:eq(0)");
	ul.append(html);
	ul.find("li").arrangeable();
};
function eediter_upload(obj,type)
{
	var url=$(obj).parent().parent().attr("vpath") + "Plugins/ProUpload.aspx?type=file";
	var maxWidth=$(obj).parent().parent().attr("maxWidth");
	if(maxWidth){url+="&MaxWidth=" + maxWidth;}

	if(obj.files)
	{
		var formData = new FormData();
		for(var i=0;i<obj.files.length;i++)
		{
			formData.append('files', obj.files[i], obj.files[i].name);
		}		
		$(obj).hide();
		$.ajax({
            type: "POST", 
			async: true,
			data:formData,
            url: url,           
			contentType: false,
			//dataType: "formData",
			cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
			dataType: "json",
            success: function (data) 
			{
				//alert(JSON.stringify(data));
				if (data.errcode == "0") 
				{
					for(var i=0;i < data.files.length; i++)
					{
						//alert( data.files[i].url);
						if(type=="image")
						{
							$(obj).parent().parent().find("ul:eq(0)").append('<li data-type="' + type + '"><img src="' + data.files[i].url + '" class="editerimg" ondragstart="return false;" ondrag="return false;" /><a href="javascript:;" class="del" onclick="eediter_del(this);"></a></li>');		
						}
						else
						{
							$(obj).parent().parent().find("ul:eq(0)").append('<li data-type="' + type + '" class="' + type + '"><span src="' + data.files[i].url + '"></span><a href="javascript:;" class="del" onclick="eediter_del(this);"></a></li>');		
						}
					}
				}
				else
				{
					layer.msg(data.message);
				}
				obj.value="";
				$('.eediter li').arrangeable();
				var ul=$(obj).parent().parent().find("ul");
				eediter_setjson(ul);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
				obj.value="";
			}
        });
		$(obj).show();	
	}
	else
	{
		$.ajaxFileUpload ({
		 	type: "post",
			url: url, //用于文件上传的服务器端请求地址 
			secureuri: false, //一般设置为false 
			fileElementId: $(obj).attr("id"), //文件上传空间的id属性  <input type="file" id="file" name="file" /> 
			dataType: "json", //返回值类型 一般设置为json 			
			success: function (data, status)  //服务器成功响应处理函数
			{
				//alert(JSON.stringify(data));
				if (data.errcode == "0") 
				{
					for(var i=0;i < data.files.length; i++)
					{
						//$(obj).parent().parent().find("ul:eq(0)").append('<li data-type="text"><img src="' + data.files[i].url + '" class="editerimg" ondragstart="return false;" ondrag="return false;" /><a href="javascript:;" class="del" onclick="eediter_del(this);"></a></li>');		
						if(type=="image")
						{
							$(obj).parent().parent().find("ul:eq(0)").append('<li data-type="' + type + '"><img src="' + data.files[i].url + '" class="editerimg" ondragstart="return false;" ondrag="return false;" /><a href="javascript:;" class="del" onclick="eediter_del(this);"></a></li>');		
						}
						else
						{
							$(obj).parent().parent().find("ul:eq(0)").append('<li data-type="' + type + '" class="' + type + '"><span src="' + data.files[i].url + '"></span><a href="javascript:;" class="del" onclick="eediter_del(this);"></a></li>');		
						}
					}
				}
				else
				{
					layer.msg(data.message);
				}
				obj.value="";
				var ul=$(obj).parent().parent().find("ul");
				eediter_setjson(ul);
			}, 
			error: function (data, status, e)//服务器响应失败处理函数
			{
			} 
		});	
	}	
};

//移动端
//插入位置
function getAppendArea(ul)
{
	var top=document.body.scrollTop;
	var rect=ul.get(0).getBoundingClientRect();
	if(ul.children().length==0)//
	{
		return {obj:ul.get(0),up:true};
	}
	else
	{	
		var editer_tool=$(".mediter_tool:eq(0)");
		var span=editer_tool.find("span:eq(0)");	
		var toolTop = top + editer_tool.get(0).offsetTop + span.get(0).offsetTop;		
		var rec=ul.get(0).getBoundingClientRect();

		if((top + rec.top) > toolTop) //最顶部
		{
			return {obj:ul.get(0),up:true};
		}
		else if(toolTop > (top + rec.top + ul.get(0).offsetHeight))//最底部
		{
			return {obj:ul.get(0),up:false};
		}
		else
		{
			for(var i=0;i<ul.children().length;i++)
			{
				var rect=ul.children()[i].getBoundingClientRect();
				var _min= top +  rect.top; 
				var _max=_min + ul.children()[i].offsetHeight;
				if(_min < toolTop && _max > toolTop)
				{
					if(toolTop < (_min +  parseInt(ul.children()[i].offsetHeight/2)))
					{
						return {obj:ul.children()[i],up:true};
					}
					else
					{
						return {obj:ul.children()[i],up:false};
					}
				}
			}			
		}
	}	
};
//添加节点
function mediter_add(obj,type,value)
{
	var html='<li data-type="'+ type +'">';
    html+='<dl>';
    html+='<dt>';
	html+='<a href="javascript:;" onclick="mediter_del(this);" class="titledel">&nbsp;</a>';
    html+='<a href="javascript:;" onclick="mediter_move(this,false);" class="titledown">&nbsp;</a>';
    html+='<a href="javascript:;" onclick="mediter_move(this,true);" class="titleup">&nbsp;</a>';
    html+='</dt>';
    html+='<dd>';
	switch(type)
	{
		case "title":
			html+='<input onblur="mediter_setjson($(this).parent().parent().parent().parent());" placeholder="请输入标题" />';
			break;
		case "text":
			html+='<textarea onblur="mediter_setjson($(this).parent().parent().parent().parent());" placeholder="请输入内容" />';
			break;
		case "image":
			html+='<img src="' + value + '" />';
			break;
		case "audio":
			html+='<audio src="' + value + '" controls="controls" />';
			break;
		case "video":
			html+='<video src="' + value + '" controls="controls" />';
			break;
	}
	html+='</dd>';
    html+='</dl>';
    html+='</li>';
	var ul=$(obj).parent().next();
	var area=getAppendArea(ul);
	if(area.obj.tagName=="UL")
	{
		if(area.up)
		{
			$(area.obj).prepend(html);//最前面
		}
		else
		{
			$(area.obj).append(html);//底部
		}
	}
	else
	{
		if(area.up)
		{
			$(area.obj).before(html);//前
		}
		else
		{
			$(area.obj).after(html);//后
		}
	}
	
};
//删除内容
function mediter_del(obj)
{
	var _back=confirm('确认要删除吗？');
	if(!_back){return;};
	var tmp="";
	var type=$(obj).parent().parent().parent().attr("data-type");
	switch(type)
	{
		case "text":
			break;
		case "image":
			tmp=$(obj).parent().next().find("img").attr("src");
			break;
		case "audio":
			tmp=$(obj).parent().next().find("audio").attr("src");
			break;
		case "video":
			tmp=$(obj).parent().next().find("video").attr("src");
			break;
	}
	if(tmp.toLowerCase().indexOf("/temp/") > -1)
	{
		var url=$(obj).parent().parent().parent().parent().parent().attr("vpath") + "Plugins/ProUpload.aspx?act=del&file=" + tmp;
		$.ajax({
			type: "GET", async: true,
			url: url,
			dataType: "html",
			success: function (data) {}
		});		
	}
	var ul=$(obj).parent().parent().parent().parent();
	$(obj).parent().parent().parent().remove();	
	mediter_setjson(ul);
};
//移动内容
function mediter_move(obj,up)
{
	var li=$(obj).parent().parent().parent();
	if(up)
	{
		if(li.index()==0)
		{
			//alert("已经在顶部!");
			return;
		}
		li.prev().before(li);
	}
	else
	{
		if(li.index()==li.parent().children().length-1)
		{
			//alert("已经在底部!");
			return;
		}
		li.next().after(li);
	}
	
	var ids="";
	li.parent().children().each(function(index,elem)
	{
		
		if(index>0){ids+=',';}
		ids+= $(elem).attr("rowid");
    });
	var ul=$(obj).parent().parent().parent().parent();
	mediter_setjson(ul);
};
function mediter_setjson(ul)
{
	var json='[';
	//$(".mediter li").each(function(index,elem)
	ul.find("li").each(function(index, elem)
	{
		if(index>0){json+=',';}
		var type=$(elem).attr("data-type").toLowerCase();
		switch(type)
		{
			case "title":
				json+='{"type":"title","body":"' + HtmlEncode($(elem).find("input").val()) + '"}';
				break;
			case "text":
				json+='{"type":"text","body":"' + HtmlEncode($(elem).find("textarea").val()) + '"}';
				break;
			case "image":
				json+='{"type":"image","body":"' + $(elem).find("img").attr("src") + '"}';
				break;
			case "audio":
				json+='{"type":"audio","body":"' + $(elem).find("audio").attr("src") + '"}';
				break;
			case "video":
				json+='{"type":"video","body":"' + $(elem).find("video").attr("src") + '"}';
				break;
		}
    });	
	json+=']';
	var txtid=ul.parent().attr("id").replace("_body","");	
	$("#"+ txtid).val(json);
};
function mediter_upload(obj,type)
{
	
	var url=$(obj).parent().parent().parent().attr("vpath") + "Plugins/ProUpload.aspx?type=file";
	var maxWidth=$(obj).parent().parent().parent().attr("maxWidth");
	if(maxWidth){url+="&MaxWidth=" + maxWidth;}
	if(obj.files)
	{
		var formData = new FormData();
		for(var i=0;i<obj.files.length;i++)
		{
			formData.append('files', obj.files[i], obj.files[i].name);
		}		
		$(obj).hide();
		$.ajax({
            type: "POST", 
			async: true,
			data:formData,
            url: url,           
			contentType: false,
			//dataType: "formData",
			cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
			dataType: "json",
            success: function (data) 
			{
				if (data.errcode == "0") 
				{
					for(var i=0;i < data.files.length; i++)
					{						
						mediter_add($(obj).parent().get(0),type,data.files[i].url);
					}
				}
				else
				{
					layer.msg(data.message);
				}
				obj.value="";
				var ul=$(obj).parent().parent().next();
				mediter_setjson(ul);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
        });
		
		$(obj).show();
	}
	else
	{
		$(obj).hide();
		$.ajaxFileUpload ({
		 	type: "post",
			url: url, //用于文件上传的服务器端请求地址 
			secureuri: false, //一般设置为false 
			fileElementId: $(obj).attr("id"), //文件上传空间的id属性  <input type="file" id="file" name="file" /> 
			dataType: "json", //返回值类型 一般设置为json 			
			success: function (data, status)  //服务器成功响应处理函数
			{
				if (data.errcode == "0") 
				{
					for(var i=0;i < data.files.length; i++)
					{
						mediter_add(type,data.files[i].url);
					}
				}
				else
				{
					layer.msg(data.message);
				}
				obj.value="";
				var ul=$(obj).parent().parent().next();
				mediter_setjson(ul);
			}, 
			error: function (data, status, e)//服务器响应失败处理函数
			{
			} 
		});	
		$(obj).show();
	}
};

//eFileList.js
function eFileList_setjson(ol)
{
	var json='[';
	ol.find("li").each(function(index, element){		
		if(index>0){json+=',';}
		json+='{"name":"' + $(this).find("a:eq(0)").text() + '","url":"' + $(this).find("a:eq(0)").attr("href") + '"}';
    });
	json+=']';
	var txtid=ol.parent().attr("id").replace("_body","");
	ol.parent().find("#" + txtid).val(json);
	/*
	if(json.length>2)
	{
		ol.parent().find("[type='hidden']").val(json);
	}
	else
	{
		ol.parent().find("[type='hidden']").val("");
	}
	*/
};
function eFileList_del(obj)
{
	if(!confirm("确认要删除吗？")){return;}	
	var ol=$(obj).parent().parent();
	var src=$(obj).parent().find("a:eq(0)").attr("href");
	if(src.toLowerCase().indexOf("/temp/") > -1)
	{
		var url=ol.parent().attr("vpath") + "Plugins/ProUpload.aspx?act=del&file=" + src;
		$.ajax({
		   	type: "GET", async: true,
           	url: url,
           	dataType: "html",
           	success: function (data) {}
      	 });		
	}
	$(obj).parent().remove();
	eFileList_setjson(ol);	
};
function eFileList_upload(obj)
{	
	var url=$(obj).parent().parent().attr("vpath") + "Plugins/ProUpload.aspx?type=file";
	var maxWidth=$(obj).parent().parent().attr("maxWidth");
	if(maxWidth){url+="&MaxWidth=" + maxWidth;}
	if(obj.files)
	{
		var formData = new FormData();
		for(var i=0;i<obj.files.length;i++)
		{
			formData.append('files', obj.files[i], obj.files[i].name);
		}		
		$(obj).hide();
		$.ajax({
            type: "POST", 
			async: true,
			data:formData,
            url: url,           
			contentType: false,
			//dataType: "formData",
			cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
			dataType: "json",
            success: function (data) 
			{
				//alert(JSON.stringify(data));
				if (data.errcode == "0") 
				{
					for(var i=0;i < data.files.length; i++)
					{		
						$(obj).parent().parent().find("ol:eq(0)").append('<li><a href="' + data.files[i].url + '" target="_blank">' + data.files[i].name + '</a><a href="javascript:;" class="del" onclick="eFileList_del(this);">&nbsp;</a></li>');					
					}
				}
				else
				{
					layer.msg(data.message);
				}
				var ol=$(obj).parent().parent().find("ol");			
				obj.value="";
				eFileList_setjson(ol);				
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
        });
		$(obj).show();	
	}
	else
	{
		 $.ajaxFileUpload ({
		 	type: "post",
			url: url, //用于文件上传的服务器端请求地址 
			secureuri: false, //一般设置为false 
			fileElementId: $(obj).attr("id"), //文件上传空间的id属性  <input type="file" id="file" name="file" /> 
			dataType: "json", //返回值类型 一般设置为json 			
			success: function (data, status)  //服务器成功响应处理函数
			{
				//alert(JSON.stringify(data));
				if (data.errcode == "0") 
				{
					for(var i=0;i < data.files.length; i++)
					{
						$(obj).parent().parent().find("ol:eq(0)").append('<li><a href="' + data.files[i].url + '" target="_blank">' + data.files[i].name + '</a><a href="javascript:;" class="del" onclick="eFileList_del(this);">&nbsp;</a></li>');			
					}
				}
				else
				{
					layer.msg(data.message);
				}
				var ol=$(obj).parent().parent().find("ol");
				obj.value="";
				eFileList_setjson(ol);
			}, 
			error: function (data, status, e)//服务器响应失败处理函数
			{
			} 
		});		 
	}
};

//eReport.js
  function now() { date = new Date(); var t = date.getFullYear().toString(); t += (date.getMonth() + 1).toString(); t += (date.getDate()).toString(); t += (date.getHours()).toString(); t += (date.getMinutes()).toString(); t += (date.getSeconds()).toString(); t += (date.getMilliseconds()).toString(); return t; };

    function close_eDlg() {
        //$(".eDlg").hide();
        //$(".eDlg").css("top", "-2000px");
        //$(".eDlg").css("left", "-2000px");
        $(".eDlg").remove();
    };
    function eReport_Refresh(ReportID, CtrlID, ObjID, timeObj)
    {
        if (timeObj) { clearInterval(timeObj); }
        var rep = $("#" + CtrlID).parent();
        var timetype = rep.attr("TimeType") ? rep.attr("TimeType") : "";
        var ctrltype = rep.attr("ControlType");
        var url = "?ctrltype=" + ctrltype + "&ReportID=" + ReportID;
		
		
		if(typeof(AppItem)=="string" && AppItem.length > 0)
		{
			url+="&AppItem=" + AppItem;
		}
		else
		{
			if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		}
		
        if (ObjID.length > 0) { url += "&obj=" + ObjID; }
        if (timetype.length > 0)
        {
            if (timetype == "year")
            {
                url += "&syear=" + rep.attr("SYear") + "&eyear=" + rep.attr("EYear");
            }
            if (timetype == "quarter" || timetype == "month") {
                url += "&year=" + rep.attr("DefaultYear");
            }
            if (timetype == "day") {
                url += "&year=" + rep.attr("DefaultYear") + "&month=" + rep.attr("DefaultMonth");
            }            
        }
        url += "&t=" + now();
        $.ajax({
            type: 'get',
            url: url,
            dataType: "html",
            success: function (data) {
                rep.html(data);

            }
        });

    };
    function eReport_Confirm(ReportID, CtrlID, ObjID, timeObj)
    {      
        
        var rep = $("#" + CtrlID).parent();
        var timetype = rep.attr("TimeType");
        var ctrltype = rep.attr("ControlType");
        var maxyear = 0;
        var minyear = 0;
        if (rep.attr("maxYear").length > 0) maxyear = parseInt(rep.attr("maxYear"));
        if (rep.attr("minYear").length > 0) minyear = parseInt(rep.attr("minYear"));
        var year = 0;
        if (rep.attr("DefaultYear").length > 0) year = parseInt(rep.attr("DefaultYear"));
        var month = 0;
        if (rep.attr("DefaultMonth").length > 0) month = parseInt(rep.attr("DefaultMonth"));

        if ((timetype == "quarter" || timetype == "month") && year == parseInt($(".ereport_year").val()))
        {

            close_eDlg();
            return;
        }

        var url = "?ctrltype=" + ctrltype + "&";
        if (ObjID.length > 0) { url += "obj=" + ObjID + "&"; }
        if (timetype == "year")
        {
            rep.attr("sYear", $(".ereport_syear").val());
            rep.attr("eYear", $(".ereport_eyear").val());
            url += "ReportID=" + ReportID + "&syear=" + $(".ereport_syear").val() + "&eyear=" + $(".ereport_eyear").val();
        }
        if (timetype == "quarter" || timetype == "month")
        {
            rep.attr("DefaultYear", $(".ereport_year").val());
            url += "ReportID=" + ReportID + "&year=" + $(".ereport_year").val();
        }
        if (timetype == "day")
        {
            rep.attr("DefaultYear", $(".ereport_year").val());
            rep.attr("DefaultMonth", $(".ereport_month").val());
            url += "ReportID=" + ReportID + "&year=" + $(".ereport_year").val() + "&month=" + $(".ereport_month").val();
        }
		
		if(typeof(AppItem)=="string" && AppItem.length > 0)
		{
			url+="&AppItem=" + AppItem;
		}
		else
		{
			if(typeof(ModelID)=="string" && ModelID.length > 0){url+="&ModelID=" + ModelID;}
		}
		
		
        url += "&t=" + now();
        if (timeObj) { clearInterval(timeObj); }
        var html = '<div id="eReportLoading" class="loading">&nbsp;</div>';
        rep.append(html);

        $.ajax({
            type: 'get',
            url: url,
            dataType: "html",
            success: function (data) {
                 rep.html(data);
                close_eDlg();
            }
        });

    };
    function eReport_Reset(obj, ReportID, CtrlID, ObjID, timeObj) {
        var rect = obj.getBoundingClientRect();
        var html = '<div class="eDlg">';
        html += '<h1>报表选项<a href="javascript:;" onclick="close_eDlg();"></a></h1>';
        html += '<p></p>';
        html += '<div class="footer"><a class="btn" href="javascript:;" onclick="eReport_Confirm(\'' + ReportID + '\',\'' + CtrlID + '\',\'' + ObjID + '\',' + timeObj + ');">确定</a></div>';
        html += '</div>';
        $(document.body).append(html);


        $(".eDlg").css("top", eScroll().top + rect.top + (rect.bottom - rect.top));
        $(".eDlg").css("left", eScroll().left + rect.left - 200);
        // return;

        var rep = $(obj).parent().parent();

        var timetype = rep.attr("TimeType");
        var ctrltype = rep.attr("ControlType");
        var maxyear = 0;
        var minyear = 0;
        if (rep.attr("maxYear").length > 0) maxyear = parseInt(rep.attr("maxYear"));
        if (rep.attr("minYear").length > 0) minyear = parseInt(rep.attr("minYear"));
        var year = 0;
        if (rep.attr("DefaultYear").length > 0) year = parseInt(rep.attr("DefaultYear"));
        var month = 0;
        if (rep.attr("DefaultMonth").length > 0) month = parseInt(rep.attr("DefaultMonth"));


        html = '<div style="margin:10px;">';
        if (timetype == "year") {
            var syear = 0;
            if (rep.attr("sYear").length > 0) syear = parseInt(rep.attr("sYear"));
            var eyear = 0;
            if (rep.attr("eYear").length > 0) eyear = parseInt(rep.attr("eYear"));

            html += '<select name="select" class="ereport_syear">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == syear ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';
            html += ' 至 ';
            html += '<select name="select" class="ereport_eyear">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == eyear ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';

        }
        if (timetype == "quarter" || timetype == "month") {
            html += '<select name="select" class="ereport_year">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == year ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';
        }
        if (timetype == "day") {

            html += '<select name="select" class="ereport_year">';
            for (var i = minyear; i <= maxyear; i++) {
                html += '<option value="' + i + '"' + (i == year ? ' selected="true"' : '') + '>' + i + '年</option>';
            }
            html += '</select>';

            html += '<select name="select" class="ereport_month">';
            for (var i = 1; i <= 13; i++) {
                html += '<option value="' + i + '"' + (i == month ? ' selected="true"' : '') + '>' + i + '月</option>';
            }
            html += '</select>';
        }
        html += '</div>';
        $(".eDlg p").html(html);
        /*
    layer.open({
    type: 1
	, area: ['200px', '150px']
    //,shade: 0.2 //透明度
  	, title: "报表选项"
	, closeBtn: 1
    , offset: [ (eScroll().top + rect.top) + 'px',( eScroll().left + rect.left - 200) + 'px']
	, scrollbar: false
	, shadeClose: true //开启遮罩关闭
  	, content: html
    , shade: 0
	, btn: ['确定'] //只是为了演示
	, end: function () { }
	, success: function (layero, index) {}
    , yes: function (index) {
        
    }
    });
        */

    };
//fileManage.js
function checkfrm(frm)
{
    if (frm.imgFile.value.length == 0)
	{
		alert("请选择要上传的文件!");
		frm.imgFile.focus();
		return false;
	}
	return true;
};
function addTag(id,txt)
{
	var obj=document.getElementById(id);	
	if (obj.selectionStart !== undefined)
	{
		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
        obj.value = obj.value.substring(0, startPos) + txt + obj.value.substring(endPos, obj.value.length);
		obj.focus();
        obj.selectionStart = startPos + txt.length;
        obj.selectionEnd = startPos + txt.length;
	}
	else
	{
		  if(document.selection) 
		  { 		  
		  	 obj.focus();
             var sel = document.selection.createRange();
             sel.text =  txt;
		  }
		  else
		  {
		  	obj.value=[obj.value,txt].join("");
		  }
	}	
};
function showHtmlTag()
{
	
	var url = "?modelid=" + ModelID + "&act=getjson";
	$.ajax({type:"get",async:false,url:url,dataType:"json",success:function(json)
		{
			if(json.success=="1")
			{
				viewJson=json.viewJson;
				contentJson=json.contentJson;
				siteJson=json.siteJson;
			}
		}
	});
	var html='';
	html+='<div style="padding:4px 0px 4px 10px;border: 0px dashed #ccc;background-color:#f2f2f2;">全局标签：</div>';
	html+='<div style="margin:6px;">';
	$.each(publicJson, function()
	{
		html+='<a href="javascript:;" class="htmltag" onclick="addTag(\'content\',\'{'+ this["type"] +':'+ this["value"] +'(' + this["text"] + ')}\');">' + this["text"] + '</a>';
	});	
	html+='</div>';
	
	html+='<div style="padding:4px 0px 4px 10px;border: 0px dashed #ccc;background-color:#f2f2f2;">站点标签：</div>';
	html+='<div style="margin:6px;">';
	$.each(siteJson, function()
	{
		html+='<a href="javascript:;" class="htmltag" onclick="addTag(\'content\',\'{site:'+ this["value"] +'(' + this["text"] + ')}\');">' + this["text"] + '</a>';
	});	
	html+='</div>';
	
	html+='<div style="padding:4px 0px 4px 10px;border: 0px dashed #ccc;background-color:#f2f2f2;">动态数据：</div>';
	html+='<div style="margin:6px;">';	
	$.each(viewJson, function()
	{
		html+='<a href="javascript:;" class="htmltag" onclick="addTag(\'content\',\'{view:'+ this["value"] +'(' + this["text"] + ')}\');">' + this["text"] + '</a>';
	});		
	html+='</div>';
	html+='<div style="padding:4px 0px 4px 10px;border: 0px dashed #ccc;background-color:#f2f2f2;">静态数据：</div>';
	html+='<div style="margin:6px;">';
	$.each(contentJson, function()
	{
		html+='<a href="javascript:;" class="htmltag" onclick="addTag(\'content\',\'{content:'+ this["value"] +'(' + this["text"] + ')}\');">' + this["text"] + '</a>';
	});	
	html+='</div>';
	
	layer.open({
					type: 1 //此处以iframe举例
					,title: "插入数据"
					//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
					,shadeClose: false //点击遮罩关闭层
					, area: ['80%', '80%']
					,shadeClose: true //点击遮罩关闭
					,shade: 0.2 //透明度
					,maxmin: false
					,resize: false
					,btnAlign: 'l' //lcr
					,moveType: 0 //拖拽模式，0或者1
					,anim: 0 //0-6的动画形式，-1不开启
					,content: html
					,btn: ['返回'] //只是为了演示
					,yes: function(index,layero)
					{ 
						layer.close(index); 
					}	
					,cancel: function(index, layero)
					{
						//layer.msg("X关闭!");
					}
					,success: function(layero, index)
					{
					}
				});
};
function addPath(txt)
{
	var obj=document.getElementById("content");	
	if (obj.selectionStart !== undefined)
	{
		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
        obj.value = obj.value.substring(0, startPos) + txt + obj.value.substring(endPos, obj.value.length);
		obj.focus();
        obj.selectionStart = startPos + txt.length;
        obj.selectionEnd = startPos + txt.length;
	}
	else
	{
		  if(document.selection) 
		  { 		  
		  	 obj.focus();
             var sel = document.selection.createRange();
             sel.text =  txt;
		  }
		  else
		  {
		  	obj.value=[obj.value,txt].join("");
		  }
	}	
	parent.layer.close( parent.FileSelectFormIndex);
    parent.FileSelectFormIndex = null;
};
function showPathSelect()
{
	var url = "FileSelect.aspx";
    parent.layer.open({
      type: 2,
      title: "选择库文件",
      maxmin: false,
      shadeClose: true, //点击遮罩关闭层
      area : ["900px;" , "700px"],	
	  // content: [url,'no'], 
	  content: url,
	  success: function(layero, index)
	  {
	      parent.FileSelectFormIndex = index;
  	  }
    });	
};
//文件编辑
function edit(name)
{
	var url = "?" + (typeof (ModelID) == "string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "") + "act=edit" + (path.length>0 ? "&path=" + path : "") + "&name=" + name;
	$.ajax({type:"get",async:false,url:url,dataType:"json",success:function(json)
		{
			if(json.success=="1")
			{
				var html='';
				html+='<textarea id="content" name="content" class="autoNumber" style="width:98%;height:540px;">' + json.value + '</textarea>';
				layer.open({
					type: 1 //此处以iframe举例
					,title: name
					//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
					,shadeClose: false //点击遮罩关闭层
					,area: ['90%', '90%']
					,shade: 0.2 //透明度
					,maxmin: false
					,resize: false
					,btnAlign: 'l' //lcr
					,moveType: 0 //拖拽模式，0或者1
					,anim: 0 //0-6的动画形式，-1不开启
					,content: html
					,btn: ['保存修改','关闭'] //只是为了演示
					,yes: function(index,layero)
					{ 
						//var value=$("#content").val().replace(/\r/ig,"").replace(/\n/ig,"0x\\r\\n");	
						var value=$("#content").val().encode();					
						url =  "?" + (typeof (ModelID) == "string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "") + "act=save" + (path.length>0 ? "&path=" + path : "") + "&name=" + name;						
						$.ajax({
							type: "post", 
							async: true,
							data:{value:value},
							url: url,
							dataType: "json",
							success: function (data) {
								layer.msg(data.message);
								//layer.close(index); 不关闭、继续修改
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {				
							}
						});
					}	
					,cancel: function(index, layero)
					{
						//layer.msg("X关闭!");
					}
					,success: function(layero, index)
					{
						//alert($('#layui-layer'+ index).height());
						var h=$('#layui-layer'+ index).height()-110;
						var w=$('#layui-layer'+ index).width()-6;
						$("#content").height(h).width(w);
						$("#content").setTextareaCount({width: "40px",bgColor: "#f2f2f2",color: "#000",display: "inline-block"});
					}
				});
			}
		}
	});		
};
//模板编辑
function editFile(name)
{
	var url = "?" + (typeof (ModelID) == "string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "") + "act=edit" + (path.length>0 ? "&path=" + path : "") + "&name=" + name;
	$.ajax({type:"get",async:false,url:url,dataType:"json",success:function(json)
		{
			if(json.success=="1")
			{
				var html='';
				if(name.toLowerCase().indexOf(".html")>-1)
				{
					html+='<div style="padding:8px;background-color:#f2f2f2;"><a href="javascript:;" onclick="showHtmlTag();" style="color:#0026ff;">插入数据</a>&nbsp;&nbsp;<a href="javascript:;" onclick="showPathSelect();" style="color:#0026ff;">插入库文件</a></div>';
				}
				html+='<textarea id="content" name="content" class="autoNumber" style="width:98%;height:540px;">' + json.value + '</textarea>';
				layer.open({
					type: 1 //此处以iframe举例
					,title: name
					//,skin: 'layui-layer-molv' //加上边框 layui-layer-rim  layui-layer-lan layui-layer-molv layer-ext-moon
					,shadeClose: false //点击遮罩关闭层
					, area: ['90%', '90%']
					,shade: 0.2 //透明度
					,maxmin: false
					,resize: false
					,btnAlign: 'l' //lcr
					,moveType: 0 //拖拽模式，0或者1
					,anim: 0 //0-6的动画形式，-1不开启
					,content: html
					,btn: ['保存修改','关闭'] //只是为了演示
					,yes: function(index,layero)
					{ 

						//var value=$("#content").val().replace(/\r/ig,"").replace(/\n/ig,"0x\\r\\n");
						var value=$("#content").val().encode();
						url = "?" + (typeof (ModelID) == "string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "") + "act=save" + (path.length>0 ? "&path=" + path : "") + "&name=" + name;						
						$.ajax({
							type: "post", 
							async: true,
							data:{value:value},
							url: url,
							dataType: "json",
							success: function (data) {
								layer.msg(data.message);
								//layer.close(index); 不关闭、继续修改
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {				
							}
						});
					}	
					,cancel: function(index, layero)
					{
						//layer.msg("X关闭!");
					}
					,success: function(layero, index)
					{
						//alert($('#layui-layer'+ index).height());
						var h=$('#layui-layer'+ index).height()-140;
						var w=$('#layui-layer'+ index).width()-6;
						$("#content").height(h).width(w);
						$("#content").setTextareaCount({width: "40px",bgColor: "#f2f2f2",color: "#000",display: "inline-block"});
						
					}
				});
			}
		}
	});	
};﻿
//文件上传
function fileManage_upload(obj) {
    var url = "?" + (typeof (ModelID) == "string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "") + "act=upload" + (path.length > 0 ? "&path=" + path : "");
    if (obj.files) {
        var formData = new FormData();
        for (var i = 0; i < obj.files.length; i++) {
            formData.append('files', obj.files[i], obj.files[i].name);
        }
        $(obj).hide();
        $.ajax({
            type: "POST",
            async: true,
            data: formData,
            url: url,
            contentType: false,
            //dataType: "formData",
            cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
            dataType: "html",
            success: function (data) {
                // alert(JSON.stringify(data));
                //$(".filemanage_files .clear").before(data);
                $("#filemanage_files").children().last().before(data);
                obj.value = "";
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
        $(obj).show();



    }
    else {       
        $.ajaxFileUpload({
            type: "post",
            url: url, //用于文件上传的服务器端请求地址 
            secureuri: false, //一般设置为false 
            fileElementId: $(obj).attr("id"), //文件上传空间的id属性  <input type="file" id="file" name="file" /> 
            dataType: "html", //返回值类型 一般设置为json 		
            complete:function(){},
            success: function (data, status)  //服务器成功响应处理函数
            {
                //$(".filemanage_files .clear").before(data);
                $("#filemanage_files").children().last().before(data);
            },
            error: function (data, status, e)//服务器响应失败处理函数
            {
            }
        });
    }
};

function addFile()
{
	layer.prompt({ title: '输入文件名称', formType: 3, value: '' }, function (value, index) {
		var url ="?" + (typeof(ModelID)=="string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "" ) + "act=addfile" + (path.length>0 ? "&path=" + path : "") + "&name=" + value;
        layer.close(index);
        document.location.href = url;
    });
};
function addFolder()
{
	layer.prompt({ title: '输入文件夹名称', formType: 3, value: name }, function (value, index) {
		var url = "?" + (typeof(ModelID)=="string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "" ) + "act=addfolder" + (path.length>0 ? "&path=" + path : "") + "&name=" + value;
        layer.close(index);
        document.location.href = url;
    });
};
function ReName(name,type)
{
	layer.prompt({ title: '输入文件' + (type == 1 ? '夹' : '') + '名称', formType: 3, value: name }, function (value, index) {
    	var url = "?" + (typeof(ModelID)=="string" && ModelID.length > 0 ? "ModelID=" + ModelID + "&" : "" ) + "act=rename" + (path.length>0 ? "&path=" + path : "") + "&type=" + type + "&oldname=" + name + "&newname=" + value;
        layer.close(index);
        document.location.href = url;
    });
};





