// 取对象
function $()
{
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++)
    {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}

function ImgError(obj, url)
{
	if(url != obj.src) {if(url==0) $('#avator').html(''); else obj.src = url;}
}

function MM_goToURL() 
{ //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function doPrint() 
{    
	bdhtml=window.document.body.innerHTML;    
	sprnstr="<!--startprint-->";    
	eprnstr="<!--endprint-->";    
	prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);    
	prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));    
	window.document.body.innerHTML=prnhtml;    
	window.print();    
}

//大图片缩小
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 replyComment(obj,nickname)
{
    if (obj.value == '')
    {
        obj.value = "RE "+nickname+"：\n";
    }
	else
	{
		var content = obj.value;
		obj.value = "RE "+nickname+"：\n" + content;
	}
}

function storeCaret (textObj){
        if(textObj.createTextRange){
                textObj.caretPos = document.selection.createRange().duplicate();
        }
}

// 提交
function actionSubmit(form, url, msg, target)
{
    if(msg)
    {
        if(confirm(msg))
        {
            form.action = url;
            if (target)
            {
                form.target = target;
            }
            form.submit();
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        form.action = url;

        if (target)
        {
            form.target = target;
        }

        form.submit();
        return true;
    }
}

function hideTipInfo(tipBox, tipBoxShadow) {
    if (tipBox && tipBoxShadow) {
        tipBox.style.display = 'none';
    }
    else if($('tipBoxDiv')) {
        $('tipBoxDiv').style.display = 'none';
    }
}

function InitAjax()
{
    var http_request = false;

    if (window.XMLHttpRequest)
    {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {}
        }
    }
    if (!http_request)
    {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    return http_request;
}

function showTipInfo(text, tipBox) {
    if ($('tipBoxDiv')) {
        var tipBox = $('tipBoxDiv');
    }
    var body = document.body;
    if (!tipBox) {
        var tipBox = document.createElement("div");
        body.appendChild(tipBox);
    }
    tipBox.innerHTML = text;
    tipBox.id = "tipBoxDiv";
	tipBox.height = 25;
    tipBox.style.color = "#000000";
    tipBox.style.border = "1px solid #cccccc";
    tipBox.style.background = "#f5f5f5";
    tipBox.style.padding = "5px";
    tipBox.style.display = "block";
    tipBox.style.zIndex = "1";
    tipBox.style.position = "absolute";
    var x = (body.offsetWidth - tipBox.offsetWidth)/2;
    var y = Math.ceil((document.body.clientHeight - tipBox.height)/2) + document.body.scrollTop;
    tipBox.style.left = x + "px";
    tipBox.style.top  = y + "px";

}