ERP / application /assets /jss /allscript.js
cappucaine's picture
Upload 5949 files
bae6a7c verified
Raw History Blame Contribute Delete
84.8 kB
/* * Author = Dian Hermanto * Create Date = 21 Maret 2014 * File Name = allscript.css * Function = Default page after login * Location = ./asset/js/allscript.js */ function confirmDelete() { return confirm("Are you sure you want to delete this file?"); } function validateInVendCat() { if(document.getElementById('VendCat_Name').value == '') { alert('Vendor Category can not empty.') return false; } } // Purchase Requisition function selPURRREQ_Type(myValue) { var type = document.getElementById('PURRREQ_Type').value; if(type==2) { document.getElementById('labelProject1').style.display = ''; document.getElementById('labelProject2').style.display = ''; } else { document.getElementById('labelProject1').style.display = 'none'; document.getElementById('labelProject2').style.display = 'none'; } } function doCloseChild(myChild) { if(myChild.length) { for(var i=0;i<myChild.length;i++) { if(myChild[i] && myChild[i].open && !myChild[i].closed) { myChild[i].close(); } } } } function deletecommaperiod(str,type) { var A = new Array(); if ((type=="both") || (type=="comma")) { A = str.split(","); str = A.join(""); } if ((type=="both") || (type=="period")) { A = str.split("."); str = A.join(""); } return str; } function decimalin(ini) { var i, j; var bil2 = deletecommaperiod(ini.value,'both') var bil3 = "" j = 0 for (i=bil2.length-1;i>=0;i--) { j = j + 1; if (j == 3) { bil3 = "." + bil3 } else if ((j >= 6) && ((j % 3) == 0)) { bil3 = "," + bil3 } bil3 = bil2.charAt(i) + "" + bil3 } ini.value = bil3 } function decimalin1(ini) { var i, j; var bil2 = deletecommaperiod(ini,'both') var bil3 = "" j = 0 for (i=bil2.length-1;i>=0;i--) { j = j + 1; if (j == 3) { bil3 = "." + bil3 } else if ((j >= 6) && ((j % 3) == 0)) { bil3 = "," + bil3 } bil3 = bil2.charAt(i) + "" + bil3 } return bil3; } function ReturnToNumberFormat(value) { arrNum = value.split(','); var A = arrNum.join(""); return A; } /*********************************************************************************************************************************/ // Syntax : // PopWindow(URL, Title, Width, Height, Attributes); // Example : // PopWindow('http://doweb1/satria/test.cfm','WindowName', '730', '580', 'scrollbars=yes,location=yes,status=yes'); // Attributes Parameter can be filled with following options : // toolbar=no/yes, location=no/yes, directories=no/yes, status=no/yes, menubar=no/yes, scrollbars=no/yes, resizable=no/yes function PopWindow(theUrl, theName, theWidth, theHeight) { // Updated by Bing, Oct 08, 2002 //alert(theUrl); var theAttributes = '' if(arguments[4]!=null) theAttributes = arguments[4] if (theUrl==null || theWidth==null || theHeight==null || theUrl.length==0 || theWidth.length==0 || theHeight.length==0) return false; var theLeft = Math.ceil((screen.width - 10 - theWidth) / 2); var theTop = Math.ceil((screen.height - 30 - theHeight) / 2); var varAttributes = "width="+theWidth+",height="+theHeight+",left="+theLeft+",top="+theTop; if(theAttributes.length==0) varAttributes = varAttributes + ",toolbar=0,location=0,directories=0,status=0,menubar=-0,scrollbars=1,resizable=1"; else varAttributes = varAttributes + "," + theAttributes; return window.open(theUrl, theName, varAttributes); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (trimkarakter(document.formname.formfield.value).length == 0) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } function trimkarakter(str) { var i, j, k, hasil, tamp; if (str.length == 0) return str; hasil = ""; tamp = ""; i = 0; do { if (str.charAt(i) == " ") { tamp = str.charAt(i); i++; } else tamp = '%'; } while (tamp == " "); j = str.length - 1; do { if (str.charAt(j) == " ") { tamp = str.charAt(j); j--; } else tamp = '%'; } while (tamp == " "); for (k=i;k<=j;k++) hasil = hasil + str.charAt(k); return hasil; } function deletespaces(str) { var A = new Array(); A = str.split("\n"); str = A.join(""); A = str.split(" "); str = A.join(""); A = str.split("\t"); str = A.join(""); return str; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // spec_char = ""; Fill in with 'not allowed' Special Character, blank to use default; // if (!check_spec_char(document.formname.formfield.value,spec_char) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } /* function check_spec_char(object_value,spec_char) { if (object_value.length == 0) return true; if (spec_char == null) return false; if (spec_char.length == 0) spec_char = '~`/-!$#%^&*()+={}[]|\\:;"\'<,>?'; var check; for (var i = 0; i < object_value.length; i++) { check = spec_char.indexOf(object_value.charAt(i)); if (check > 0) return false; else if (check == 0) return false; } return true; } */ function check_spec_char(object_value,spec_char) { /* if (object_value.length == 0) return true; if (spec_char == null) return false; */ if (spec_char.length == 0) spec_char = '~`/-!$#%^&*()+={}[]|\\:;"\'<,>?'; var check; for (var i = 0; i < object_value.length; i++) { check = spec_char.indexOf(object_value.charAt(i)); if (check >= 0) { return true; } //else if (check == 0) //return false; } return false; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function selectunselect(object_value) { for (var i=0;i<object_value.length;i++) //object_value[i].checked = (object_value[i].checked == true ? false : true); object_value[i].checked = object_value[0].checked; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // allow_char = ""; Fill in with 'allowed' Regular Expression; // if (ValidateAny(document.formname.formfield.value,allow_char)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function for 'User Defined' Regular Expression //'^[a-zA-Z]([ ]|[\][a-zA-Z])*$' function ValidateAny(object_value,any_format) { if (any_format == null) return false; if (any_format.length == 0) return false; any_pattern = new RegExp(any_format); return object_value.search(any_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateLocNat(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept string that begins with a letter, // may follow by space or letters(a-zA-Z). // Use this function usually to check Province/State input like : DKI Jakarta. function ValidateLocNat(object_value) { locnat_pattern=new RegExp('^[a-zA-Z]([ ]?[a-zA-Z])+$'); return object_value.search(locnat_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateUser(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept string that begin with a letter, // followed by letters(a-zA-Z) or numbers(0-9) or underscore(_) and no spaces function ValidateUser(object_value) { user_pattern=new RegExp('^[a-zA-Z]([a-zA-Z]|[_0-9])*$'); return object_value.search(user_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateString(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept only string[a-zA-Z] function ValidateString(object_value) { string_pattern=new RegExp('^[a-zA-Z]+$'); return object_value.search(string_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateNumber(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept only positif numeric value[0-9] function ValidateNumber(object_value) { num_pattern=new RegExp('^[0-9]+$'); return object_value.search(num_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateEmail(document.formname.formfield.value) // { // alert("Wrong Email Syntax!!"); // document.formname.formfield.focus(); // } // Use this function to accept a valid email address // This function is using 'allowed' character. function ValidateEmail(object_value) { email_pattern=new RegExp('^[a-zA-Z0-9]+(([_]|\\.|-)?[a-zA-Z0-9])*@([a-zA-Z0-9]+([_]|-?[a-zA-Z0-9])*(\\.))+[a-zA-Z]{2,4}$'); return object_value.search(email_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidatePhone(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a phone number // Example : 62.21.5296440 // Still have some bugs in this function. Don't use it first function ValidatePhone(object_value) { phone_pattern=new RegExp('^[^\']*$'); return object_value.search(phone_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function check_many_phone(txt) { var friendList = new Array() friendList = eval("txt").split(','); for (var i=0;i<friendList.length;i++) { if (ValidatePhone(friendList[i])) return false; } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateStringNumSpace(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a string and number and spaces function ValidateStringNumSpace(str) { locnatpattern=new RegExp('^[a-zA-Z0-9]([ ]?[a-zA-Z0-9])+$'); return str.search(locnatpattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateStringNum(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a string and number function ValidateStringNum(str) { membernamepattern=new RegExp('^[a-zA-Z0-9]*$'); return str.search(membernamepattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateCurrency(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a currency format function ValidateCurrency(txt) { currency_pattern=new RegExp('^[0-9]*(([.]|[,])?[0-9])+$'); return txt.search(currency_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateDecimal(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a decimal number format function ValidateDecimal(txt) { currency_pattern=new RegExp('^[0-9]*[\.]([0-9]{1,2}$)|[0-9]+$'); return txt.search(currency_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateDecimalNum(document.formname.formfield.value,3)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a decimal number format - r function ValidateDecimalNum(txt,num) { currency_pattern=new RegExp('^[0-9]*[\.]([0-9]{1,'+num+'}$)|[0-9]+$'); return txt.search(currency_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (ValidateAddress(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a valid address // Example : - St. Dreamland Avenue blk.37 #25-28 // - PT. Esprit de Corp. // - PT. Seven Up, ltd. function ValidateAddress(object_value) { address_pattern=new RegExp('^[a-zA-Z0-9]([a-zA-Z\&\,\.\#\-\:]|[0-9 ])*$'); return object_value.search(address_pattern); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (!check_creditcard(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a valid credit card number function check_creditcard(object_value) { var white_space = " -"; var creditcard_string = ""; var check_char; if (object_value.length == 0) return true; for (var i = 0; i < object_value.length; i++) { check_char = white_space.indexOf(object_value.charAt(i)) if (check_char < 0) creditcard_string += object_value.substring(i, (i + 1)); } if (creditcard_string.length == 0) return false; if (creditcard_string.charAt(0) == "+") return false; if (!check_integer(creditcard_string,"")) return false; var doubledigit = creditcard_string.length % 2 == 1 ? false : true; var checkdigit = 0; var tempdigit; for (var i = 0; i < creditcard_string.length; i++) { tempdigit = eval(creditcard_string.charAt(i)) if (doubledigit) { tempdigit *= 2; checkdigit += (tempdigit % 10); if ((tempdigit / 10) >= 1.0) { checkdigit++; } doubledigit = false; } else { checkdigit += tempdigit; doubledigit = true; } } return (checkdigit % 10) == 0 ? true : false; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // int_format = ""; Fill in with 'allowed' Integer Format // if (!check_integer(document.formname.formfield.value,int_format)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a valid Integer Format // If number_format is not blank (not ""), the function will use the defined number_format // If number_format is blank (""), the function will use following format : // The number value can be +/- number. // Example : -3, +62, 62. function check_integer(object_value,int_format) { if (object_value.length == 0) return true; if (int_format == null) return false; var decimal_format = "."; var check_char; if (int_format.length != 0) { for(var i=0;i<object_value.length;i++) { check = int_format.indexOf(object_value.charAt(i)); if(check == -1) return false; } } else { check_char = object_value.indexOf(decimal_format) if (check_char < 0) return check_number(object_value,""); else return false; } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // number_format = ""; Fill in with 'allowed' Number Format // if (!check_number(document.formname.formfield.value,number_format)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a valid Number Format // If number_format is not blank (not ""), the function will use the defined number_format // If number_format is blank (""), the function will use following format : // The number value can be +/- number, decimal number. // Example : -3, -3.25, +62, 62, 62.5, 62500.2 function check_number(object_value,number_format) { if (object_value.length == 0) return true; if (number_format == null) return false; if (number_format.length != 0) { for(var i=0;i<object_value.length;i++) { check = number_format.indexOf(object_value.charAt(i)); if(check == -1) return false; } } else { var start_format = " .+-0123456789"; var number_format = " .0123456789"; var check_char; var decimal = false; var trailing_blank = false; var digits = false; check_char = start_format.indexOf(object_value.charAt(0)) if (check_char == 1) decimal = true; else if (check_char < 1) return false; for (var i = 1; i < object_value.length; i++) { check_char = number_format.indexOf(object_value.charAt(i)) if (check_char < 0) return false; else if (check_char == 1) { if (decimal) return false; else decimal = true; } else if (check_char == 0) { if (decimal || digits) trailing_blank = true; } else if (trailing_blank) return false; else digits = true; } } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (!number_range(document.formname.formfield.value,min_value,max_value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a Number in a range format between min_value and max_value // Return True if the number is min_value, max_value, or between the range. // Example : number_range(document.formname.formfield.value,1,3) // It will return true if the value is 1,2,3. function number_range(object_value, min_value, max_value) { if (object_value.length == 0) return true; if (min_value == null) return false; if (max_value == null) return false; if (!check_number(object_value,"")) { return false; } else { if (min_value != null) if (object_value < min_value) return false; if (max_value != null) if (object_value > max_value) return false; } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // This function is deprecated. Use ValidateEmail instead. //function check_email(mail) //{ //mailpatern = new RegExp('^[a-zA-Z]+(([_]|\\.)?[a-zA-Z0-9])*@([a-zA-Z0-9]+([_]?[a-zA-Z0-9])*(\\.))+[a-zA-Z]{2,4}$'); //mailpatern = new RegExp('^[a-zA-Z]+(([_]|\\.)?[a-zA-Z0-9_-])*@([a-zA-Z0-9_-]+([_]?[a-zA-Z0-9-_])*(\\.))+[a-zA-Z]{2,4}$'); //mailpattern = new RegExp('^[^0-9-()<>:?&*!~`=|#$%]+@[^#$%]*(\\.)+[^#$%]{2,4}$'); // mailpattern = new RegExp('^[a-zA-Z]+(([_]|\\.|-)?|[a-zA-Z0-9])*@([a-zA-Z0-9]+([_]?[a-zA-Z0-9])*(\\.))+[a-zA-Z]{2,4}$'); // return mail.search(mailpattern); //} /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (!check_email(document.formname.formfield.value)) // { // alert("Fill in the field"); // document.formname.formfield.focus(); // } // Use this function to accept a valid Email Address // This is the other way to describe a valid Email Address // This function is using 'not allowed' characters. function check_email(emailad) { var a = emailad.split(";") var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/; var check=/@[\w\-]+\./; var checkend=/\.[a-zA-Z]{2,3}$/; for(var i=0;i<a.length;i++) { emailad = a[i]; if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)) return false } return true } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // var Ext = 'gif*jpg*GIF*JPG'; //Separated by * // if (!check_ext(document.formname.formfield.value,valid_ext)) // { // alert("Wrong extension"); // document.formname.formfield.focus(); // } // Use this function to accept an allowed file upload extension. function check_ext(Path, Ext) { if (Ext == null) return false; var arrPathExt = new Array(); arrPathExt = Path.split('.'); var PathExt = arrPathExt[arrPathExt.length-1]; var arrRightExt = new Array(); arrRightExt = Ext.split('*'); var ExtIsRight = false; for (i=0; i<arrRightExt.length; i++) ExtIsRight = ExtIsRight || (PathExt==arrRightExt[i]); return ExtIsRight; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // if (!checkFriend(document.formname.formfield.value)) // { // alert("Invalid Email Address in the list!"); // document.formname.formfield.focus(); // } // Use this function to check a valid Email Address in the list(textarea) // Email address separated by semicolon (;) // Example : mailme@anywhere.com;replyme@soon.com function checkFriend(txt) { var friendList = new Array() friendList = eval("txt").split(';'); for (var i=0;i<friendList.length;i++) { if (ValidateEmail(friendList[i])) return false; } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function TotDayInMonth(intMonth,intYear) { if((intMonth == 1) || (intMonth == 3) || (intMonth == 5) || (intMonth == 7) || (intMonth == 8) || (intMonth == 10) || (intMonth == 12)) return 31; else if ((intMonth == 4) || (intMonth == 6) || (intMonth == 9) || (intMonth == 11)) return 30; else if (intMonth == 2) return (((intYear % 4) == 0) ? 29 : 28); } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function check_date(object_value,varsplit) { /*if (ValidateDate(object_value)) return false; */ if (varsplit == null) return false; /*if (varsplit.length == 0) varsplit = "/";*/ var inpDate = new Array(); inpDate = object_value.split(varsplit); var buildmonth = inpDate[0]; var builddate = inpDate[1]; var buildyear = inpDate[2]; if (inpDate.length < 3) return false; if (ValidateNumber(buildmonth)) return false; if (ValidateNumber(builddate)) return false; if (ValidateNumber(buildyear)) return false; var d = new Date(); var Nowyear = d.getYear(); var Nowhour = d.getHours(); var Nowmin = d.getMinutes(); var Nowsec = d.getSeconds(); var maxday = TotDayInMonth(inpDate[0],inpDate[2]); buildmonth = eval(buildmonth) - 1; var TimeNow = new Date(buildyear,buildmonth,builddate,Nowhour,Nowmin,Nowsec); if (TimeNow == d) return false; if (inpDate[0] == 00 || inpDate[0] > 12) return false; if (inpDate[1] == 00 || inpDate[1] > maxday) return false; if (inpDate[2] == 0000 || inpDate[2].length < 4) return false; //if (inpDate[2] == 0000 || inpDate[2] > Nowyear) return false; return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function check_datebackforward(object_value,varsplit) { /*if (ValidateDate(object_value)) return false; */ if (varsplit == null) return false; if (varsplit.length == 0) varsplit = "/"; var inpDate = new Array(); inpDate = object_value.split(varsplit); var buildmonth = inpDate[0]; var builddate = inpDate[1]; var buildyear = inpDate[2]; if (inpDate.length < 3) return false; if (ValidateNumber(buildmonth)) return false; if (ValidateNumber(builddate)) return false; if (ValidateNumber(buildyear)) return false; var d = new Date(); var Nowyear = d.getYear(); var Nowhour = d.getHours(); var Nowmin = d.getMinutes(); var Nowsec = d.getSeconds(); var maxday = TotDayInMonth(inpDate[0],inpDate[2]); buildmonth = eval(buildmonth) - 1; var TimeNow = new Date(buildyear,buildmonth,builddate,Nowhour,Nowmin,Nowsec); if (TimeNow == d) return false; if (inpDate[0] == 00 || inpDate[0] > 12) return false; if (inpDate[1] == 00 || inpDate[1] > maxday) return false; if (inpDate[2] == 0000 || inpDate[2] > Nowyear) return false; return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function check_date_tomorrowonly(object_value,varsplit) { /*if (ValidateDate(object_value)) return false; */ if (varsplit == null) return false; if (varsplit.length == 0) varsplit = "/"; var inpDate = new Array(); inpDate = object_value.split(varsplit); var buildmonth = inpDate[0]; var builddate = inpDate[1]; var buildyear = inpDate[2]; if (inpDate.length < 3) return false; if (ValidateNumber(buildmonth)) return false; if (ValidateNumber(builddate)) return false; if (ValidateNumber(buildyear)) return false; var d = new Date(); var Nowyear = d.getYear(); var Nowmonth = d.getMonth(); var Nowdate = d.getDate(); Nowdate = eval(Nowdate) - 1; var Nowhour = d.getHours(); var Nowmin = d.getMinutes(); var Nowsec = d.getSeconds(); var maxday = TotDayInMonth(inpDate[0],inpDate[2]); buildmonth = eval(buildmonth) - 1; var TimeNow = new Date(buildyear,buildmonth,builddate,Nowhour,Nowmin,Nowsec); //d = new Date(Nowyear,Nowmonth,Nowdate,Nowhour,Nowmin,Nowsec); /*alert('timenow='+TimeNow+'\n'+'d='+d) if (TimeNow == d) alert('timenow == d') else if (TimeNow < d) alert('timenow < d') else if (TimeNow > d) alert('timenow > d')*/ if (TimeNow < d) return false; if (inpDate[0] == 00 || inpDate[0] > 12) return false; if (inpDate[1] == 00 || inpDate[1] > maxday) return false; //if (inpDate[2] == 0000 || inpDate[2] > Nowyear) return false; if (inpDate[2] === 0000) return false; return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ function ChangeDatewDefault(objdate,objmonth,objyear) { var i, j; var seldate = objdate.selectedIndex; var selmonth = objmonth.selectedIndex; var selyear = objyear.selectedIndex; if (selmonth > 0) { intTotDay = TotDayInMonth(selmonth,objyear.options[selyear].value); objdate.options.length = intTotDay; for (i=1;i<=intTotDay;i++) { objdate.options[i-1].value = i; objdate.options[i-1].text = i; } objyear.options.length = 192; j = 1900; for (i=1;i<=192;i++) { objyear.options[i-1].value = j; objyear.options[i-1].text = j; j++; } seldate = ((seldate > intTotDay-1) ? intTotDay-1 : seldate); } else { intTotDay = 1; objdate.options.length = intTotDay; objdate.options[0].value = 0; objdate.options[0].text = 'Day'; objyear.options.length = intTotDay; objyear.options[0].value = 0; objyear.options[0].text = 'Year'; } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Sample Usage : // <select name="selMonth" onchange="ChangeDate(document.frmAppointment.selDay,document.frmAppointment.selMonth,document.frmAppointment.selYear);"> // <select name="selDay"> // <select name="selYear" onchange="ChangeDate(document.frmAppointment.selDay,document.frmAppointment.selMonth,document.frmAppointment.selYear);"> // Use this function to check the date in 3 select box, date select, month select, and year select // Note : The previous function of this ChangeDate() function is ChangeTime(5), only for id 5, the rest is using the ChangeTime() function below. function ChangeDate(objdate,objmonth,objyear) { var seldate = objdate.selectedIndex; var selmonth = objmonth.selectedIndex; var selyear = objyear.selectedIndex; intTotDay = TotDayInMonth(selmonth+1,objyear.options[selyear].value); objdate.options.length = intTotDay; for (var i=1;i<=intTotDay;i++) { objdate.options[i-1].value = i; objdate.options[i-1].text = i; } seldate = ((seldate > intTotDay-1) ? intTotDay-1 : seldate); return true; } /*function ChangeDate(objdate,objmonth,objyear) { var i, j; var seldate = objdate.selectedIndex; var selmonth = objmonth.selectedIndex; var selyear = objyear.selectedIndex; if (selmonth > 0) { intTotDay = TotDayInMonth(selmonth,objyear.options[selyear].value); objdate.options.length = intTotDay; for (i=1;i<=intTotDay;i++) { objdate.options[i-1].value = i; objdate.options[i-1].text = i; } objyear.options.length = 133; j = 1960; for (i=1;i<=133;i++) { objyear.options[i-1].value = j; objyear.options[i-1].text = j; j++; } seldate = ((seldate > intTotDay-1) ? intTotDay-1 : seldate); } else { intTotDay = 1; objdate.options.length = intTotDay; objdate.options[0].value = 0; objdate.options[0].text = 'Day'; objyear.options.length = intTotDay; objyear.options[0].value = 0; objyear.options[0].text = 'Year'; } return true; }*/ /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Sample Usage : // id 1 : <select name="selStartMinutes" onchange="ChangeTime(1, // document.frmAppointment.selStartHours, // document.frmAppointment.selStartMinutes, // document.frmAppointment.selDurHours, // document.frmAppointment.selDurMinutes, // document.frmAppointment.selEndHours, // document.frmAppointment.selEndMinutes);"> // <cfloop index="intMinutes" from="0" to="59" step="#duration#"> // <option value="#intMinutes#" <cfif intMinutes eq selStartMinutes>SELECTED</cfif>>:#NumberFormat(intMinutes,'09')# // </cfloop> // </select> // This id 1 is used to change the End Time value based on the Start Time value + Duration value. This change is put in Start Time onchange // id 2 : <select name="selDurHours" onchange="ChangeTime(2, // document.frmAppointment.selStartHours, // document.frmAppointment.selStartMinutes, // document.frmAppointment.selDurHours, // document.frmAppointment.selDurMinutes, // document.frmAppointment.selEndHours, // document.frmAppointment.selEndMinutes);"> // <cfloop index="intTime" from="0" to="23"> // <option value="#intTime#" <cfif intTime eq selDurHours>SELECTED</cfif>>#NumberFormat(intTime,'09')# // </cfloop> // </select> // This id 2 is used to change the End Time value based on the Start Time value + Duration value. This change is put in Duration onchange // id 3 : <select name="selEndMinutes" onchange="ChangeTime(3, // document.frmAppointment.selStartHours, // document.frmAppointment.selStartMinutes, // document.frmAppointment.selDurHours, // document.frmAppointment.selDurMinutes, // document.frmAppointment.selEndHours, // document.frmAppointment.selEndMinutes);"> // <cfloop index="intMinutes" from="0" to="59" step=#duration#> // <option value="#intMinutes#" <cfif intMinutes eq selEndMinutes>SELECTED</cfif>>:#NumberFormat(intMinutes,'09')# // </cfloop> // </select> // This id 3 is used to change the Duration Time value based on the End Time value - Start Time value. This change is put in End Time onchange // id 4 : <input onclick= "ChangeTime(4, // document.frmAppointment.selStartHours, // document.frmAppointment.selStartMinutes, // document.frmAppointment.selDurHours, // document.frmAppointment.selDurMinutes, // document.frmAppointment.selEndHours, // document.frmAppointment.selEndMinutes);" // type="Checkbox" name="chkAllDay" // <cfif Len(Trim(chkAllDay)) and ((chkAllDay eq "on") or (chkAllDay eq "1"))>CHECKED</cfif>> // This id 4 is used to change the Start Time to 12.00 AM, Duration Time to 23:50, End Time to 11.50 PM together. function ChangeTime(changeid,objstartH,objstartM,objdurH,objdurM,objendH,objendM) { var i; var selStartH = objstartH.selectedIndex; var selStartM = objstartM.selectedIndex; var selDurH = objdurH.selectedIndex; var selDurM = objdurM.selectedIndex; var selEndH = objendH.selectedIndex; var selEndM = objendM.selectedIndex; var intStartH = objstartH.options[selStartH].value*1; var intDurH = objdurH.options[selDurH].value*1; var intEndH = objendH.options[selEndH].value*1; var intStartM = objstartM.options[selStartM].value*1; var intDurM = objdurM.options[selDurM].value*1; var intEndM = objendM.options[selEndM].value*1; if (changeid == 1 || changeid == 2) { //var d, s = "Today's date is: "; //Declare variables. //d = new Date(); //Create Date object. //s += (d.getMonth() + 1) + "/"; //Get month //s += d.getDate() + "/"; //Get day //s += d.getYear(); //Get year. //return(s); //Return date. var dtEndDate = new Date(2000,1,1,intStartH + intDurH, intStartM + intDurM,0); var intEndH = dtEndDate.getHours(); var intEndM = dtEndDate.getMinutes(); for(i=0;i<objendH.options.length;i++) objendH.options[i].selected = (objendH.options[i].value == intEndH); for(i=0;i<objendM.options.length;i++) objendM.options[i].selected = (objendM.options[i].value == intEndM); } else if (changeid == 4) { var intEndHour = objendH.options[objendH.options.length-1].value*1; var intEndMin = objendM.options[objendM.options.length-1].value*1; var intStartHour = objstartH.options[0].value*1; var intStartMin = objstartM.options[0].value*1; var intDurHour = intEndHour - intStartHour; var intDurMin = intEndMin - intStartMin; objendH.options[objendH.options.length-1].selected = true; objendM.options[objendM.options.length-1].selected = true; objstartH.options[0].selected = true; objstartM.options[0].selected = true; //document.frmAppointment.chkAllDay.checked = true; for(i=0;i<objdurH.options.length;i++) objdurH.options[i].selected = (objdurH.options[i].value == intDurHour); for(i=0;i<objdurM.options.length;i++) objdurM.options[i].selected = (objdurM.options[i].value == intDurMin); } else if (changeid == 3) { var dtStartDate = new Date(2000,1,1,intStartH,intStartM,0); var dtEndDate = new Date(2000,1,1,intEndH,intEndM,0); var intDiff = (dtEndDate.getTime() - dtStartDate.getTime()) / 60000; if((intDiff*1) < 0) { intStartH = intEndH - intDurH; intStartM = intEndM - intDurM; intStartH = (intStartH < 0 ? 0 : intStartH); intStartM = (intStartM < 0 ? 0 : intStartM); dtStartDate = new Date(2000,1,1,intStartH,intStartM,0); intDiff = (dtEndDate.getTime() - dtStartDate.getTime()) / 60000; for(i=0;i<objstartH.options.length;i++) objstartH.options[i].selected = (objstartH.options[i].value == intStartH); for(i=0;i<objstartM.options.length;i++) objstartM.options[i].selected = (objstartM.options[i].value == intStartM); } var intDurHour = Math.floor(intDiff / 60); var intDurMin = intDiff % 60; for(i=0;i<objdurH.options.length;i++) objdurH.options[i].selected = (objdurH.options[i].value == intDurHour); for(i=0;i<objdurM.options.length;i++) objdurM.options[i].selected = (objdurM.options[i].value == intDurMin); } return true; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Use this function to change between multiple select type with wddx. // Usage : // 1. Build the cf settings. (The caller file). // <CFPARAM NAME="selCountry" DEFAULT=O> // <CFPARAM NAME="selState" DEFAULT=0> // <CFPARAM NAME="selCity" DEFAULT=0> // <CFQUERY NAME = "qCountry" DATASOURCE = "#DSN#"> SELECT TCountry.* FROM TCountry Order By Country_Name </CFQUERY> // <CFQUERY NAME = "qCountryState" DATASOURCE = "#DSN#"> SELECT TCountryState.* FROM TCountryState Order By Country_ID,State_ID </CFQUERY> // <CFQUERY NAME = "qCountryState1" DATASOURCE = "#DSN#"> SELECT TCountryState.* FROM TCountryState WHERE Country_ID=#selCountry# Order By Country_ID,State_ID </CFQUERY> // <CFQUERY NAME = "qCountryCity" DATASOURCE = "#DSN#"> SELECT TCountryCity.* FROM TCountryCity Order By State_ID,City_ID </CFQUERY> // <CFQUERY NAME = "qCountryCity1" DATASOURCE = "#DSN#"> SELECT TCountryCity.* FROM TCountryCity WHERE State_ID=#selState# Order By State_ID,City_ID </CFQUERY> // 2. Put the "wddx.js" file in the same file of the caller of this script (File in step 1). // <script language="JavaScript" src="wddx.js"></script> // the wddx.js file // <script language="JavaScript" src="allscript.js"></script> // this file // 3. Put the cfwddx function at the file of the caller of this script. (File in step 1). // <script language="JavaScript"> // <cfwddx action="CFML2JS" input="#qCountryState#" toplevelvariable="State"> // <cfwddx action="CFML2JS" input="#qCountryCity#" toplevelvariable="City"> // </script> // 4. Set the cf settings. (The caller file). // <tr> // <td>Country : </td> // <td><select name="selCountry" onchange="change_wddx(document.frmtest.selCountry,document.frmtest.selState,State,'country_id','state_id','state_name'); // change_wddx(document.frmtest.selState,document.frmtest.selCity,City,'state_id','city_id','city_name');"> // <cfloop query="qCountry"> // <option value="#Country_id#"<cfif Country_id eq selcountry>selected</cfif>>#Country_Name#</option> // </cfloop> // </select> // </td> // </tr> // <tr> // <td>State : </td> // <td><select name="selState" onchange="change_wddx(document.frmtest.selState,document.frmtest.selCity,City,'state_id','city_id','city_name');"> // <cfloop query="qCountryState1"> // <option value="#State_id#"<cfif State_id eq selState>selected</cfif>>#State_Name#</option> // </cfloop> // <cfif #qCountryState1.Recordcount# eq 0> // <option value="0"<cfif #selState# eq 0>selected</cfif>>Other</option> // </cfif> // <option></option><option></option><option></option> // </select> // </td> // </tr> // <tr> // <td>City : </td> // <td><select name="selCity"> // <cfloop query="qCountryCity1"> // <option value="#City_id#"<cfif City_id eq selcity>selected</cfif>>#City_Name#</option> // </cfloop> // <cfif #qCountryCity1.Recordcount# eq 0> // <option value="0"<cfif #selCity# eq 0>selected</cfif>>Other</option> // </cfif> // <option></option><option></option><option></option> // </select> // </td> // </tr> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 5. Important Part : // <select name="selState" onchange="change_wddx(document.frmtest.selState,document.frmtest.selCity,City,'state_id','city_id','city_name');"> // The change_wddx function has 6 parameter : // Parameter 1 : Form select Source object (The first select that you click) // Parameter 2 : Form select Target object (The select that change when you click the 1st select) // Parameter 3 : TopLevelVariabel from the Target <cfwddx> // Parameter 4 : Database Field Name from the First Select value // Parameter 5 : Database Field Name for the Second Select value // Parameter 6 : Database Field Name for the Second Select display // eq. Source = Country and Target = State, or Source = State and Target = City // Note that when you call the Change for Country, you should call this function twice, 'cause // the First is when you change the State (Source = Country and Target = State) // and Second is when you change the City (Source = State and Target = City) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function change_wddx(source_object,target_object,var_wddx,sourceid_field,targetid_field,targetval_field) { var index = source_object.selectedIndex; var sourceval = source_object.options[index].value; var reccount = var_wddx.getRowCount(); var i = 0; for (var j=0;j<reccount;j++) { getval = var_wddx.getField(j,sourceid_field); if (sourceval == getval) { target_object.options.length = i + 1; target_object.options[i].value = var_wddx.getField(j,targetid_field); target_object.options[i].text = var_wddx.getField(j,targetval_field); i++; //target_object.options[i] = new Option(var_wddx.getField(j,targetval_field),var_wddx.getField(j,targetid_field),false,true) } } if (i == 0) { target_object.options.length = i + 1; target_object.options[i].value = 0; target_object.options[i].text = 'Other'; i++; target_object.options[0].selected = true; } } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // Put this function in your body onload() : // <body onload="funClock();"> // Use this function to display moving digital clock continuously. // Works Fine in IE, need some modifications in your layer display position in Netscape. // Example : // <tr> // <td>Now is : </td> // <td><font color="brown" face="Arial" size="3"> // <cfif FindNoCase("MSIE", CGI.HTTP_USER_AGENT)> // <div id = "clock" style="position:relative"></div> // </cfif> // <layer name="clock" bgcolor="Lime"></layer> // </font> // </td> // </tr> function MakeArrayday(size) { this.length = size; for(var i = 1; i <= size; i++) { this[i] = ""; } return this; } function MakeArraymonth(size) { this.length = size; for(var i = 1; i <= size; i++) { this[i] = ""; } return this; } function funClock() { if (!document.layers && !document.all) return; var runTime = new Date(); var hours = runTime.getHours(); var minutes = runTime.getMinutes(); var seconds = runTime.getSeconds(); var dn = "AM"; if (hours >= 12) { dn = "PM"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes <= 9) { minutes = "0" + minutes; } if (seconds <= 9) { seconds = "0" + seconds; } var movingtime = hours + ":" + minutes + ":" + seconds + " " + dn; if (document.layers) { document.layers.clock.document.write(movingtime); document.layers.clock.document.close(); } else if (document.all) { clock.innerHTML = movingtime; } setTimeout("funClock()", 1000) } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // Is Valid Time is used to validate Time entered // Note. when using this function, you don't have to user the alert function. // if (!IsValidTime(thisform.txtStartEnd.value)) // { // thisform.txtStartEnd.focus(); // } function IsValidTime(timeStr) { var timePat = /^(\d{1,2}):(\d{1,2})(:(\d{1,2}))?(\s?(AM|am|PM|pm))?$/; var matchArray = timeStr.match(timePat); if (matchArray == null) { alert("Time is not in a valid format."); return false; } var hour = matchArray[1]; var minute = matchArray[2]; var second = matchArray[4]; var ampm = matchArray[6]; if (second=="") { second = null; } if (ampm=="") { ampm = null } if (hour < 0 || hour > 23) { alert("Hour must be between 0 and 23 for military time"); return false; } if (minute<0 || minute > 59) { alert ("Minute must be between 0 and 59."); return false; } if (second != null && (second < 0 || second > 59)) { alert ("Second must be between 0 and 59."); return false; } return true } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : // limitChar function is used to limit the text filled in the textarea // <tr><td colspan="2" valign="top"><textarea name="txt_Message" cols="40" rows="5" wrap="hard" onkeyup="limitChar(this,this.form.txt_nbchar,160)"></textarea></td></tr> // <tr><td><font color="0000FF">max 160 characters</font></td><td><input type="Text" name="txt_nbchar" size="3" readonly value="160"></td></tr> /*********************************************************************************************************************************/ function limitChar(obj_,obj_target,nbmax) { if (obj_.value.length > nbmax) { obj_.value=obj_.value.substring(0,nbmax) alert("Sorry, you have reached maximum character allowed"); } obj_target.value=nbmax-obj_.value.length; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : /*********************************************************************************************************************************/ function valid_dateformat(object_value) { var varsplit = "/"; var inpDate = new Array(); inpDate = object_value.split(varsplit); for(var i=0;i<2;i++) {//alert(inpDate[i]); if (inpDate[i]) {//alert(inpDate[i]+'1'); if (inpDate[i].length == 1) inpDate[i] = '0'+ inpDate[i] } else {//alert("masuk"); var x = false; break; return x; } } var x = inpDate[0]+'/'+inpDate[1]+'/'+inpDate[2] return x; } /*********************************************************************************************************************************/ /*********************************************************************************************************************************/ // Usage : /*********************************************************************************************************************************/ function change_dateformat(object_value) { var varsplit = "/"; var x = valid_dateformat(object_value); if (!x) { return x; } var inpDate = new Array(); inpDate = x.split(varsplit); x = inpDate[2]+'/'+inpDate[0]+'/'+inpDate[1] return x; } function getyear1(object_value) { var varsplit = "/"; var x = valid_dateformat(object_value); var inpDate = new Array(); inpDate = x.split(varsplit); x = inpDate[2] return x; } function adddate(object_value,i) { var varsplit = "/"; var x = valid_dateformat(object_value); var inpDate = new Array(); inpDate = x.split(varsplit); var y = parseInt(inpDate[1]) + i; x = inpDate[0]+'/'+y+'/'+inpDate[2] return x; } /*Usage : get_max_day_inmonth(month,year), it will return days ammount in the selected month and year*/ function get_max_day_inmonth(month1,year1) { var x = 30; if ((month1 == 1) || (month1 == 3) || (month1 == 5) || (month1 == 7) || (month1 == 8) || (month1 == 10) || (month1 == 12)) { x = 31; return x; } else if (month1 == 2) { if (year1 % 4 == 0) { x = 29; return x; } else { x = 28; return x; } } else { return x; } } /*Usage : get_max_day_inyear(year), it will return days ammount in the selected year*/ function get_max_day_inyear(year1) { var x = 365; if (year1 % 4 == 0) { x = 366; return x; } else { return x; } } /*Usage : subdate(fromdate,todate) , it will return the amount day betwen fromdate to todate please be sure to input the right fromdate and todate, cause there is no validation in this function*/ function subdate(fromdate,todate) { var varsplit = "/"; var hasil = 0; var x = valid_dateformat(fromdate); var y = valid_dateformat(todate); var inpDate1 = new Array(); var inpDate2 = new Array(); inpDate1 = x.split(varsplit); inpDate2 = y.split(varsplit); /*alert('inpDate1: '+inpDate1); alert('inpDate2: '+inpDate2); alert('inpDate1[0]: '+inpDate1[0]); alert('inpDate2[0]: '+inpDate2[0]); alert('inpDate1[1]: '+inpDate1[1]); alert('inpDate2[1]: '+inpDate2[1]); alert('inpDate1[2]: '+inpDate1[2]); alert('inpDate2[2]: '+inpDate2[2]); var coba = parseInt(07); alert('coba: '+coba);*/ var day1 = inpDate1[1]; var month1 = inpDate1[0]; var year1 = inpDate1[2]; var day2 = inpDate2[1]; var month2 = inpDate2[0]; var year2 = inpDate2[2]; var subyear = year2 - year1; var submonth = month2 - month1; var subday = day2 - day1; var i; var dummonth; var dumyear; /*alert('year1: '+year1); alert('year2: '+year2); alert('month1: '+month1); alert('month2: '+month2); alert('day1: '+day1); alert('day2: '+day2); alert('subyear: '+subyear);*/ if (subyear > 0) { dumyear = year1; for(i = 1;i <= subyear;i++) {//alert('masuk subyear'); hasil = hasil + get_max_day_inyear(dumyear); dumyear++; } }//alert(hasil+' 1'); //alert('submonth: '+submonth); if (submonth > 0) { dummonth = month1; dumyear = year1; for(i = 1;i <= submonth;i++) {//alert('masuk submonth'); hasil = hasil + get_max_day_inmonth(dummonth,dumyear); dummonth++; if (dummonth == 13) { dummonth = 1; dumyear++; } } }//alert(hasil+' 2'); if ((subday == 0) && (submonth == 0) && (subyear == 0)) { hasil = 1; } else { hasil = hasil + subday + 1; }//alert(hasil+' 3'); return hasil; } /*********************************************************************************************************************************/ function disablerightclick(nets) { if((!document.all && nets.which!=1) || (document.all && event.button!=1)) alert('This action has been disabled.') return false } function IsChecked(chkBox) { if(chkBox!=null) { var Found = false if(chkBox.length!=null) for(var i=0; (i<chkBox.length) && !Found; i++) Found = chkBox[i].checked else Found = chkBox.checked return Found } else return false } /*********************************************************************************************************************************/ // usage : Round2Decimal(100.234324); function Round2Decimal(X) { var T, S=new String(Math.round(X*100)) while (S.length<3) S='0'+S return S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2) } /*********************************************************************************************************************************/ // usage : RoundNDecimal(100.789798, 3); // X --> number to round // N --> decimal digit function RoundNDecimal(X, N) { var T, S=new String(Math.round(X*Number("1e"+N))) while (S.length<=N) S='0'+S return S.substr(0, T=(S.length-N)) + '.' + S.substr(T, N) } function decformat(pval) { var scval=(""+pval).split("."); var stdec="00"; if (scval.length==2) stdec=(""+scval[1]).substr(0,2); var arrnum=new Array; var stnum=""+scval[0]; var stret=""; do { if (stret.length>=3) stret=","+stret; if (stnum.length<=3) { stret=stnum+stret; stnum=""; } else { stret=stnum.substr(stnum.length-3,3)+stret; stnum=stnum.substr(0,stnum.length-3); } } while (stnum.length) return stret+"."+stdec; } /*********************************************************************************************************************************/ // Created by : Indra P., May 8 '09 // usage : doDecimalFormat(100.789798); function doDecimalFormat(angka) { var a, b, c, dec, i, j; angka = String(angka); if(angka.indexOf('.') > -1){ a = angka.split('.')[0] ; dec = angka.split('.')[1] } else { a = angka; dec = -1; } b = a.replace(/[^\d]/g,""); c = ""; var panjang = b.length; j = 0; for (i = panjang; i > 0; i--) { j = j + 1; if (((j % 3) == 1) && (j != 1)) c = b.substr(i-1,1) + "," + c; else c = b.substr(i-1,1) + c; } if(dec == -1) return angka; else return (c + '.' + dec); } /********************************************************************************************************************************* Create by Bing Usage : - Top Checkbox (required) <input type="checkbox" name="chkTop" onclick="checkAll(document.frmName.chkDetail, document.frmName.chkTop)"> - Details Checkbox (required) <input type="checkbox" name="chkDetail" onclick="uncheckAll(document.frmName.chkDetail, document.frmName.chkTop)"> *********************************************************************************************************************************/ function checkAll(chkList, chkAll) { if(chkList != null) { if(chkList.length!=null) for(var i=0; i<chkList.length; i++) chkList[i].checked = chkAll.checked else chkList.checked=chkAll.checked } } function uncheckAll(chkList, chkAll) { var len = chkList.length; var x = 0 if(chkList != null) { if(len != null) { if(!chkList.checked && chkAll.checked) { chkAll.checked = false; } else { for(var i=0; i<len; i++) { if(chkList[i].checked) x++ } if(x >= len) chkAll.checked = true; } } else chkAll.checked = chkList.checked; } } // ****************************************************************** // This function accepts a string variable and verifies if it is a // proper date or not. It validates format matching either // mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month // has the proper number of days, based on which month it is. // The function returns true if a valid date, false if not. // ****************************************************************** function isDate(dateStr,wrongdateformatmsg,wrongmonth,wrongday,month1,noday,nohave,days) { var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/; var matchArray = dateStr.match(datePat); // is the format ok? if ((wrongdateformatmsg.length == 0) || wrongdateformatmsg == "") { wrongdateformatmsg = " Please enter date as mm/dd/yyyy. "; } if ((wrongmonth.length == 0) || wrongmonth == "") { wrongmonth = " Month must between 1 - 12. "; } if ((wrongday.length == 0) || wrongday == "") { wrongday = " day must between 1 - 31. "; } if ((month1.length == 0) || month1 == "") { month1 = " Month "; } if ((noday.length == 0) || noday == "") { noday = " Doesn't have 31 days. "; } if ((nohave.length == 0) || nohave == "") { nohave = " Doesn't have "; } if ((days.length == 0) || days == "") { days = " Days. "; } if (matchArray == null) { alert(wrongdateformatmsg); return false; } month = matchArray[1]; // parse date into variables day = matchArray[3]; year = matchArray[5]; if (month < 1 || month > 12) { // check month range alert(wrongmonth); return false; } if (day < 1 || day > 31) { alert(wrongday); return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert(month1 +month+ noday) return false; } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day > 29 || (day==29 && !isleap)) { alert("February " + year + nohave + day + days); return false; } } return true; // date is valid } // Emulates printf("blah blah %s blah %s",str1,str2) like in C // Used for concatenating message for easier localization. // Returns assembled string. function printf() { var i,numArgs,errStr="",argNum=0,startPos; numArgs = printf.arguments.length; if (numArgs) { theStr = printf.arguments[argNum++]; startPos = 0; endPos = theStr.indexOf("%s",startPos); if (endPos == -1) endPos = theStr.length; while (startPos < theStr.length) { errStr += theStr.substring(startPos,endPos); if (argNum < numArgs) errStr += printf.arguments[argNum++]; startPos = endPos+2; endPos = theStr.indexOf("%s",startPos); if (endPos == -1) endPos = theStr.length; } if (!errStr) errStr = printf.arguments[0]; } return errStr; } function strTrim(AStr) { return AStr.replace(/^\s+/,'').replace(/\s+$/,''); } function isIntOnly(e,elm) { var evt=window.event?event:e; var ekey=evt.keyCode?evt.keyCode:evt.which; var ret=((ekey >= 48 && ekey <= 57) || (ekey >= 35 && ekey <= 39) || ekey == 46 || ekey==13 || ekey==9 || ekey==8);//|| ekey==190 if (ret && elm!=null) { ret=(ekey != 46 || elm.value.search(/\./)==-1); } // window.status+="_"+ret; // if (!ret) alert(ekey); return ret; // return ((event.keyCode == 46) || (event.keyCode >= 48) && (event.keyCode <= 57)) } /********************************************************************************************************************************/ function isIntOnlyNew(evt){ if (evt.which){ var charCode = evt.which; } else if(document.all && event.keyCode){ var charCode = event.keyCode; } else { return true; } return ((charCode == 45) || (charCode == 46) || (charCode == 8) || (charCode >= 48) && (charCode <= 57)); } function isIntOnlyNew1(evt){ var charCode = (evt.which) ? evt.which : event.keyCode; return ((charCode == 8) || (charCode >= 48) && (charCode <= 57)); } /* function decimalin(ini,nottyped){ // ini: object , nottyped: determine whether this function is used for typing (don't set anything) or number format (set 1) var allowedchars="-1234567890.",isminus,end,val,tmpchar,ischar,k,decval,newval; if(event == null || (event.keyCode != 37 && event.keyCode != 39)){ var oldpos=getSelectionStart(ini); val=ini.value; if((event != null) && (!((event.keyCode == 46) || (event.keyCode == 190) || (event.keyCode == 189) || (event.keyCode >= 48) && (event.keyCode <= 57)))){ tmpchar=val.charAt(oldpos-1); ischar=allowedchars.indexOf(tmpchar); if(ischar<0){ var flag=true; var cnt=0; while(flag){ found=val.indexOf(tmpchar); if(found>=0){ val=val.replace(tmpchar,""); } else break; cnt++; if(cnt>15)break; } } } if(oldpos==val.length){ end=1; } else{ end=0; } isminus=0; if(val.charAt(0)=="-"){ val=val.substr(1,val.length) isminus=1; } val=val.split(",").join(""); decval=val.split("."); val=decval[0]; if(val=="")val=0; newval=""; var idx=0 for(k=val.length-1;k>=0;k--){ idx++; newval=val.charAt(k)+newval; if(idx%3==0 && idx < val.length){ newval=","+newval; } } // app_dec variable is declared in erp\eaccounting\application.cfc if(decval[1]!=null){ if(decval[1].length > parseInt(app_dec)){ decval[1]=decval[1].substr(0,parseInt(app_dec)); } newval=newval+"."+decval[1]; } if(isminus==1)newval="-"+newval; ini.value=newval; if(end==1){ oldpos=ini.value.length; } if(nottyped!=1){ setCaretPosition(ini,oldpos); } } } */ /********************************************************************************************************************************* Create by Tiono Usage : Clear select box options *********************************************************************************************************************************/ function ClearSelectObject(selObj) { /* if (selObj.length>0) { for(i=selObj.length-1;i>=0;i--) selObj.options[i] = null; } */ try {while(selObj.hasChildNodes) selObj.removeChild(selObj.lastChild);} catch (e) {} } /********************************************************************************************************************************* Usage : Populate Select Box option. Works for IE, NN+ and firefox. Hope works for other browser also. Example : AddSelectOption(document.frm.selObj, "Label", "value") *********************************************************************************************************************************/ function AddSelectOption(oSelect, label, value, idx) { var oOption = document.createElement('option'); var oLabel = document.createTextNode(label); oOption.appendChild(oLabel); oOption.setAttribute('value', value); try { if (idx==0) oSelect.insertBefore(oOption, oSelect.firstChild); else oSelect.appendChild(oOption); } catch (e) { oSelect.appendChild(oOption); } } /********************************************************************************************************************************* Create by Tiono Usage : Populate combobox with grouping based on parent combobox selected value data array must have following format arr[x][0] = parent combobox id arr[x][1] = data id arr[x][2] = label filterAllId is used to set fill ALL id at parent combobox. If parent doesn't have ALL option then leave this param as empty string '' *********************************************************************************************************************************/ function populateComboBox(dtsource, filterid, targetOSelect, selectedValue, filterAllId) { ClearSelectObject(targetOSelect); for(i=0;i<dtsource.length;i++) { if(dtsource[i][0]==filterid || filterid==filterAllId) { AddSelectOption(targetOSelect, dtsource[i][2], dtsource[i][1]); } } for (i=0;i<targetOSelect.length;i++) { if(targetOSelect.options[i].value==selectedValue) { targetOSelect.selectedIndex = i; break; } } } /* Functions for handling AJAX */ function sethtml(obj,content) { var search = content;//.toLowerCase(); orgsearch = content; var script; adembed=""; obj.innerHTML=content;//+javascript[^>]+ while( script = search.match(/(<script[^>]*>\s*(<!--)?)/i)) { search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length); if (!(endscript = search.match(/((-->)?\s*<\/script>)/i))) break; block = search.substr(0, search.indexOf(RegExp.$1)); search = search.substring(block.length + RegExp.$1.length); var oScript = document.createElement('script'); if (block.substr(0,14).toUpperCase()=="CF_RUNCONTENT(") { adembed+=block.substr(15,block.length-18); block=""; } if (block!="") { oScript.text = block; document.getElementsByTagName("head").item(0).appendChild(oScript); } } if (adembed!="") obj.insertAdjacentHTML("beforeEnd",adembed); } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function getAJAXContent(theURL,plcHolder,keepcursor) { //alert(theURL); // add ............. if (keepcursor==null) keepcursor=0; nmr = 1; var BB = new Array(); BB = theURL.split('&'); for (i=0;i<BB.length;i++) { if(BB[i].match("row") != null) { CC = BB[i]; var DD = new Array(); DD = CC.split('='); nmr = DD[1]; } } for (i=0;i<BB.length;i++) { if(BB[i].match("frmname") != null) { ZZ = BB[i]; var DD = new Array(); YY = ZZ.split('='); eval("document."+YY[1]).hdnrow.value= nmr; } } if (theURL==null) return ""; var ajaxMethod="GET"; ajaxParam=""; if (plcHolder==null) divPlc=null; else { scPlc=plcHolder.split("."); if (scPlc.length==2) { docPlc=eval(scPlc[0]+".document"); plcHolder=scPlc[1]; divPlc=docPlc.getElementById(plcHolder); } else docPlc=document; divPlc=docPlc.getElementById(plcHolder); } spInfo=divPlc; if (theURL.length==0) { if (divPlc!=null) divPlc.innerHTML=""; else return ""; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser is not support AJAX"); return ""; } xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4) { if (divPlc!=null) { sethtml(divPlc,xmlHttp.responseText); /*document.write("<textarea name='test'>"+xmlHttp.responseText+"</textarea>")*/ if (keepcursor!=1) document.body.style.cursor="default"; if (divPlc.innerHTML!="" && keepcursor!=3) { divPlc.style.display=""; } } else { return xmlHttp.responseText; } } } xmlHttp.open(ajaxMethod,theURL,true); xmlHttp.send(ajaxParam); if (divPlc!=null && keepcursor==0) { divPlc.style.display="none"; } if (keepcursor!=1) document.body.style.cursor="wait"; } /********************************************************************************************************************************* Create by Tiono Usage : Check if at lease one checkbox is checked *********************************************************************************************************************************/ function isCheckboxChecked(chkobj) { if (chkobj && chkobj.length) {for (i=0;i<chkobj.length;i++) {if (chkobj[i].checked) {return true;break;}}} else if (chkobj && chkobj.checked) {return true;} return false; } function removecomma(value){ A = value.split(","); value = A.join(""); return value; } /********************************************************************************************************************************* Create by Randytia Usage : Untuk selected document menggunakan ajax *********************************************************************************************************************************/ function hideAllSelect(isVisible) { objAllSel = document.getElementsByTagName('select'); // hide or display all select box for(i=0; i<objAllSel.length; i++) { if (isVisible == 'yes') objAllSel[i].style.visibility = 'hidden'; else objAllSel[i].style.visibility = ''; } } function hoover(thisobj) { thisobj.style.backgroundColor = 'A1B4D8' thisobj.style.color = 'white' //thisobj.style.fontWeight = 'bold' thisobj.style.fontWeight = 'normal' thisobj.style.cursor = 'hand' } function unHoover(thisobj) { thisobj.style.backgroundColor = 'white' thisobj.style.color = 'black' thisobj.style.fontWeight = 'normal' } function popLookup(isVisible) { hideAllSelect(isVisible); if (isVisible == 'yes') { document.getElementById(objLookupField).style.left = xMousePos; document.getElementById(objLookupField).style.top = yMousePos; document.getElementById(objLookupField).style.display = 'block'; } else { document.getElementById(objLookupField).style.display = 'none'; } } function onEnter(evt) { evt = (evt) ? evt : ((window.event) ? event : null); if(evt) { var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if(elem) { var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode); if(charCode == 13) { onEvent(); return false; } } } } function onPick(thisobj) { document.getElementById(objTextField).value = thisobj.id; document.getElementById(objTextField).focus(); onEvent(thisobj); // close search field popLookup('no'); } //how to use onblur="timeValidation(this);" function timeValidation(objTime) { var str = objTime.value ; var str1 = "00"; var str2 = "00"; if(str.split(":").length == 1 ) { if(str.length == 4) { str1 = str[0] + str[1]; str2 = str[2] + str[3]; objTime.value = str1+":"+str2 ; } else { alert("Invalid Time Format"); objTime.value = str1+":"+str2 ; } } str = objTime.value ; if(str.split(":").length > 2) { alert("Invalid Time Format"); objTime.value = str1+":"+str2 ; } else if(str.split(":")[0] == "" || parseInt(str.split(":")[0],10) < 0 ) { alert("Invalid Time Format"); str1 = "00" ; objTime.value = str1+":"+str2 ; } else if(str.split(":")[1] == "" || parseInt(str.split(":")[1],10) < 0 ) { alert("Invalid Time Format"); str2 = "00" ; objTime.value = str1+":"+str2 ; } else if(parseInt(str.split(":")[0],10)>23 || parseInt(str.split(":")[1],10)>59) { alert("Invalid Time Format"); if(parseInt(str.split(":")[0],10)>23) { str1 = "23" ; } if(parseInt(str.split(":")[1],10)>59) { str2 = "59" ; } objTime.value = str1+":"+str2 ; } else { str1 = parseInt(str.split(":")[0],10); if(parseInt(str.split(":")[0],10)<10) str1 = "0"+parseInt(str.split(":")[0],10); str2 = parseInt(str.split(":")[1],10); if(parseInt(str.split(":")[1],10)<10) str2 = "0"+parseInt(str.split(":")[1],10); objTime.value = str1+":"+str2 ; } } function ceklen(val) { var len = 1 ; var pembagi while((val/pembagi)>1) { len++; pembagi = pembagi * 10 ; } return len ; } function decimalinForMoney(ini){ if(ini.value == '') ini.value = 0; var min = 0; if(parseInt(ini.value) < 0) min = 1 ; else min = 0 ; ini.value = ini.value.split("-").join(""); if(ini != null){ if (ini.value.indexOf('.') >= 0) { // bukan bilangan bulat var pembagi = 1; for(var i=0;i<parseInt(app_dec) ; i++) pembagi = pembagi * 10; var z = ini.value.split(".")[1] ; var zero = "" ; for(i=0;i<z.length;i++) { if(z.substring(i,i+1) == "0") { zero = zero + "0" ; } else break; } z=parseFloat(z); var lenz = ceklen(z); for(var j=0;j<(lenz-parseInt(app_dec));j++) { z= Math.round(z/10); } var strz = 0 + "." + zero + z ; strz = parseFloat(strz); strz = strz * pembagi ; var y = Math.round(strz) ; var stry = String(y); if(y == Math.pow(10,parseInt(app_dec))){ ini.value = parseInt(ini.value) + 1; stry=""; } for(i=stry.length;i<parseInt(app_dec);i++) stry = "0" + stry ; ini.value =ini.value.split(".")[0] + "." + stry ; } else { // bilangan bulat var z = parseInt(ini.value); z = z + "." ; for(var i=0;i<parseInt(app_dec) ; i++) z = z + "0"; ini.value = z; } } if(ini.value.indexOf('.') > -1) { a = ini.value.split('.')[0] ; dec = ini.value.split('.')[1] } else { a = ini.value; dec = -1; } b = a.replace(/[^\d]/g,""); c = ""; panjang = b.length; j = 0; for (i = panjang; i > 0; i--) { j = j + 1; if (((j % 3) == 1) && (j != 1)) c = b.substr(i-1,1) + "," + c; else c = b.substr(i-1,1) + c; } if(dec == -1) ini.value = c; else ini.value = c + '.' + dec; if(min==1) { ini.value = "-" + ini.value ; } } function decimalinAngka(ini){ if(ini.value == '') ini.value = 0; var min = 0; if(parseInt(ini.value) < 0) min = 1 ; else min = 0 ; ini.value = ini.value.split("-").join(""); if(ini != null){ if (ini.value.indexOf('.') >= 0) { // bukan bilangan bulat var pembagi = 1; for(var i=0;i<parseInt(app_dec); i++) pembagi = pembagi * 10; var z = ini.value.split(".")[1] ; var zero = "" ; for(i=0;i<z.length;i++) { if(z.substring(i,i+1) == "0") { zero = zero + "0" ; } else break; } z=parseFloat(z); var lenz = ceklen(z); for(var j=0;j<(lenz-parseInt(app_dec));j++) { z= Math.round(z/10); } var strz = 0 + "." + zero + z ; strz = parseFloat(strz); strz = strz * pembagi ; var y = Math.round(strz) ; var stry = y / pembagi; ini.value =parseInt(ini.value.split(".")[0]) + parseFloat(stry) ; } else { // bilangan bulat var z = parseInt(ini.value); ini.value = z; } } if(min==1) { ini.value = "-" + ini.value ; } } function decimalinFormat(val){ val = val+'' if(val == '') val = 0; var min = 0; if(parseInt(val) < 0) min = 1 ; else min = 0 ; val = val.split("-").join(""); if(val != null){ if (val.indexOf('.') >= 0) { // bukan bilangan bulat var pembagi = 1; for(var i=0;i<parseInt(app_dec) ; i++) pembagi = pembagi * 10; var z = val.split(".")[1] ; var zero = "" ; for(i=0;i<z.length;i++) { if(z.substring(i,i+1) == "0") { zero = zero + "0" ; } else break; } z=parseFloat(z); var lenz = ceklen(z); for(var j=0;j<(lenz-parseInt(app_dec));j++) { z= Math.round(z/10); } var strz = 0 + "." + zero + z ; strz = parseFloat(strz); strz = strz * pembagi ; var y = Math.round(strz) ; var stry = y / pembagi; val=parseInt(val.split(".")[0]) + parseFloat(stry) ; } else { // bilangan bulat var z = parseInt(val); val = z; } } if(min==1) { val = val * -1 ; } return val ; } function decimalinForRate(ini){ if(ini.value == '') ini.value = 0; var min = 0; if(parseInt(ini.value) < 0) min = 1 ; else min = 0 ; ini.value = ini.value.split("-").join(""); if(ini.value.indexOf('.') > -1) { a = ini.value.split('.')[0] ; dec = ini.value.split('.')[1] } else { a = ini.value; dec = -1; } b = a.replace(/[^\d]/g,""); c = ""; panjang = b.length; j = 0; for (i = panjang; i > 0; i--) { j = j + 1; if (((j % 3) == 1) && (j != 1)) c = b.substr(i-1,1) + "," + c; else c = b.substr(i-1,1) + c; } if(dec == -1) ini.value = c; else ini.value = c + '.' + dec; if(min==1) { ini.value = "-" + ini.value ; } } function viewdimension(dimensionID,path,obj) { var URL = path+"/include/ajax/inventory/dimensiondetail.cfm?dimension_ID="+dimensionID ; // Start Ajax var pageToRequest = false; if (window.XMLHttpRequest) // if Mozilla, Safari etc pageToRequest = new XMLHttpRequest(); else if (window.ActiveXObject){ // if IE try { pageToRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ pageToRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } else { return false; } pageToRequest.onreadystatechange = function() { if (pageToRequest.readyState == 4) { return overlib(pageToRequest.responseText); } } pageToRequest.open('GET', URL, true); pageToRequest.send(null); } function dimensionDetail(objItem,elementItem,dimension_id,vst_idx){ objItem.setHTTPMethod('POST'); // default is GET objItem.setReturnFormat('json'); // default is JSOn // itemclass.setAsyncMode(); *** Automatic set by below {setCallbackHandler() | setErrorHandler()} objItem.setCallbackHandler(handleGetDimension); objItem.setErrorHandler(handleError); objItem.detailDimension(dimension_id,elementItem,vst_idx); } function handleGetDimension(result){ resultset = result.split("XX") elementItem = resultset[0]; document.getElementById(elementItem).innerHTML = resultset[1] } function handleError(statusCode, statusMsg) { alert('Status: ' + statusCode + ', ' + statusMsg); } function decimalinMoney(nilai2){ var nilai = "" + nilai2 if(nilai == '') nilai = 0; nilai = nilai.split("-").join(""); if(nilai != null){ if (nilai.indexOf('.') >= 0) { // bukan bilangan bulat var pembagi = 1; for(var i=0;i<parseInt(app_dec) ; i++) pembagi = pembagi * 10; var z = nilai.split(".")[1] ; var zero = "" ; for(i=0;i<z.length;i++) { if(z[i] == "0") { zero = zero + "0" ; } else break; } z=parseFloat(z); var lenz = ceklen(z); for(var j=0;j<(lenz-parseInt(app_dec));j++) { z= Math.round(z/10); } var strz = 0 + "." + zero + z ; strz = parseFloat(strz); strz = strz * pembagi ; var y = Math.round(strz) ; var stry = String(y); for(i=stry.length;i<parseInt(app_dec);i++) stry = "0" + stry ; nilai =nilai.split(".")[0] + "." + stry ; } else { // bilangan bulat var z = parseInt(nilai); z = z + "." ; for(var i=0;i<parseInt(app_dec) ; i++) z = z + "0"; nilai = z; } } if(nilai.indexOf('.') > -1) { a = nilai.split('.')[0] ; dec = nilai.split('.')[1] } else { a = nilai; dec = -1; } b = a.replace(/[^\d]/g,""); c = ""; panjang = b.length; j = 0; for (i = panjang; i > 0; i--) { j = j + 1; if (((j % 3) == 1) && (j != 1)) c = b.substr(i-1,1) + "," + c; else c = b.substr(i-1,1) + c; } if(dec == -1) nilai = c; else nilai = c + '.' + dec; return nilai; }
/*
* Author = Dian Hermanto
* Create Date = 21 Maret 2014
* File Name = allscript.css
* Function = Default page after login
* Location = ./asset/js/allscript.js
*/
function confirmDelete()
{
return confirm("Are you sure you want to delete this file?");
}
function validateInVendCat()
{
if(document.getElementById('VendCat_Name').value == '')
{
alert('Vendor Category can not empty.')
return false;
}
}
// Purchase Requisition
function selPURRREQ_Type(myValue)
{
var type = document.getElementById('PURRREQ_Type').value;
if(type==2)
{
document.getElementById('labelProject1').style.display = '';
document.getElementById('labelProject2').style.display = '';
}
else
{
document.getElementById('labelProject1').style.display = 'none';
document.getElementById('labelProject2').style.display = 'none';
}
}
function doCloseChild(myChild) {
if(myChild.length) {
for(var i=0;i<myChild.length;i++) {
if(myChild[i] && myChild[i].open && !myChild[i].closed) {
myChild[i].close();
}
}
}
}
function deletecommaperiod(str,type)
{
var A = new Array();
if ((type=="both") || (type=="comma"))
{
A = str.split(",");
str = A.join("");
}
if ((type=="both") || (type=="period"))
{
A = str.split(".");
str = A.join("");
}
return str;
}
function decimalin(ini)
{
var i, j;
var bil2 = deletecommaperiod(ini.value,'both')
var bil3 = ""
j = 0
for (i=bil2.length-1;i>=0;i--)
{
j = j + 1;
if (j == 3)
{
bil3 = "." + bil3
}
else if ((j >= 6) && ((j % 3) == 0))
{
bil3 = "," + bil3
}
bil3 = bil2.charAt(i) + "" + bil3
}
ini.value = bil3
}
function decimalin1(ini)
{
var i, j;
var bil2 = deletecommaperiod(ini,'both')
var bil3 = ""
j = 0
for (i=bil2.length-1;i>=0;i--)
{
j = j + 1;
if (j == 3)
{
bil3 = "." + bil3