// JavaScript Document







/************************5.0增加开始*************************/

function moviePlayByUrl(filename,playerID,divWidth,divHeight,isAutoPlay){    //视频播放
	 if(filename != null && filename != ""){
		 filename = filename.toLowerCase();
		 if(filename.indexOf(".flv") != -1){
			 var s1 = new SWFObject("system/media/player.swf","single",divWidth,divHeight,"9","#FFFFFF");
			 s1.addParam("allowfullscreen","true");
			 s1.addVariable("file",filename);
			 //s1.addVariable("image","images/video.jpg");
			 s1.addVariable("image","");
			 s1.addVariable("width",divWidth);
			 s1.addVariable("height",divHeight)
			 s1.addVariable("autostart",isAutoPlay);
			 s1.write(playerID);
		  }else{
			 temp  = "<EMBED src="+filename+" width='"+divWidth+"' height='"+divHeight+"'  ";
			 temp += " type='audio/x-pn-realaudio-plugin' console='Clip3' controls='IMAGEWINDOW' ";
			 temp += " autostart='"+isAutoPlay+"'></EMBED> ";
			 document.getElementById(playerID).innerHTML = temp;
		  }
	 }
}

function FormatImagesCenter(id,leftNums){
   var divObj = $$(id);
   var imgObj = divObj.getElementsByTagName("IMG");
   for(var i=0; i < imgObj.length; i++){
      if(imgObj[i].src.indexOf("sysimage/") == -1){  //office图标
	     imgObj[i].style.paddingLeft = ((divObj.offsetWidth-imgObj[i].width-leftNums)/2).toString() + "px";
	  }  
   }
}

function FormatImagesSize(id,w,h){
   var imgObj = $$(id).getElementsByTagName("IMG");
   for(var i=0; i < imgObj.length; i++){
      if(imgObj[i].src.indexOf("sysimage/") == -1){  //office图标
	     DrawImage(imgObj[i],w,h);
	  }
   }
}

function DrawImage(ImgD,w,h){  
	var flag=false;
	var image=new Image();
	image.src=ImgD.src;
	if((image.width>0)&&(image.height>0)){
		flag=true;
		if(image.width/image.height>= w/h){
			if(image.width>w){
				ImgD.width=w;
				ImgD.height=(image.height*w)/image.width;
			}
			else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		else{
			if(image.height>h){
				ImgD.height=h;
				ImgD.width=(image.width*h)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		ImgD.title="点击查看原图";
        ImgD.style.cursor="hand";
        ImgD.onclick=function(){window.open(this.src,'_blank');}
	}
}

function resizepic(o,w,h){ 
	var maxwidth=w;   //定义最大宽度
	var maxheight=h;  //定义最大高度
	var a=new Image();
	a.src=o.src
	if(a.width > maxwidth){
	  o.style.width=maxwidth;
	}
	if (a.height> maxheight){
	   o.style.height=maxheight;
	}
	o.title="点击查看原图";
    o.style.cursor="hand";
    o.onclick=function(){window.open(this.src,'_blank');}
}

function filterHtml(str){
	//var str = document.getElementById("curChanName").innerHTML;
	if(trim(str) != ""){
		str = str.replace(/<\/?[^>]*>/g,'');       //去除HTML tag
		str = str.replace(/[ | ]*\n/g,'\n');       //去除行尾空白
		str = str.replace(/\n[\s| | ]*\r/g,'\n');  //去除多余空行
		str = str.replace(/(^\s*)|(\s*$)/g, "");   //去除左右空白
	}
	return str;
}

var $$=function(id){
	return "string" == typeof id ? document.getElementById(id) : id;
}
/************************5.0增加结束*************************/

function SetWhir_Acc(id){
   if(IsObjById(id)){
     var str = trim(document.getElementById(id).innerHTML);
	 if(str != "附件下载:"){
	    document.getElementById(id).style.display = "block";
	 }
   }
}

/*
movieNameID:从置标获取的视频地址
playerID:播放位置
isAutoPlay:true 自动播放
*/
function movieplay(movieNameID,playerID,divWidth,divHeight,isAutoPlay){    //视频播放
   if(IsObjById(movieNameID)){
	   var temp = "";
	   var filename = document.getElementById(movieNameID).innerHTML;
	   filename = rtrim(ltrim(filename)); 
	   if(filename != null && filename != ""){
		  filename = filename.toLowerCase();
		  filename = document.createElement(filename).getAttribute("href");
		  if(filename.indexOf(".flv") != -1){
			 var s1 = new SWFObject("system/media/player.swf","single",divWidth,divHeight,"9","#FFFFFF");
			 s1.addParam("allowfullscreen","true");
			 s1.addVariable("file",filename);
			 //s1.addVariable("image","images/video.jpg");
			 s1.addVariable("image","");
			 s1.addVariable("width",divWidth);
			 s1.addVariable("height",divHeight)
			 s1.addVariable("autostart",isAutoPlay);
			 s1.write(playerID);
		  }else{
			 temp  = "<EMBED src="+filename+" width='"+divWidth+"' height='"+divHeight+"'  ";
			 temp += " type='audio/x-pn-realaudio-plugin' console='Clip3' controls='IMAGEWINDOW' ";
			 temp += " autostart='"+isAutoPlay+"'></EMBED> ";
			 document.getElementById(movieNameID).innerHTML = temp;
		  }
	   }
   }
}   

function visited(id,imgtype){   //访问量
   if(IsObjById(id)){
       var nums = document.getElementById(id).innerHTML;
	   nums = rtrim(ltrim(nums));
	   if(nums != "" && nums != "0"){
		  if(nums.length > 1){
			 for(var i=0; i < nums.length; i++){
				document.write("<img src='system/images/pub/"+nums.substring(i,i+1)+"."+imgtype+"' />");
			 }
		  }else{
			 document.write("<img src='system/images/pub/"+nums+"."+imgtype+"' />");
		  }
	   }
   }
}
function getCurDate(){	   //当前日期，周
	var enabled = 0; today = new Date();
	var day; var date;
	if(today.getDay()==0) day = " 星期日"
	if(today.getDay()==1) day = " 星期一"
	if(today.getDay()==2) day = " 星期二"
	if(today.getDay()==3) day = " 星期三"
	if(today.getDay()==4) day = " 星期四"
	if(today.getDay()==5) day = " 星期五"
	if(today.getDay()==6) day = " 星期六"
	document.fgColor = "000000";
	date = "" + (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日" + day +"";
	return date;
}
function checksearch(objId,defaultText){   //搜索文本框检测
  if(document.getElementById(objId)){
     var obj = document.getElementById(objId);
	 if(obj.value != ""){
		if(defaultText != "" && defaultText == obj.value){
		   alert("请输入搜索关键字");
		   obj.focus();
		   return false;
		}else{
			if(!checkUnprohibited(obj.value)){
			   alert("请不要搜索非法字符！");
			   obj.focus();
			   return false;
			}
		}
	 }
  }else{
     alert("未检测到搜索文本框！");
	 return false;
  }
}
function checkUnprohibited(str){   //JS检测非法字符
   var yes = true;
   var SPECIAL_STR = "￥#$~!@%^&*();'\"?><[]{}\\|,:/=+—“”‘";
   for(i=0;i<str.length;i++){
      if(SPECIAL_STR.indexOf(str.charAt(i)) !=-1){
		 yes = false;
	  }
   }
   return yes;
}
//跳转页大于总页数时设置跳转页等于总页数
function pageNum(Id,pageTotalCount){
   if(IsObjById(Id)){
	  var textValue = document.getElementById(Id).value;
	  //alert(alltrim(textValue) !='' && alltrim(pageTotalCount) !='');
	  if(alltrim(textValue) !='' && alltrim(pageTotalCount) !=''){
		 if(parseInt(textValue) > parseInt(pageTotalCount)){setValue(Id,pageTotalCount);}
	  }else{setValue(Id,"1");}
   }
}
function pageJump(Id,showstr,gotoUrl,totalPage){
  if(IsObjById(Id)){
	 if(alltrim(document.getElementById(Id).value) ==''){alert(showstr);}
	 else{window.location.href=gotoUrl;}
  }
}
//验证是否数字及是否要设置其默认值
function checkNum(Id,returnValue){   
  if(IsObjById(Id)){
	 if(isNaN(alltrim(document.getElementById(Id).value))){
		if(returnValue != null && returnValue != ""){setValue(Id,returnValue);} 
	 }
  }
}
function setValue(Id,Value){
   if(IsObjById(Id)){
      document.getElementById(Id).value = Value;
   }
}
function IsObjByObj(obj){
  return (typeof(obj)=="object")?true:false;
}
function IsObjById(Id){
  return (document.getElementById(Id))?true:false;
}
//去字符串前后空格
function trim(tt){
  return rtrim(ltrim(tt));
}
function ltrim(s){   
  return s.replace(/^\s*/, "");   
}
function rtrim(s){   
  return s.replace(/\s*$/, "");   
}
//去字符串所有空格
function alltrim(tt){
  return tt.replace(/(^\s*)|(\s*$)/g, "");
}
function CloseWindow(){
  window.opener=null;
  window.open('','_self');
  window.close();	
}
function selectall(obj){
  obj.select();
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
