<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理後臺</title>
<meta name="keywords" content="管理後臺" />
<meta name="description" content="管理後臺" />
<script src="/jquery/jquery-1.8.2.min.js"></script>
</head>

<body>
	<div class="wrapper">
    	<?# header ?>
    	<div class="wrap">
        	<?# sidePage ?>
            <div class="contentMain">
            	<h3>插入關鍵字列表</h3>
                <div class="article">
                    <form id="form1" name="form1" action="autokeywordAdd.php" method="post">
                    	<fieldset style="width: 100%;">
                        	<input type="hidden" id="action1" name="action" value="key" />
                            <p style="width: 900px; margin: 15px auto;">
                                新增關鍵字： <input type="text" id="KeywordTitle" name="KeywordTitle" />
                                <input type="button" id="btnAddK" name="btnAddK" value="新增" />
                            </p>
                        </fieldset>
                    </form>
                    <form id="form2" name="form2" action="autokeywordAdd.php" method="post">
                        <fieldset style="width: 100%;">
                        	<input type="hidden" id="action2" name="action" value="link" />
                            <p style="width: 900px; margin: 15px auto;">
                                關鍵字： <select id="KeywordID" name="KeywordID">
                                <option value="0">請選擇關鍵字</option>
                                <php:repeater id="listK">
                                    <template>
                                        <option value="<?# KeywordID ?>"><?# KeywordTitle ?></option>
                                    </template>
                                </php:repeater>
                                </select>&nbsp;&nbsp;&nbsp;&nbsp;
                                新增超連結： <input type="text" id="LinkURL" name="LinkURL" />
                                <input type="button" id="btnAddL" name="btnAddL" value="新增" />
                            </p>
                        </fieldset>
                    </form>
                    <div class="titleTyp">
                        <div class="visible">重要</div>
                        <div class="userName" style="width: 600px;">關鍵字/超連結</div>
                        <div class="operating">操作</div>
                    </div>
                    <div class="listTyp">
                        <div class="visible"><input type="radio" name="Important" value="0" /></div>
                        <div class="userName" style="width: 600px;">沒有重要關鍵字</div>
                    </div>
                    <php:repeater id="listL">
                        <template>
                            <div class="listTyp">
                                <div class="visible"><?# td1 ?></div>
                                <div class="userName" style="width: 600px;"><?# td2 ?></div>
                                <div class="operating"><?# td3 ?></div>
                            </div>
                        </template>
                    </php:repeater>
                    <p>
                    	<input type="button" id="btnOK" value="變更重要關鍵字" />
                    </p>
                </div>
            </div>
        </div>
        <?# footer ?>
    </div>
<script>
<!--
	$(function(){
		$('input:radio[name="Important"][value="<?# ImportantID ?>"]').attr('checked',true);

		$('#btnAddK').click(function(){
			if($('#KeywordTitle').val() == ''){
				alert('請輸入要新增的關鍵字!');
				$('#KeywordTitle').focus();
				return false;
			}
			$('#form1').submit();
		});
		$('#btnAddL').click(function(){
			if($('#KeywordID').val() == '0' || $('#KeywordID').val() == ''){
				alert('請先選擇關鍵字!');
				$('#KeywordID').focus();
				return false;
			}
			if($('#LinkURL').val() == ''){
				alert('請輸入要新增的超連結!');
				$('#LinkURL').focus();
				return false;
			}
			$('#form2').submit();
		});
		$('#btnOK').click(function(){
			if($('input:radio[name="Important"]:checked').size() == 0){
				alert('請先選取重要關鍵字!');
				return false;
			}else{
				var id = $('input:radio[name="Important"]:checked').eq(0).val();
				$.ajax({
					url: 'ajax/autokeyword.php',
					async: false,
					type: 'POST',
					data: {'do':'imp','id':id},
					dataType: 'text',
					success: function(Msg){
						if(Msg == "1"){
							alert('重要關鍵字已經變更!');
						}else{
							alert('重要關鍵字變更失敗!');
							location.href = location.href;
						}
					},
					error: function(){
						alert('系統異常!請重新整理頁面再試一次!');
					}
				});
			}
		});
		$('a[data-action="delKey"]').click(function(){
			if(!confirm('刪除資料後將無法恢復!是否確定要刪除關鍵字資料?')){
				return false;
			}else{
				$.ajax({
					url: 'ajax/autokeyword.php',
					async: false,
					type: 'POST',
					data: {'do':'delk','id':$(this).data('id')},
					dataType: 'text',
					context: $(this).parent('div').parent('div'),
					success: function(Msg){
						if(Msg == "1"){
							$(this).remove();
						}else{
							alert('刪除關鍵字失敗!');
						}
					},
					error: function(){
						alert('系統異常!請重新整理頁面再試一次!');
					}
				});
			}
		});
		$('a[data-action="delLink"]').click(function(){
			if(!confirm('刪除資料後將無法恢復!是否確定要刪除超連結資料?')){
				return false;
			}else{
				$.ajax({
					url: 'ajax/autokeyword.php',
					async: false,
					type: 'POST',
					data: {'do':'dell','id':$(this).data('id')},
					dataType: 'text',
					context: $(this).parent('div').parent('div'),
					success: function(Msg){
						if(Msg == "1"){
							$(this).remove();
						}else{
							alert('刪除超連結失敗!');
						}
					},
					error: function(){
						alert('系統異常!請重新整理頁面再試一次!');
					}
				});
			}
		});
	});
//-->
</script>
</body>
</html>