﻿function ctrlSubmit(submitId, event)
{
	if (event.ctrlKey && (event.keyCode == 13)) { document.getElementById(submitId).click(); }
}

function setTab(/*string*/name,/*int*/ itemCnt,/*int*/ curItem, /**/classHide, /**/classShow)
{
	for(i=1;i<=itemCnt;i++)
	{
		eval("document.getElementById('tab_" + name + "_" + i + "').className='" + classHide + "'");
	}	
	eval("document.getElementById('tab_" + name + "_" + curItem + "').className='" + classShow + "'");
	
	for(i=1;i<=itemCnt;i++)
	{
		eval("ele_hide = document.getElementById('con_" + name + "_" + i +"')");
		if(ele_hide) ele_hide.style.display = "none";
	}
	eval("ele_play = document.getElementById('con_" + name + "_" + curItem + "')");
	if(ele_play) ele_play.style.display = "block";
}

function trim(content)
{
	content = content.replace(/(^\s*)|(\s*$)/g, "");
	return content;
}

function isEmpty(s)
{
	return (s==null)||(s.length==0);
}

function searchAnswer(questionTitle)
{		
	var title = trim(questionTitle.value);
	if(isEmpty(title))
	{
		alert('请输入【问题标题】的内容。');
		questionTitle.select();
		return false;
	}
	return true;
}

var search_url = '';
var ask_url = '';
var cateId = '';
function checkKey(questionTitle, ev)
{
	if(ev.keyCode==13)
	{
		if(searchAnswer(questionTitle))
			window.location.href = search_url + encodeURIComponent(questionTitle.value);
		return false;
	}
	return true;
}
function redirectSearch(questionTitle, isSrch)
{
	if(isSrch)
	{
		if(searchAnswer(questionTitle))
			window.location.href = search_url + encodeURIComponent(questionTitle.value) + '&ch=k2';
		return false;
	}
	else window.location.href = ask_url + encodeURIComponent(questionTitle.value) + '&ch=k1';
}
function redirectForAsk(questionTitle, first)
{
	var title = trim(questionTitle.value);
	
	if (isEmpty(title))
	{
		var url = ask_for_title_url + "&ch=" + pageId;
		window.location.href = url;  
	}
	else 
	{
		var url = ask_url + encodeURIComponent(questionTitle.value) + "&ch=" + pageId;		
		if(!first)
	    	url += "&ch=k9";
		window.location.href = url;
	}
}
function mark(node, tagValue, tagFlag)
{
    var childs = node.childNodes;
    var childTagValue = null;
    if(!childs || !childs.length) return;

    for(var i=0; i<childs.length;i++)
    {
        childTagValue = null;
        if(childs[i].tagName=='A')
        {
            if(tagValue && childs[i].setAttribute)
            {
                var x = childs[i].href.indexOf('?')<0 ? '?' : '&';
                var linkText = childs[i].innerHTML;
                if(tagFlag == "pid")
                        childs[i].href += x + 'pid=' + tagValue;
                if(tagFlag == "ch")
                        childs[i].href += x + 'ch=' + tagValue;
                childs[i].innerHTML = linkText;
            }
        }
        else
        {
            if(typeof childs[i] != 'null')
            {
                if(document.all && childs[i].ch)
                {
                        childTagValue = childs[i].ch;
                        tagFlag = "ch";
                }
                else if(document.all && childs[i].pid)
                {
                        childTagValue = childs[i].pid;
                        tagFlag = "pid";
                }
                else if(navigator.userAgent.toLowerCase().search('msie')<0 && childs[i].getAttribute)
                {
                        if(childs[i].getAttribute('ch'))
                        {
                                childTagValue = childs[i].getAttribute('ch');
                                tagFlag = "ch";
                        }
                        if(childs[i].getAttribute('pid'))
                        {
                                childTagValue = childs[i].getAttribute('pid');
                                tagFlag = "pid";
                        }
                }

                if(childTagValue)
                     mark(childs[i], childTagValue, tagFlag);
                else
                     mark(childs[i], tagValue, tagFlag);
            }
        }
    }
}

function focus_input(input)
{
	if(!input || input.disabled) return true;
	else {
		input.select();
		return false;
	}
}

function aboutSpecialty()
{
	w=window.open('http://cache.soso.com/wenwen/help_sw.htm','关于声望','width=380,height=429,left=200,top=160');
	if(w.focus) w.focus();
}


function splitResNum( total )
{
        var ts = total.toString();
        var tl = ts.length;
        if(tl<4) 
        {
                document.write(ts);
                return;
        }
        var tmp = tl/3;
        var tlC = Math.floor(tmp);   
        var tlY = tl%3; res = "";
        if(tlY == 0) 
        {
                tlY = 3;
                tlC = tlC-1;
        }
        res += ts.substr(0,tlY)+"," + ts.substr(tlY,3);
        for(var i=1; i<tlC; i++)
        {
                res += ","+ts.substr(tlY+i*3,3);
        }
        document.write(res);
}
String.prototype.trim=function()
{
        return   this.replace(/(^\s*)|(\s*$)/g,'');
}
 
$d = function(id){
        return  document.getElementById(id);
}
var st='';
function sm(event)
{
        clearTimeout(st);
        o=$d('tm');
        o.style.display = "block";
        document.onmousemove = cp;
}
function cp(event)
{
                evt = window.event?window.event:event;
                var pointer=function(event) {
            return {
              x: event.pageX || (event.clientX +
                (document.documentElement.scrollLeft || document.body.scrollLeft)),
              y: event.pageY || (event.clientY +
                (document.documentElement.scrollTop || document.body.scrollTop))
            };
        }(evt);
                l=o.offsetLeft;t = o.offsetTop-20;
                r=l+o.offsetWidth;b=o.offsetTop+o.offsetHeight;
 
                py = pointer.y;px = pointer.x;
 
                if((py>t && py<b) && (px>l&&px<r)){
                        }
                else{ 
                        st = setTimeout(function(){o.style.display="none";},500);
                        document.onmousemove=function(){};
                }
}


function togDispMore(e){stopB(e);var elems=document.getElementsByName('tm');for(var i=0;i<elems.length;i++){var obj=elems[i],dp="";if(obj.style.display==""){dp="none";}obj.style.display=dp;}return false;}
function stopB(e){if(!e)e=window.event;e.cancelBubble=true;}
document.onmouseup=function(event){var elems=document.getElementsByName('tm');if(elems[0] && elems[0].style.display==""){togDispMore(event);}}
