//傅巍
//function fFormatTime(that,type) ：把传入的4位时间数字转换成tt:ss的5位标准时间格式
//function fFormatTimeCommon(Time)：把传入的4位时间数字进行校验后转换成tt:ss的5位标准时间格式(String)
//function fRoundTime(strTime)    ：把传入的4位时间数字进行4舍5入


//=============================================
//Purpose: Trim left spaces
//=============================================
function fGetStandardToobar()  //根据用户权限添加工具条
{

	if(document.FormName.currentUserRight==null)
	{
		alert("你没有表单currentUserRight。");
		return;
	}
	var strRight=document.FormName.currentUserRight.value;
	var strResult="";
	if(strRight.indexOf("a")!=-1)   
	  strResult=strResult+
		"<TD class=coolButton width=1 onClick=\"fNewBasicData();return false\"><img src=../html/images/toobar/new.gif alt=新增 align=center></TD>";
			
	if(strRight.indexOf("s")!=-1)   
	  strResult=strResult+
		"<TD class=coolButton width=1 onClick=\"fSaveBasicData();return false\"><img src=../html/images/toobar/save.gif alt=存档 align=center></TD>";

	if (strRight.indexOf("c") != -1)
	{
		strResult=strResult +
		"<TD class=coolButton width=1 onClick=\"fSaveNewBasicData();return false\"><img src=../html/images/toobar/savenew.gif alt=存盘后新增 align=center></TD>";
	}


	if(strRight.indexOf("d")!=-1)   
	  strResult=strResult+
		"<TD class=coolButton width=1 onClick=\"fDeleteBasicData();return false\"><img src=../html/images/toobar/delete.gif alt=删除 align=center></TD>";

	if(strRight.indexOf("b")!=-1)   
	  strResult=strResult
		+"<TD class=coolButton width=1 onClick=\"fRefreshBasicData();return false\"><img src=../html/images/toobar/refresh.gif alt=刷新 align=center></TD>";

	if(strRight.indexOf("f")!=-1)   
	  strResult=strResult+
		"<TD width=23 class=coolBar2>&nbsp;</TD>"
		+"<TD class=coolButton width=1 onClick=\"fCheckBasicData();return false\"><img src=../html/images/toobar/check.gif alt=审核 align=center></TD><TD width=23 class=coolBar2>&nbsp;</TD>";
		
	if(strRight.indexOf("b")!=-1)   
	  strResult=strResult
		+"<TD class=coolButton width=1 onClick=\"fFirstBasicData();return false\"><img src=../html/images/toobar/first.gif alt=最前一笔 align=center></TD>"
			
		+"<TD class=coolButton width=1 onClick=\"fPreBasicData();return false\"><img src=../html/images/toobar/left.gif alt=前一笔 align=center></TD>"
			
		+"<TD class=coolButton width=1 onClick=\"fNextBasicData();return false\"><img src=../html/images/toobar/right.gif alt=后一笔 align=center></TD>"
			
		+"<TD class=coolButton width=1 onClick=\"fLastBasicData();return false\"><img src=../html/images/toobar/last.gif alt=最后一笔 align=center></TD><TD width=5 class=coolBar2>&nbsp;</TD>";
			
	strResult=strResult+"<TD width=1 ><span id='promptwin'></span></TD>";
	return strResult;
}


function jsLTrim(str){
var rtnStr;
rtnStr=""
for (var i=0;i<str.length;i++){
if (str.charAt(i)!=" "){
rtnStr=str.substr(i);
break;
}
}
return rtnStr;
}

//==========================================
//Purpose: Trim right spaces
//==========================================
function jsRTrim(str){
var rtnStr;
rtnStr=""
for (var i=str.length-1;i>=0;i--){
if (str.charAt(i)!=" "){
rtnStr=str.substring(0,i+1);
break;
}
}
return rtnStr;
}

//==========================================
//Purpose: Trim both left and right spaces
//==========================================
function jsTrim(str){
return(jsLTrim(jsRTrim(str)));
}

function fCheckNum(data)
{
    
	var i,err=false,f;
    var str=jsTrim(data);
    for(i=0;i<str.length;i++) 
    {		
     	f=str.substring(i,i+1);
        if(((f>=0) && (f<=9))||(f=='.')) 
		{ err=true; }
          else{err=false; break;}
    }

    if(err)
      return true; 
    else 
      return false; 

}


function checkFirst() 
{
	var value=currentBillFristOrLast();
	if(value.indexOf("F")!=-1)
	{
		alert("当前数据已为最前一笔.");
		return false;
	}
	if(value.indexOf("W")!=-1)
	{
		alert("数据库中没有资料.");
		return false;
	}
	return true;
}

function checkLast()
{
	var value=currentBillFristOrLast();
	if(value.indexOf("L")!=-1)
	{
		alert("当前数据为最后一笔.");
		return false;
	}
	if(value.indexOf("W")!=-1)
	{
		alert("数据库中没有资料.");
		return false;
	}
	return true;
}

function checkPre() 
{
	var value=currentBillFristOrLast();
	if(value.indexOf("F")!=-1)
	{
		alert("当前数据已为最前一笔.");
		return false;
	}
	if(value.indexOf("W")!=-1)
	{
		alert("数据库中没有资料.");
		return false;
	}
	return true;
}

function checkNext()
{
	var value=currentBillFristOrLast();
	if(value.indexOf("L")!=-1)
	{
		alert("当前数据为最后一笔.");
		return false;
	}
	if(value.indexOf("W")!=-1)
	{
		alert("数据库中没有资料.");
		return false;
	}
	return true;
}

function checkSave()
{
	if(!checkBillUserIdentity())
		return false;

/*	if(document.FormName.billChecked==null)
	{
		alert("请添加 当前单据的用户表单。");
		return false;
	}	
	var  checkFlag=document.FormName.billChecked.value;
	if(checkFlag.indexOf("T")!=-1)
	{
		alert("对不起！此单据已复核。");
		return false;
	}
*/
	return true;
}


function checkNew()
{
	return true;	
}

//检查单据锁
function checkBillUserIdentity()
{

	if(document.FormName.ingUserId==null)
	{
		alert("请添加当前单据的用户（ingUserId）表单。");
		return false;
	}	
	if(document.FormName.ingUserName==null)
	{
		alert("请添加当前单据的用户（ingUserName）表单。");
		return false;
	}	
	if(document.FormName.currentUserId==null)
	{
		alert("请添加当前用户（currentUserId）表单。");
		return false;
	}	

	var  ingUserId=document.FormName.ingUserId.value;
	var  ingUserName=document.FormName.ingUserName.value;
	var  currentUserId=document.FormName.currentUserId.value;

	if(ingUserId!=currentUserId)
	{
		alert("对不起！当前数据由“"+ingUserName+"“正在使用中。请稍后再试！");
		return false;
	}
    
	return true;
}

function checkDelete()
{
	if(!checkBillUserIdentity())
		return false;

	var value=currentBillFristOrLast();
	if(value.indexOf("N")!=-1)
	{
		alert("新增状态，不能删除。");
		return false;
	}
	return true;
}

function checkRefresh()
{
	var value=currentBillFristOrLast();
	if(value.indexOf("N")!=-1)
	{
		alert("新增状态，不能刷新。");
		return false;
	}
	
	return true;
}

function checkCheck()
{
	if(!checkBillUserIdentity())
		return false;

	if(document.FormName.billChecked==null)
	{
		return false;
	}	
	var  checkFlag=document.FormName.billChecked.value;
	if(checkFlag.indexOf("T")!=-1)
	{
		alert("对不起！此单据已复核。");
		return false;
	}

	if(document.FormName.currentUserRight==null)
	{
		return false;
	}	
	var value=document.FormName.currentUserRight.value;
	if(value.indexOf("f")==-1)
	{
		alert("对不起！你没有复核的权限。");
		return false;
	}
	
	return true;
}

function checkDeleteDetail()
{
	if(!checkBillUserIdentity())
		return false;

	if(document.FormName.currentUserRight==null)
	{
		alert("没有：document.FormName.currentUserRight");
		return false;
	}	
	var strRight=document.FormName.currentUserRight.value;
	if(strRight.indexOf("d")==-1)
	{
		alert("对不起！你没有存档权限。");
		return false;
	}

	return true;
}

function checkSaveDetail()
{

	if(!checkBillUserIdentity())
		return false;

	if(document.FormName.currentUserRight==null)
	{
		alert("没有：document.FormName.currentUserRight");
		return false;
	}	
	var strRight=document.FormName.currentUserRight.value;
	if(strRight.indexOf("s")==-1)
	{
		alert("对不起！你没有存档权限。");
		return false;
	}

	return true;
}


function currentBillFristOrLast()
{
	if(document.FormName.billFristOrLast==null)
	{
		alert("error without form:billFristOrLast");
		return "";
	}	
	var value=document.FormName.billFristOrLast.value;
	return value;
}

function replaceName(strData,strFrom,strTo)
{
    var nIndex=strData.indexOf(strFrom);
    var strResult="";
    while(nIndex!=-1)
    {
      strResult =strResult+ strData.substring(0,nIndex)
                   +strTo;
      var len=strData.length;
	  strData = strData.substring(nIndex+strFrom.length,len);
      nIndex=strData.indexOf(strFrom);
    }
    strResult =strResult+strData;
    return strResult;
}

function fGetDecimalNum(value,length)
{
	var str=""+value;
	var len=str.indexOf(".");
	
	if(len!=-1)
	{
		for(var i=0;i<length;i++)
			str+="0";
		if(length==0)
			str=str.substring(0,len+length);
		else
			str=str.substring(0,len+length+1);
	}
	else
	{
		if(length!=0)
		{
			var tail=".";
			for(var i=0;i<length;i++)
				tail+="0";
			str+=tail;
		}
	}
	return str;
}



function fOnLoad() //添加用户初始化界面数据
{

//	alert("only for test? 001");
}

function showAlertWindow(formData)
{
	var features =
		'dialogWidth:'  + 275 + 'px;' +
		'dialogHeight:' + 125 + 'px;' +
		'dialogLeft:'   + 275 + 'px;' +
		'dialogTop:'    + 275 + 'px;'+
		'directories:yes; localtion:yes; menubar:no; status=no; toolbar=no; scrollbars:no;Resizeable=no';
	window.open(formData,"NewWindow",features);
}


function updateInputWindow(formData)
{
	this.location.href=formData;
}


function getPureDate(date)
{
  var result=
	date.substring(0,4)
	+date.substring(5,7)
	+date.substring(8);
	  	 
  return result;	
}

function setPureDate(date)
{
 if(date.length>8)
	return date;
 var result=
	date.substring(0,4)+"/"
	+date.substring(4,6)+"/"
	+date.substring(6);
	  	 
  return result;	
}

/*
  0：得到当前月的第一天(YYYY/MM/DD)
  1：得到当前年月日(YYYY/MM/DD)
  2：得到当前年月(YYYY/MM)
  3：得到当前年(YYYY)
*/

function getCurrentDate(type)
{
  var today=new Date();
  var month=today.getMonth()+1;
  var date=today.getDate();
  if(month<10)
  	month="0"+month;
  if(date<10)
  	date="0"+date;
  	
  if(type == 0)  //得到当前月的第一天(YYYY/MM/DD)
	  date=(today.getYear())+"/"
	  	+month+"/"
	  	+"01"; 
  if(type == 1)  //得到当前年月日(YYYY/MM/DD)
  	  date=(today.getYear())+"/"
	  	+month+"/"
	  	+date;
  if(type == 2)  //得到当前年月(YYYY/MM)
	  date=(today.getYear())+"/"
	  	+month;
  if(type == 3)  //得到当前年(YYYY)
	  date=(today.getYear());
	  	 
  return date;	
}



//得到当前时间 write by rgh at 5.13
function getCurrentTime()
{
  var today=new Date();
  var hour=today.getHours();
  var minu=today.getMinutes();
  if(hour<10)
  	hour="0"+hour;
  if(minu<10)
  	minu="0"+minu;

  return hour + ':' + minu;	
}

function fPopUpCalendarDlg_8(ctrlobj)
{

	//得到当前页面的路径(change by wqs(2004-3-8))
	var the_url = location.href;
	var str1 = the_url.split("//");
	var str2 = str1[1];
	var str3 = str2.split("/");
	var folder = str3[1];

	//showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	//showy = event.screenY - event.offsetY + 18; // + deltaY;
	showx = 350;
	showy = 200;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("./script/calendardlg_8.htm", "", "dialogWidth:235px; dialogHeight:230px; dialogLeft:300px; dialogTop:150px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	//retval = window.showModalDialog("/" + folder + "/script/CalendarDlg_8.htm", "", "dialogWidth:235px; dialogHeight:230px; dialogLeft:300px; dialogTop:150px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		ctrlobj.value = retval;
	}else{
		//alert("canceled");
	}
}

function fPopUpCalendarDlg(ctrlobj)
{	
	//得到当前页面的路径(change by fw(2004/02/09))
	var the_url = location.href;
	var str1 = the_url.split("//");
	var str2 = str1[1];	
	var str3 = str2.split("/");
	var folder = str3[1];
	var pot = the_url.indexOf("site");
	var aa = '';
	if( pot >= 0 )
	{
		aa = the_url.substring(0,pot+4);
	}
	else
		aa = str1[0]+"//"+str3[0];	

	//showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	//showy = event.screenY - event.offsetY + 18; // + deltaY;
	showx = 350;
	showy = 200;
	newWINwidth = 210 + 4 + 18;
//	retval = window.showModalDialog("/module/search/script/CalendarDlg.htm", "", "dialogWidth:197px; dialogHeight:205px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	retval = window.showModalDialog(aa + "/module/search/script/calendardlg.htm", "", "dialogWidth:197px; dialogHeight:205px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );

	if( retval != null ){
		ctrlobj.value = retval;
	}else{
		//alert("canceled");
	}
}

function fPopUpCalendarDlgYear(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("/module/search/script/calendardlg.htm", "", "dialogWidth:197px; dialogHeight:210px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		ctrlobj.value = retval.substring(0,4);
	}else{
		//alert("canceled");
	}
}

function fPopUpCalendarDlgMonth(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("/module/search/script/calendardlg.htm", "", "dialogWidth:197px; dialogHeight:210px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		ctrlobj.value = retval.substring(0,7);
	}else{
		//alert("canceled");
	}
}


function fPopUpMonthDlg(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("/module/search/script/calendardlg.htm", "", "dialogWidth:197px; dialogHeight:210px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null )
	{
		ctrlobj.value = retval.substring(0,7);
	}
	else{
		//alert("canceled");
	}
}

function fPopUpYearDlg(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("/module/search/script/calendardlg.htm", "", "dialogWidth:197px; dialogHeight:210px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null )
	{
		ctrlobj.value = retval.substring(0,4);
	}
	else{
		//alert("canceled");
	}
}

//用户已修改了界面参数， 设定
function fSetPromptUserChange()
{
	if(document.FormName.promptUserChange==null)
		return;
	document.FormName.promptUserChange.value="已修改";
}

//用户已修改了界面参数， 恢复
function fResetPromptUserChange()
{
	if(document.FormName.promptUserChange==null)
		return;
	document.FormName.promptUserChange.value="";
}

//存档时检查用户的输入是否为空，数字类型是否为0
function checkUserMustInput(promptName,promptType,promptValue)
{
	if(promptName.length!=promptType.length||
		promptType.length!=promptValue.length)
	{
		alert("存档提示用户信息长度不正确！");
		return false;
	}
	var len=promptName.length;
	for(var i=0;i<len;i++)
	{
		if(promptValue[i]=="")
		{	
			alert("注意栏位："+promptName[i]+"不能为空！");
			return false;
		}	
		if(promptType[i]=="n"&&promptValue[i]==0)
		{	
			alert("注意栏位："+promptName[i]+"不能为"+promptValue[i]+"！");
			return false;
		}
		if(promptType[i]=="i"&&promptValue[i]==0)
		{	
			alert("注意栏位："+promptName[i]+"不能为空！");
			return false;
		}
		if(promptType[i]=="o")
		{	
			theDes="status:no;center:yes;help:no;minimize:yes;maximize:no;dialogWidth:350px;scroll:no;dialogHeight:200px";
			//self.showModalDialog("http://www.sina.com.cn",null,theDes);
			self.showModelessDialog("http://www.sina.com.cn",null,theDes);

		}

	}
	return true;
    
}

function updatePopWindow(formData)
{
	parent.parent.parent.hiddenFrame.location.href=formData;
}

//转换回车键
function fConvertEnterCode(txt)
{
	txt=replaceName(txt,"#","＃");
	txt=replaceName(txt,"&","＆");
	txt=replaceName(txt,"%","％");

	txt=fConvertEnterCode_(txt);
	return txt;
}

function fConvertEnterCode_(txt)
{
  for(var n=0;n<txt.length;n++)
  {
    var strCode=txt.charCodeAt(n);
    if(strCode==13)
    {
	txt=txt.substring(0,n)+"§"+txt.substring(n+1);
    }
  }
  return txt;
}

function fConvertEncode(txt)
{
	txt=replaceName(txt,"#","＃");
	txt=replaceName(txt,"&","＆");
	txt=replaceName(txt,"%","％");

	txt=fConvertEnterCode_(txt);
	return txt;
}

function closeShowMenu()
{
	return true;	
}

//推出系统时调用
function fExitCurrentSystem(strModule,strType)
{
	if(!checkBillUserIdentity())
		return false;

	var formData="ManagerOfBasic"
		+"?rptModule="+strModule
		+"&rptType=" +strType
		+"&billStatus=Z";
	updatePromptWindow(formData);

}

function updatePromptWindow(formData)
{
//	parent.parent.parent.hiddenFrame.location.href=formData;
promptwin.innerHTML="<iframe src='"+formData+"' width=100 height=20 marginwidth=0 "
			+" marginheight=0 hspace=0 vspace=1 frameborder=0 scrolling=NO></iframe>";

}

function  setTimeToExit(strModule,strType,nTime)
{
	var nMin=nTime;  
	var ss="fExitCurrentSystem('"+strModule+"','"+strType+"')";
	var strTimeName=setTimeout(ss,nMin*60000);

}



/****************************************************************************
*设计人  ：傅巍                                                              *
*时间    ：2002-03-15                                                        *
*传入参数：0：24小时；1：18:00——6:00；2：6:00——18:00                       *
*传出参数：                                                                  *
*功能说明：把传入的4位时间数字转换成tt:ss的5位标准时间格式，并进行4舍5入         *
*算法说明：                                                                  *
*修改记录：                                                                  *
*****************************************************************************/
function fFormatTime(that,type)
{

    var strTime = that.value;

    //如果已经是标准的5位时间格式，则不进行其它处理
    if (strTime.length == 5)
    {
        return;
    }

    //如果是''，则不进行其它处理
    if (strTime == '')
    {
        return;
    }

    //排除异常的输入格式
    if ( (strTime.length < 4) || (strTime.indexOf(":") >= 0) || (strTime.substring(2,5) > "60") )
    {                                                                

        alert("您输入的时间不正确，请核实。");
   	    that.value = "";
		return;
    }


    //校验输入的时间是否在0000——2400之间，并且位数必须是4位
    if ( (strTime < "0000") || (strTime > "2400") )
    {
        alert("您输入的时间不正确，请重新输入。");
        that.value = "";
        return;
    } 


    if (type == 1)
    {

        //校验输入的时间是否在1800——0600之间，并且位数必须是4位
        if ( (!((strTime >= "1800" && strTime <= "2400") || (strTime >= "0000" && strTime <= "0600"))) )
        {
            alert("您输入的夜时间不正确，请重新输入。");
    	    that.value = "";
            return;
        } 
    }
    else if (type == 2)
    {
 
        //校验输入的时间是否在0600——1800之间，并且位数必须是4位
        if ( (strTime < "0600") || (strTime > "1800") )
        {
            alert("您输入的日时间不正确，请重新输入。");
	        that.value = "";
            return;
        } 
    }

	strTime = fFormatTimeCommon(strTime);  //进行时间的公共处理处理

    //把传入的4位时间数字转换成tt:ss的5位标准时间格式(ttss——>tt:ss)
    that.value = strTime.substring(0,2) + ":" + strTime.substring(2,4);
}



/****************************************************************************
*设计人  ：傅巍                                                              *
*时间    ：2002-06-04                                                        *
*传入参数：4位的时间                                                          *
*传出参数：                                                                  *
*功能说明：对4位的时间进行处理                                                *
*算法说明：                                                                  *
*修改记录：                                                                  *
*****************************************************************************/
function fFormatTimeCommon(strTime)
{

	strTime = fRoundTime(strTime);  //对时间进行四舍五入

	if (strTime.substring(0,2) == '24')    //如果时间是24点——>0点
	{
		strTime = "00" + strTime.substring(2,strTime.length);
	}

	return strTime;  
}





/****************************************************************************
*设计人  ：傅巍                                                              *
*时间    ：2002-04-26                                                        *
*传入参数：4位时间                                                           *
*传出参数：                                                                  *
*功能说明：把传入的4位时间数字进行4舍5入                                       *
*算法说明：                                                                  *
*修改记录：                                                                  *
*****************************************************************************/
function fRoundTime(strTime)
{

    //对输入的时间(分)进行4舍5入
    if (strTime.substring(3,4) < 5)  //4舍
    {
		strTime = strTime.substring(0,3) + '0';
    }
	else  //5入
    {
		//如果10分位 < 5，则4舍；如果10位分是5则小时需进位，分变为00
        if (strTime.substring(2,3) < 5)  //10秒
        {
//alert("10分位 < 5：" + strTime.substring(2,3));
			var Temp = parseInt(strTime.substring(2,3)) + 1;  //取10分
            strTime = strTime.substring(0,2) + Temp + '0';
        }
		else  //如果10分是5则小时需进位
        {
			var a = strTime.substring(0,2);

			var Temp = strTime.substring(0,2) * 1 + 1;  //取小时

			Temp = Temp + "";

			if (Temp.length < 2)  //如果小时的长度 < 2，前面需要补0
			{
				Temp = "0" + Temp;
			}

            strTime = Temp + '00';
		}
	}

	return strTime;  

}