<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -20,6 +20,41 @@ function $CBFG(followup_id){
 	//console.log(followup_id+':  '+cur_idx_values.inspect());
 	return cur_idx_values;
 }
+
+function check_year(year) {
+	if (/[^\d]/.exec(year)) {return null;}
+	if (year.length == 4) {return year;}
+	if (year.length == 2) {
+		var y = parseInt(year);
+		if (y &lt;= 37) {return &quot;20&quot;+year;}
+		if (y&gt;37 &amp;&amp; y &lt;100) {return &quot;19&quot;+year;}
+	}
+	return null;
+}
+
+function check_num(num) {
+	if (/[^\d]/.exec(num)) {return null;}
+	var n = parseInt(num);
+	if (isNaN(n)) {return null}
+	return n;
+}
+
+function make_date(year,month,date) {
+	year = check_year(year);
+	if (year == null || year == 0)  {return null};
+	month = check_num(month)
+	if (month == null || month == 0)  {return null};
+	var day = check_num(date)
+	if (day == null || day == 0)  {return null};
+  var d = new Date(month + &quot;/&quot; + day + &quot;/&quot; + year);
+	// implementations of javascript do different things if date is invalid, sometimes return &quot;Invalid Date&quot;
+	// other times returning NaN and other times just interpolating higher values than it should
+  if ((d == &quot;Invalid Date&quot;) || isNaN(d) || d.getMonth() + 1 != month || d.getDate() != day || d.getFullYear() != year) {
+		return null
+	}
+	return d
+}
+
 //Get value of radiobutton widgets
 function $RF(rb_class){
 	var chosen_element = $$(rb_class).find(function(rb){return rb.checked});
@@ -27,36 +62,28 @@ function $RF(rb_class){
 }
 //Get value of date and month_year widgets
 function $DF(name){
-	var yield_field = $F(name+'_year');
-	var year = yield_field.length &gt; 0 ? (new Date).getFullYear().toString().substring(0,4-yield_field.length) + yield_field : &quot;&quot;;
-	var d = new Date($F(name+'_month') + &quot;/&quot; + $F(name+'_day')  + &quot;/&quot; + year);
-	return (d == &quot;Invalid Date&quot;) ? null : d;
-}
-//Get value of date_time widgets
-function $DTF(name){
-	var yield_field = $F(name+'_year');
-	var year = yield_field.length &gt; 0 ? (new Date).getFullYear().toString().substring(0,4-yield_field.length) + yield_field : &quot;&quot;;
-	var hours = parseInt($F(name+'_hours'));
-	if (isNaN(hours)) {return null};
-	if ($F(name+'_am_pm') == 'pm') {hours = hours + 12};
-	var minutes = parseInt($F(name+'_minutes'));
-	if (isNaN(minutes)) {return null};
-	var d = new Date($F(name+'_month') + &quot;/&quot; + $F(name+'_day')  + &quot;/&quot; + year + &quot; &quot;+ hours + ':' + minutes);
-	return (d == &quot;Invalid Date&quot;) ? null : d;
+	return make_date($F(name+'_year'),$F(name+'_month'),$F(name+'_day'));
 }
 //Get value of time widgets
 function $TF(name){
-	var hours = $F(name+'_hours');
-	var minutes = $F(name+'_minutes');
-	if (/[^\d]/.exec(hours) || /[^\d]/.exec(minutes)) {
-		return null
-	}
-	var hours = parseInt(hours);
-	if (isNaN(hours) || hours &gt; 12 || hours &lt; 1) {return null};
-	var minutes = parseInt(minutes);
-	if (isNaN(minutes) || minutes &gt; 59 || minutes &lt; 0) {return null};
+	var hours = check_num($F(name+'_hours'));
+	if (hours == null || hours &gt; 12 || hours &lt; 1) {return null};
+	var minutes = check_num($F(name+'_minutes'));
+	if (minutes == null || minutes &gt; 59 || minutes &lt; 0) {return null};
 	var d = new Date(&quot;1/1/1 &quot;+ hours + ':' + minutes + ' ' + $F(name+'_am_pm'));
-	return (d == &quot;Invalid Date&quot;) ? null : d;
+	return ((d == &quot;Invalid Date&quot;)||isNaN(d)) ? null : d;
+}
+//Get value of date_time widgets
+function $DTF(name){
+	d = make_date($F(name+'_year'),$F(name+'_month'),$F(name+'_day'));
+	if (d == null) {return null};
+	var hours = check_num($F(name+'_hours'));
+	if (hours == null || hours &gt; 24) {return null};
+	if ($F(name+'_am_pm') == 'pm') {hours = hours + 12};
+	var minutes = check_num($F(name+'_minutes'));
+	if (minutes == null || minutes &gt; 59 || minutes &lt; 0) {return null};
+	d = new Date((d.getMonth()+1) + &quot;/&quot; + d.getDate() + &quot;/&quot; + d.getFullYear() + &quot; &quot;+ hours + ':' + minutes);
+	return ((d == &quot;Invalid Date&quot;)||isNaN(d)) ? null : d;
 }
 //Get value of factor_textfield widgets
 function $FTF(name){
@@ -242,6 +269,11 @@ function find_current_idx() {
 	return cur_idx;
 }
 function update_date(write_date,read_date) {
+	if (window.execScript) {
+				window.execScript('record_'+write_date+'_first_pass = true;'); //ie
+			}else{
+			 	top.eval('record_'+write_date+'_first_pass = true;'); //others
+			}
 	$('record_'+write_date+'_am_pm').value = $F('record_'+read_date+'_am_pm');
 	$('record_'+write_date+'_month').value = $F('record_'+read_date+'_month');
 	$('record_'+write_date+'_day').value = $F('record_'+read_date+'_day');</diff>
      <filename>generators/metaform/templates/metaform.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3c169432e6d92283a0adf1aac4ea2d047e704d26</id>
    </parent>
  </parents>
  <author>
    <name>Eric Harris-Braun</name>
    <email>eric@harris-braun.com</email>
  </author>
  <url>http://github.com/zippy/metaform/commit/9b6ec2728ec3652361893422a19eab66f14a68d7</url>
  <id>9b6ec2728ec3652361893422a19eab66f14a68d7</id>
  <committed-date>2009-05-05T10:17:38-07:00</committed-date>
  <authored-date>2009-05-05T10:17:38-07:00</authored-date>
  <message>fixes to widget javascript date handling to work on IE

IE doesn't always return &quot;Date Invalid&quot; the same way Safari and FF do, instead it just interpolates things like 13/1/2001 to be 1/1/2002.  This new javascript handles this bogusness.</message>
  <tree>e12eae29186dc13f7521da8720a0528ff319ad7c</tree>
  <committer>
    <name>Eric Harris-Braun</name>
    <email>eric@harris-braun.com</email>
  </committer>
</commit>
