<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset={sys_charset}">
<title>template select</title>
<link href="{adminStylePath}style/common.css" rel="stylesheet" type="text/css">
<script language="javascript" src="{adminStylePath}js/common.js"></script>
<script language="javascript" src="{adminStylePath}js/ajax_call.js"></script>
<script>
var act = null;
var tplTxt = '';
var btn_value = "选择";
function getTemplateIdAjax(template_id,layout_type)
{

	var tb_layout = document.getElementById("tb_layout");
	for (var j= tb_layout.rows.length - 1; j>=0 ; j--)
	{
		tb_layout.deleteRow(j);	
	}

	if(template_id=='') return;
	//alert(template_id);
	document.getElementById('progress_layout').innerHTML = "<img src='{adminStylePath}images/progressbar_green.gif'>";
	document.getElementById('td_status').innerHTML = "<img src='{adminStylePath}images/indicator_mozilla.gif'>";
	XMLHttp.sendReq('GET', 'template_layout_list.ajax.php?template_id='+template_id+'&type='+layout_type, '', returnAjax); 
	
	template_id='';
}

function returnAjax(obj) 
{ 
	if(obj!=null)
	{
		var resultObj = new Array(); 
		eval(obj.responseText); 
		if(resultObj.errorCode>0)
		{
			fillDate(resultObj.dataArr);
		}
		else
		{
			document.getElementById('progress_layout').innerHTML = "";
			document.getElementById('td_status').innerHTML = "";
		}
		resultObj.dataArr.clear();
	}
	
}

function fillDate(dataArr)
{
	var tb_layout = document.getElementById("tb_layout");
	for (var i=0;i<dataArr.length;i++)
	{
	  var rowObj = tb_layout.insertRow(i);
		rowObj.className = "tr_line";	
	  var cellObj0 = rowObj.insertCell(0);
	  cellObj0.noWrap = true;
	  cellObj0.className = "td_line";	 
	  cellObj0.title = dataArr[i].layout_code;	 
	  //cellObj0.innerHTML = "<a href=\"javascript:openerSelect('"+dataArr[i].id+"','"+dataArr[i].title+"')\">"+dataArr[i].title+"</a>"; 
	  cellObj0.innerHTML = dataArr[i].title; 
	 
	  var cellObj1 = rowObj.insertCell(1);
	  cellObj1.noWrap = true;	  
	  cellObj1.className = "td_line";
	  cellObj1.innerHTML = ""+dataArr[i].intro+"&nbsp;"; 
	  
	  var cellObj2 = rowObj.insertCell(2);
	  cellObj2.noWrap = true;	  
	  cellObj2.className = "td_line";
	  //cellObj2.innerHTML = "<input type='button' name='btn_add' value='插入' onclick=\"window.opener.referencebrowser_setReference('layout_id','"+dataArr[i].id+"','"+dataArr[i].title+"',1)\"><input type='button' name='btn_preview' value='预览' onclick=\"winOpen('template_view.php?selectid="+dataArr[i].template_id+"&layout_id="+dataArr[i].id+"')\">"; 
	  cellObj2.innerHTML = "<input type='button' name='btn_add' value='"+btn_value+"' onclick=\"returnLayoutValue('"+dataArr[i].id+"','"+dataArr[i].title+"')\"><input type='button' name='btn_preview' value='预览' onclick=\"winOpen('template_view.php?selectid="+dataArr[i].template_id+"&layout_id="+dataArr[i].id+"')\">"; 
	}
	document.getElementById('progress_layout').innerHTML = "";
	document.getElementById('td_status').innerHTML = "";
}

function openerSelect(tmpValue,tmpTxt)
{	
	if(confirm("你确认选择\""+tmpTxt+"\"吗？"))
	{    			
		if(window.opener.document.getElementById('layout_id') && window.opener.document.getElementById('layout_id_show'))
		{
			document.getElementById('td_status').innerHTML = "成功选择["+tmpTxt+"]! <br />如果没有自动关闭当前窗口,请手动关闭.";
			window.opener.document.getElementById('layout_id').value=tmpValue;
			window.opener.document.getElementById('layout_id_show').value = tmpTxt;
			window.close();
		}
	}	
}	

function returnLayoutValue(LayoutValue,LayoutTxt)
{
	if(act=="insert")
	{
		if(tplTxt) LayoutTxt = tplTxt+'->'+LayoutTxt;
		window.opener.referencebrowser_setReference('layout_id',LayoutValue,LayoutTxt,1);
	}
	else openerSelect(LayoutValue,LayoutTxt);
}

function clearSelect()
{
	window.opener.document.getElementById('layout_id').value='';
	window.opener.document.getElementById('layout_id_show').value ='选择板块位置';
	window.close();
}

function closeWin()
{
	window.close();
}

function selectTemplateId(template_id,layout_type,template_title,isAjax)
{
	tplTxt = template_title;
	if(isAjax) getTemplateIdAjax(template_id,layout_type);
	else showTable(template_id);
}

function showTable(template_id)
{
	
	var tagO = document.getElementsByTagName('table');

	for (var ti=0;ti<tagO.length;ti++)
  {    
    if(tagO[ti].getAttribute("name") == "tbLayout")
    {
		  tagO[ti].style.display="none";
		}
  }
  
  document.getElementById('tbLayout_'+template_id).style.display="";

}

function init()
{
	QueryString_Parse();
	act = QueryString("act");
	if(act=="insert")
	{
		btn_value = "插入";
	}
	else
	{
		document.getElementById('span_clear').style.display="";
	}
}

</script>
<style>
BODY {
	FONT-SIZE: 9pt; FONT-FAMILY: "宋体";
	background-color: #FFFFFF;
	margin-left: 5px;
	margin-top: 5px;
	margin-right: 5px;
	margin-bottom: 5px;

}
</style>
</head>

<body onload="init()">
<table width="100%" height="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td width="30%" valign="top">
						<div class="line_space"><img src="{adminStylePath}images/blank.gif"></div>
						<table class="list_tb" cellpadding="0" cellspacing="0">
						<!-- BEGIN ListTemplate -->
						<tr>
						<td width="20" class="td_menu" {ListTemplate.td_onmouse}>{ListTemplate.num}</td>
						<td title="{ListTemplate.filename} [{ListTemplate.program_filename}]" onclick="selectTemplateId('{ListTemplate.id}','{type}','{ListTemplate.title}',{is_ajax})" class="td_menu" >
							{ListTemplate.title}
						</td>	
						</tr>
						<!-- END ListTemplate -->
						</table>
					</td>
					<td width="2%">&nbsp;</td>
					<td width="68%" valign="top" id="td_layout">
						<div id="progress_layout"></div>
						<table id="tb_layout" width="100%" cellpadding="0" cellspacing="0">
                        </table>
            
                        <!-- BEGIN ListTemplate -->
                        <table name="tbLayout" class="list_tb" cellpadding="0" cellspacing="0" id="tbLayout_{ListTemplate.id}" style="display:none">
                            <!-- BEGIN ListLayoutInfo -->
                            <tr class="tr_line">
                            <td class="td_line" title="{ListTemplate.ListLayoutInfo.layout_code}">{ListTemplate.ListLayoutInfo.title}</td>
                            <td class="td_line" >{ListTemplate.ListLayoutInfo.intro}&nbsp;</td>
                            <td class="td_line" >
                                <input type='button' name='btn_add' value='{btn_value}' onclick="returnLayoutValue('{ListTemplate.ListLayoutInfo.id}','{ListTemplate.ListLayoutInfo.title}')">
                                <input type='button' name='btn_preview' value='预览' onclick="winOpen('template_view.php?selectid={{ListTemplate.template_id}}&layout_id={ListTemplate.ListLayoutInfo.id}')">
                            </td>	
                            </tr>
                            <!-- END ListLayoutInfo -->
						</table>
						<!-- END ListTemplate -->
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td valign="bottom" height="26">
			<table class="select_window_bottom" width="100%" cellpadding="0" cellspacing="0">
				<tr>
				<td width="300"  id="td_status" class="select_window_bottom_left">&nbsp;</td>
				<td align="right"><span id="span_clear" style="display:none"><a href="javascript:clearSelect()">[---清空---]</a></span>&nbsp;&nbsp;<a href="javascript:closeWin()">[---关闭---]</a>&nbsp;&nbsp;</td>
				</tr>
			</table> 
		</td>
	</tr>
</table>
</body>
</html>