// JavaScript Document
	/*
	Copyright (C) 2004,2007 OA86.COM. All rights reserved.
	Written by 陈祥山
	Web: http://www.oa86.com.cn,http://www.oa86.cn/
	Email: chenxsh@gmail.com
	*/

//分页函数
function Page_Search(iVer){
	if(iVer==1 || iVer==3 || iVer==6){
		var iPage=parseInt(document.all.page.value);
		if(iPage>0){
			window.location=addParam(window.location.href,"page",iPage);
		}
	}
	if(iVer==2 || iVer==7 || iVer==10 || iVer==12){
		var sUrl=Reg(location.href,"_p(\\d*).html","_p{$CurrPage}.html");
		var iPage=parseInt(document.all.page.value);
		if(iPage>0){
			if(sUrl.indexOf("{$CurrPage}")>0){
				window.location=sUrl.replace("{$CurrPage}",iPage)
			}else{
				window.location=sUrl.replace(".htm","_p"+iPage.toString()+".htm")
			}
		}
	}
}
function Check_keycode(iVer){
	if(event.keyCode==13){
		if(iVer==1 || iVer==3 || iVer==6){
			var iPage=parseInt(document.all.page.value);
			if(iPage>0)
				window.location=addParam(window.location.href,"page",iPage)
		}
		if(iVer==2 || iVer==7 || iVer==10 || iVer==12){
			var sUrl=Reg(location.href,"_p(\\d*).html","_p{$CurrPage}.html");
			var iPage=parseInt(document.all.page.value);
			if(iPage>0){
				if(sUrl.indexOf("{$CurrPage}")>0){
					window.location=sUrl.replace("{$CurrPage}",iPage)
				}else{
					window.location=sUrl.replace(".htm","_p"+iPage.toString()+".htm")
				}
			}
		}
	}
}

//参数传递
function ridParam(strParam,strRid){
	strRid=strRid.toLowerCase();
	var arrParam=strParam.split("&");
	var j=arrParam.length;
	if(strParam=="")j=-1;
	var paramRid="";
	for(var i=0;i<j;i++){
		if(arrParam[i].toLowerCase().indexOf(strRid+"=")!=0){
			if(paramRid!="")paramRid+="&";
			paramRid+=arrParam[i];
		}
	}
	return paramRid;
}

function addParam(strParam,strAdd,value){
	var paramAdd="";
	strParam=strParam.toLowerCase();
	strAdd=strAdd.toLowerCase();
	if(strParam.indexOf("?")==-1){
		strParam="?"+strParam;
	}
	//}else{
		var sUrl=strParam.substring(0,strParam.indexOf("?")+1);
		strParam=strParam.substring(strParam.indexOf("?")+1);
		var arrParam=strParam.split("&");
		for(var i=0;i<arrParam.length;i++){
			if(arrParam[i]!=""){
				if(arrParam[i].indexOf(strAdd+"=")==-1){
					paramAdd+=arrParam[i]+"&";
				}
			}
		}
		paramAdd=sUrl+paramAdd+strAdd+"="+value;
	//}
	return paramAdd;
}


function $() {
	
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }
  return elements;
}

//正则替换
function Reg(sStr,sReg,sRe){
	var s="",sS=sStr,sR=sReg,sRe=sRe;
	if ((sS.length>0)&&(sR.length>0)) {
		eval("re=/"+sR+"/gim;");
		s=sS.replace(re,sRe);
	}
	return (s);
}

//cookie方法
function get_cookie(name) {
	cookiename = name + '=';
	cookiepos = document.cookie.indexOf(cookiename);
	if(cookiepos != -1) {
		cookiestart =cookiepos+cookiename.length;
		cookieend = document.cookie.indexOf(';', cookiestart);
		if(cookieend == -1) {
			cookieend = document.cookie.length;
		}
		return unescape(document.cookie.substring(cookiestart, cookieend));
	}
	return '';
}
function set_cookie (name, value)
{
    var rightNow = new Date();
    var expdate = new Date();
    expdate.setTime (expdate.getTime() + 5 * (24 * 60 * 60 * 1000)); //+1 day
    document.cookie = name + "=" + value +"; expires=" + expdate.toGMTString()+";path=/";
}


//全选系统
function SelectAllCheckBox(){
  document.write('<input type="checkbox" name="AllSelect" onclick="SelectAll()">')
}
function SelectAll(){
  var check = document.all.AllSelect.checked;
  for (i=0;i< parseInt(document.forms[0].length);i++) { 
    if (document.forms[0].elements[i].type == "checkbox" & document.forms[0].elements[i].disabled==false & document.forms[0].elements[i].name=="InfoID") { 
      document.forms[0].elements[i].checked = check;
    }
  }
}


//排序方法
function setSort(obj,intSort){
	/*
	if(isNaN(parseInt(intSort))){
		intSort=0;
	}
	*/
	var intNum=window.prompt("请输入序号(整数)：",intSort);
	if(intNum!=null){
		if(isNaN(intNum))
			alert("不是整数,无效的输入");
		else{
			obj.href+="&sortTo="+intNum;
			return true;
		}	
	}
	return false;
}


//图片自动调整的模式，1为按比例调整 ，2 按大小调整。
var resizemode=2
function imgresize(o){
 	if (resizemode==2 || o.onmousewheel){
		if(parseInt(o.width)>parseInt(o.height)){
			o.style.width='500px';	
		}else
		{
			o.style.height='500px';
		}
	}else{
		var parentNode=o.parentNode.parentNode
		if (parentNode){
			if (parentNode.tagName=='DIV'){
				if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}else{
				var parentNode=o.parentNode.parentNode.parentNode
				if (parentNode)
				{
					if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
				}
			}
		}else{
			var parentNode=o.parentNode
			if (parentNode){
				if (parentNode.tagName=='DIV') alert(parentNode.tagName);
				if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}
		}
	}
}

function OA86marquee(id,mw,mh,mr,sr,ms,pause,dr){
	
	var obj=document.getElementById(id);
	obj.ss=false; //stop tag
	obj.mr=mr; //marquee rows
	obj.sr=sr; //marquee display rows
	obj.mw=mw; //marquee width
	obj.mh=mh; //marquee height
	obj.ms=ms; //marquee speed
	obj.pause=pause; //pause time
	obj.pt=0; //pre top
	obj.st=0; //stop time
	obj.dr=dr; //direction

	with(obj){
		style.width=mw+"px";
		style.height=mh+"px";
		noWrap=false;
		onmouseover=stopm;
		onmouseout=startm;
		scrollTop=0+"px";
		scrollLeft=0+"px";
	}
	
	if(obj.mr!=1){
		switch(obj.dr){
			case("up"):
				obj.tt=mh*mr/sr;
				obj.ct=mh; //current top
				obj.innerHTML+=obj.innerHTML;
				setInterval(scrollUp,obj.ms); break;
			default://("left"):
				obj.tt=mw*mr/sr;
				obj.ct=mw;
				obj.innerHTML='<div style="width:'+(obj.tt*2)+'px;"><div style="float:left;">'+obj.innerHTML+'</div><div style="float:right;">'+obj.innerHTML+'</div></div>';
				document.write('<style type="text/css">#'+id+' table{width:'+mw*mr+'px;} #'+id+' td{width:'+mw+'px;}</style>');
				setInterval(scrollLeft,obj.ms); break;
		}
	}

	function scrollUp(){
		if(obj.ss==true) return;
		obj.ct+=1;
		if(obj.ct==obj.mh+1){
			obj.st+=1; obj.ct-=1;
			if(obj.st==obj.pause){obj.ct=0; obj.st=0;}
		}else {
			obj.pt=(++obj.scrollTop);
			if(obj.pt==obj.tt){obj.scrollTop=0;}
		}
	}

	function scrollLeft(){
		if(obj.ss==true) return;
		obj.ct+=1;
		if(obj.ct==obj.mw+1){
			obj.st+=1; obj.ct-=1;
			if(obj.st==obj.pause){obj.ct=0; obj.st=0;}
		}else {
			obj.pt=(++obj.scrollLeft);
			if(obj.pt==obj.tt){obj.scrollLeft=0;}
		}
	}

	function stopm(){obj.ss=true;}
	function startm(){obj.ss=false;}
}