function announce() {
    $('announce').innerHTML = '<marquee style="margin: 0 2px 0 12px" direction="left" scrollamount="2" scrolldelay="1" onmouseover="this.stop();" onmouseout="this.start();">' + $('announce').innerHTML + '</marquee>';
    $('announce').style.display = 'block';
}

function deploy(ID)
{
    obj=$(ID);    
    if(obj.style.display=="none")
	{
        obj.style.display="";
    }
	else
	{
        obj.style.display="none";
    }
    return false;
}

function $(id)
{
    return document.getElementById(id);
}

function doZoom(x)
{
    var textId = document.getElementById('text-body');
    textId.style.fontSize=x+'px';
}

//此函数来自xoyo blog
function resizePic(ImgD,maxwidth,maxheight)
{
        var image=new Image();
        image.src = ImgD.src;
        ImgD.resized = false;

        iWidth  = image.width;
        iHeight = image.height;
        picwidth  = iWidth;
        picheight = iHeight;

        //大图缩小
        if(iWidth > maxwidth || iHeight > maxheight)
        {
            if (iWidth>iHeight)
            {
                if(iWidth>maxwidth)
                {
                    picwidth = maxwidth;
                    picheight = (iHeight*maxwidth)/iWidth;
                }
                if(picheight>maxheight)
                {
                    picheight = maxheight;
                    picwidth  = (iWidth*maxheight)/iHeight;
                }
            }
            else
            {
                if(iHeight>maxheight)
                {
                    picheight = maxheight;
                    picwidth  = (iWidth*maxheight)/iHeight;

                }
                if(picwidth>maxwidth)
                {
                    picwidth = maxwidth;
                    picheight = (iHeight*maxwidth)/iWidth;
                }
            }

            ImgD.resized = true;
        }
        else
        {
            //小图原样输出
            picwidth  = iWidth;
            picheight = iHeight;

        }

        ImgD.width  = parseInt(picwidth);
        ImgD.height = parseInt(picheight);

}

function searchCheck(obj)
{
    if (obj.keyword.value == '')
    {
        alert("请填写关键词");
        return false;
    }
    
    if (obj.keyword.value.length < 2)
    {
        alert("关键词太短,不能少于2个字符!");
        return false;
    }
    
    if (obj.keyword.value.length > 30)
    {
        alert("关键词太长,不能大于30个字符!");
        return false;
    }
    
    return true;
}

function postCommentCheck()
{
    if ($('username').value == "")
    {
        alert("请填写昵称!");
        return false;
    }
    if (GetCharLength($('username').value) > 10)
    {
        alert("昵称不能超过10个字符或5个汉字!")
        return false;
    }
    if ($('content').value == "")
    {
        alert("请填写评论内容!");
        return false;
    }
    if ($('authcode').value == "")
    {
        alert("请填写验证码!");
        return false;
    }
    
    if (GetCharLength($('content').value) > 400)
    {
        alert("评论内容不能超过400个字符或200个汉字!")
        return false;
    }
    
    return true;
}

function GetCharLength(str)
{
	var iLength = 0;
	for(var i = 0;i<str.length;i++)
	{
		if(str.charCodeAt(i) >255)
		{
			iLength += 2;
		}else{
			iLength += 1;
		}
	}
	return iLength;
}

function postCheck()
{
    if ($('subject').value == "")
    {
        alert("请填写文章标题!");
        return false;
    }
    if ($('category').value == "" || $('category').value == '-1')
    {
        alert("请选择文章所属分类!");
        return false;
    }
    return true;
}

function registerCheck()
{
    if ($('username').value == "")
    {
        alert("用户名不能为空！");
        return false;
    }
    if ($('username').value.length < 3 || $('username').value.length > 20)
    {
        alert("用户名输入错误！\n请确保用户名在3-20个字符之间！");
        return false;
    }
    if ($('password').value == "")
    {
        alert("密码不能为空！");
        return false;
    }
    if ($('password').value.length < 6)
    {
        alert("密码的长度须大于6个字符");
        return false;
    }
    if ($('password').value != $('repassword').value)
    {
        alsert("两次密码不一致，请重新输入！");
        return false;
    }
    if ($('email').value == "")
    {
        alert("Email 不能为空！");
        return false;
    }

    return true;
}

//document.write("<div id='tipLayer' style='position:absolute;z-index:1000' class='tiptext'></div>");

function showTipTxt(event)
{
    document.onmousemove = moveToMouse;
    if(event.srcElement)
    {
        tips = event.srcElement;
    }
    else
    {
        tips = event.target;
    }
    if(!tips) return;

    if(tips.alt != null && tips.alt != '')
	{
        tips.tiptxt = tips.alt;
        tips.alt = '';
    }
    if(tips.title != null && tips.title != '')
    {
        tips.tiptxt = tips.title;
        tips.title = '';
    }
    
    if(tips.tiptxt == null || tips.tiptxt == '')
    {
        $('tipLayer').style.visibility = "hidden";
    }
	else
	{
        $('tipLayer').style.visibility = "visible";
        $('tipLayer').className = tips.dyclass != null ? tips.dyclass : 'tiptext';
        $('tipLayer').innerHTML = tips.tiptxt;
    }
}

function moveToMouse(e)
{
    if(e)
    {
        x = e.pageX;
        y = e.pageY;
    }
    else
    {
        x =  document.documentElement.scrollLeft + event.x;
        y =  document.documentElement.scrollTop + event.y;
    }

    $('tipLayer').style.left = x+'px';
    $('tipLayer').style.top = (y + 20)+'px';
  
    return true;
}
/*
document.onmouseover = function(e)
{
    var event = e ? e : window.event;
    showTipTxt(event);
}
*/
function showBigPic(showid, url, w, h){
		if($(showid).style.display == "none"){
			$(showid).style.display = "";
		}
		$(showid).innerHTML = '<img src="'+url+'" onload="resizePic(this,"'+w+'","'+h+'")" align="absmiddle" />';
}