// 创建 phprpc 客户端对象 rpc
phprpc_client.create('rpc');

var class_sub  = []; // 用于缓存已加载的城市数据


/* 
 * 清除 select 中的选项，该方法可复用
 *
 * so: 要清除选项的 select 对象
 *
 */
function clear_select(so) {
    for (var i = so.options.length - 1; i > -1; i--) {
        // 有些浏览器不支持 options 属性的 remove 方法，
        // 但支持 DOM 的 removeChild 方法（比如：Konqueror）
        if (so.options.remove) {
            so.options.remove(i);
        }
        else {
            so.removeChild(so.options[i]);
        }
    }
}

/*
 * 设置 select 中的选项，该方法可复用
 *
 * so: 要设置选项的 select 对象
 *  d: 选项数据数组
 * vf: 选项值所对应的数组中的字段名
 * tf: 选项文本所对应的数组中的字段名
 */
function set_select(so, d, vf, tf) {
	if(tf!=1){
		var opt = document.createElement('option'); 
        opt.text = '--请选择栏目--';
        opt.value = '';        
        if (so.options.add) {
            //so.options.add(opt);
        }else{
		    //so.appendChild(opt);	
		}
	}	
	
    for (var i = 0, n = d.length; i < n; i++) {
        var opt = document.createElement('option');
        opt.text = d[i][tf];
        opt.value = d[i][vf];
		//alert(opt.text);
        // 有些浏览器不支持 options 属性的 add 方法，
        // 但支持 DOM 的 appendChild 方法（比如：Konqueror）
        if (so.options.add) {
            so.options.add(opt);
        }
        else {
            so.appendChild(opt);
        }
    }
}

// 设置class_main的下拉菜单
function set_province_select(d) {
    var so = document.getElementById('search_sortid');
    set_select(so, d, 'sort_id', 'sort_name');
    
}


// 定义当 rpc 客户端初始化（use_service）完毕后执行的内容
rpc.onready = function () {
    // 调用获取class_main内容的远程过程，并设置回调函数为 set_province_select
    rpc.select_msort(set_province_select);
}


function ck_searhform(){
	if(document.form1.search_v.value==''){
		alert('请输入查询关键字');
		document.form1.search_v.focus();
		return false;
	}
	if(document.form1.search_sortid.value==''){
		alert('请选择一个栏目');
		document.form1.search_sortid.focus();
		return false;
	}
}