﻿
function TxtChangColor(txt)
{
	if(txt.style.color=="red")
	{
		txt.style.color="blue";
	}
}
function btngotFocus(btn)
{  
	if (event.keyCode==13)
	{
	btn.focus()
	}
} 
function gotFocus()
{ 
	if (event.keyCode==13)
	{
	event.keyCode=9;
	}
} 
//转换整型
function PInt(txtid)
{
txtid.value=parseInt(parseFloat("0"+txtid.value))
}
function PIntNull(txtid)
{
txtid.value=parseInt(parseFloat("0"+txtid.value))
if(txtid.value=='0')
{
txtid.value='';
}
}
function PBInt(txtid)
{
txtid.value=parseInt(parseFloat("0"+txtid.value))
}
function PIntNull(txtid)
{
txtid.value=parseInt(parseFloat("0"+txtid.value))
if(txtid.value=='0')
{
txtid.value='1';
}
}
//转换整型
function PIntC(txtid)
{
return parseInt(parseFloat("0"+txtid.value))
}
//转换浮点数
function PFloat(txtid)
{
txtid.value=parseFloat("0"+txtid.value);
}
//转换浮点数
function CPrice(txtid)
{
txtid.value=parseFloat("0"+txtid.value);
if(txtid.value=='0')
{
txtid.value='';
}
}
//价格显示
function displayPrice(img,dt,first,btn,v1,v2)
{
flag=(dt.rows[dt.rows.length-1].style.display=='none');
for(i=first;i<dt.rows.length;i++)
{
			var dr=dt.rows[i];
			dr.style.display=flag?'block':'none';
}
btn.value=flag?v1:v2;
img.src=flag?'images/icon6-1.gif':'images/icon6.gif';
}
//分页
function dtPage(dt,pagecount,drphp,drpfp,btnhp,btnhn,btnfp,btnfn,page,rows)
{
if(pagecount<1)
	return;
drpfp.value=drphp.value;
page=PIntC(drphp)+page
drphp.value=page;
drpfp.value=drphp.value;
btnfp.disabled=false;
btnfn.disabled=false;
btnhp.disabled=false;
btnhn.disabled=false;
if(drphp.value=='1')
{
	btnhp.disabled=true;
	btnfp.disabled=true;
}
if(drphp.value==pagecount)
{
	btnhn.disabled=true;
	btnfn.disabled=true;
}
for(i=0;i<dt.rows.length;i++)
{
	var dr=dt.rows[i];
	 if(i>=rows*(page-1)&&i<rows*page)
	{
	dr.style.display='block';	
	}
	else{
	dr.style.display='none';
	}
}	
}

//设置ListBox项
function ListSet(list,txt1,txt2)
{
	temp1=txt1.split(",");
	temp2=txt2.split(",");
	if(temp1.length!=temp2.length)
	{
	alert("字符串不一致！");
	return;
	}
	else
	{
	//list.options.length=0;
		for(i=0;i<temp1.length;i++)
		{
			list.options[list.options.length]=new Option(temp2[i],temp1[i]);
		}
	}
	
}

//移动ListBox
function ListMove(list,row)
{
if(list.selectedIndex<0)
	{
				return;
	}
rows=list.selectedIndex+row;
if(rows==-1||rows==list.options.length)
{return;}
	var value=list.options[list.selectedIndex+row].value;
	var text=list.options[list.selectedIndex+row].innerText;
	list.options[rows]=new Option(list.options[list.selectedIndex].innerText,list.options[list.selectedIndex].value);
	list.options[rows-row]=new Option(text,value);
	list.selectedIndex=rows;
}

//返回ListBox的Value
function ListValue(list,s)
	{

	var temp="";
	for(var i=0;i<list.options.length;i++)
		{
			temp+=list.options[i].value+s;
			}
	if(temp.length>0)
		{
			temp=temp.substring(0,temp.length-1);
		}
return temp;
}

//返回ListBox的text
function ListText(list,s)
	{

	var temp="";
	for(var i=0;i<list.options.length;i++)
		{
			temp+=list.options[i].innerText+s;
			}
	if(temp.length>0)
		{
			temp=temp.substring(0,temp.length-1);
		}
return temp;
}
//删除选项		
function ListDel(list)
{
	if(list.selectedIndex<0)
	{
				return;
	}
	else
	{
			list.options[list.selectedIndex]=null;
			list.selectedIndex=-1;
	}
}
function ShowListDialog(Url,List)
{
	var vReturnValue = window.showModalDialog(Url,null,"dialogWidth:505px;dialogHeight:330px;center:1;scroll:0;help:0;status:no");				
	if(vReturnValue != null)
	{
		var temp=vReturnValue.split("|");
		ListSet(List,temp[0],temp[1]);
	}
}
function ShowDialog(Url,Controls)
{
	var vReturnValue = window.showModalDialog(Url,null,"dialogWidth:505px;dialogHeight:330px;center:1;scroll:0;help:0;status:no");				
	if(vReturnValue != null)
	{
	var temp=vReturnValue.split("|");
	for(i=0;i<Controls.length;i++)
	{
		Controls[i].value=temp[i];
	}
	}
}
function ShowFaxDialog(Url,Controls)
{
	var vReturnValue = window.showModalDialog(Url,null,"dialogWidth:460px;dialogHeight:310px;center:1;scroll:0;help:0;status:no");				
	if(vReturnValue != null)
	{
	Controls.value=vReturnValue;
	}
}

function TBdisplay(obj)
{
	var td=obj.parentElement;
	for(i=1;i<td.rows.length;i+=2)
{
	
	if(td.rows[i-1]==obj)
	{
		if(td.rows[i].style.display=='none')
		{
			td.rows[i].style.display='block';
		}
		else
		{
			td.rows[i].style.display='none';
		}
		continue;
	}
	td.rows[i].style.display='none';
}
}

function CHKAll(chk,crl)
{	
	for (var i=0;i<crl.all.length;i++)
	{
		if( crl.all[i].type=="checkbox")
		{
		crl.all[i].checked=chk.checked;
		}
	}
}
//日期计算
function DayChange(d1,d2,days,sign)
{
			var	date=d1.value.replace("-","/");
			f=new Date(date);
			fs=f.getTime();
			if(sign=='day')
			{
			ss=fs+86400000*days.value;
			endday=new Date(ss);
			d2.value=endday.getYear()+"-"+(endday.getMonth()+1)+"-"+endday.getDate();
			}
			else
			{
				var date2=d2.value.replace("-","/");
				f2=new Date(date2);
				fs2=f2.getTime();
				days.value=(fs2-fs)/86400000;
				
			}
}



