function showObj(id,flag){
	var obj = eval("document.getElementById(\""+id + "\")");
	var showflag;
	if (flag){
		showflag = "block";
	}
	else{
		showflag = "none";
	}
	obj.style.display = showflag;
}
/*************************************************
  Description:	移动id到obj对象位置
  @param:		id		对象id
  				obj		本对象
  @see:			在shortStr里用到
  History：             
				曾光		2007-1-15
*************************************************/
function moveTo(id,obj){
	var iobj = eval("document.getElementById(\""+id + "\")");
	var left = obj.offsetLeft;
	var top = obj.offsetTop;
	iobj.style.left = left;
	iobj.style.top = top;
}

/*************************************************
  Description:	获得N层以上的父容器
  @param:		obj		本对象id
  				num		层次
  @see:			在shortStr里用到
  History：             
				曾光		2007-1-15
*************************************************/
function getPElement(obj,num){
	var i = 0;
	var iobj = obj;
	for( i=0;i<num;i++ ){
		if( iobj.parentElement )
			iobj = iobj.parentElement;
		else
			return iobj;
	}
	return iobj;	
}
/*************************************************
  Description:	关闭高级检索区
  @param:		flag	是否显示
  @see:			调用showObj
  History：             
				曾光		2007-1-15
*************************************************/
function showQueDetail(flag){
	if( flag ){
		var obj = eval("document.getElementById(\"div_quedetail\")");
		obj.style.left = event.x-280;
		obj.style.top = event.y+10;
	}
	showObj("div_quedetail",flag);
}
/*************************************************
  Description:	显示浮动操作层,thickbox版本，主接口
  @param:		url		地址
  				width	宽度
  				height	高度
  				title	窗口标题
  				path	显示的路径
  History：             
				曾光		2007-4-27
*************************************************/
function showTBInterface(url,title,path){
	title = title || "JCMS内容管理系统";
	var obj = getTBPath(path);
	var groupflag = getTBConfig("outGroupFlag",path);
	obj.TB_show(title, url, groupflag , obj);
}
/*************************************************
  Description:	显示浮动操作层,thickbox版本
  @param:		url		地址
  				width	宽度
  				height	高度
  				title	窗口标题
  				path	显示的路径
  History：             
				曾光		2007-4-5
*************************************************/
function showTB(url,width,height,title,path){
	str = (url.indexOf("?") >= 0) ? "&" : "?";
	showTBInterface(url+str+"TB_iframe=true&height="+height+"&width="+width,title,path);
}
/*************************************************
  Description:	显示浮动图片层,thickbox版本
  @param:		url		地址
  				title	窗口标题
  				path	显示的路径
  History：             
				曾光		2007-4-7
*************************************************/
function showTBPic(url,title,path){
	showTBInterface(url,title,path);
}
/*************************************************
  Description:	显示浮动操作层,thickbox版本
  @param:		url		地址
  				width	宽度
  				height	高度
  				title	窗口标题
  				path	显示的路径
  History：             
				曾光		2007-4-5
*************************************************/
function showTBSwf(url,width,height,title,path){
	str = (url.indexOf("?") >= 0) ? "&" : "?";
	showTBInterface(url+str+"TB_flash=true&height="+height+"&width="+width,title,path);
}
/*************************************************
  Description:	显示浮动操作层,thickbox版本
  @param:		url		地址
  				width	宽度
  				height	高度
  				title	窗口标题
  				path	显示的路径
  History：             
				曾光		2007-4-5
*************************************************/
function showTBMedia(url,width,height,title,path){
	str = (url.indexOf("?") >= 0) ? "&" : "?";
	showTBInterface(url+str+"TB_media=true&height="+height+"&width="+width,title,path);
}
/*************************************************
  Description:	显示浮动分页组,,thickbox版本
  @param:		url		地址
  				width	宽度
  				height	高度
  				title	窗口标题
  				path	显示的路径
  History：             
				曾光		2007-4-5
*************************************************/
function showTBGroup(title,url,ary,path){
	//打开组开关
	setTBConfig("outGroupFlag",true,path);
	//设置自定义组数据
	setTBConfig("outGroupAry",ary,path);
	//显示接口
	showTBInterface(url,title,path);
}
/*************************************************
  Description:	清除浮动操作层,thickbox版本	
  @param:		path	显示的路径
  				retval	返回值
  History：             
				曾光		2007-4-5
*************************************************/
function removeTB(path){
	if( getTBConfig("attachEventFlag",path) ){
		doTBAttachEvent(path);
	}
	var obj = getTBPath(path);
	obj.TB_remove();
}
/*************************************************
  Description:	返回属性值	
  @param:		path	显示的路径
  History：             
				曾光		2007-4-5
*************************************************/
function getTBConfig(name, path){
	var obj = getTBPath(path);
	return obj.TB_getConfig(name);
}
/*************************************************
  Description:	设置属性值	
  @param:		path	显示的路径
  				retval	返回值
  History：             
				曾光		2007-4-5
*************************************************/
function setTBConfig( name, value, path ){
	//当有附加事件时，自动打开附加事件开关
	if( name == "attachEvent" && value )
		setTBConfig("attachEventFlag", true, path);
	//当有并列事件时，自动打开并列事件开关
	if( name == "inEvent" && value )
		setTBConfig("inEventFlag", true, path);
	var obj = getTBPath(path);
	obj.TB_setConfig(name,value);
}
/*************************************************
  Description:	做事件	
  @param:		path	显示的路径
  				retval	返回值
  History：             
				曾光		2007-4-5
*************************************************/
function doTBAttachEvent(path){
	var obj = getTBPath(path);
	obj.TB_doEvent();
}
/*************************************************
  Description:	获取显示thickbox的默认框架对象	
  @param:		path	显示的路径
  				retval	返回值
  History：             
				曾光		2007-4-5
*************************************************/
function getTBPath(path){
	path = path || "top";
	var obj = eval(path);
	if( !obj ){
		alert("对话框框架对象为空，请刷新或者关闭浏览器重新登录。");
		return false;
	}
	return obj;
}
/*************************************************
  Description:	鼠标拖动效果部分代码start
  History：             
				曾光		2007-4-4
*************************************************/
//可以打包为js文件;
var drag_x0=0,drag_y0=0,drag_x1=0,drag_y1=0;
var moveable=false;
//开始拖动;
function startDrag(obj){
	//锁定标题栏;
	obj.setCapture();
	//定义对象;
	var win = obj.parentNode;
	//记录鼠标和层位置;
	drag_x0 = event.clientX;
	drag_y0 = event.clientY;
	drag_x1 = parseInt(win.style.left);
	drag_y1 = parseInt(win.style.top);
	moveable = true;
}
//拖动;
function drag(obj){
	var win = obj.parentNode;
	if(moveable){
		win.style.left = drag_x1 + event.clientX - drag_x0;
		win.style.top = drag_y1 + event.clientY - drag_y0;
	}
}
//停止拖动;
function stopDrag(obj){
	//放开标题栏;
	var win = obj.parentNode;
	var t = win.style.top;
	t = parseInt(t.substring(0,t.length - 2));
	if( t < 0 ){
		win.style.top = 5;
	}
	if( top ){
		var h = parseInt(top.document.body.offsetHeight);
	}else{
		var h = parseInt(top.document.body.offsetHeight);
	}
	if( t >= h ){
		win.style.top = 5;
	}
	obj.releaseCapture();
	moveable = false;
}
/*************************************************
  Description:	鼠标拖动效果部分代码end
*************************************************/
// 弹出日历的框架
// format 默认完全格式　1=yyyy-mm-dd 2=yyyy-mm-dd HH:ii 
function popUpCalendarDlg(ctrlobj,format,path){
	if (!path)
		path = "..";
	showx = event.screenX - event.offsetX;
	showy = event.screenY - event.offsetY; 
	retval = window.showModalDialog(path+"/script/calendar.htm?format="+format, "", "dialogWidth:370px;dialogHeight:260px;dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no;directories:yes;scrollbars:no;Resizable=no;");
	if( retval != null ){
		ctrlobj.value = retval;
	}
}
// 弹出颜色的框架
function callColorDlg(formo,o){		
	var sInitColor = null;
	if (sInitColor == null) 
		var sColor = formo.colorHelper.ChooseColorDlg();
	else
		var sColor = formo.colorHelper.ChooseColorDlg(sInitColor);
	sColor = sColor.toString(16);	
	if (sColor.length < 6)
	{
		var sTempString = "FFFFFF".substring(0,6-sColor.length);
		sColor = sTempString.concat(sColor);
	}
	o.value = "#"+sColor;
}




function calendar(link,objName,name,date,width,height){
	this.link=link;
	this.objName=objName;
	this.calendarName=name!=null?name.toString():'calendar';
	this.width=width!=null?width:'100%';
	this.height=height!=null?height:'100%';
	this.dayName=['日','一','二','三','四','五','六'];
	this.nowDate=new Date();
	this.dateTime=date!=null?date:new Date();
	this.str='';
	this.dateTable='';
	this.days=31;
	this.pastDays=0;
	this.generated=false;
	
	this.channel='news';

	this.generate=generate;
	this.getTable=getTable;
	this.focusDate=focusDate;
	this.attachLink=attachLink;
	this.refresh=refresh;
	this.previewMonth=previewMonth;
	this.nextMonth=nextMonth;
	this.setDate=setDate;
	this.afterRefresh=function(){};

	function generate(date){
		this.str='<table id="'+this.calendarName+'" bgcolor="#ECEE55" cellspacing="0" cellpadding="2" border="0" width="'
			+this.width+'" height="'
			+this.width+'"><tr><th onselectstart="return(false)"><font style="font-size:9pt">'
			+this.dayName.join('</th><th onselectstart="return(false)"><font style="font-size:9pt">')+'</font></th></tr>';
		this.dateTime=date!=null?new Date(date):this.dateTime;
		this.days=new Date(this.dateTime.getYear(),this.dateTime.getMonth()+1,0).getDate();
		this.pastDays=new Date(this.dateTime.getFullYear()+'/'+(this.dateTime.getMonth()+1)+'/1').getDay();
		this.str+='<tr><td colspan="7" id="'+this.calendarName+'Td" style="filter:blendtrans(duration=0.1)">';
		this.getTable();
		this.str+=this.dateTable+'</td></tr></table>';
		this.generated=true;
		return this.str;
	}
	
	
	function getTable(){
		//this.proid=proid!null?proid:'20';
		
		this.dateTable='<table width="100%" height="100%" cellspacing="2" cellpadding="1" class="caltb"><tr>'
			+new Array(this.pastDays+1).join('<td></td>');
		for(var i=1;i<=this.days;i++){
		var monthValue = (this.dateTime.getMonth()+1);
		if(monthValue <10) monthValue="0"+monthValue;
		var dayValue = i;
		if(i<10) dayValue ="0"+dayValue;
		var parent_type=document.getElementById('parent_type').value;
		var child_type=document.getElementById('child_type').value;
		var wd=document.getElementById('select_website').value;
		var openurl="";
		var ropenurl="";
		if(parent_type=='sitegroup'){
		 	openurl= '<td id="'+this.calendarName+i+'">'+'<a href='+this.link+'parent_type='+parent_type+'&child_type='+child_type+'&y='+this.dateTime.getFullYear()+'&m='+monthValue+'&d='+dayValue+' target="_parent">'+i+'</a></td>';
		 	ropenurl= '<td id="'+this.calendarName+i+'">'+'<a href='+this.link+'parent_type='+parent_type+'&child_type='+child_type+'&y='+this.dateTime.getFullYear()+'&m='+monthValue+'&d='+dayValue+' target="_parent"><font color="red">'+i+'</font></a></td>';			
		}else{
		 	openurl= '<td id="'+this.calendarName+i+'">'+'<a href='+this.link+'parent_type='+parent_type+'&child_type='+child_type+'&y='+this.dateTime.getFullYear()+'&m='+monthValue+'&d='+dayValue+'&wd='+wd+' target="_parent">'+i+'</a></td>';
		 	ropenurl= '<td id="'+this.calendarName+i+'">'+'<a href='+this.link+'parent_type='+parent_type+'&child_type='+child_type+'&y='+this.dateTime.getFullYear()+'&m='+monthValue+'&d='+dayValue+'&wd='+wd+' target="_parent"><font color="red">'+i+'</font></a></td>';		
		}

		var closeurl='<td id="'+this.calendarName+i+'">'+i+'</td>';
		
		if(this.dateTime.getFullYear() > this.nowDate.getFullYear())
		{
			this.dateTable+=closeurl;
		}
		else
		if(this.dateTime.getFullYear()== this.nowDate.getFullYear())
		{
			if(this.dateTime.getMonth() > this.nowDate.getMonth())
			{
				this.dateTable+=closeurl;
			}
			else
			if(this.dateTime.getMonth() == this.nowDate.getMonth())
			{
				if(i<=this.nowDate.getDate())
				{
					if(i == this.nowDate.getDate())
					{
						this.dateTable+=ropenurl;
					}
					else
					this.dateTable+=openurl;
				}
				else
				{
					this.dateTable+=closeurl;
				}
			}
			else
			{
				this.dateTable+=openurl;
			}
		}
		else
			this.dateTable+=openurl;
				if((i+this.pastDays)%7==0)this.dateTable+='</tr><tr>';
		}
		for(var i=1;i<=37-this.days-this.pastDays;i++){
			this.dateTable+='<td></td>';
			if((i+this.pastDays+this.days)%7==0)this.dateTable+='</tr><tr>';
		}
		if((this.dateTime.getFullYear()<=2004) && (this.dateTime.getMonth()<9))
		{
					this.dateTable+='<td><button hidefocus="true"><span>3</span></button></td>'
			+'<td colspan="2">'+this.dateTime.getFullYear().toString().bold()+'</td>'
			+'<td>'+(this.dateTime.getMonth()+1).toString().bold()+'</td>'
			+'<td><button onmouseup="void('+this.objName+'.nextMonth())" hidefocus="true"><span>4</span></button></td>'
			+'</tr></table>';
		}
		else
		{
		this.dateTable+='<td><button onmouseup="void('+this.objName+'.previewMonth())" hidefocus="true"><span>3</span></button></td>'
			+'<td colspan="2">'+this.dateTime.getFullYear().toString().bold()+'</td>'
			+'<td>'+(this.dateTime.getMonth()+1).toString().bold()+'</td>'
			+'<td><button onmouseup="void('+this.objName+'.nextMonth())" hidefocus="true"><span>4</span></button></td>'
			+'</tr></table>';
		}
		return this.dateTable;
	}
	function focusDate(date){
		try{
			eval(this.calendarName+(date!=null?date|0:new Date().getDate())+'.className="focus"');
			return(true);
		} catch(e) { return(false); }
	}
	function attachLink(date,link,target,title){
		try{
			eval(this.calendarName+(date!=null?date|0:new Date().getDate())
				+'.innerHTML="<a href=\\"'+link+'\\"'
				+' target=\\"'+(target!=null?target:'_self')+'\\"'
				+' title=\\"'+(title!=null?title:'')+'\\">'+date.toString()+'</a>"');
			return(true);
		} catch(e) { alert(e.message);return(false); }
	}
	function refresh(){
		try{
			eval(this.calendarName+'Td.filters[0].apply()');
			eval(this.calendarName+'Td.innerHTML=\''+this.getTable()+'\'');
			eval(this.calendarName+'Td.filters[0].play()');
			this.afterRefresh();
			return(true);
		} catch(e) { return(false); }
	}
	function previewMonth(){
		try{
			this.dateTime.setMonth(this.dateTime.getMonth()-1)
			this.generate();
			this.refresh();
			return(true);
		} catch(e) { return(false); }
	}
	function nextMonth(){
		try{
			this.dateTime.setMonth(this.dateTime.getMonth()+1)
			this.generate();
			this.refresh();
			return(true);
		} catch(e) { return(false); }
	}
	function setDate(dateStr){
		try{
			this.dateTime=new Date(dateStr);
			return(true);
		} catch(e) { return(false); }
	}
}
