

<%
/*
<script type="text/javascript" src="/js/jquery.1.3.2.js"></script>
<script type="text/javascript" src="/js/Common_Main.js"></script>
<script type="text/javascript" src="/js/Common_Utils.js"></script>
<script type="text/javascript" src="/js/Common.js"></script>
//__CurrentDirPath
*/
%>

<%
//public int PhotoUserType = 0;--图片上传者类型：0默认；1前台上传；2；后台上传
//public int PhotoType = 0;--图片所属类型：0头像；
//public int PhotoTypeFormatType = 0;--图片所属格式类型：0默认,1:首页横图.
//本页：头像
//10读取，20上传，25更新，30删除
%>


<script>
//使用指定图
function SetPicToUsing(Id,PhotoPath)
{
	var _url = '<%=__CurrentDirPath%>Update.aspx?IsAdd=25&PhotoUserType=<%=PhotoUserType%>&PhotoType=<%=PhotoType%>&InfoId=<%=InfoId%>&PhotoTypeFormatType=<%=PhotoTypeFormatType%>&id='+Id;
	jQuery.ajax({
		type: "GET",
		url: _url,
	    data:"",
		cache: false,
		success: function(msg){
			if(msg==1){
				jQuery("#td_a_<%=InfoId%>").attr("href",PhotoPath);
				GetPicList();
			}
			else{
				//操作失败
			}
			//alert(msg)
		}
	});				
}

//编辑
function GetPicList()
{
	jQuery.ajax({
		type: "POST",
		url: "<%=__CurrentDirPath%>Update.aspx?IsAdd=10&PhotoUserType=<%=PhotoUserType%>&PhotoType=<%=PhotoType%>&InfoId=<%=InfoId%>&PhotoTypeFormatType=0",
		data:"",//产品编号,图片分类
		cache: false,
		dataType:"json",
		success: function(msg){
			//ID,PID,PhotoPath,PhotoTitle,PhotoExplain,PhotoUserType,PhotoType,PhotoOrderId,InfoId,PhotoTypeFormatType
			var json = msg;
			var s="";
			if(json)
			{
				jQuery.each(json,function(i,DataRow)
				{
					//if(DataRow["filename"]!="Thumbs.db")
					{
						s += '<div id="div_'+ i +'">\r\n'
						  +  '<span id="li_'+ i +'" >'
						  + '<a  href="'+ DataRow["PhotoPath"]+'" target="_blank">'
						  +  '<img onerror01="this.src=\'/images/DefaultPic_1.JPG\'" src="'  + DataRow["PhotoPath"].replace("imglarge","imgmiddle") +'" alt="(预览)标题:'+ DataRow["PhotoTitle"] +'" />'
						  +  '</a></span>\r\n'//图片
						  //+  '<li id="li_Title_'+ i +'" style="text-align:left">标题:'+ DataRow["PhotoTitle"] +'</li>\r\n'//标题
						  + '';
						  
						  <%
						  if(PhotoType<4||PhotoType==15)
						  {
						  %>
						  if(DataRow["PhotoTypeFormatType"] ==1){
						  	s +=  '<span id="li_ope_'+ i +'" style="line-height:22px" >' + (DataRow["PhotoTypeFormatType"] ==1?'<b style="color:red">首页大图</b>':"")
						  }
						  else{
							  if(jQuery("#td_a_<%=InfoId%>").attr("href")==DataRow["PhotoPath"].replace("imgmiddle","imglarge"))//.replace("imgmiddle","imglarge"))
							  	s += '<font color="red"><b>默认</b></font> ';
							  else
							  	s += '<a href="javascript:;" onclick="return SetPicToUsing('+ DataRow["id"] +',\''+ DataRow["PhotoPath"] +'\')">设为默认</a>';//
						  }							  
						  <%
						  }
						  %>
						  s += '  <a href="javascript:;" onclick="return PicDelBox('+ DataRow["id"] +')">删除</a> </span>\r\n' //标题
						  + '</div>';	 
						i++;
					}
				});
				//ShowErrorMsg(s);
				jQuery("#MyPic").html(s);
			}
			else
				jQuery("#MyPic").html("暂无图片");
		}
		,error:function(msg)
		{
		//	ShowErrorMsg("获取时异常:" + msg.responseText);
		}
	});	
	return false;

}

//删除
function PicDelBox(id)
{
var type=3;
var _IsAdd=30;
//弹出框ID,标题，内容，删除程序执行路径，参数表
var _url =  "<%=__CurrentDirPath%>update.aspx?IsAdd=30";
var _data ={"InfoId":<%=InfoId%>,"ID":id,"PhotoType":<%=PhotoType%>,"OpeType":type};

//提交方式，目标地址，数据表，弹出框ID，标题，内容,是否按默认方式刷新（1或true）,删除后的操作
Common.ConfirmDelete2 ("POST",_url,_data,"ImageManage_deletepic","删除确认?","",false,"GetPicList();");

SetActive(id);	
return false;
}


//上传图片



var UpPic ={};
UpPic.Config={
	FileFilter:".jpg;.jpeg;.gif;.png;.bmp",//图片类型	
	SetTimeOutSecond :100 //倒计时的计时器
};

UpPic.Utils= {
	parseJson : function (text) {
		var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
		cx.lastIndex = 0;
		if (cx.test(text)) {
			text = text.replace(cx, function (a) {
				return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
			});
		}
		if (/^[\],:{}\s]*jQuery/.
		test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
		replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
		replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
			return eval('(' + text + ')');
		}
		throw 'JSON parse error';
	}
	,
	addEvent : function () {  
	     if (window.addEventListener) {  
	         return function(el, eventName, fn, capture) {  
	             el.addEventListener(eventName, fn, (capture));  
	         };  
	     } else if (window.attachEvent) {  
	         return function(el, eventName, fn, capture) {  
	             el.attachEvent("on" + eventName, fn);  
	         };  
	     } else {  
	         return function() {  
	         };  
	     }  
	 }	
	 ,
	 getFileExt	:function(filePath){ //获取文件扩展名
	 	var extIndex = filePath.lastIndexOf(".");
		filePath = filePath.substr(extIndex);//.jpg
		return filePath.toLowerCase();
	 } 
	 ,
	 checkFileType:function(fileExt){//检查是否是图片.
	 	return (UpPic.Config.FileFilter.indexOf(fileExt)>=0);//查询不到的话,返回 false
	 }	 	 
};

function GetUploadPicPath(oIframe)
{
	try{
		var oIframe = document.getElementById("IFrame1");
		var s = oIframe.contentWindow.document.forms[0].action.split("?")[1].split("&");

		var t ;var t1=0;var t2=0;
		for(var param in s){
			t =s[param].split("="); 
			if(t[0].toLowerCase ()=="infoid"){
				t1=1;if(t[1].length<1)t2=1;
			}
		}
		if(t1==1 && t2==1){
			UpPic.Config.SetTimeOutSecond = 100;
			oIframe.contentWindow.document.location.href="<%=__CurrentDirPath%>UpPicForm.aspx?t=1";
			GetPicList();return true;
		}//正常返回.
		else{
			UpPic.Config.SetTimeOutSecond -=1;
			if(UpPic.Config.SetTimeOutSecond>1) setTimeout(function(){GetUploadPicPath();},100);
		}
	}
	catch(e){
		if(oIframe.contentWindow.document.body!=null){
			var s = oIframe.contentWindow.document.body.innerHTML;
			if(s==1){UpPic.Config.SetTimeOutSecond = 100;
			oIframe.contentWindow.document.location.href="<%=__CurrentDirPath%>UpPicForm.aspx?t=1";
			GetPicList();}
		}
		else{
		
			UpPic.Config.SetTimeOutSecond -=1;
			if(UpPic.Config.SetTimeOutSecond>1) setTimeout(function(){GetUploadPicPath();},100);
		}
	}
}


</script>



<style>
.tableStyle
{
	width:552px;
	height:300px;
	border:1px solid #DDD;
	margin:10px 10px 0px 10px;
}

.PicListTd
{
	height:260px;
	overflow-y:scroll;
	vertical-align: top;
	border:1px solid #aaa;
	background-color:#efefef;
	display: inline-block;
	margin:3px 3px 3px 0px;
	/*width:598px;*/
	width:99%;
}
#MyPic
{
	
}
.PicListTd div
{
	width :112px;
	height:130px;
	border:0px dotted #aaa;
	margin:2px 2px 2px 2px;
	padding:0px 0 0 0;
	float:left;
/*	background-color:#fff;*/

	
	
}
.PicListTd div span
{

	display: block;/*inline-*/
	margin:3px 0px 1px 1px!important;
	margin:3px 1px 1px 1px;
	border:1px solid #aaa;
	list-style:none;
	

}

.PicListTd div span img
{
	margin:3px 2px 2px 2px;
	width:100px;
	height:80px;
	text-align:center;

}
.DivBottom
{
	margin:-10px 0px 0px 0px;
	
}
.button
{
	width:50px;height:22px;margin:2px;
}
.HtmlTextBox{border:1px solid #6699FF}
</style>



<table border="0" style="width:500px">

<tr style="height:30px;	font-weight: bold;">
<td align="center">
<%//编辑区 %>
		<div style="margin-left:0px;margin-top:2px;vertical-align: middle;" >
	<iframe id="IFrame1" src="<%=__CurrentDirPath%>UpPicForm.aspx?t=1" frameborder="0" marginwidth="0" marginheight="0" align="left" height="22" width="396px"  scrolling="no"  style="margin:0px 0 0px 0px;"></iframe>	</div>
	<div style="float:left;margin-left:0px;line-height:40px;margin-top:2px;vertical-align: middle;margin-top:0px;display:none;">
	&nbsp;&nbsp;	<!--
	<span style="display:inline-block;display:none;">首页横图：</span>-->
	<input type="checkbox" id="input_2_PhotoTypeFormatType" style=""  />
	</div>
	<div style="float:left;line-height:20px;display:inline-block;margin-left:5px;margin-bottom:0px;border:0px solid red;">
	<input type="button" id="input_2_Submit" value="上传"  />
	</div>

	
</td>
</tr>

<tr>
	<td valign="top"  style="border:0px"><%//列表区 %>
	<div id="MyPic" class="PicListTd" >
	
	
	
	</div>

	</td>
</tr>

</table>
<div style="background-color:#e6e6e6;color:#555555;text-align:left;;margin:0px 0px 0px 0px">
<span style="margin:5px 5px 0px 5px;display:block">


</span>
</div>


<script>
//RemoveDialogbox("#Div_PicManage")
//11:43 2010-9-29
//jQuery(document).ready(function(){

	//确定组
	jQuery("#input_2_Submit").click(function()
	{
		var oIframe = document.getElementById("IFrame1");
		if( oIframe.contentWindow.document.getElementById("imgFile")!=null )
		{
			if(oIframe.contentWindow.document.getElementById("imgFile").value.length>5){
				var filename = oIframe.contentWindow.document.getElementById("imgFile").value;
				if(UpPic.Utils.checkFileType( UpPic.Utils.getFileExt(filename)))
				{
					if(oIframe.contentWindow.document.getElementById("frmImageUpload"))
					{
						var _tmp = jQuery("#input_2_PhotoTypeFormatType").attr("checked");
						//alert(_tmp);return ;
						var __url = "<%=__CurrentDirPath%>Update.aspx?IsAdd=20&PhotoUserType=<%=PhotoUserType%>&PhotoType=<%=PhotoType%>&InfoId=<%=InfoId%>&PhotoTypeFormatType="+ (_tmp?1:0) ;
						oIframe.contentWindow.document.getElementById("frmImageUpload").action = __url;
						oIframe.contentWindow.document.forms[0].submit(); //上传
						setTimeout(function(){GetUploadPicPath();},100);						
					}	
					else
					{
						alert("没找到文件,上传终止.");
					}			
				}
				else{
					alert("文件类型无效,上传已取消.");
				}
			}
			else{
				alert("请先选择待上传的文件.");
			}			
		}	
		else{
			GetUploadPicPath(oIframe);
		}
	});	

	GetPicList();


//});






</script>