function overme(id)
{
	$('#submenu').html($('#submenu'+id).html());
	reset = true;
}
function setactive(id)
{
	if(reset){
		$('#menu'+id).attr('class',"active");
		$('#submenu').html($('#submenu'+id).html());
		reset = false;
	}
}
function addBookmark(title,url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
function DrawImage(ImgD){ 
	var image=new Image(); 
	image.src=ImgD.src; 
	if(image.width>0 && image.height>0){ 
	   if(image.width>400){
	    ImgD.width=400; 
	    ImgD.height=(image.height*400)/image.width; 
	   }else{ 
	    ImgD.width=image.width;
	    ImgD.height=image.height; 
	   } 
	}
}
function ShowSubDiv(cid)
{
	el = document.getElementById("sub"+cid);
	el.style.visibility = (el.style.display == "block") ? "none" : "block";
}
function ShowHide(divid)
{
	div = document.getElementById(divid);
	div.style.display = (div.style.display == "block") ? "none" : "block";
}
function ShowHideTR(TRid)
{
	div = document.getElementById(TRid);
	div.style.display = (div.style.display == "table-row") ? "none" : "table-row";
}
function ClearErrorMsg()
{
	$("div.msg").each(function(){$(this).html('');$(this).hide();});
}
function ShowLoading()
{
	dl = document.getElementById('Loading');
	dl.style.left = (document.documentElement.clientWidth/2-100)+"px";
	dl.style.top = (document.documentElement.clientHeight/2-50+document.documentElement.scrollTop)+"px";
	dl.style.display="block";
}
function SendAjaxRequest(url, frm, checkselect)
{
	ClearErrorMsg();
	if(checkselect && !CheckGroupBox(frm))
	{
		alert("请至少选择一条记录。");
		return false;
	}
	$.post(url, $('#'+frm).serialize(), ShowResult);
}
function ShowResult(t)
{
	var r = new Array();
	r = t.split("|");
	if(r[0]=="0")
	{
		window.location=r[1];
	}
	else	if(r[0]=="1")
	{
		for(i=1;i<r.length;i++)
		{
			$("#e_"+r[i]).html(r[i+1]);
			$("#e_"+r[i]).show();
			i = i+1;
		}
	}
	else	if(r[0]=="2")
	{
		eval(r[1]);
	}
	else
	{
		alert(t);
	}
}
//给Checkbox提供全选功能
function SelectGroupBox(self)
{
	if(self.name=='SelectAll'){
		var all = self.checked;
		$("input[name='SelectID']").each(function(){$(this).attr('checked',all);});
	}else{
		var all = true;
		$("input[name='SelectID']").each(function(){if(!$(this).attr('checked'))all=false;});
		$("input[name='SelectAll']").attr('checked', all);
	}
}
//检查Checkbox至少要选中一条
function CheckGroupBox(frm)
{
	var one = false;
	$("input[name='SelectID']").each(function(){if($(this).attr('checked'))one=true;});
	return one;
}

function AddSmile(id)
{
	document.formNote.content.value=document.formNote.content.value+'[smile]'+id+'[/smile]';
}
function ShowRepeatDay(sel)
{
	if(sel.value=="1" || sel.value=="2")
		$("#repeatday").html("<input type='text' name='repeatday' value='1' class='InputBox'/>　多个日期用逗号分开，比如&quot;1,3,5&quot;");
	else
		$("#repeatday").html("");
}
function AddTags(tag)
{
	var txt = document.getElementById('tags');
	var str = txt.value;
	if(str == ''){
		str = tag;
	}
	else if(str.indexOf(tag)==-1)
	{
		str += ' '+tag;
	}
	txt.value=str;
}
function getTop(e){
	var t=e.offsetTop;
	while(e=e.offsetParent)t+=e.offsetTop;
	return t;
}
function getLeft(e){
	var t=e.offsetLeft;
	while(e=e.offsetParent)t+=e.offsetLeft;
	return t;
}
var timer=null;
var outdiv=true;
function ShowTags()
{
	var tags = '';
	var txt = document.getElementById('tags');
	var op = document.getElementById('TagsDiv');
	var ts = mytags.split(' ');
	for(i=0;i<ts.length;i++)
	{
		tags += "<a href='javascript:;' onclick='AddTags(\""+ts[i]+"\")'>"+ts[i]+"</a> ";
	}
	op.innerHTML=tags;
	ClearTimer();
	op.style.top = getTop(txt)+txt.offsetHeight+'px';
	op.style.left= getLeft(txt)-getLeft(document.getElementById('content'))+'px';
	op.style.display='block';
}
function ClearTimer()
{
	if(timer) clearTimeout(timer);
}
function HideTags()
{
	if(outdiv) timer=setTimeout("DoHide()",1000);
}
function DoHide()
{
	$('#TagsDiv').hide();
}

function openWin(title, url, width) {
    if (document.getElementById('dialog')) {
        $("#dialog").dialog("destroy").remove();
    }
    if(width==undefined){width=400;}
    url = url+'&'+new Date().getTime();
    $.get(url, function(t){
        var body = document.getElementsByTagName('body').item(0);
        var div = document.createElement('div');
        div.id = "dialog";
        div.innerHTML = t;
        body.appendChild(div);
        $("#dialog").dialog({ title: title, width: width, height: 'auto', resizable: false });
    });
}
function CloseWin(){$('#dialog').dialog('close');}
function LoadTask(type){$('#task_'+type).load('/task/list/?type='+type+'&random='+new Date().getTime());}
