// JavaScript Document
function opensystem()
{
		//打开系统后台设置

		window.open("systemindex.asp","systemwindow","menubar=no,scrollbars=yes,channelmode=yes,resizable=yes,status=yes,top=0,left=0");

}


function doc(docid)
{
		window.open("document.asp?docid="+docid,"");
}


function xxcx()
{
			//信息查询
		//window.open("xgkl.asp","","menubar=no,scrollbars=yes,width=,height=300,resizable=yes,status=yes,top=200,left=200");
		window.location="query.asp";
}


function xgkl()
{
			//打开系统后台设置
		//window.open("xgkl.asp","","menubar=no,scrollbars=yes,width=,height=300,resizable=yes,status=yes,top=200,left=200");
		window.location="xgkl.asp";
}

function relogin()
{
	window.location="relogin.asp";
}
function gopage(page,att,category)
{
	var obj=document.form2;
	if(att==1)
	{//上一页
		if(obj.siteid.value>1)
		{
			window.location="kmshow.asp?cat="+category+"&localcat="+obj.Lcat.value+"&page="+(page-1)+"&siteid="+obj.siteid.value;
		}else
			{
				window.location="kmshow.asp?cat="+category+"&page="+(page-1);
			}
	}else if(att==0){
		//下一页
		if(obj.siteid.value>1)
		{
			window.location="kmshow.asp?cat="+category+"&localcat="+obj.Lcat.value+"&page="+(page+1)+"&siteid="+obj.siteid.value;
		}else
			{
				window.location="kmshow.asp?cat="+category+"&page="+(page+1);
		}
}	
}
function pagesubmit()
{
	var obj=document.form2;
	if(obj.pagesize.value=="")
	{
		alert("请输入每页显示多少条");
		obj.pagesize.focus();
		return false;
	}
	if(chrstring(obj.pagesize.value,"0123456789"))
	{
		alert("对不起只能输入数字");
		obj.pagesize.value="15";
		return false;
	}
	if(obj.pages.value=="")
	{
		alert("请输入每当前页");
		obj.pagesize.focus();
		return false;
	}
	if(chrstring(obj.pages.value,"0123456789"))
	{
		alert("对不起只能输入数字");
		obj.pagesize.value="1";
		return false;
	}
	return true;
}

function chrstring(thestring,tostring)
{
	for(var i=0;i<thestring.length;i++)
	{
		var temp=thestring.charAt(i).toLowerCase();
		if(tostring.indexOf(temp)==-1)
		{
			return true;
			break;
		}
	}
	
}


function picpage(page,att,category)
{
	if(att==1)
	{//上一页
		window.location="picnew.asp?page="+(page-1)+"&category="+category;
	}else if(att==0){
		//下一页
		window.location="picnew.asp?page="+(page+1)+"&category="+category;
}	
}
function flipnew(category)
{
	//弹出新闻
	//alert(category);
	window.open("flipnew.asp?category="+category,"plipnew","top=0,left=0,width=400,height=300,location=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no");
}
function setvote(x,cat,voteid,mostitems)
{
	var obj=eval("document.frm"+voteid)
	if(x==0)
	{//单选按钮
		if(count(x,obj)==1)
		{
			//alert(chalkup(x,obj));
			setvotes(cat,voteid,chalkup(x,obj));
		}else{
		alert("你没有选中任何一项");
	}
	}else if(x==1)
	{//多选按钮
		if(count(x,obj)==0)
		{
			alert("你没有选中任何一项");
		}else{
		if(mostitems==0)
		{//可以选择全部
			//alert(chalkup(x,obj));
			setvotes(cat,voteid,chalkup(x,obj));
		}else{
		if(count(x,obj)>mostitems)
		{
			alert("对不起，您最多只能选择"+mostitems+"个");
		}else{
		//alert(chalkup(x,obj));
		setvotes(cat,voteid,chalkup(x,obj));
	}
	}
	}
	}
}
function count(x,obj)
{
 var lens=0;
 if(x==1)
 {
 	objs="checkbox";
 }else{
  objs="radio"
}
 for(var i=0;i<obj.elements.length;i++)
 {
  if(obj.elements[i].type==objs)
  {
    if(obj.elements[i].checked==true)
    {
     lens++;
    }
  }
 }
 return lens;
}
function chalkup(x,obj)
{
 var idstr="";
 if(x==1)
 {
 	objs="checkbox";
 }else{
  objs="radio"
}
 for(var i=0;i<obj.elements.length;i++)
 {
  if(obj.elements[i].type==objs)
  {
    if(obj.elements[i].checked==true)
    {
     idstr=idstr+obj.elements[i].value+",";
    }
  }
 }
 return idstr;
}
function setvotes(category,voteid,voteitemid)
{
	window.open("votehandle.asp?selectedCat="+category+"&voteID="+voteid+"&action=vote&voteitemid="+voteitemid,"","width=500,height=300,location=no,menubar=no,scrollbars=auto,resizable=no,toolbar=no");
}
function showvote(category,voteid)
{
	window.open("votehandle.asp?selectedCat="+category+"&voteID="+voteid,"","width=500,height=300,location=no,menubar=no,scrollbars=auto,resizable=no,toolbar=no");
}

function getstr(str,num)
{
	if(str.length>num)
	{
		return str.substring(0,num)+"...";
	}
else
	{
		return str;
	}
	
}

function fmstr(titles,author,publishdate,wordcount)
//字符输出格式化
//wordcount是输出内容的总的字数，然后根据标题作者和发布日期进行字符截取
//发布的文档时间要是在三天之内，发布NEW的字样
//2是包含左括号、右括号、空格三个字符以及标题和作者之间的空格一个
{
	var today = new Date();
	var nowday=today.getYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();
	var newstr="";
	var p_date="";
	var datecount=0;
  
	if(publishdate!="")p_date=getDates(publishdate);
	if(p_date!="")datecount=p_date.length/2+1;
	
	//三天之内的就显示new的字样
	if(DateDiff(nowday,p_date)<=2){
		var iswriteIcon=true;
		}
		
	if(iswriteIcon==true){
		newstr=gettitle(titles,wordcount-datecount);
	}else{
		newstr=gettitle(titles,wordcount-datecount);
}
	document.write(newstr);

}

function printnewicon(publishdate)
{
	var newstr="";
	var today = new Date();
	var nowday=today.getYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();
	var p_date=getDates(publishdate);
	if(DateDiff(nowday,p_date)<=2)
	{
	var iswriteIcon=true;
	var newstr="&nbsp;<img src=styles/lyt/images/new.gif width=27 height=7 border=0>&nbsp;";
	}
	
	if(iswriteIcon==true)
	{
		document.write(newstr);
	}
	
}

function w_AuthorPdate(author,publishdate)
{
	var p_date=getDates(publishdate);
	if(author.length==0){
	document.write("["+p_date+"]");
	}else{
	document.write("["+p_date+"]");
	}
}


// 计算两个日期的间隔天数
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式 
var aDate, oDate1, oDate2, iDays 
aDate = sDate1.split("-") 
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式 
aDate = sDate2.split("-") 
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) 
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数 
return iDays 
} 


function gettitle(titles,wordcount)
{
	var w_count=wordcount;
	if(getallwordcount(titles)<=wordcount)
	{
		return titles;
	}
else
	{	
		for (var i=0; i<titles.length; i++)
		{
			var c = titles.charAt(i);

			if(IsHanZi(c)==true)
				w_count--;
			else
				w_count-=0.5;
				
				if(w_count<=0)
				{
					return getstr(titles,i+1);
					break;
				}
		}
		if(w_count>0)	return titles;
	}
}

function getallwordcount(Words)
{
	var count=0;
	count=getwordcount(Words);
	return (count+(Words.length-count)/2);
}

function getwordcount(Words)
//获得汉字的总的字数
{	
	var wordcount=0;
	for (var i=0; i<Words.length; i++) {
	var c = Words.charAt(i);
	if(IsHanZi(c)==true)wordcount++;	
}
	return wordcount;
}


function IsHanZi(strHanZi) 
{ 
    if(!strHanZi) return; if(strHanZi=='') return; 
    var PatSWord=/^[\x00-\xff]+$/; //匹配所有单字节长度的字符组成的字符串 
    var PatDWord=/[^\x00-\xff]+/g; //匹配双字节长度的字符组成的字符串 
    if(!PatSWord.test(strHanZi)) return true; 
    return false; 
} 

function getDates(str)
{
	var lens=str.indexOf(" ");
	var newstr=str.substring(0,lens);
	var arr=newstr.split("-");
	if(arr[0].length==1)arr[0]="0"+arr[0];
	if(arr[1].length==1)arr[1]="0"+arr[1];
	if(arr[2].length==1)arr[2]="0"+arr[2];
	
	return arr[0]+"-"+arr[1]+"-"+arr[2];
	
}

function showcount(showcount)
{
	var len=showcount.length;
	//alert(len)
	for(var i=0;i<8-len;i++)
	{
		document.write('<img src="images/0.gif">');
	}
	//alert(showcount);
	for(var j=0;j<len;j++)
	{
		var num=showcount.substring(j,j+1);
		//alert(num);
		switch(num)
		{
			case "0":
			document.write('<img src="images/0.gif">');
			break;
			case "1":
			document.write('<img src="images/1.gif">');
			break;
			case "2":
			document.write('<img src="images/2.gif">');
			break;
			case "3":
			document.write('<img src="images/3.gif">');
			break;
			case "4":
			document.write('<img src="images/4.gif">');
			break;
			case "5":
			document.write('<img src="images/5.gif">');
			break;
			case "6":
			document.write('<img src="images/6.gif">');
			break;
			case "7":
			document.write('<img src="images/7.gif">');
			break;
			case "8":
			document.write('<img src="images/8.gif">');
			break;
			case "9":
			document.write('<img src="images/9.gif">');
			break;
		}
	}
}
function setpicarr(picid,docid,category,x,imgpath)
{
	var picidarr=new Array();
	var picidarr=picid.split(",");
	var imgpatharr=imgpath.split(",");
	//alert(picidarr.length);
	if(picidarr.length>1)
	{
		pics=false;
	}
	for(var i=0;i<picidarr.length;i++)
	{
		if(imgpatharr[i]=="1")
		{
			dropimages[i]="imagecache/"+picidarr[i]+".gif";
			
		}else
			{
				dropimages[i]="showimg.asp?id="+picidarr[i];
			}
			
		droplinks[i]="document.asp?docid="+docid;
	}
		
	if(x=="1")
	{
		flipnew(category)
	}
	if(pics==true)
	{
		
		if(imgpath==1)
		{
			document.write('<a href="document.asp?docid='+docid+'" target="_blank"><img src="imagecache/'+picid+'.gif";" width="160" height="120" border="0"></a>');
		}else{
			document.write('<a href="document.asp?docid='+docid+'" target="_blank"><img src="showimg.asp?id='+picid+'" width="160" height="120" border="0"></a>');
		}
	}
}

function ly()
{
	var hrefs="styles/yongan/lyb/addlyb.asp?bm_id=lyb58";
	window.open(hrefs,"","width=420,height=200,left=300,top=300,scrollbars=no");
}
function showtime()
{
	var d=new Date();
	var year=d.getYear();
	var month=d.getMonth()+1;
	var day=d.getDate();
	var week=d.getDay();
	var weekday="";
	switch(week)
	{
		case 0:
			weekday="星期天";
			break;
		case 1:
			weekday="星期一";
			break;
		case 2:
			weekday="星期二";
			break;
		case 3:
			weekday="星期三";
			break;
		case 4:
			weekday="星期四";
			break;
		case 5:
			weekday="星期五";
			break;
		case 6:
			weekday="星期六";
			break;
	}
	document.write(year+"年"+month+"月"+day+"日 "+weekday);
}