<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Admin_Ad_Pic.aspx.vb" Inherits="TourEx.Web.Admin_Ad_Pic" %>
<%@ Import Namespace="TourEx.BLL" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="Css/Style.css"/>
<script language="javascript" src="../Sys/Js/jquery.js"></script>
<script language="javascript" src="../Sys/Js/AlertWindow.js"></script>
</head>
<body>
    <div id="messWindow" class="messWindow">
    </div>
    <div id="promptWindow" class="promptWindow" align="center">
        <div class="titleBar">
            <span>添加图片广告</span><span onclick="HideWindow()" style="float: right;"><img src="Images/popclose.gif" /></span></div>
        <div class="mainContent">
            <form method="post" onsubmit="return CheckForm();" id="TEForm">
		    <input name="A_RanNum" id="A_RanNum_0" type="hidden" value="" />
		    <input name="A_ID" type="hidden" id="A_ID_0" value="" />
            <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D6DFF7">
                <tr>
                    <td class="subMainLeft">链接：</td>
                    <td class="subMainRight">
                        <input name="A_Url" type="text" id="A_Url_0" size="30" class="formTitle"/>
                    </td>
                    <td class="subMainRight" rowspan="2" id="Preview" width="200" align="center">&nbsp;</td>
                </tr>
                <tr>
                    <td class="subMainLeft" width="80">位置描述：</td>
				    <td class="subMainRight">
					    <input name="A_Description" type="text" id="A_Description_0" size="30" maxlength="50" class="formTitle"/>
				    </td>
                </tr>
                <tr>
                    <td class="subMainLeft">图片：</td>
                    <td class="subMainRight" colspan="2">
                        <input name="A_Text" type="hidden" id="A_Text_0"/>
			            <iframe src="" id="upload" width="230" height="25" scrolling="No" frameborder="0"></iframe>
                    </td>
                </tr>
            </table>
			<div class="subMainFoot"><input name="submit" type="submit" class="formInput01" value="添加" />  <input type="button" class="formInput02" value="取消" onclick="HideWindow()"/></div>
            </form>
        </div>
    </div>
	<ul class="tools">
		<li class="add" p="39"><span><a href="javascript:void(0);" onclick="Show(0)">添加</a></span></li>
		<li class="save" p="40"><span><a href="javascript:void(0);" onclick="Save(0);return false;">保存</a></span></li>
		<li class="del" p="41"><span><a href="javascript:void(0);" onclick="Del(0);return false;">删除</a></span></li>
		<li class="search"><select onchange="location=this.value;">
			<option value="Admin_Ad_Text.aspx" p="42,43,44">文字广告</option>
			<option value="Admin_Ad_Pic.aspx" selected>图片广告</option>
			<option value="Admin_Ad_Code1.aspx" p="45,46,47">代码广告</option>
			</select></li>
	</ul>
    <form id="BatchSubmit" name="BatchSubmit" method="post" action="?act=edit" style="display: none">
    </form>
<asp:Repeater ID="Repeater" runat="server">
    <HeaderTemplate>
		<table width="100%" border="0"  cellpadding="0" cellspacing="0" class="tabBox">
            <tr class="tabTitleMain">
                <td width="35" class="selectAll">
                    <a href="javascript:void(0);" onclick="$('input[name=\'A_ID\'][id!=\'A_ID_0\']').attr('checked',!$(this).attr('checked'));$(this).attr('checked',!$(this).attr('checked'));">全选</a>
                </td>
                <td width="50">广告位</td>
                <td width="300">链接</td>
                <td>图片</td>
                <td>描述</td>
                <td width="100">操作</td>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr class="tabTextMain" id="From_<%#Eval("A_ID")%>" onmouseout="this.style.background='#FFFFFF';" onmouseover="this.style.background='#F4F7FA';">
            <td><input name="A_ID" id="A_ID_<%#Eval("A_ID")%>" type="checkbox" value="<%#Eval("A_ID")%>" /></td>
            <td><%#Eval("A_OrderId")%></td>
            <td><input id="A_Url_<%#Eval("A_ID")%>" name="A_Url_<%#Eval("A_ID")%>" type="text" value="<%#Eval("A_Url")%>" ovalue="<%#Eval("A_Url")%>" size="50" class="formTitle"/></td>
            <td>
			    <img src="<%=UpFolder%><%#Eval("A_Pic")%>" width="200" height="50" />
                <input id="A_RanNum_<%#Eval("A_ID")%>" name="A_RanNum_<%#Eval("A_ID")%>" type="hidden" value="<%#Eval("A_RanNum")%>" />
                <input id="A_Text_<%#Eval("A_ID")%>" name="A_Text_<%#Eval("A_ID")%>" type="hidden" value="<%#Eval("A_Pic")%>" />
            </td>
            <td>
                <input maxlength="50" id="A_Description_<%#Eval("A_ID")%>" name="A_Description_<%#Eval("A_ID")%>" type="text" value="<%#Eval("A_Description")%>" ovalue="<%#Eval("A_Description")%>" size="50" class="formTitle"/>
            </td>
            <td>
                <a href="javascript:void(0);" onclick="Save(<%#Eval("A_ID")%>);return false;" p="40">保存</a>
                <a href="javascript:void(0);" onclick="Show(<%#Eval("A_ID")%>);return false;" p="40">编辑</a>
                <a href="javascript:void(0);" onclick="Del(<%#Eval("A_ID")%>);return false;" p="41">删除</a>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
        <asp:Label ID="lblEmpty" Text="暂无" runat="server" Visible="<%#Boolean.Parse((Repeater.Items.Count = 0).ToString())%>"
            Width="100%" Style="text-align: center">     
        </asp:Label>
    </FooterTemplate>
</asp:Repeater>
<webdiyer:AspNetPager ID="TourExPage" runat="server" UrlPaging="true" ShowPageIndexBox="Never"
    PageIndexBoxType="DropDownList" TextBeforePageIndexBox=""
    PageSize="20" OnPageChanged="BindData" EnableTheming="true" FirstPageText="首页"
    LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" CssClass="page" 
        PagingButtonSpacing="" CurrentPageButtonClass="current" 
    CurrentPageButtonStyle="">
</webdiyer:AspNetPager>
<script type="text/javascript">
    <!--//
     var AP='<%=TourEx.BLL.GetSession("AdminPermissions") %>';
     if(AP!='')
     {
        if(AP.indexOf(',39,')==-1)$('*[p="39"]').remove();
        if(AP.indexOf(',40,')==-1)$('*[p="40"]').remove();
        if(AP.indexOf(',41,')==-1)$('*[p="41"]').remove();
        if(AP.indexOf(',42,')+AP.indexOf(',43,')+AP.indexOf(',44,')==-3)$('*[p="42,43,44"]').remove();
        if(AP.indexOf(',45,')+AP.indexOf(',46,')+AP.indexOf(',47,')==-3)$('*[p="45,46,47"]').remove();
     }
	var Timer,RanNum='<%=RanNum %>';
	function Show(ID){
		var Str;
		if(ID!=0)
		{
			$(".titleBar > span:first").text("编辑图片广告");
			$("#A_ID_0").val(ID);
			UpReturn("",$("#A_Text_"+ID).val());
			$('#A_Text_0').attr('name','A_Text_'+ID);
			$("#A_RanNum_0").val($("#A_RanNum_"+ID).val()).attr('name','A_RanNum_'+ID);
			$("#upload").attr("src","../sys/Upload.aspx?r="+$("#A_RanNum_"+ID).val());
			$("#A_Url_0").val($("#A_Url_"+ID).val()).attr('name','A_Url_'+ID);
			$("#A_Description_0").val($("#A_Description_"+ID).val()).attr('name','A_Description_'+ID);
			$('[name="submit"]').val('保存');
			$("#TEForm").attr("action","?act=edit");
		}else{
			$(".titleBar > span:first").text("添加图片广告");
			$("#A_Text_0").val("");
			$("#Preview").html("");
			$("#A_RanNum_0").val(RanNum).attr('name','A_RanNum');
			$("#upload").attr("src","../sys/Upload.aspx?r="+RanNum);
			$("#A_Url_0").val("").attr('name','A_Url');
			$("#A_Description_0").val("").attr('name','A_Description');
			$('[name="submit"]').val('添加');
			$("#TEForm").attr("action","?act=add");
		}
		ShowWindow();
	}
	function CheckForm()
	{
		if($('#A_Text_0').val()==""){alert("请上传图片！");return false;}
		if($('#A_Url_0').val()==""){alert("请填写链接！");return false;}
		return true;
	}
    function UpReturn(err,msg)
    {
	    var M=200;
	    var Pic='A_Text_0';
	    $("#"+Pic).val(msg);
	    if(err!=""){
		    alert(err);
	    }else if(msg!=''){
		    $("#Preview").html('<div style="position:relative;float:left"><img src="Images/cross.gif" style="position:absolute;cursor:pointer;right:0;top:0" onClick="$(this).parent().remove();$(\'#'+Pic+'\').val(\'\');"/><img src="<%=UpFolder%>'+msg+'" style="max-height:'+M+'px; max-width:'+M+'px"/></div>');
	    }
    }
    function Save(ID)
    {
        var A_IDs=ID==0?$('input[name="A_ID"][id!="A_ID_0"]'):$('#A_ID_'+ID);
        var A_T,A_O,A_D;
        $('#BatchSubmit').html('');
        for(var i=0;i<A_IDs.length;i++)
        {
            A_T =$('#A_Text_'+A_IDs[i].value).val();
            A_O=$('#A_Url_'+A_IDs[i].value).val();
		    A_D=$.trim($('#A_Description_'+A_IDs[i].value).val());
            if(A_O!=$('#A_Url_'+A_IDs[i].value).attr('ovalue') || A_D!= $.trim($('#A_Description_'+A_IDs[i].value).attr('ovalue')))
            {
	            A_IDs[i].checked=true;
	            $('#From_'+A_IDs[i].value).clone().prependTo("#BatchSubmit");
	            $('#A_Text_'+A_IDs[i].value,'#BatchSubmit').val(A_T);
			    $('#A_Description_'+A_IDs[i].value,'#BatchSubmit').val(A_D);
	            $('#A_Url_'+A_IDs[i].value,'#BatchSubmit').val(A_O);
            }
        }
        if($('#BatchSubmit').html()==''){alert('数据没有改动过，无需保存！');return;}
        $('input[name="A_ID"]','#BatchSubmit').attr('checked',true);
        $('#BatchSubmit').submit();
    }
    function Add()
    {
        if($("Title_0").val()=='')
        {
            alert('请填写广告内容！');return false;
        }
        if($("Url_0").val()=='')
        {
            alert('请填写广告链接！');return false;
        }
        return true;
    }
    function Del(ID)
    {
        var Url='?Act=del&';
        var IDs;
        if(ID>0)
        {
            Url +='A_ID='+ID;
        }else{
            IDs = $("input[name='A_ID'][id!='A_ID_0']").serialize().replace(/&A_ID=/g,',');
            if(IDs==''){alert('请选择您要删除的帮广告！');return;}
            Url +=IDs;
        }
        if(confirm('您确定删除吗！')){location=Url;}
    }
    //-->
</script>

</body>
</html>
