function GetObj(obj){
	if(document.getElementById){
		return document.getElementById(obj);
	}
	else{
		return document.all[obj];
	}
}

/**
 * 用于判断参数是否真的为空 (而不是 false);
 *@author  xs 
 */
function isNull(a){
	if(!a && typeof a == 'boolean') return false;
	return (typeof a == 'undefined' || a == '' || a == null);
}

String.prototype.inc=function(s){return this.indexOf(s)>-1?true:false}
String.prototype.lenB=function(){return this.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**").length}
String.prototype.leftB=function(len, els){
	if (isNull(els) || this.lenB() <= len){
		els = "";
	}
	len -= els.length;
	var s=this.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**");
	return this.slice(0,s.slice(0,len).replace(/\*\*/g," ").replace(/\*/g,"").length) + els;
}


//复制连接
function copyToClipBoard(url){
	var clipBoardContent=''; 
	clipBoardContent+=url;
	window.clipboardData.setData("Text",clipBoardContent);
	alert("您已经复制了连接地址");
	return false;
}

//加入收藏
function bookmarkit(){
    if (window.external != null){
	    window.external.addFavorite(window.location.href,'中华论坛')
    }
}

//设置图片大小
var flag=false; 
function DrawImage(ImgD){ 
var image=new Image(); 
var iwidth = 630;  //定义允许图片宽度 
var iheight = 630;  //定义允许图片高度 
image.src=ImgD.src;
if(image.width>0 && image.height>0){ 
	flag=true; 
	if(image.width/image.height>= iwidth/iheight){ 
		if(image.width>iwidth){   
			ImgD.width=iwidth; 
			ImgD.height=(image.height*iwidth)/image.width; 
		}else{ 
			ImgD.width=image.width;   
			ImgD.height=image.height; 
		} 
	} 
	else{ 
		if(image.height>iheight){   
			ImgD.height=iheight; 
			ImgD.width=(image.width*iheight)/image.height;   
		}else{ 
			ImgD.width=image.width;   
			ImgD.height=image.height; 
		} 
	}
} 
}


function hello(){
	var now = new Date();
	if( now.getHours() >= 6 && now.getHours() < 9 ){
		return "早上好，";
	}
	else if( now.getHours() >= 9 && now.getHours() < 11){
		return "上午好，";
	}
	else if( now.getHours() >= 11 && now.getHours() < 14 ){
		return "中午好，";
	}
	else if( now.getHours() >= 14 && now.getHours() < 19 ){
		return "下午好，";
	}
	else{
		return "晚上好，";
	}
}


function get_hello(userName)
{
	hello = hello();

	if('' == userName)
	{
		len = hello.length;
		new_hello = hello.substr(0,len-1);
		return new_hello;
	}
	else
	{
		return hello;
	}
}

//用户登陆验证
function btnlogin_check(){
    if(GetObj("loginname").value == ""){
        alert("请输入登陆名");return false;
    }
    
    if(GetObj("passwd").value == ""){
        alert("请输入登陆密码");return false;
    }
    GetObj("login").click();
}

//舌签功能
function ShowSub(id_num,num){
	for(var i = 0;i <= 10;i++){
		if(GetObj("S_Menu_" + id_num + i)){GetObj("S_Menu_" + id_num + i).className = '';}
		if(GetObj("S_Cont_" + id_num + i)){GetObj("S_Cont_" + id_num + i).style.display = 'none';}
	}
	if(GetObj("S_Menu_" + id_num + num)){GetObj("S_Menu_" + id_num + num).className = 'onselected';}
	if(GetObj("S_Cont_" + id_num + num)){GetObj("S_Cont_" + id_num + num).style.display = 'block';}
}


//论坛分类
function hide_menu(id){
    if (GetObj("menu_"+id).className == "dt_off")
    {
        GetObj("menu_"+id).className = "dt_on";
	    GetObj("g_menu_"+id).className = "mylist_btn_on";
	    Show_menu(id);
	    GetObj("menu_list_"+id).style.display = "";
	}else{
        GetObj("menu_"+id).className = "dt_off";
	    GetObj("g_menu_"+id).className = "mylist_btn_off";
	    GetObj("menu_list_"+id).style.display = "none";
	}
}

function open_sub(obj, id){
    if(obj.className == "sub_on"){
        obj.className = "sub_off"
        GetObj("sub_"+id).style.display = "none";
    }else{
        obj.className = "sub_on"
        GetObj("sub_"+id).style.display = "";
    }
}

function set_list(id){
	var str='';
	if (bbsList.list.length>0)
	{
	    str += '<dl class="list_tree">';
	    str += '<dt><img src="../img/bbs_list.gif" alt=""/></dt>'
	    for(var i=0;i<bbsList.list.length;i++){
		    var o=bbsList.list[i];
		    if (o.OneList == "0" && o.TwoList == "0")
		    {
		        str+='<dt id="menu_'+o.listid+'" class="dt_off" onclick="hide_menu('+o.listid+');">';
		        str+='  <div class="dt_pic"><img src="../img/touming.gif" width="11" height="11" class="mylist_btn_off"  id="g_menu_'+o.listid+'" /></a></div>';
			    str+='  <div class="dt_txt"><a href="'+o.ListURL+'">'+o.ListName+'</a></div>';
			    str+='</dt>';
			    str+='<dd><dl id="menu_list_'+o.listid+'" style="display:none"></dl></dd>';
			}
	    }
	    str += '</dl>';
    }
	if(GetObj("bbslist")){
		GetObj("bbslist").innerHTML = str;
	}
	hide_menu(id);
}

function Show_menu(id){
	var str='';
	if (bbsList.list.length>0)
	{
	    for(var i=0;i<bbsList.list.length;i++){
		    var o=bbsList.list[i];
		    if (o.OneList == id && o.TwoList == "0")
		    {
		        if (o.listid == "71" || o.listid == "75" || o.listid == "76")
		        {
                    str+='<dd class="dd_on"><img class="sub_on" src="../img/touming.gif" onclick="open_sub(this, '+o.listid+');" /> <a href="'+o.ListURL+'">'+o.ListName+'</a>\
                        <dl class="sub_dl" style="display:" id="sub_'+o.listid+'">'+Sub_menu(id, o.listid)+'</dl></dd>';
		        }else{
		            str+='<dd class="dd_on"><a href="'+o.ListURL+'">'+o.ListName+'</a></dd>';
		        }
			}
	    }
	    if (GetObj("menu_list_"+id))
	    {
	        GetObj("menu_list_"+id).innerHTML = str;
	    }
    }

}

function Sub_menu(id,tid){
    var str = '';
    for (var n = 0; n < bbsList.list.length; n++)
    {
        var t=bbsList.list[n];
        if (t.OneList == id && t.TwoList ==tid)
        {
            if ( t.listid == "84" || t.listid == "91" || t.listid == "98" ){
                str +='<dd class="sub_dd_end"><a href="'+t.ListURL+'">'+t.ListName+'</a></dd>';
            }else{
                str +='<dd class="sub_dd"><a href="'+t.ListURL+'">'+t.ListName+'</a></dd>';
            }
        }
    }
    return str;
}

