<!--<?php
if(!defined('AJAX')){
	include_once PrintEot('left');
	include_once PrintApp('admin_header');
}
print<<<EOT
-->
<!--
EOT;
if ($type == 'add' || $type == 'edit') { 
$title = ($type == 'add') ? '勛章添加' : '勛章編輯';
$url = ($type == 'add') ? "$basename&type=adddo" : "$basename&type=editdo";
print<<<EOT
-->
<form action="$url" method="post">
<input name="id" type="hidden" value="$medal[medal_id]" />
  <h2 class="h1">$title</h2>
  <div class="admin_table mb10">
    <table width="100%" cellspacing="0" cellpadding="0">
      <tr class="tr1 vt">
        <td class="td1">勛章名稱</td>
        <td class="td2"><input name="name" class="input input_wa" value="$medal[name]" maxlength="200"></td>
        <td class="td2">&nbsp;</td>
      </tr>
      <tr class="tr1 vt">
        <td class="td1">勛章圖片</td>
        <td class="td2"><a href="javascript:void(0)"  onclick="sendmsg('$basename&type=img','',this.id,initMedal);" id="imgadd"/>[選圖]</a>
<!--
EOT;
if ($type == 'edit') { 
print<<<EOT
-->
<input name="image" type="hidden" id="image" value="$medal[image]" />
<div id="imageShow"><img src="$medal[bigimage]" width="80" height="80" class="mr10" /><img src="$medal[smallimage]" width="24" height="24"  /></div>
<!--
EOT;
} else {
print<<<EOT
-->		
<input name="image" type="hidden" id="image" value="" />
<div id="imageShow"><img src="images/blank.gif" style="background:url(images/nopreview.png);" width="80" height="80" class="mr10" /><img src="images/blank.gif" style="background:url(images/nopreview.png);" width="24" height="24" class="mr10" /></div>
<!--
EOT;
}
print<<<EOT
-->
        </td>
        <td class="td2">
					<p>圖片規範︰大圖尺寸為120 X 120,小圖尺寸為24 X 24，圖片格式為.gif或者.png</p>
					<p>存放位置︰大圖位置images/medal/big目錄，小圖位置images/medal/small目錄</p>
				</td>
      </tr>
      <tr class="tr1 vt">
        <td class="td1">勛章描述</td>
        <td class="td2"><textarea name="descrip"class="textarea">$medal[descrip]</textarea></td>
        <td class="td2">&nbsp;</td>
      </tr>
      <tr class="tr1 vt">
        <td class="td1">發放機制</td>
        <td class="td2">
					<ul class="list_A list_80">
<!--
EOT;
if ($type == 'edit') { 
$typeArr[$medal[type]] = 'checked="checked"';
if ($type == 'edit') $enable = 'disabled="disabled"';  
print<<<EOT
-->
					<li><input name="tp" type="radio" value="1" $enable checked="checked" $typeArr[1] onclick="changeType();" >自動勛章</li><li><input name="tp" type="radio" value="2" $enable $typeArr[2] onclick="changeType();" >
<!--
EOT;
} else { 
print<<<EOT
-->
					<li><input name="tp" type="radio" value="1" checked="checked" onclick="changeType();" >自動勛章</li><li><input name="tp" type="radio" value="2" onclick="changeType();" >
<!--
EOT;
}
print<<<EOT
-->
          手動勛章</li></ul></td>
        <td class="td2">勛章添加成功後，此類型不可修改。自動勛章是指滿足設定條件後系統自動發放勛章；手動勛章指用戶申請或管理員手動頒發勛章。</td>
      </tr>
      <tr class="tr1 vt" id="medallimit" style="display:none;">
        <td class="td1">勛章有效期</td>
        <td class="td2"><input name="day" value="$medal[confine]" type="text" class="input input_wa mr5" />天</td>
        <td class="td2">&nbsp;</td>
      </tr>
      <tr class="tr1 vt">
        <td class="td1">可領取用戶組</td>
        <td class="td2">
					<label for="allgroup"><input name="allgroup" type="checkbox" value="1" id="allgroup" onclick="checkAllGroup()">全選</label>
          $creategroup </td>
        <td class="td2">全選或者全部不選擇，則所有用戶都可以申請</td>
      </tr>
      <tr class="tr1 vt" id="medalcondition">
        <td class="td1">勛章自動頒發條件</td>
<!--
EOT;
$enable = '';
if ($type == 'edit') $enable = 'disabled="disabled"';  
print<<<EOT
-->
        <td class="td2"><p class="mb10"><select name="associate" $enable onchange="associateList()" id="associate" >
<!--
EOT;
foreach ($medalCondition as $k => $v) { 
	$selected = '';
	if ($type == 'edit' && $k == $medal['associate']) $selected = 'selected';  
print<<<EOT
-->
            <option value="{$k}" $selected>{$v}</option>
<!--
EOT;
} print<<<EOT
-->
          </select><span style=" font-family:Simsun;margin:0 5px 0 8px; font-weight:700;">&gt;&nbsp;= </span><input name="confine" type="text" value="$medal[confine]" class="input input_wc" /></p>
					<div id="associateShow"></div>
          </td>
        <td class="td2">當用戶滿足此條件時，勛章自動發放<!-- <div style="margin-top:20px;" id="associateShowMsg">獲得更高等級勛章後，會自動替換較低等級勛章。</div> -->
		</td>
      </tr>
    </table>
  </div>
  <div class="mb10 tac"><span class="btn"><span><button type="submit">提 交</button></span></span></div>
</form>

<script type="text/javascript">
	
	//會員組全部選中
	function checkAllGroup() {
		var allgroup = document.getElementById('allgroup');
		var result = (allgroup.checked == true) ? true : false;
		var e = document.getElementsByName('allow_group[]');
		var len  = e.length;
		for (var i=0; i<len; i++) {
			e[i].checked = result;
		}
	}
	
	//切換發放機制
	function changeType() {
		var typeVal = document.getElementsByName('tp');
		var len = typeVal.length;
		var result;
		for (var i=0; i<len; i++) {
			if (typeVal[i].checked == true) {
				result = typeVal[i].value;
				break;
			}
		}
		var medallimit = document.getElementById('medallimit');
		var medalcondition = document.getElementById('medalcondition');
		if (result == 1) {
			medallimit.style.display = "none";
			medalcondition.style.display = "";
		} else {
			medallimit.style.display = "";
			medalcondition.style.display = "none";
		}
	}
	
	var medallist = eval($openMedal);
	//自動頒發獎章的擴展列表
	function associateList() {
		var associateVal = document.getElementById("associate").value;
		var len = medallist.length;
		var result = '<div style="width:334px;text-align:center;"><div style="border:#CCCCCC 1px solid;background-color:#e4e4e4;" class="s3">已有同種勛章列表 </div><div style="width:100%;"><div style=" background-color:#f7f7f7;border-left:#CCCCCC 1px solid; width:50px; border-bottom:#CCCCCC 1px solid; border-right:#CCCCCC 1px solid; width:50px; float:left;">等級</div><div style="background-color:#F5F5F5;border-bottom:#CCCCCC 1px solid; border-right:#CCCCCC 1px solid; width:80px; float:left;">>=數值</div><div style="background-color:#F5F5F5;border-right:#CCCCCC 1px solid;border-bottom:#CCCCCC 1px solid; width:200px; float:left;">名稱</div></div>';
		var ii = 1;
		for (var i=0; i<len; i++) {
			if (associateVal == medallist[i].associate) {
				result += '<div style="width:100%;background:#fff;"><div style="border:#CCCCCC 1px solid; width:80px;border-top:0 none; width:50px; float:left;">'+ii+'</div><div style="border-bottom:#CCCCCC 1px solid; border-right:#CCCCCC 1px solid; width:80px; float:left;">'+medallist[i].confine+'</div><div style="border-right:#CCCCCC 1px solid;border-bottom:#CCCCCC 1px solid; width:200px; float:left;">'+medallist[i].name+'</div></div>';
			ii++;
			}
		}
		if (ii == 1) { 
			result = '';
		} else {
			result += '</div>';
		}
		document.getElementById("associateShow").innerHTML = result;
		//document.getElementById("associateShowMsg").style.display = '';
		
	}
	associateList(); //頁面加載就執行
	
		//勛章圖片選擇
	function toggleChecked(obj){
		var checked=obj.checked;
		obj.checked=obj.checked?"":"checked";
	}
	function contains(a, b){
		//元素a是否包含元素B
        if (document.compareDocumentPosition) {
            return !!(a.compareDocumentPosition(b) & 16);
        }
        else {
            return a !== b && (a.contains ? a.contains(b) : true);
        }
    }
	function initMedal(){
		var box_container=getObj("box_container");
		var medalIconList=getObj("medalIconList").getElementsByTagName("li");
		for(var i=0,len=medalIconList.length;i<len;i++){
			(function(item,i){
				item.onclick=function(){
					toggleClass(this,"current");
					var val=this.getAttribute("data-val");
					getObj("image").value = val;
					getObj("imageShow").innerHTML = "<img src='$imgpath/medal/big/"+val+"' width=\"80\" height=\"80\" class=\"mr10\"><img src='$imgpath/medal/small/"+val+"' width=\"24\" height=\"24\">";
					read&&read.close();
				}
			})(medalIconList[i],i)
		}
		document.onmousedown=function(e){
			var ele = window.event?window.event.srcElement:e.target;
			if(!contains(box_container,ele)){
				read&&read.close();
			}
		}
	}
</script>
<!--
EOT;
if ($type == 'edit') { 
print<<<EOT
-->
<script type="text/javascript">changeType();</script>
<!--
EOT;
} print<<<EOT
-->

<!--
EOT;
} elseif ($type == 'img') { print<<<EOT
-->
<h2 class="h1" style="cursor:move" onmousedown="read.move(event);">選圖</h2>
<div class="admin_table mb10" style="padding:10px;">
  <ul id="medalIconList" class="medal_icon_list">
<!--
EOT;
foreach ($medalImg as $k => $v) { print<<<EOT
--> 
    <li data-val="{$v}"><img src="$imgpath/medal/big/{$v}" width="80" height="80" /></li>
<!--
EOT;
} print<<<EOT
-->
  </ul>
</div>
<div class="tac mb10"></div>
<!--
EOT;
} print<<<EOT
-->
<!--
EOT;
if(!defined('AJAX')){
	include_once PrintEot('adminbottom');
}
?>-->
