// adapted from: http://www.quirksmode.org/js/croswin.html var minicalwin = null; function openminical (r,e) { // set the year-month, and form and field names for the calendar to set values into var d = document[r][e+'[y]'].value + document[r][e+'[m]'].value; // var url = "/minical.php?d="+d+"&r="+r+"&e="+e; var url = "/minical/"+d+"/"+r+"/"+e; // open window, unless already open, then just change url if (minicalwin && !minicalwin.closed) { minicalwin.location.href = url; } else { minicalwin = window.open(url, "_blank", "height=200,width=300,resizable=0,scrollbars=0,toolbar=0,location=0,status=0,menubar=0,directories=0,copyhistory=0"); if (!minicalwin.opener) { minicalwin.opener = self; } } // force popup to be able to access this window if (window.focus) { minicalwin.focus(); } // make sure to focus on pop up! } // these allow us to process a text field as a date instead of using separate dropdowns function zero_pad (i) { n = i.toString(); return (n.length < 2 ? '0'+n : n); } function setdateymd (e,y,m,d) { // turn on/off range checking easily if (true) { // do range checking -- if it starts w/ a zero, it will be considered octal! y = parseInt(y); m = parseInt(m,10); d = parseInt(d,10); if (y < 1111 || y > 9999) { e.focus(); alert('Year is out of range!'); return false; } if (m < 1 || m > 12) { e.focus(); alert('Month is out of range!'); return false; } else { m = zero_pad(m); } if (d < 1 || d > 31) { e.focus(); alert('Day is out of range!'); return false; } else { d = zero_pad(d); } } // fill in the hidden fields / dropdowns with the parsed values r = e.form; e = e.name.slice(0,-3); r[e+'[y]'].value = y.toString(); r[e+'[m]'].value = m; r[e+'[d]'].value = d; return true; } var months = ['unk','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']; function monthnamenum (n) { for (i in months) { if (months[i] == n.toLowerCase()) { return i; } } return 0; } var re_mdy = /^(\d{1,2})\D+(\d{1,2})\D+(\d{4})$/i; var re_ymd = /^(\d{4})\D*(\d{1,2})\D*(\d{1,2})$/i; var re_text = /^([a-z]{3})[a-z]*\W*(\d{1,2})\D*(\d{4})$/i; function checkdatetext (e) { if (e.value == '') { return true; } var r = null; if (r = re_mdy.exec(e.value)) { return setdateymd(e,r[3],r[1],r[2]); } if (r = re_ymd.exec(e.value)) { return setdateymd(e,r[1],r[2],r[3]); } if (r = re_text.exec(e.value)) { return setdateymd(e,r[3],monthnamenum(r[1]),r[2]); } e.focus(); alert('You must input a valid date format: m/d/Y, or Y-m-d, or Mon[th] d, Y'); return false; } function settimehi (e,h,i,m) { // turn on/off range checking easily if (true) { // do range checking -- if it starts w/ a zero, it will be considered octal! h = parseInt(h); i = parseInt(i,10); m = (m ? m.substr(0,1).toLowerCase() : ''); if (m != '' && m != 'a' && m != 'p') { e.focus(); alert('AM/PM is out of range!'); return false; } if (m == 'a' && h > 12) { e.focus(); alert('Hours is out of range!'); return false; } // AM must match! if (m == 'p' && h < 12) { h += 12; } // shift into 24 hour clock if (h < 0 || h > 23) { e.focus(); alert('Hours is out of range!'); return false; } else { h = zero_pad(h); } if (i < 0 || i > 59) { e.focus(); alert('Minutes is out of range!'); return false; } else { i = zero_pad(i); } } // fill in the hidden fields / dropdowns with the parsed values r = e.form; e = e.name.slice(0,-3); r[e+'[hi]'].value = h + ':' +i; } var re_time = /^\D*(\d{1,2})\D*(\d{2})\W*([ap]m?)?\D*$/i; function checktimetext (e) { var r = null; if (r = re_time.exec(e.value)) { return settimehi(e,r[1],r[2],r[3]); } e.focus(); alert('You must input a valid time format: h:i, or g:i [a|p]m'); return false; }