function alphaNumOnly(e,pType,pUpperCaseOnly){ // onKeyPress="return alphaNumOnly(event,'alphanum')" var unicode=e.charCode? e.charCode : e.keyCode var flag = 1 //allow if (unicode!=8 && unicode!=13 && unicode!=9){ //if the key isn't the backspace,enter,tab key (which we should allow) switch(pType){ case 'numeric' : if (unicode < 48 || unicode > 57) flag = 0 break; case 'alphabet' : if (pUpperCaseOnly == true){ if (unicode < 65 || unicode > 90) flag = 0 }else{ if (unicode < 65) flag = 0 else if (unicode > 90){ if (unicode < 97 || unicode > 122) flag = 0 } } break; case 'alphanum' : if (unicode < 48) flag = 0 else if (unicode > 57){ if (pUpperCaseOnly == true){ if (unicode < 65 || unicode > 90) flag = 0 }else{ if (unicode < 65) flag = 0 else if (unicode > 90){ if (unicode < 97 || unicode > 122) flag = 0 } } } break; } } if (flag==0)return false //disable key press } function fNextFocus(ev,pObj){ if (pObj){ if (ev.keyCode==13){ if (pObj.disabled!=true && pObj.style.visibility!='hidden' && pObj.style.display!='none') pObj.focus(); } /*if (pObj.disabled==true || pObj.style.visibility=='hidden'){ alert() pObj.fireEvent('onkeyup'); }*/ } } function fBeforeNextFocus(ev,pObj){ return true } /* function untuk input */ g_keep_old_data_status=2; g_old_data=""; function fKeepOldData(p_obj){ if (g_keep_old_data_status==2) { g_old_data=p_obj.value } } function fRestoreOldData(p_obj){ if (g_keep_old_data_status==0) { p_obj.value=g_old_data; g_keep_old_data_status=2; } } function fGetNC(pIsSubmit,pModule,pField,pStatus,pObj,pObjNext,pOption,pFunction, pAdditionalUrlParam){ url='modal_'+pModule+'_get.php?p_id='+pObj.value+'&'+pField+'='+((pOption==undefined || pOption=="")?pObj.value:pOption.value)+'&p_status=edit'+((pAdditionalUrlParam==undefined || pAdditionalUrlParam=="")?'':pAdditionalUrlParam); lWindow=show_modal(url, 'dialogwidth:800px;dialogheight:600px;dialogleft:'+getCenterX(800)+';dialogtop:'+getCenterY(600)+';',function (pValue) { if (pIsSubmit){ if (pObjNext!=null && document.form1.hidden_focus) { document.form1.hidden_focus.value="document.form1."+pObjNext.name+".focus();"; } if (document.form1.status){ document.form1.status.value=pStatus; } document.form1.submit(); } else { pObjNext.focus(); } if (pFunction) pFunction(); }); lWindow.objectReturn=pObj } function fGetWC(pIsSubmit,pModule,pModuleName,pField,pStatus,pObj,pObjNext,pOption,pFunction, pAdditionalUrlParam){ if (fConfirm(pModule,pModuleName)) { url='modal_'+pModule+'_get.php?p_id='+pObj.value+'&'+pField+'='+((pOption==undefined || pOption=="")?pObj.value:pOption.value)+'&p_status=edit'+((pAdditionalUrlParam==undefined || pAdditionalUrlParam=="")?'':pAdditionalUrlParam); lWindow=show_modal(url, 'dialogwidth:800px;dialogheight:600px;dialogleft:'+getCenterX(800)+';dialogtop:'+getCenterY(600)+';',function (pValue) { if (pIsSubmit){ if (pObjNext!=null && document.form1.hidden_focus) { document.form1.hidden_focus.value="document.form1."+pObjNext.name+".focus();"; } if (document.form1.status){ document.form1.status.value=pStatus; } document.form1.submit(); } else { pObjNext.focus(); } if (pFunction) pFunction(); }); lWindow.objectReturn=pObj } } function fChangeTextWC(pModule,pModuleName,pStatus,pObjNext){ if (fConfirm(pModule,pModuleName)) { document.form1.hidden_focus.value="document.form1."+pObjNext.name+".focus();"; document.form1.status.value=pStatus document.form1.submit(); } } function fConfirm(pModule,pCaption){ lConfirm=confirm('Data will be reset, if you change '+pCaption+'?'); if(lConfirm){ if (lObj=eval("document.form1.table_input_table_"+pModule+"_isi")){ lObj.value=""; } } return lConfirm } function fChangeText(pStatus,pObjNext){ document.form1.hidden_focus.value="document.form1."+pObjNext.name+".focus();"; document.form1.status.value=pStatus document.form1.submit(); } function stripquote(pText){ if (pText.charAt(0)=="\"")return pText.substring(1,pText.length-1) else return pText } function dateFormat(pDate,param){ if (param=="" || param==undefined){ lDate = pDate.substr(0,10) lDate = lDate.split('-') return lDate[2]+'/'+lDate[1]+'/'+lDate[0] }else if (param=="/"){ lDate = pDate.split('/') return lDate[2]+'/'+lDate[1]+'/'+lDate[0] } } function addSeparator(num,thousand,decimal){ // separator untuk number format num += ''; x = num.split(decimal); x1 = x[0]; x2 = x.length > 1 ? decimal + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + thousand + '$2'); } return x1 + x2; } function number_format(num,dec,negative){ //====================================================new // if (num=='')num=0; // temp = num.toString().split(',') // temp[0] = temp[0].toString().replace(/\$|\./g,''); // temp[1] = '0.'+temp[1] // point = (dec)? 2 : 0 // temp[1] = parseFloat(temp[1]).toFixed(point) // num = parseFloat(temp[0]) + parseFloat(temp[1]) // num = num.toFixed(point).toString().replace(/\$|\./g,','); // num = addSeparator(num,'.',',') // return num // return (negative)?'-'+(num):(num) return number_format2(num,dec,'','id') // pake function baru lebih flexibel bs en/id //===================================================old // //num = num.toString().replace(/\$|\,/g,''); // if (isNaN(num)) // num = "0"; // sign = (num == (num = Math.abs(num))); // num = Math.floor(num*100+0.50000000001); // cents = num%100; // num = Math.floor(num/100).toString(); // if (cents<10) // cents = "0" + cents; // for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) // num = num.substring(0,num.length-(4*i+3))+'.'+ // num.substring(num.length-(4*i+3)); // cents = (dec)? ',' + cents : "" // //return (((sign)?'Rp ' + num + cents : 'Rp('+ num + cents +')')); // return (negative)?'-'+(num + cents):(num + cents) // //return (num + cents) //===================================================end } function detect_region_number_format(str){ // nyari region number format region = "DEFAULT_NUMBER_FORMAT_REGION"; x = str.toString().split(',') // split by , => klo length > 2 region en, klo == 2 region id if (x.length > 2)region = 'en' else if (x.length == 2){ if (x[1].length <= 2)region = 'id' else if (x[1].length > 2)region = 'en' }else { x = str.toString().split('.') //split by . => klo length = 2 region en, klo > 2 region id if (x.length > 2) region = 'id' else if (x.length == 2){ if (x[1].length <= 2)region = 'en' else if (x[1].length == 3)region = 'id' else region = 'en' } } return region } function normalize_number_format(str,from){ // di jadiin default inggris tanpa number format if (typeof from === 'undefined' || !from) from = detect_region_number_format(str) //regex if (from=='id') var lRegExpEraseNumFormat=/(\.|\,00)/gi else if (from=='en') var lRegExpEraseNumFormat=/(\,|\.00)/gi str = str.toString().replace(lRegExpEraseNumFormat,"") if (from=='id')str = str.replace(',','.') return str } function number_format2(num,dec,from,to){//id => indonesia, en => english //pake config utk ngambil parameter //to !== undefined => ngecek ada isi gak, true klo ada isi, false klo gak ada isi //typeof to === 'undefined' || !to => ngecek ada isi gak, klo gak ada dy true, klo ada false //ngecek ada isi gak param from dan to nya var float = /\D\.\d{1,2}/g if (typeof to === 'undefined' || !to) to = 'DEFAULT_NUMBER_FORMAT_REGION' if (typeof from === 'undefined' || !from) from = detect_region_number_format(num) if (typeof dec === 'undefined') dec = true if (typeof num === 'undefined' || !num) num = 0 // param decimal point nya point = (dec)? 2 : 0 //dijadiin default dulu num = normalize_number_format(num,from) if (num.match(float)!=null)num = 0 //di set decimal point nya num = parseFloat(num).toFixed(point) if (to=='id'){thousand='.';decimal=',';num = num.toString().replace('.',',')} else if (to=='en'){thousand=',';decimal='.';} num = addSeparator(num,thousand,decimal) return num } function convert_data(pText){ var txt = new Array var c = 0 var start = 0 var end = 0 var flag = 0 var temp = "" txt[c]="" if (pText.charAt(0)=="("){ var str = pText.substring(1,(pText.length)-1) }else{ var str = pText } for(i=0;i<=str.length;i++){ if (str.charAt(i)==','){ if (str.charAt(i-1)=='\"' && str.charAt(i+1)=='\"'){ // klo char 1 adalah tnda petik c++ txt[c]="" }else if (txt[c].charAt(0)!='\"'){ c++ txt[c]="" }else if (txt[c].charAt(0)=='\"' && str.charAt(i-1)=='\"'){ c++ txt[c]="" }else if (txt[c].charAt(0)=='\"' && str.charAt(i-1)!='\"'){ txt[c]+=str.charAt(i) } }else{ txt[c]+=str.charAt(i) } } return txt } function getDateOfNextDay(datestring, separator, nozero,jump) { if (!separator) { separator="/";//="yyyy-dd-mm" format } var a_date = datestring.split(separator); var myday = new Date(a_date[1]+'/'+a_date[0]+'/'+a_date[2]); myday.setDate(myday.getDate()+parseInt(jump)); var next_day_year = myday.getFullYear(); var next_day_month = myday.getMonth()+1; if (!nozero) { next_day_month = (parseInt(next_day_month)<10)?"0"+next_day_month:next_day_month; } var next_day_day = myday.getDate(); next_day_day = (parseInt(next_day_day)<10)?"0"+next_day_day:next_day_day; return next_day_day+"/"+next_day_month+"/"+next_day_year; } function dateDiffer(a,b,c,d){//a start date, b end date, c where to show the result by innerHTML, d show the result by value lDate = a.value.split('/') startD = lDate[2]+'/'+lDate[1]+'/'+lDate[0] lDate = b.value.split('/') endD = lDate[2]+'/'+lDate[1]+'/'+lDate[0] var start = new Date(startD) //Month is 0-11 in JavaScript var end = new Date(endD) //Month is 0-11 in JavaScript //Get 1 day in milliseconds var one_day=1000*60*60*24 //Calculate difference btw the two dates, and convert to days diff = (Math.ceil((start.getTime()-end.getTime())/(one_day))) if (b.value!=""){ if (diff>=0){text = " Hari Lagi ch. 1k"} else {diff=diff*(-1); text = " Hari Terlambat"} } if (c!="")c.innerHTML = diff+text else if (d!="")d.value = diff+text else return diff } function timeDiffer(pStart,pEnd){ start = new Date( pStart ) end = new Date( pEnd ) temp = Date.parse(end) - Date.parse(start) var day = 1000*60*60*24 var hour = 1000*60*60 var min = 1000*60 var sec = 1000 result = new Array() total_day=0 total_hour=0 total_min=0 total_sec=0 while(temp >= 1000){ if (temp >= hour){ total_hour = temp / hour total_hour = Math.floor(total_hour) temp = temp - (total_hour * hour) }else if (temp >= min){ total_min = temp / min total_min = Math.floor(total_min) temp = temp - (total_min * min) }else if (temp >= sec){ total_sec = temp / sec total_sec = Math.floor(total_sec) temp = temp - (total_sec * sec) } } result[0] = total_hour result[1] = total_min result[2] = total_sec return result } function roundTo (pValue,pTo){ lValue = parseFloat(pValue) lTo = parseFloat(pTo) lMod = lValue % lTo if (lMod < lTo && lMod > 0)return ( lValue - lMod ) + lTo else if (lMod > lTo) return ( lValue - lMod ) + ( lTo * 2 ) else return lValue }