/* 07-May-09 12:26:10 AM add inlist to sub for $ usage inlist('RCL',['INV_RCL_IGN']) would return 1 orhterwise -1 Saturday, May 30, 2009 add setValue in dbUse for assigning value to column */ function can_u_view(){ var rightno = "guest_view"; var rightname = "ผู้เยี่ยมชมระบบ"; if ((issupervisor=="1") || (checkrights(userid,rightno,rightname,false,false) == "-1")) { return true; }else{ return false; } } function alertSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } return [myWidth,myHeight]; // window.alert( 'Width = ' + myWidth ); // window.alert( 'Height = ' + myHeight ); } function tsdnodefault(event){ if (AW.ie){ event.keyCode = 0; }else{ event.preventDefault(); event.stopPropagation(); } } function ischanged(title,obj,fldvalue,namecolumn){ /* title = "น้ำหนัก (mailcharge.kgs)" obj = txtkgs fld = mr.kgs if (lnkgs != mr.kgs){ lcupdatelog += "น้ำหนัก (mailcharge.kgs)"+char(13); lcupdatelog += " จาก : "+iif(mr.kgs =='','null',mr.kgs)+" เป็น : "+iif(lnkgs =='','null',lnkgs)+char(13); } */ var retval = ""; var newvalue,oldvalue,newtext,oldtext; if (obj.getType()=="tsdinput"){ if (obj.getControlText() != fldvalue){ retval += title + char(13); retval += " จาก : "+iif(fldvalue=="","null",fldvalue)+" เป็น : "+iif(obj.getControlText()=="","null",obj.getControlText())+char(13); } return retval; }else if(obj.getType()=="tsdnumber"){ oldvalue = iif(fldvalue=="","null",val(fldvalue)); newvalue = iif(isNaN(obj.getValue()),"null",obj.getValue()); if (oldvalue != newvalue){ retval += title + char(13); retval += " จาก : "+iif(fldvalue=="","null",fldvalue)+" เป็น : "+iif(isNaN(obj.getValue()),"null",obj.getControlText())+char(13); } return retval; }else if(obj.getType()=="tsddate"){ oldvalue = iif(obj.getYearType()=="thai",thaildate(fldvalue),engldate(fldvalue)); newvalue = obj.getControlText(); if(oldvalue != newvalue){ retval += title + char(13); retval += " จาก : "+iif(oldvalue=="","null",oldvalue)+" เป็น : "+iif(newvalue=="","null",newvalue)+char(13); } return retval; }else if(obj.getType()=="tsdlookup"){ oldvalue = fldvalue; newvalue = obj.getDataID(); if(oldvalue != newvalue){ retval += title + char(13); retval += " จาก : "+iif(oldvalue=="","null","["+oldvalue+"] "+namecolumn)+" เป็น : "+iif(newvalue=="","null","["+newvalue+"] "+obj.getControlText())+char(13); } return retval; }else if(obj.getType()=="tsdradio"){ oldvalue = fldvalue; newvalue = obj.getValue(); if(oldvalue != newvalue){ retval += title + char(13); // retval += " จาก : "+iif(oldvalue=="","null","["+oldvalue+"] "+obj.getOptionArray(oldvalue))+" เป็น : "+iif(newvalue=="","null","["+newvalue+"] "+obj.getOptionArray(newvalue))+char(13); retval += " จาก : "+iif(((oldvalue=="")||(oldvalue==0)),"null","["+oldvalue+"] "+obj.getOptionArray(oldvalue))+" เป็น : "+iif(((newvalue=="")||(newvalue==0)),"null","["+newvalue+"] "+obj.getOptionArray(newvalue))+char(13); } return retval; }else if(obj.getType()=="tsdcombo"){ oldvalue = fldvalue; newvalue = obj.getListItemID(); if(oldvalue != newvalue){ retval += title + char(13); retval += " จาก : "+iif(oldvalue=="","null","["+oldvalue+"] "+obj.getListItem(oldvalue))+" เป็น : "+iif(newvalue=="-1","null","["+newvalue+"] "+obj.getListItem(newvalue))+char(13); } return retval; }else if(obj.getType()=="tsdcheckbox"){ oldvalue = fldvalue; newvalue = iif(obj.getControlValue(),"1","0"); if(oldvalue != newvalue){ retval += title + char(13); retval += " จาก : "+iif(oldvalue=="","null",oldvalue)+" เป็น : "+iif(newvalue=="-1","null",newvalue)+char(13); } return retval; }else if(obj.getType()=="tsdedit"){ if(isNaN(namecolumn)){ if(obj.getControlText() != fldvalue){ retval += title + char(13); retval += " ไม่ได้จำครับ"+char(13); } }else{ if(obj.getControlText() != fldvalue){ retval += title + char(13); retval += " จาก : "+iif(fldvalue=="","null",replace(fldvalue,"\n",char(32)))+char(13); retval += " เป็น : "+iif(obj.getControlText()=="","null",replace(obj.getControlText(),"\n",char(32)))+char(13); } } return retval; }else{ return retval; } } function updatelog_add(lcdbname,lnid){ var cmd = "select updatewhen from "+lcdbname+" where id="+lnid; var chk = new dbUse(cmd,dsn); var updatelog = "'"+thaidatetime(chk.updatewhen)+" เพิ่มโดย "+username+" ที่เครื่อง "+nodeaddress+"'"+char(13); cmd = "update "+lcdbname+" set updatelog="+updatelog+" where id="+lnid; sqlpt(cmd,dsn); return true; } function updatelog_edit(lcdbname,getid,lcupdatelog,xupdatelog){ var cmd = "select updatewhen from "+lcdbname+" where id="+getid; var chk = new dbUse(cmd,dsn); xupdatelog = replace(xupdatelog,"\n",char(13)); updatelog = thaidatetime(chk.updatewhen)+" แก้ไขโดย "+username+" ที่เครื่อง "+nodeaddress+char(13); updatelog += lcupdatelog; updatelog += "-----------------------------------------------------------------------------------------------------------"+char(13)+xupdatelog; cmd = "update "+lcdbname+" set updatelog='"+cleanquote(updatelog)+"' where id="+getid; sqlpt(cmd,dsn); return true; } function tsdcandelete(lalist,lnid){ var lcdbname,cmd,chk,i; var retval = false; for (i=0;i0){ alert( "มีข้อมูลที่ต้องการจะลบถูกอ้างถึงในตาราง"+lalist[i][2]+" อยู่ "+chk.cnt+" รายการ\nต้องไปลบเหล่านั้นให้หมดเสียก่อนจึงจะลบข้อมูลนี้ได้" ); retval = false; break; } } return retval; } function isthaichr( lcstr ){ var i; var chkstr = "ภถคตจขชๆไำฎพฑะธณรนฯยญบฐลฟฤหฆกฏดโเฌาษสศวซงผปแฉอฮทมฒใฬฝฦ"; for (i=0;i 1){ vr.go(lnrec-1); var xx = "vr."+idcol; retid = eval(xx); }else{ retid = "-1"; } }else{ vr.go(lnrec+1); var xx = "vr."+idcol; retid = eval(xx); } return retid; } function lower(text){ return text.toLowerCase(); } function upper(text){ return text.toUpperCase(); } function tsdseries(text){ // 1,2,3,7,9,10,11, = 1-3,7,9-11 var retval = ""; var alist,i; // เอาคอมมาขวาออก if (right(text,1)==","){ text = substr(text,1,text.length-1); } // ถ้าไม่มี comma กั้นก็ return เลย if (text.indexOf(",")==-1){ return text; } // ทำ alist ให้เป็น array จาก text alist = text.split(","); retval = ""; var lastitem = 0; for (i=0;i'"+cleanquote(xx)+"'" } else { if (lcvalue.indexOf("%") != -1) { cretval = lccolname+" NOT LIKE '"+cleanquote(lcvalue)+"'"; } else { cretval = lccolname+" NOT LIKE '%"+cleanquote(lcvalue)+"%'"; } } }else{ if (lcvalue.charAt(0)=="=") { xx = lcvalue.substr(1); cretval = lccolname+"='"+cleanquote(xx)+"'" } else { if (lcvalue.indexOf("%") != -1) { cretval = lccolname+" LIKE '"+cleanquote(lcvalue)+"'"; } else { cretval = lccolname+" LIKE '%"+cleanquote(lcvalue)+"%'"; } } } return cretval; } function tsdstringwhere(lcwhere,lccolname,lcvalue){ var lcaddwhere; if(typeof(lccolname)=="object"){ lcaddwhere = ""; var lcorwhere = ""; for(var i=0;i="+lcfromvalue+" AND "+lccolname+"<="+lctovalue; }else if ((lcfromvalue != "") && (lctovalue == "")){ lcaddwhere = lccolname+">="+lcfromvalue; }else if ((lcfromvalue == "") && (lctovalue != "")){ lcaddwhere = lccolname+"<="+lctovalue; }else{ lcaddwhere = lccolname+" is null"; } return iif(lcwhere=="",lcaddwhere,lcwhere+" and "+lcaddwhere); } function tsdstrbetweenwhere(lcwhere,lccolname,lcfromvalue,lctovalue){ var lcaddwhere; lcaddwhere = ""; if ((lcfromvalue != "") && (lctovalue != "")){ lcaddwhere = lccolname+">='"+lcfromvalue+"' AND "+lccolname+"<='"+lctovalue+"'"; }else if((lcfromvalue != "") && (lctovalue == "")){ lcaddwhere = lccolname+">='"+lcfromvalue+"'"; }else if((lcfromvalue == "") && (lctovalue != "")){ lcaddwhere = lccolname+"<='"+lctovalue+"'"; }else{ lcaddwhere = lccolname+" is null"; } return iif(lcwhere=="",lcaddwhere,lcwhere+" and "+lcaddwhere); } function tsdnumberwhere(lcwhere,lccolname,lcvalue){ var lcaddwhere; if(lcvalue==""){ lcaddwhere = lccolname+" is null" }else{ if((substr(lcvalue,1,1)!= "-") && (lcvalue.indexOf("-") != -1)){ var lcsplit = lcvalue.split("-"); lcaddwhere = lccolname+">="+lcsplit[0]+" and "+lccolname+"<="+lcsplit[1]; }else if((substr(lcvalue,1,1)==">") || (substr(lcvalue,1,1)=="<")){ lcaddwhere = lccolname+lcvalue; }else if(lcvalue.indexOf(",")!=-1){ if(right(lcvalue,1)==","){lcvalue=substr(lcvalue,1,lcvalue.length-1);} lcaddwhere = lccolname+" in ("+lcvalue+")"; }else{ lcaddwhere = lccolname+"="+lcvalue; } } return iif(lcwhere=="",lcaddwhere,lcwhere+" and "+lcaddwhere); } function txtchange(lcname){ var chkobj; var txtobj; var chkval; chkobj = document.getElementById("chk"+lcname); txtobj = document.getElementById("txt"+lcname); if (txtobj.value == "") { chkobj.checked = false; } else { chkobj.checked = true; } return true; } function chkclicked(lcname){ var chkobj; var txtobj; var chkval; chkobj = document.getElementById("chk"+lcname); txtobj = document.getElementById("txt"+lcname); chkval = chkobj.checked if (chkval) { txtobj.focus(); } return true; } function spanclicked(lcname){ var chkobj; var txtobj; var chkval; chkobj = document.getElementById("chk"+lcname); txtobj = document.getElementById("txt"+lcname); chkval = chkobj.checked if (chkval) { chkobj.checked = false; } else { chkobj.checked = true; txtobj.focus(); } return true; } function disabledtext(myfield,e){ return false; } function numbersonly(myfield, e, dec) { var key; var keychar; if (window.event) key = window.event.keyCode; else if (e) key = e.which; else return true; keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true; // numbers else if ((("0123456789").indexOf(keychar) > -1)) return true; // decimal point jump else if (dec && (keychar == ".")) { myfield.form.elements[dec].focus(); return false; } else return false; } // for fox's old time sake // iif(isempty(stdata.fld('fatherid')),'-1',stdata.fld(fatherid)); function iif(what,if_true,if_false) { if (what){ return if_true; } else { return if_false; } } function isempty(what){ if (typeof(what)=="undefined"){ return true; } if (what=="undefine") { return true; } if (typeof(what)=="number"){ return (isNaN(what) || (what==0)); } if (typeof(what)=="string"){ return what=="" } return false; } function ltrim(sString) { if (sString==null){ return ""; } if (sString=="undefined"){ return ""; } while (sString.substring(0,1) == ' '){ sString = sString.substring(1, sString.length); } return sString; } function rtrim(sString) { if (sString==null){ return ""; } if (sString=="undefined"){ return ""; } while (sString.substring(sString.length-1, sString.length) == ' ') { sString = sString.substring(0,sString.length-1); } return sString; } function alltrim(sString) { if (sString==null){ return ""; } if (sString=="undefined"){ return ""; } while (sString.substring(0,1) == ' ') { sString = sString.substring(1, sString.length); } while (sString.substring(sString.length-1, sString.length) == ' '){ sString = sString.substring(0,sString.length-1); } return sString; } function left(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0,n); } function right(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } function substr(str,from,to){ if (to==null){ if (from > String(str).length){ return ''; } if (from <= 0) {from = 1;} return String(str).substring(from-1,String(str).length); }else{ if (from > String(str).length) {return '';} if (from <= 0) {from = 1;} if (from+to-1 >= String(str).length) { return String(str).substring(from-1,String(str).length) }; return String(str).substring(from-1,from+to-1); } } function numtrim(str){ var retval,retval1,tail; if (str.indexOf(".") == -1){ if (str=="") { return "0"; }else{ return str; } } else { retval = str.split("."); retval1 = retval[0]; if (retval1=="") {retval1="0";} tail = retval[1]; while (right(tail,1)=="0") { if (tail.length=0) { break; } tail = tail.substr(0,tail.length-1); } if (tail=="") { return retval1; } else { return retval1+"."+tail; } } } function cleanquote(str) { var retval; if (str=="") { return str; } retval = replace(str,"[","("); retval = replace(retval,"]",")"); retval = replace(retval,"'","\'\'"); retval = replace(retval,";",'~'); // alert( retval ); return retval; } function replace(fullString,text,by) { // Replaces text with by in string var strLength = fullString.length, txtLength = text.length; if ((strLength == 0) || (txtLength == 0)) return fullString; var i = fullString.indexOf(text); if ((!i) && (text != fullString.substring(0,txtLength))) return fullString; if (i == -1) return fullString; var newstr = fullString.substring(0,i) + by; if (i+txtLength < strLength) newstr += replace(fullString.substring(i+txtLength,strLength),text,by); return newstr; } function trans( xnumstr,xpicstr ){ var retval; var picstr = new String(xpicstr); var numstr = new String(xnumstr); var obj = new NumberFormat(numstr); if (picstr.indexOf(".") != -1) { var xx = picstr.split("."); var lnPlaces = xx[1].length; }else{ var lnPlaces = 0 } if (picstr.indexOf(",") != -1) { var lSep = true }else{ var lSep = false } obj.setPlaces(lnPlaces ); obj.setSeparators( lSep ); retval = obj.toFormatted(); return retval; } function at(what,inwhat){ if (inwhat.indexOf(what)==-1) { return 0; } return inwhat.indexOf(what)+1; } function rat(atwhat,inwhat){ var i; for (i=inwhat.length; i>=0; i--) { if (inwhat.substr(i,1) == atwhat) { return i+1; } } return -1; } function replicate(what,howmany){ var lcretval = ""; for (var i=1;i<=howmany;i++){ lcretval += what; } return lcretval; } function val(str,base){ if (typeof(str)=="number"){ return str; } if (str.indexOf(".") != -1){ if((typeof(debugging) != "undefined") && (debugging)){ alert( str+" to float" ); } return parseFloat(str); }else{ if((typeof(debugging) != "undefined") && (debugging)){ alert( str+" to int" ); } if (base== null){ return parseInt(str,10); }else{ return parseInt(str,base); } } } function str(number){ if (isNaN(number)){ return ""; } return number.toString(); } function strzero(number,len){ if (typeof(number)=="number"){ return right( '00000000000'+str(number),len ); } if (typeof(number)=="string"){ return right( '00000000000'+str(val(number)),len ); } return ''; } function iseven(num) { return !(num % 2); } function isodd(num) { return !iseven(num); } function dtos(date) { var ndate, sdate, day, month, year; if (date == ""){ return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0]); year = String(year); month = strzero(val(sdate[1]),2); day = strzero(val(sdate[2]),2); date = year+month+day; return date; } function getfiscalyear(date){ var ndate, sdate, day, month, year; if (date == ""){ return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0]); month = val(sdate[1]); year += 543; if (month>9) { year++; } return year.toString(); } function datetext(date) { if (date == ""){ return ""; } // date = 2009-08-07 12:00:00 var ndate, sdate, day, month, year; ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0]); year = String(year); month = sdate[1]; // strzero(parseInt(sdate[1]),2); // alert( date+" "+sdate[2] ); day = sdate[2]; //strzero(parseFloat(sdate[2]),2); return month+'/'+day+'/'+year; } function engsdate(date) { var ndate, sdate, day, month, year; if (date == "") { return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0]); year = String(year); month = sdate[1]; day = sdate[2]; date = day+"/"+month+"/"+right(year,2); return date; } function engldate(date) { var ndate, sdate, day, month, year; if (date == "") { return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0]); year = String(year); month = sdate[1]; day = sdate[2]; date = day+"/"+month+"/"+year; return date; } function thaisdate(date) { var ndate, sdate, day, month, year; if (date == "") { return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0])+543; year = String(year); month = sdate[1]; day = sdate[2]; date = day+"/"+month+"/"+right(year,2); return date; } function thaildate(date) { var ndate, sdate, day, month, year; if (date == "") { return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0])+543; year = String(year); month = sdate[1]; day = sdate[2]; date = day+"/"+month+"/"+year; return date; } function thaidate2text(date){ if (date==""){ return ""; } var ndate = date.split("/"); var day = ndate[0]; var month = ndate[1]; var year = str(val(ndate[2])-543); return month+"/"+day+"/"+year; } function thaidatetime( date ) { var ndate, sdate, day, month, year; if (date == "") { return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0])+543; year = String(year); month = sdate[1]; day = sdate[2]; date = day+"/"+month+"/"+year+" "+ndate[1].substr(0,8); return date; } function timepart( date ){ var ndate; if (date=="") { return ""; } ndate = date.split(" "); return ndate[1]; } function thaismdate(date) { var ndate, sdate, day, month, year, cmonth; if (date == "") { return ""; } ndate = date.split(" "); sdate = ndate[0].split("-"); year = val(sdate[0])+543; year = String(year); month = val(sdate[1]); day = sdate[2]; cmonth = athmonthshort[month-1]; date = day+" "+cmonth+""+right(year,2); return date; } function thai2sqldate(text){ if (text == "") { return ""; } var datepart = text.split("/"); var nday = datepart[0]; var nmonth = datepart[1]; var nyear = val( datepart[2])-543; if (dsn=='oracle'){ return nday+'/'+nmonth+'/'+nyear; } else { return nmonth+'/'+nday+'/'+nyear; } } function ShowDateFromTo(fromdate,todate){ var lcfrom,lcto,lnday if ((fromdate=="") && (todate=="")) { return ""; } if ((fromdate != "") && (todate != "")) { lcfrom = dtos(fromdate); lcto = dtos(todate); if ( lcfrom.substr(0,8) == lcto.substr(0,8) ) // วันเดียวกัน { return thaismdate(fromdate); } else if (lcfrom.substr(0,6) == lcto.substr(0,6)) // เดือนเดียวกัน { lnday = val(right(lcfrom,2)); return lnday.toString()+"-"+thaismdate(todate); } else if (lcfrom.substr(0,4) == lcto.substr(0,4)) { lcfrom = thaismdate(fromdate); return lcfrom.substr(0,rat(".",lcfrom)) +"-"+thaismdate(todate); } else { return thaismdate(fromdate)+"-"+thaismdate(todate); } } else if ((fromdate!="") && (todate=="")) { return thaismdate(fromdate); } else if ((fromdate=="") && (todate != "")) { return thaismdate(todate); } } function truefalse(uvalue) { if (uvalue == 1) { return true; } else { return false; } } function abs(value){ if (typeof(value)=="string"){ value = val(value); } if (value < 0) { return value*-1; }else{ return value; } } function int(number){ number = number.toString(); if (number.indexOf(".")==-1){ return number; }else{ return val(number.substr(0,number.indexOf("."))); } } function tsdround(num, dec) { // var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); var cpow = "1"+replicate('0',dec+1); var npow = val(cpow); var result = str(Math.round(num*npow)/npow); if (right(result,1)=='5'){ var added = val("0."+replicate('0',dec)+"1"); num += added; cpow = "1"+replicate('0',dec); npow = val(cpow); result = str(Math.round(num*npow)/npow); }else{ cpow = "1"+replicate('0',dec); npow = val(cpow); result = str(Math.round(num*npow)/npow); } return val(result); } function NumberFormat(num, inputDecimal) { this.VERSION = 'Number Format v1.5.4'; this.COMMA = ','; this.PERIOD = '.'; this.DASH = '-'; this.LEFT_PAREN = '('; this.RIGHT_PAREN = ')'; this.LEFT_OUTSIDE = 0; this.LEFT_INSIDE = 1; this.RIGHT_INSIDE = 2; this.RIGHT_OUTSIDE = 3; this.LEFT_DASH = 0; this.RIGHT_DASH = 1; this.PARENTHESIS = 2; this.NO_ROUNDING = -1 this.num; this.numOriginal; this.hasSeparators = false; this.separatorValue; this.inputDecimalValue; this.decimalValue; this.negativeFormat; this.negativeRed; this.hasCurrency; this.currencyPosition; this.currencyValue; this.places; this.roundToPlaces; this.truncate; this.setNumber = setNumberNF; this.toUnformatted = toUnformattedNF; this.setInputDecimal = setInputDecimalNF; this.setSeparators = setSeparatorsNF; this.setCommas = setCommasNF; this.setNegativeFormat = setNegativeFormatNF; this.setNegativeRed = setNegativeRedNF; this.setCurrency = setCurrencyNF; this.setCurrencyPrefix = setCurrencyPrefixNF; this.setCurrencyValue = setCurrencyValueNF; this.setCurrencyPosition = setCurrencyPositionNF; this.setPlaces = setPlacesNF; this.toFormatted = toFormattedNF; this.toPercentage = toPercentageNF; this.getOriginal = getOriginalNF; this.moveDecimalRight = moveDecimalRightNF; this.moveDecimalLeft = moveDecimalLeftNF; this.getRounded = getRoundedNF; this.preserveZeros = preserveZerosNF; this.justNumber = justNumberNF; this.expandExponential = expandExponentialNF; this.getZeros = getZerosNF; this.moveDecimalAsString = moveDecimalAsStringNF; this.moveDecimal = moveDecimalNF; this.addSeparators = addSeparatorsNF; if (inputDecimal == null) { this.setNumber(num, this.PERIOD); } else { this.setNumber(num, inputDecimal); } this.setCommas(true); this.setNegativeFormat(this.LEFT_DASH); this.setNegativeRed(false); this.setCurrency(false); this.setCurrencyPrefix('$'); this.setPlaces(2); } function setInputDecimalNF(val) { this.inputDecimalValue = val; } function setNumberNF(num, inputDecimal) { if (inputDecimal != null) { this.setInputDecimal(inputDecimal); } this.numOriginal = num; this.num = this.justNumber(num); } function toUnformattedNF() { return (this.num); } function getOriginalNF() { return (this.numOriginal); } function setNegativeFormatNF(format) { this.negativeFormat = format; } function setNegativeRedNF(isRed) { this.negativeRed = isRed; } function setSeparatorsNF(isC, separator, decimal) { this.hasSeparators = isC; if (separator == null) separator = this.COMMA; if (decimal == null) decimal = this.PERIOD; if (separator == decimal) { this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD; } else { this.decimalValue = decimal; } this.separatorValue = separator; } function setCommasNF(isC) { this.setSeparators(isC, this.COMMA, this.PERIOD); } function setCurrencyNF(isC) { this.hasCurrency = isC; } function setCurrencyValueNF(val) { this.currencyValue = val; } function setCurrencyPrefixNF(cp) { this.setCurrencyValue(cp); this.setCurrencyPosition(this.LEFT_OUTSIDE); } function setCurrencyPositionNF(cp) { this.currencyPosition = cp } function setPlacesNF(p, tr) { this.roundToPlaces = !(p == this.NO_ROUNDING); this.truncate = (tr != null && tr); this.places = (p < 0) ? 0 : p; } function addSeparatorsNF(nStr, inD, outD, sep) { nStr += ''; var dpos = nStr.indexOf(inD); var nStrEnd = ''; if (dpos != -1) { nStrEnd = outD + nStr.substring(dpos + 1, nStr.length); nStr = nStr.substring(0, dpos); } var rgx = /(\d+)(\d{3})/; while (rgx.test(nStr)) { nStr = nStr.replace(rgx, '$1' + sep + '$2'); } return nStr + nStrEnd; } function toFormattedNF() { var pos; var nNum = this.num; var nStr; var splitString = new Array(2); if (this.roundToPlaces) { nNum = this.getRounded(nNum); nStr = this.preserveZeros(Math.abs(nNum)); } else { nStr = this.expandExponential(Math.abs(nNum)); } if (this.hasSeparators) { nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue); } else { nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); } var c0 = ''; var n0 = ''; var c1 = ''; var n1 = ''; var n2 = ''; var c2 = ''; var n3 = ''; var c3 = ''; var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH; var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH; if (this.currencyPosition == this.LEFT_OUTSIDE) { if (nNum < 0) { if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL; if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR; } if (this.hasCurrency) c0 = this.currencyValue; } else if (this.currencyPosition == this.LEFT_INSIDE) { if (nNum < 0) { if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL; if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR; } if (this.hasCurrency) c1 = this.currencyValue; } else if (this.currencyPosition == this.RIGHT_INSIDE) { if (nNum < 0) { if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL; if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR; } if (this.hasCurrency) c2 = this.currencyValue; } else if (this.currencyPosition == this.RIGHT_OUTSIDE) { if (nNum < 0) { if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL; if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR; } if (this.hasCurrency) c3 = this.currencyValue; } nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3; if (this.negativeRed && nNum < 0) { nStr = '' + nStr + ''; } return (nStr); } function toPercentageNF() { nNum = this.num * 100; nNum = this.getRounded(nNum); return nNum + '%'; } function getZerosNF(places) { var extraZ = ''; var i; for (i=0; i= 0 ? Math.floor(val) : Math.ceil(val); } else { val = Math.round(val); } val = this.moveDecimalLeft(val); return val; } function preserveZerosNF(val) { var i; val = this.expandExponential(val); if (this.places <= 0) return val; var decimalPos = val.indexOf('.'); if (decimalPos == -1) { val += '.'; for (i=0; i= 5){ lntoround ++; } if (lntoround < 5){ lnadd = 0; } if (lntoround > 5){ lnadd = 1; } if (lntoround==5){ var lnbeforeround = parseInt( right(lnsignificant.toString(),1) ); if (iseven(lnbeforeround)){ lnadd = 0; }else{ lnadd = 1; } } // 1225 --> 12 lnretval = lnsignificant + lnadd; lcretval = lnretval.toString(); lcretval = lcretval+replicate("0",allpart.length-lcretval.length); //1225.5 // 12255 // decat = 5 if (decat != 0){ if (intpart=='0'){ lcretval = "0."+lcretval; }else{ lcretval = substr(lcretval,1,decat-1)+"."+substr(lcretval,decat); } } return parseFloat(lcretval); } } function char(num){ return String.fromCharCode(num); } shortcut = { 'all_shortcuts':{},//All the shortcuts are stored in this array 'add': function(shortcut_combination,callback,opt) { //Provide a set of default options var default_options = { 'type':'keydown', 'propagate':false, 'disable_in_input':false, 'target':document, 'keycode':false } if(!opt) opt = default_options; else { for(var dfo in default_options) { if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo]; } } var ele = opt.target; if(typeof opt.target == 'string') ele = document.getElementById(opt.target); var ths = this; shortcut_combination = shortcut_combination.toLowerCase(); //The function to be called at keypress var func = function(e) { e = e || window.event; if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields var element; if(e.target) element=e.target; else if(e.srcElement) element=e.srcElement; if(element.nodeType==3) element=element.parentNode; if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return; } //Find Which key is pressed if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; var character = String.fromCharCode(code).toLowerCase(); if(code == 188) character=","; //If the user presses , when the type is onkeydown if(code == 190) character="."; //If the user presses , when the type is onkeydown var keys = shortcut_combination.split("+"); //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked var kp = 0; //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken var shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&", "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<", ".":">", "/":"?", "\\":"|" } //Special Keys - and their codes var special_keys = { 'esc':27, 'escape':27, 'tab':9, 'space':32, 'return':13, 'enter':13, 'backspace':8, 'scrolllock':145, 'scroll_lock':145, 'scroll':145, 'capslock':20, 'caps_lock':20, 'caps':20, 'numlock':144, 'num_lock':144, 'num':144, 'pause':19, 'break':19, 'insert':45, 'home':36, 'delete':46, 'end':35, 'pageup':33, 'page_up':33, 'pu':33, 'pagedown':34, 'page_down':34, 'pd':34, 'left':37, 'up':38, 'right':39, 'down':40, 'f1':112, 'f2':113, 'f3':114, 'f4':115, 'f5':116, 'f6':117, 'f7':118, 'f8':119, 'f9':120, 'f10':121, 'f11':122, 'f12':123 } var modifiers = { shift: { wanted:false, pressed:false}, ctrl : { wanted:false, pressed:false}, alt : { wanted:false, pressed:false}, meta : { wanted:false, pressed:false} //Meta is Mac specific }; if(e.ctrlKey) modifiers.ctrl.pressed = true; if(e.shiftKey) modifiers.shift.pressed = true; if(e.altKey) modifiers.alt.pressed = true; if(e.metaKey) modifiers.meta.pressed = true; for(var i=0; k=keys[i],i 1) { //If it is a special key if(special_keys[k] == code) kp++; } else if(opt['keycode']) { if(opt['keycode'] == code) kp++; } else { //The special keys did not match if(character == k) kp++; else { if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase character = shift_nums[character]; if(character == k) kp++; } } } } if(kp == keys.length && modifiers.ctrl.pressed == modifiers.ctrl.wanted && modifiers.shift.pressed == modifiers.shift.wanted && modifiers.alt.pressed == modifiers.alt.wanted && modifiers.meta.pressed == modifiers.meta.wanted) { callback(e); if(!opt['propagate']) { //Stop the event //e.cancelBubble is supported by IE - this will kill the bubbling process. e.cancelBubble = true; e.returnValue = false; //e.stopPropagation works in Firefox. if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } return false; } } } this.all_shortcuts[shortcut_combination] = { 'callback':func, 'target':ele, 'event': opt['type'] }; //Attach the function with the event if(ele.addEventListener) ele.addEventListener(opt['type'], func, false); else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func); else ele['on'+opt['type']] = func; }, //Remove the shortcut - just specify the shortcut and I will remove the binding 'remove':function(shortcut_combination) { shortcut_combination = shortcut_combination.toLowerCase(); var binding = this.all_shortcuts[shortcut_combination]; delete(this.all_shortcuts[shortcut_combination]) if(!binding) return; var type = binding['event']; var ele = binding['target']; var callback = binding['callback']; if(ele.detachEvent) ele.detachEvent('on'+type, callback); else if(ele.removeEventListener) ele.removeEventListener(type, callback, false); else ele['on'+type] = false; } }