function winopen(targeturl)
{
	newwin=window.open("","","scrollbars")
	if (document.all)
	{
		newwin.moveTo(0,0)
		newwin.resizeTo(screen.width,screen.height-30)
	}
	newwin.location=targeturl
}

function winopen2(theURL,features)
{
	newwin=window.open(theURL,'',features)
	if (document.all)
	{
		newwin.moveTo(0,0)
		newwin.resizeTo(screen.width,screen.height-30)
	}
	newwin.location=theURL;
}

//打开最大化窗口
function fOpenMaxWin(url){
	var x=window.screen.width - 10;
	var y=window.screen.height - 50;
	window.open(url,"","width=" + x + ",height=" + y + ",resizable=yes,srollbars=yes,left=0,top=0")
}

//打开居中的窗口
function fOpenCenterWin(theURL,winName,w,h,otherFeatures){
	var x=window.screen.width - 10;
	var y=window.screen.height;
	var left,top
	if(x>w)
	{
		left = (x-w)/2
	}
	else
	{
		left = 0
	}
	if(y>h)
	{
		top = (y-h)/2
	}
	else
	{
		top = 0
	}
	if(otherFeatures+''=='')
	{
		otherFeatures = ",resizable=yes"
	}
	var str = "width=" + w + ",height=" + h + ",left=" + left + ",top=" + top + otherFeatures
	window.open(theURL,winName,str)
}

function fOpenWinByElt(url,x,y,onElt){
//根据指定对象的位置显示隐藏的对象
//hidElt: 要显示的对象; onElt:显示的位置的依据对象

	var wd = window.screen.width;
	var left=onElt.offsetLeft;
	if(left + x > wd)
	{
		left = wd - x;
	}
	var top=window.event.screenY;
	window.open(url,'','scrollbars=yes,width='+x+",height="+y+",left="+left+",top="+top)
}

function fShowHidByElt(hidElt,onElt){
//根据指定对象的位置显示隐藏的对象
//hidElt: 要显示的对象; onElt:显示的位置的依据对象

	selElt=onElt  //赋予公用变量
	hidElt.style.left=onElt.offsetLeft;
	hidElt.style.top=parseInt(onElt.offsetTop) + 20;
	hidElt.style.display="";
	hidElt.focus();
}

function fAddOption(sel,text,value){
//添加下拉列表的一个option
//sel: 传入的下拉框对象; text: 要添加的option的显示文本; value: 要添加的option的值
//By neat

	var newOption=document.createElement("option");
	newOption.text=text;
	newOption.value=value;
	sel.add(newOption);
}

function fDelOption(sel){
//删除下拉列表选中的option,可多选
//sel: 传入的下拉列表对象
//返回值: true--交换成功; false--未交换,并有提示语句
//By Neat

	if(sel.value=="")
	{
	alert("请选择项目!")
	return false;
	}
	for(i=0;i<sel.options.length;i++)
	{
		if(sel.options(i).selected)
		{
			sel.options.remove(i);
			i--;
		}
	}
	return true;
}
function fSwapSelectOption(sel1,sel2){
//交换两个下拉框的option,可多选  **从sel1到sel2
//sel1: 传入的下拉框对象1; sel2: 传入的下拉框对象2
//返回值: true--交换成功; false--未交换,并有提示语句
//Code By Neat

	if(sel1.value=="")
	{
		alert("请选择要改变的项目!");
		return false;
	}else

	{
		for(i=0;i<sel2.options.length;i++)
		{
			if(sel2.options(i).value==sel1.value)
			{
				return true;
			}
		}
		var newOption;
		for(i=0;i<sel1.options.length;i++)
		{
			if(sel1.options(i).selected)
			{
				newOption=document.createElement("option");
				newOption.value=sel1.options(i).value;
				newOption.text=sel1.options(i).text;
				sel2.add(newOption);
				sel1.options.remove(i);
				i--;
			};
		};
		return true;
	}
	return false;
}

function fSwapSelectOption2(sel1,sel2){
//交换两个下拉框的option,可多选  **从sel1到sel2
//sel1: 传入的下拉框对象1; sel2: 传入的下拉框对象2
//重复值按Value和Text来判断
//返回值: true--交换成功; false--未交换,并有提示语句
//Code Chang By Xuxm

	if(sel1.value=="" && sel1.text=="")
	{
		alert("请选择要改变的项目!");
		return false;
	}else

	{
		var newOption;
		for(i=0;i<sel1.options.length;i++)
		{
			if(sel1.options(i).selected)
			{
				for(j=0;j<sel2.options.length;j++)
						if(sel2.options(j).value==sel1.options(i).value&&sel2.options(j).text==sel1.options(i).text)break;
				  
				if(j==sel2.options.length){
						newOption=document.createElement("option");
						newOption.value=sel1.options(i).value;
						newOption.text=sel1.options(i).text;
						sel2.add(newOption);
				}		
				sel1.options.remove(i);
				i--;
				
			};
		};
		return true;
	}
	return false;
}

function fChgOptionsSq(elt,dir){
//改变下拉框option的顺序
//elt:下拉框对象；dir：方向("up","down")
	var i
	var tmpText,tmpValue
	
	if(dir=="up"){
		for(i=0;i<elt.options.length;i++){
			if(elt.options(i).selected && i>0){
				tmpText=elt.options(i).text;
				tmpValue=elt.options(i).value;
				elt.options(i).text=elt.options(i-1).text;
				elt.options(i).value=elt.options(i-1).value;
				elt.options(i-1).text=tmpText;
				elt.options(i-1).value=tmpValue;
				elt.options(i).selected=false;
				elt.options(i-1).selected=true;
			}
		}
	}else{
		for(i=elt.options.length-1;i>=0;i--){
			if(elt.options(i).selected && i<elt.options.length-1){
				tmpText=elt.options(i).text;
				tmpValue=elt.options(i).value;
				elt.options(i).text=elt.options(i+1).text;
				elt.options(i).value=elt.options(i+1).value;
				elt.options(i+1).text=tmpText;
				elt.options(i+1).value=tmpValue;
				elt.options(i).selected=false;
				elt.options(i+1).selected=true;
			}
		}
	}
}


//字符串替换(功能同VB的replace函数)  By Neat
function fReplace(str1,str2,str3){
	var str="";
	var pos;
	var con=true;
	while(con)
	{
		pos=str1.indexOf(str2);
		if(pos>0)
		{
			str=str + str1.substring(0,pos);
			str=str + str3;
			str1=str1.substring(pos+str2.length,str1.length)
		}else
		{
			con=false;
		}
	}
	if(str.length>0)
	{
		return str+str1;
	}else
	{
		return str1;
	}
}



function fPicLimit(IncludeName,sLength)
//限制所有图片显示尺寸
//参数: IncludeName--字符串,所有图片包含的名称
//	sLength: 限制的宽度或长度,取最大的作限制,等比缩小图片


{
	var imgs=document.images;
	for(i=0;i<imgs.length;i++)
	{
		if(imgs(i).name.indexOf(IncludeName)!=-1)
		{
			if(imgs(i).height>imgs(i).width)
			{
				if(imgs(i).height>sLength){imgs(i).height=sLength}
			}else
			{
				if(imgs(i).width>sLength){imgs(i).width=sLength}
			}
		}
	}
}

function fCloseNormalWin()
{
 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">'
      str += '<param name="Command" value="Close"></object>';
      document.body.insertAdjacentHTML("beforeEnd", str);
      document.all.noTipClose.Click();
     }
     else
     {
      window.opener =null;
      window.close();
     }
 }
 else
 {
  window.close()
 }
}
function GN(item,tempJ)
{
	flag=false;
	num=0;
	j=0;
	var etext=item.toString();
	elen=etext.length;
	
	if (etext==0)
	{
		
		return 0;
	}
	else
	{	
		for (i=0;i<=elen-1;i++)
		{	
			if (j==tempJ) {return(parseFloat(num));} 
  			var aa=etext.charAt(i);
				if (aa==".") 
				{	
					flag=true;
					num=num + aa;
									
				}else
				{
					if(flag==true){
					j=j+1;
					} 

					num=num + aa;  
				}
							
		}
	}
	
  	return(parseFloat(num));
}

function Number.prototype.Fixed(n)
{
	if(n<=0)
	{
		return Math.round(this);
	}
	
	var t= (this + 0.5*Math.pow(10,-n)).toString();
	
	t+=(/\./.test(t)?"":".")+new Array(n+1).join("0");
	
	return t.match(new RegExp("\\d+\\.\\d{"+n+"}"))
}

function GNA(n,m)
{
	return n.Fixed(m);
}
