function trim(str) {
  return str.replace(/^\s*|\s*$/g,'');
}

function $(id) {
    return document.getElementById(id);
}
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g, "");};
/*
 指定时间实现跳转
 target--操作窗口 url--转向url sTime--等待时间
*/
function jumpurl(target,url,sTime)
{
  if(typeof(arguments[0])=='undefined') target='self';
  if(typeof(arguments[2])=='undefined'||sTime<2000) sTime=3000;
	var a=target+".location.href='"+url+"'";
	
  setTimeout(eval("a"),sTime);
}
function urlBack(sTime) {
  setTimeout("history.back()",sTime);
}
 
function initArray(){   
   this.length=initArray.arguments.length
   for(var i=0;i<this.length;i++)
   this[i+1]=initArray.arguments[i];
}

function writeGreeting() {
   var today=new Date();
   var d=new initArray(
     "星期日",
     "星期一",
     "星期二",
     "星期三",
     "星期四",
     "星期五",
     "星期六");
   var greetingStr;
   var hour=today.getHours();
    if(hour < 6){ greetingStr="凌晨好！"} 
   else if (hour < 9){ greetingStr="早上好！"} 
   else if (hour < 12){greetingStr="上午好！"}
   else if (hour < 13){greetingStr="中午好！"}
   else if (hour < 17){greetingStr="下午好！"}
   else if (hour < 19){greetingStr="傍晚好！"} 
   else if (hour < 22){greetingStr="晚上好！"} 
   else {greetingStr="夜里好！"} 
   
   document.write(
     "<font class='f12' color='#FFFFFF'>&nbsp;&nbsp;",
     today.getYear(),"年",
     today.getMonth()+1,"月",
     today.getDate(),"日   ",
     d[today.getDay()+1],  " ",
     greetingStr,
     "</font>" ); 
}

function openLayer(url,divName,features) {
  var layerDiv=document.createElement("DIV");
  var fWidth=200,fHeight=100,fTop=30,fLeft=300
  var fTitle="法律教育网"

  var reWidth  =/(width[ |\t]*=[ |\t]*)(\d+)/i;
  var reHeight =/(height[ |\t]*=[ |\t]*)(\d+)/i;
  var reTop  =/(top[ |\t]*=[ |\t]*)(\d+)/i;
  var reLeft =/(left[ |\t]*=[ |\t]*)(\d+)/i;
  var reTitle=/(title[ |\t]*=[ |\t]*)(.+)/i;

  if(features.match(reWidth))  fWidth  =features.match(reWidth)[2]
  if(features.match(reHeight)) fHeight =features.match(reHeight)[2]
  if(features.match(reTop))    fTop    =features.match(reTop)[2]
  if(features.match(reLeft))   fLeft   =features.match(reLeft)[2]
  if(features.match(reTitle))  fTitle  =features.match(reTitle)[2]

  with(layerDiv) {
    style.position ="absolute";    
    style.display  ="block";
    style.border   ="1px solid black"
    style.zIndex   =100;
    style.width    =fWidth + "px";
    style.height   =fHeight+"px";
    style.left     =fLeft;
    style.top      =fTop;
    style.backgroundColor='#c0c0bb';
    innerHTML = "<iframe allowTransparency frameborder=0 width="+ fWidth+" height=25 src=/huangye/js/title.htm?t="+ fTitle+"></iframe>"
    innerHTML += "<iframe allowTransparency frameborder=0 width="+ fWidth+" height="+ (fHeight-25) +" src="+ url+"></iframe>"
   }
   document.body.appendChild(layerDiv);
}

/*
Purpose : 选择加入收藏夹
备注 : 可传入参数,第一个为title，第二个为收藏路径 like "this is a test"(title)  "http://www.sina.com.cn"(path)
示例 : addFav("this is a test","http://www.chinaacc.com")
*/
function addFav() {
	var linkName;    // 收藏显示名称
	var filePath;    //收藏url
	if(!arguments[0]) { linkName=document.title;}
	else {linkName=arguments[0];}
	if(!arguments[1]) {filePath=document.location;}
	else { filePath=arguments[1];}
	
  var url="/huangye/shoucangjia/addFav.asp?title="+ linkName +"&filepath="+ filePath;
	
  //openLayer(url,'','width=500,height=200,top=300,left=300');
  window.open(url,'','width=500,height=200,top=300,left=300');
}

function modiFav(favID) {
    var url="/huangye/shoucangjia/modiFav.asp?favid="+ favID;
    //openLayer(url,'','width=500,height=200,top=300,left=300');
    window.open(url,'','width=500,height=200,top=300,left=300');
}

function getQryVal(priStrQueryName){
 priStrValue = "";
 priIsFound = false;
 if (this.location.search.indexOf("?")==0&&this.location.search.indexOf("=")>1){
  priArraySource = unescape(this.location.search).substring(1,this.location.search.length).split("&");
  priGetQSi = 0;
  while (priGetQSi<priArraySource.length&&!priIsFound){
   if (priArraySource[priGetQSi].indexOf("=")>0){
    if (priArraySource[priGetQSi].split("=")[0].toLowerCase()==priStrQueryName.toLowerCase()){
     priStrValue = priArraySource[priGetQSi].split("=")[1];
     priIsFound = true;
    }
   } 
   priGetQSi ++ ;
  } 
 }
 return priStrValue;
}

//替换指定传入参数的值
function replaceParamVal(paramName,replaceWith,addParamUrl) {
	var oUrl = this.location.href.toString();
	if(addParamUrl) {
		oUrl = replaceParam(addParamUrl.trim().split("=")[0],addParamUrl.trim().split("=")[1])
	}
	var re=eval('/('+ paramName+'=)([^&]*)/gi');
  
	var nUrl
	if(re.test(oUrl))
	  nUrl = oUrl.replace(re,paramName+'='+replaceWith);
	else { //当前url传入参数中不存在param时
	  if(oUrl.indexOf('?')<1) nUrl=oUrl+'?'+paramName+'='+replaceWith;
		else nUrl=oUrl+'&'+paramName+'='+replaceWith;
	}
	this.location.href = nUrl;
}

function replaceParam(paramName,replaceWith) {
	var oUrl = this.location.href.toString();
	
	var re=eval('/('+ paramName+'=)([^&]*)/gi');
  
	var nUrl
	if(re.test(this.location.search))
	  nUrl = oUrl.replace(re,paramName+'='+replaceWith);
	else { //当前url传入参数中不存在param时
	  if(this.location.search.length==0) nUrl=oUrl+'?'+paramName+'='+replaceWith;
		else nUrl=nUrl=oUrl+'&'+paramName+'='+replaceWith;
	}
	return nUrl;
}

function closeWin() {
 var ua=navigator.userAgent;
 var ie=navigator.appName=="Microsoft Internet Explorer"?true:false;
 if(ie){
  var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
  if(IEversion< 5.5){
   var str  = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"><param name="Command" value="Close"></object>';
   document.body.insertAdjacentHTML("beforeEnd", str);
   document.all.noTipClose.Click();
  }
  else{ window.opener =null; window.close(); }
 }
 else{ window.close();}
}

String.prototype.len=function() {
  return this.replace(/[^\x00-\xff]/g,'**').length;
}