//四舍五入
Number.prototype.toFixed=function(len)
{
var add = 0;
var s,temp;
var s1 = this + "";
var start = s1.indexOf(".");
if(s1.substr(start+len+1,1)>=5)add=1;
var temp = Math.pow(10,len);
s = Math.floor(this * temp) + add;
return s/temp;
}
function ForDight1(Dight,How){
 if(Dight.toString().split(".").length==2){
   if(Dight.toString().split(".")[1].length>0){
     Dight=(Dight*Math.pow(10,How)/Math.pow(10,How)).toFixed(How);
   }
  }
 return Dight;
}
function ForDight2(Dight,How){
 Dight  =Math.round (Dight*Math.pow(10,How))/Math.pow(10,How);
 return  Dight;
}
//建议使用第一种ForDight1()，原加JS用二进制计算
function cknum(pname){
	 var ck=document.all.item(pname).value;
	 var ck_gz=new RegExp("^[0-9]*$");
	 if(ck_gz.test(ck)==false){
	  alert('请输入数字!');
	  document.all.item(pname).focus();
	  return false;
	 }
	 else 
	  return true;
}

function left_menu(meval,sn)
    {
      var left_n=eval(meval);

      if (left_n.style.display=="none")
         { eval(meval+".style.display='';"); 
           document.all.item(sn).innerHTML='隐藏';
         }
      else
         { eval(meval+".style.display='none';"); 
           document.all.item(sn).innerHTML='查询';
         }
     }
function gtrim(ck){
 var temp=document.all.item(ck);
 if(temp.value.replace(/(^\s*)|(\s*$)/g,'').length==0){
   temp.value="";
   temp.focus();
   alert('不能为空！');
   return false;
 }else{
   temp.value=temp.value.replace(/(^\s*)|(\s*$)/g,'');
   return true;
  }
}
//从身份证取生日
function tobirthday(val,item){
    if(val.length==15){
     var temp=val.substring(0,6)+"19"+val.substring(6,val.length);
     var birthday=temp.substring(6,10)+"-"+temp.substring(10,12)+"-"+temp.substring(12,14);
     document.all.item(item).value=birthday;
    }else if(val.length==18){
     var birthday=val.substring(6,10)+"-"+val.substring(10,12)+"-"+val.substring(12,14);
     document.all.item(item).value=birthday;
    }
   }
//算年龄
function toage(val,item){
    var birthday="";
    if(val.length==15){
     var temp=val.substring(0,6)+"19"+val.substring(6,val.length);
     birthday=temp.substring(6,10)+"-"+temp.substring(10,12)+"-"+temp.substring(12,14);
     //document.all.item(item).value=birthday;
    }else if(val.length==18){
     birthday=val.substring(6,10)+"-"+val.substring(10,12)+"-"+val.substring(12,14);
     //document.all.item(item).value=birthday;
    }
    var n1=birthday.substring(0,4);
    var now=new Date();
    var n2=now.getYear();
    if(n2!=(n2-n1)){
      if(String(n2-n1)!="NaN")document.all.item(item).value=n2-n1;
    }
   }
function getRadioValue(radioName){
   var obj = document.getElementsByName(radioName);
   for(i=0; i<obj.length;i++){
     if(obj[i].checked){
       return obj[i].value;
     }
   }
   return "none";
}
function checkEmail(email) {
               var emailStr=document.all.item(email).value;
               if (emailStr.length == 0) {
                   return true;
               }
               var emailPat=/^(.+)@(.+)$/;
               var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
               var validChars="\[^\\s" + specialChars + "\]";
               var quotedUser="(\"[^\"]*\")";
               var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
               var atom=validChars + '+';
               var word="(" + atom + "|" + quotedUser + ")";
               var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
               var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
               var matchArray=emailStr.match(emailPat);
               if (matchArray == null) {
                   alert("EMAIL is error!");
                   document.all.item(email).focus();
                   return false;
               }
               var user=matchArray[1];
               var domain=matchArray[2];
               if (user.match(userPat) == null) {
                   alert("EMAIL is error!");
                   document.all.item(email).focus();
                   return false;
               }
               var IPArray = domain.match(ipDomainPat);
               if (IPArray != null) {
                   for (var i = 1; i <= 4; i++) {
                      if (IPArray[i] > 255) {
                         alert("EMAIL is error!");
                         document.all.item(email).focus();
                         return false;
                      }
                   }
                   return true;
               }
               var domainArray=domain.match(domainPat);
               if (domainArray == null) {
                   alert("EMAIL is error!");
                   document.all.item(email).focus();
                   return false;
               }
               var atomPat=new RegExp(atom,"g");
               var domArr=domain.match(atomPat);
               var len=domArr.length;
               if ((domArr[domArr.length-1].length < 2) ||
                   (domArr[domArr.length-1].length > 3)) {
                   alert("EMAIL is error!!");
                   document.all.item(email).focus();
                   return false;
               }
               if (len < 2) {
                   alert("EMAIL is error!");
                   document.all.item(email).focus();
                   return false;
               }
               return true;
            }

      function fPopUpCalendarDlg(PropertyName)
      {
        showx = event.screenX - event.offsetX -100;//- 4 - 210 ; // + deltaX;
	    showy = event.screenY - event.offsetY +18;//+ 18; // + deltaY;
	    newWINwidth = 210 + 4 + 18;
	    var retval;
	    retval = window.showModalDialog("pop.jsp", "", "dialogWidth:210px; dialogHeight:220px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes; scrollbars:no; Resizable=no; help: no; ");
	    if( retval != null )
	     {
		   document.all.item(PropertyName).value = retval;
	      }
	
       }
       
      function   CloseWindow(nd)   
      {   
        top.returnValue=document.getElementById(nd).innerHTML;   
        window.close();   
       } 
       function getTime(){
       	var ntime=getNowtime();
        document.getElementById('nowtime123').innerHTML=ntime;
        window.setTimeout("getTime()",1000);
       }
       function getNowtime(){
         var d=new Date();
	     var mon=d.getMonth()+1;
	     var date=d.getDate();
	     var h=d.getHours();
	     var minu=d.getMinutes();
	     var s=d.getSeconds();
	     var week=d.getDay();
	     var year=d.getFullYear();
	     if(String(week)=="0") week="天"
	     if(String(week)=="1") week="一"
	     if(String(week)=="2") week="二"
	     if(String(week)=="3") week="三"
	     if(String(week)=="4") week="四"
	     if(String(week)=="5") week="五"
	     if(String(week)=="6") week="六"
	     if(String(mon).length==1) mon="0"+mon;
	     if(String(date).length==1) date="0"+date;
	     if(String(h).length==1) h="0"+h;
	     if(String(minu).length==1) minu="0"+minu;
	     if(String(s).length==1) s="0"+s;
	     //document.write(d.getYear()+"年"+mon+"月"+date+"日   "+h+":"+minu+":"+s+"  星期"+week);
	     var ntime=year+"年"+mon+"月"+date+"日   "+h+":"+minu+":"+s+"  星期"+week;
         return ntime;
       }
       function getTime1(){
       	var ntime=getNowtime1();
        document.getElementById('nowtime123').innerHTML=ntime;
        window.setTimeout("getTime1()",1000);
       }
       function getNowtime1(){
         var d=new Date();
	     var mon=d.getMonth()+1;
	     var date=d.getDate();
	     var h=d.getHours();
	     var minu=d.getMinutes();
	     var s=d.getSeconds();
	     var week=d.getDay();
	     var year=d.getFullYear();
	     if(String(week)=="0") week="Sunday"
	     if(String(week)=="1") week="Monday"
	     if(String(week)=="2") week="Tuesday"
	     if(String(week)=="3") week="Wednesday"
	     if(String(week)=="4") week="Thursday"
	     if(String(week)=="5") week="Friday"
	     if(String(week)=="6") week="Saturday"
	     if(String(mon).length==1) mon="0"+mon;
	     if(String(date).length==1) date="0"+date;
	     if(String(h).length==1) h="0"+h;
	     if(String(minu).length==1) minu="0"+minu;
	     if(String(s).length==1) s="0"+s;
	     //document.write(d.getYear()+"年"+mon+"月"+date+"日   "+h+":"+minu+":"+s+"  星期"+week);
	     var ntime=year+"-"+mon+"-"+date+"  "+h+":"+minu+":"+s+" "+week;
         return ntime;
       }