<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset={sys_charset}">
<title>channel select</title>
<link href="{adminStylePath}style/common.css" rel="stylesheet" type="text/css">
<script language="javascript" src="{adminStylePath}js/common.js"></script>
<style>
BODY {
	margin: 2px;
}
</style>

<script>
var multiselect = 'multiselect';
var act = '{act}';
var form_input = '{form_input}';
var selectChannelIds;

function init()
{
	QueryString_Parse();
	act = QueryString("act");
	form_input = QueryString("form_input");
	if(act == multiselect) { 
		_fillMultiSelectCheckbox();
        document.getElementById('selectAllChannel').disabled = false;
	} else {
        _fillSingleSelectCheckbox();
    }
    
}

function selectAllChannel()
{
    if(act == multiselect) {
        selectAll('selectAllChannel', 'channel_ids');
        if(document.getElementById('selectAllChannel').checked == true) {
            if(window.parent.document.getElementById(form_input)) {
                var strlist = getInputList("channel_ids");
                if(strlist !='') {
                    selectChannelIds = strlist.split(",");
                }
                window.parent.document.getElementById(form_input).value = strlist;
            }
        } else {
            clearSelect();
        }
    }
}

function selectChannel(cid,ctxt) 
{ 
	if(act == multiselect) {
        _updateSelect(cid);
	} else {
        _submitOne(cid,ctxt);
    }
}

function closeWin()
{
	parent.$('#modalWindow').jqmHide();
}

function clearSelect()
{
	if(act == multiselect) {
		window.parent.document.getElementById(form_input).value = '';
        clearInputList('channel_ids');
        selectChannelIds.clear();
	} else {
		if(window.parent.document.getElementById(form_input) && window.parent.document.getElementById(form_input+'_show')) {
			window.parent.document.getElementById(form_input).value='';
			window.parent.document.getElementById(form_input+'_show').value = '选择频道';
		}
	}
}

function _submitOne(cid,ctxt)
{
    if(window.parent.document.getElementById(form_input) && window.parent.document.getElementById(form_input+'_show')) {
        window.parent.document.getElementById(form_input).value=cid;
        window.parent.document.getElementById(form_input+'_show').value = ctxt;
    }
    closeWin();
}

function _updateSelect(cid)
{
    if(document.getElementById('channel_ids_'+cid).checked == true) {
        selectChannelIds.push(cid);
    } else {
        selectChannelIds.removeByValue(cid);
    }
    if(window.parent.document.getElementById(form_input)) {
        var strlist = selectChannelIds.join(",");
        window.parent.document.getElementById(form_input).value = strlist;
    }
}

function _fillCheckbox()
{
    selectChannelIds = new Array();
    var strlist = window.parent.document.getElementById(form_input).value;
    if(strlist !='') {
        selectChannelIds = strlist.split(",");
        for(i=0; i<selectChannelIds.length; i++) {
            if(document.getElementById("channel_ids_" + selectChannelIds[i])) {
                document.getElementById("channel_ids_" + selectChannelIds[i]).checked = true;
            }
        }
    }
    
    //set selectAllChannel checkbox
    var channelNum = getTagNumByName('input', 'channel_ids');
    if(channelNum > 0 && selectChannelIds.length == channelNum) {
        document.getElementById('selectAllChannel').checked = true;
    } else {
        document.getElementById('selectAllChannel').checked = false;
    }
}

function _fillMultiSelectCheckbox()
{
    selectChannelIds = new Array();
    var strlist = window.parent.document.getElementById(form_input).value;
    if(strlist !='') {
        selectChannelIds = strlist.split(",");
        for(i=0; i<selectChannelIds.length; i++) {
            if(document.getElementById("channel_ids_" + selectChannelIds[i])) {
                document.getElementById("channel_ids_" + selectChannelIds[i]).checked = true;
            }
        }
    }
    
    //set selectAllChannel checkbox
    var channelNum = getTagNumByName('input', 'channel_ids');
    if(channelNum > 0 && selectChannelIds.length == channelNum) {
        document.getElementById('selectAllChannel').checked = true;
    } else {
        document.getElementById('selectAllChannel').checked = false;
    }
}

function _fillSingleSelectCheckbox()
{
    if(window.parent.document.getElementById(form_input)) {
        var cid = window.parent.document.getElementById(form_input).value;
        if(cid != '') {
            if (document.getElementById("channel_ids_" + cid)) {
                document.getElementById("channel_ids_" + cid).checked = true;
            } else {
                document.getElementById("channel_ids_" + cid).checked = false;
            }
        }
    }
}


</script>
</head>

<body onload="init()" leftmargin="0" topmargin="0">
<div class="select_window_div">
<table class="list_tb" cellpadding="0" cellspacing="0">
<tr class="list_title_tr_bg">
<td width="30" class="list_title_td">&nbsp;</td>
<td width="50" class="list_title_td">编号</td>
<td class="list_title_td">分类名</td>
<td width="60" class="list_title_td">&nbsp;<input type="checkbox" name="selectAllChannel" id="selectAllChannel" value="" onclick="selectAllChannel()" disabled></td>
</tr>
<!-- BEGIN ListChannel -->
<tr  {ListChannel.tr_id} class="{ListChannel.tr_css}" {ListChannel.tr_onmouse} {ListChannel.tr_style}>
<td class="{ListChannel.td_css}" {ListChannel.td_onmouse}>&nbsp;{ListChannel.show_arrow}</td>
<td class="{ListChannel.td_css}" {ListChannel.td_onmouse}>{ListChannel.num}</td>
<td title="ID={ListChannel.id}" class="{ListChannel.td_css}" {ListChannel.td_onmouse}>{ListChannel.title}</td>
<td class="{ListChannel.td_css}" {ListChannel.td_onmouse}>&nbsp;<input type="checkbox" name="channel_ids" id="channel_ids_{ListChannel.id}" value="{ListChannel.id}" onclick="selectChannel('{ListChannel.id}','{ListChannel.title_info}')"; style="display:{ListChannel.is_display}" {ListChannel.is_disabled}></td>
</tr>
<!-- END ListChannel -->
</table>               
</div>
</body>
</html>
