//****************************************************************** // // Print a window, hiding the button // //****************************************************************** function printWindow(print_button){ print_button.style.visibility="hidden"; window.print(); print_button.style.visibility="visible"; } //****************************************************************** // // Convert a scanned credit card number to a "normal" card number // //****************************************************************** function parseCC(cc) { with(cc.form) { var new_cc=""; var month=null; var year=null; for(var i=0;i= 4) win.window.focus(); } //****************************************************************** // // Create a new window in which to display a receipt // //****************************************************************** function NewWindow(mypage) { win = window.open(mypage+"&new_window=yes", "ReceiptWindow", "menubar=yes,toolbar=yes,scrollbars=yes,resizable"); if (parseInt(navigator.appVersion) >= 4) win.window.focus(); } //****************************************************************** // // Format a currency field (without leading $) // //****************************************************************** function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(parseFloat(num))) num = "0"; num=parseFloat(num); var neg=num<0; if(neg)num=-num; num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; cents = Math.floor(num*100+0.5)%100; num = Math.floor((num*100+0.5)/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)); num+="." + cents; if(neg)num="-"+num; return num; } //****************************************************************** // // Validate a currency field // //****************************************************************** function validCurrency(field,field_name) { if(emptyField(field))return true; var num=parseFloat(field.value); if(isNaN(num)){ alert("The " + field_name + " contains an invalid entry"); field.focus (); return false; } field.value=formatCurrency(num); return true; } function validCurrencyNonNeg(field,field_name) { if(emptyField(field))return true; var num=parseFloat(field.value); if(isNaN(num)){ alert("The " + field_name + " contains an invalid entry"); field.focus (); return false; } if(num<0){ alert(field_name + " cannot be negative"); field.focus (); return false; } return true; } //****************************************************************** // // Complain about an empty form field // //****************************************************************** function empty(field,msg) { if(!emptyField(field)) return false; if(field.type=="text"||field.type=="password"||field.type=="textarea") { alert("Please enter "+msg+"."); field.focus(); return true; } if(field.type=="select-one"){ alert("Please select "+msg+"."); field.focus(); return true; } return false; } //****************************************************************** // // Check if a form field is empty // //****************************************************************** function emptyField(field){ if(field==null){ alert("'emptyField' called with undefined field"); return true; } if(field.type=="hidden")return false; if(field.type=="text"||field.type=="password"||field.type=="textarea"||field.type=="file") { for(var i=0;i"); this.wwrite("Calendar"); this.wwrite(""); this.wwrite(""); this.wwrite(""); this.wwrite (""); this.wwrite("
"); // Show navigation buttons var prevMMYYYY = this.calc_month_year(this.gMonth, this.gYear, -1); var prevMM = prevMMYYYY[0]; var prevYYYY = prevMMYYYY[1]; var nextMMYYYY = this.calc_month_year(this.gMonth, this.gYear, 1); var nextMM = nextMMYYYY[0]; var nextYYYY = nextMMYYYY[1]; this.wwrite("
"); this.wwrite(""); this.wwrite(""); this.wwrite(""); this.wwrite ("
[" + Calendar.Months[prevMM].substring(0,3) + "]" + this.gMonthName + " " + this.gYear + ""); this.wwrite("[" + Calendar.Months[nextMM].substring(0,3) + "]
"); // Get the complete calendar code for the month.. this.wwrite (""); this.cal_header(); this.cal_data(); this.wwrite ("
"); this.wwrite(""); this.wwrite(""); this.wwrite(""); this.wwrite ("
[" + (parseInt(this.gYear)-1) + "][" + (parseInt(this.gYear)+1) + "]
"); this.wwrite ("
"); this.wwrite("
"); this.gWinCal.document.close(); } Calendar.prototype.wwrite = function(wtext) { this.gWinCal.document.writeln(wtext); } Calendar.prototype.cal_header = function() { this.wwrite(""); this.wwrite("Sun"); this.wwrite("Mon"); this.wwrite("Tue"); this.wwrite("Wed"); this.wwrite("Thu"); this.wwrite("Fri"); this.wwrite("Sat"); this.wwrite(""); } Calendar.prototype.cal_data = function() { var vDate = new Date(); vDate.setDate(1); vDate.setMonth(this.gMonth); vDate.setFullYear(this.gYear); var vFirstDay=vDate.getDay(); var vDay=1; var vLastDay=this.get_daysofmonth(this.gMonth, this.gYear); var vOnLastDay=false; /* Get day for the 1st of the requested month/year.. Place as many blank cells before the 1st day of the month as necessary. */ this.wwrite(""); for (i=0; i "); } // Write rest of the 1st week for (j=vFirstDay; j<7; j++) { this.wwrite("" + "" + this.format_day(vDay) + ""); vDay=vDay + 1; } this.wwrite(""); // Write the rest of the weeks for (k=2; k<7; k++) { this.wwrite(""); for (j=0; j<7; j++) { this.wwrite("" + "" + this.format_day(vDay) + "" + ""); vDay++; if (vDay > vLastDay) { vOnLastDay = true; break; } } if (j == 6) this.wwrite(""); if (vOnLastDay) break; } // Fill up the rest of last week with proper blanks, so that we get proper square blocks for (m=1; m<(7-j); m++) { this.wwrite("" + m + ""); } } Calendar.prototype.format_day = function(vday) { if (vday==gNow.getDate() && this.gMonth==gNow.getMonth() && this.gYear==gNow.getFullYear()) return "" + vday + ""; else return vday; } Calendar.prototype.write_weekend_string = function(vday) { var i; // Return special formatting for the weekend day. for (i=0; i= 12) { p_Month-=12; p_Year++; } var ret_arr = new Array(); ret_arr[0] = p_Month; ret_arr[1] = p_Year; return ret_arr; } function Build(p_item, p_month, p_year,aux) { gCal = new Calendar(p_item,ggWinCal,p_month,p_year,aux); gCal.show(); } function show_calendar(p_item) { ggWinCal=window.open("", "Calendar", "width=250,height=250,status=no,resizable=no,top=200,left=200"); ggWinCal.opener = self; var s = eval(p_item).value; gNow = s=="" ? new Date () : new Date (s); Build(p_item, gNow.getMonth(), p_year=gNow.getFullYear(),null); } function show_calendar(p_item,aux) { ggWinCal=window.open("", "Calendar", "width=250,height=250,status=no,resizable=no,top=200,left=200"); ggWinCal.opener = self; var s = eval(p_item).value; gNow = s=="" ? new Date () : new Date (s); Build(p_item, gNow.getMonth(), p_year=gNow.getFullYear(),aux); } //////////////////////////////////////////////////////////////////// // // List box support functions. // //////////////////////////////////////////////////////////////////// // selects all the items in the listbox function selectAll(box){ for (var i=0;i=0; i--) { if(!box.options[i].selected)continue; box.options[i].selected=false; for(var j=i; j=0; i--) { if(!fbox.options[i].selected)continue; fbox.options[i].selected=false; if(fbox.options[i].value=="")continue; var moved = false; for (var j=0;jtbox.options[j].text)continue; tbox.options[tbox.length]=new Option(); for (var k=tbox.length-1; k>j; k--) { tbox.options[k].value=tbox.options[k-1].value; tbox.options[k].text=tbox.options[k-1].text; } tbox.options[j].value = fbox.options[i].value; tbox.options[j].text = fbox.options[i].text; moved = true; break; } if (!moved) { new_opt = new Option (); new_opt.value=fbox.options[i].value; new_opt.text=fbox.options[i].text; new_opt.selected = false; tbox.options[tbox.length]=new_opt; } for(var j=i; jmoveto;j--){ box.options[j].value=box.options[j-1].value; box.options[j].text=box.options[j-1].text; } box.options[moveto].value=value; box.options[moveto].text=text; moveto++; } } // Move selected items up one position function moveUp(box){ for(var i=0;i=0; i--) { if(!box.options[i].selected)continue; box.options[i].selected=false; var value = box.options[i].value; var text = box.options[i].text; for(var j=i;j=0; i--) { if(!box.options[i].selected)continue; box.options[i].selected=false; if(i==box.length-1)continue; var value = box.options[i+1].value; var text = box.options[i+1].text; box.options[i+1].value=box.options[i].value; box.options[i+1].text=box.options[i].text; box.options[i].value=value; box.options[i].text=text; } } //////////////////////////////////////////////////////////////////// // // Is the given value a digit? // //////////////////////////////////////////////////////////////////// var digits = "0123456789"; function isDigit(c) { return digits.indexOf(c)>=0; } //////////////////////////////////////////////////////////////////// // // Given a field assumed to contain a date, this little procedure // validates the field and reformats it to a standard form. // //////////////////////////////////////////////////////////////////// var valid_date_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; function validDate (field,msg) { if(field.value=="")return true; var new_value=""; var changed=false; var all_numeric=true; for (var i = 0; i < field.value.length; i++) { var ch = field.value.charAt(i); if(ch=='.'||ch=='-'){ ch='/'; changed=true; } if(!isDigit(ch))all_numeric=false; new_value+=ch; } if(changed){ field.value=new_value; } else if(all_numeric){ if(field.value.length>4) { field.value=field.value.substring(0,2)+"/"+field.value.substring(2,4)+"/"+field.value.substring(4); } } var millis=Date.parse (field.value); if(isNaN (millis)) { alert (""+msg+" date is invalid."); field.focus(); return false; } if (millis > new Date ().getTime () + 50 * 365 * 86400000) { alert (""+msg+" date is too far in the future (more than fifty years)."); field.focus(); return false; } var date=new Date(); date.setTime(millis); field.value=formatDate (date); return true; } function formatDate(date){ var year = date.getYear (); if (year < 100) { year += 1900; if (year < 1930) year += 100; } else if (year < 1900) { year += 1900; } return valid_date_months[date.getMonth()] + " " + date.getDate() + ", " + year; } function incrMonth(d,incr){ var month=d.getMonth(); if(month+incr<12){ d.setMonth(month+incr); } else { d.setMonth((month+incr)%12); d.setYear(d.getYear()+1); } } function validBirthDate (field,msg) { if(field.value=="")return true; var new_value=""; var changed=false; var all_numeric=true; for (var i = 0; i < field.value.length; i++) { var ch = field.value.charAt(i); if(ch=='.'||ch=='-'){ ch='/'; changed=true; } if(!isDigit(ch))all_numeric=false; new_value+=ch; } if(changed){ field.value=new_value; } else if(all_numeric){ if(field.value.length>4) { field.value=field.value.substring(0,2)+"/"+field.value.substring(2,4)+"/"+field.value.substring(4); } } if(isNaN (Date.parse(field.value))) { alert (""+msg+" date is invalid."); field.focus(); return false; } var millis=Date.parse (field.value); var date=new Date(); date.setTime(millis); var year = date.getYear (); if (year < 100) { year += 2000; if(new Date(year,date.getMonth(),date.getDate()).getTime()>new Date().getTime())year-=100; } else if (year < 1900) { year += 1900; } field.value=valid_date_months[date.getMonth()] + " " + date.getDate() + ", " + year; return true; } //////////////////////////////////////////////////////////////////// // // Given a field assumed to contain a time, this little procedure // validates the field and reformats it to a standard form. // //////////////////////////////////////////////////////////////////// function validTime(field,msg,ampm_field) { if (field.value=="")return true; var clean_string = ""; var suffix=""; var end_digits=false; for (var i = 0; i < field.value.length; i++) { var ch = field.value.charAt(i); if (ch == " "){ end_digits = clean_string.length>0; continue; } if (!end_digits && (ch==":" || ((ch >= "0") && (ch <= "9")))) { clean_string += ch; continue; } end_digits=true; suffix+=ch; } if (suffix.length>0) { suffix=suffix.toLowerCase (); if ("am".indexOf(suffix)==0) suffix="am"; else if ("pm".indexOf(suffix)==0) suffix="pm"; else { alert (""+msg+" time is invalid. The am/pm portion of the time is unrecognizable."); field.focus(); return false; } } else if (ampm_field!=null) { if (ampm_field[0].checked)suffix=ampm_field[0].value; else if (ampm_field[1].checked)suffix=ampm_field[1].value; } var hours = 0; var minutes = 0; var colon_index=clean_string.indexOf (":"); if (colon_index >= 0){ if (colon_index>0)hours = parseInt (clean_string.substring (0,colon_index), 10); minutes = parseInt (clean_string.substring (colon_index+1, clean_string.length), 10); if (isNaN(hours) || isNaN(minutes)) { alert (""+msg+" time is invalid. Please use a value of the form 'HH:MM AM/PM'"); field.focus(); return false; } } else { var x = parseInt (clean_string, 10); if (isNaN (x)) { alert (""+msg+" time is invalid. Please use a value of the form 'HH:MM AM/PM'"); field.focus(); return false; } hours=Math.floor(x/100); minutes=x-hours*100; if(hours==0&&minutes<24){ hours=minutes; minutes=0 } } if(hours==0){ hours=12; if(suffix.length==0)suffix="am"; } if(hours==12&&suffix.length==0) { alert(""+msg+" time is invalid. Please specify am/pm."); field.focus(); return false; } if (hours>12) { if (suffix.length>0){ alert(""+msg+" time is invalid. Military time does not need am/pm"); field.focus(); return false; } hours -= 12; suffix="pm"; } if (suffix.length==0)suffix="am"; var s = hours.toString() + ":"; if (minutes < 10)s+="0"; s+=minutes.toString(); var d=Date.parse("1/1/1999 "+s+" "+suffix); if(isNaN (d)) { alert (""+msg+" time is invalid. Please use a value of the form 'HH:MM AM/PM'"); field.focus(); return false; } if (ampm_field==null) { field.value=s+" "+suffix; } else { field.value=s; if (ampm_field[0].value.toLowerCase() == suffix) { if (!ampm_field[0].checked) { ampm_field[1].checked=false; ampm_field[0].checked=true; } } else { if (!ampm_field[1].checked) { ampm_field[0].checked=false; ampm_field[1].checked=true; } } } return true; }