--- nodereference_url.module	2009-07-25 17:48:29.000000000 -0700
+++ nodereference_url.module	2009-11-19 14:08:15.000000000 -0800
@@ -110,20 +110,31 @@ function nodereference_url_build_link($n
 
   if ($referenceable && user_access('create ' . $field['type_name'] . ' content')) {
     $link_settings = $field['widget']['node_link'];
+ 
     if ((!empty($link_settings['teaser']) && $teaser == TRUE) || (!empty($link_settings['full']) && $teaser == FALSE)) {
-      $link = array(
-        'title' => $link_settings['title'],
-        'href' => 'node/add/'. str_replace('_', '-', $field['type_name']) .'/'. $node->nid,
-      );
+      //Check if OG node and has context
+      if (module_exists('og') && $group_node = og_get_group_context()) {
+         $link = array(
+	        'title' => $link_settings['title'],
+	        'href' => 'node/ognodeadd/'. $node->nid,
+	      );
+	      $link['query']['type'] = str_replace('_', '-', $field['type_name']);  
+          $link['query']['gids[]'] = $group_node->nid;
+      } else {
+	      $link = array(
+	        'title' => $link_settings['title'],
+	        'href' => 'node/add/'. str_replace('_', '-', $field['type_name']) .'/'. $node->nid,
+	      );
+      }
       if (!empty($link_settings['hover_title'])) {
         $link['attributes']['title'] = $link_settings['hover_title'];
       }
       if (!empty($link_settings['destination'])) {
         if ($link_settings['destination'] == 'source') {
-          $link['query'] = drupal_get_destination();
+          $link['query']['destination'] = drupal_get_destination();
         }
         elseif ($link_settings['destination'] == 'node') {
-          $link['query'] = 'destination='. urlencode(drupal_get_path_alias('node/'. $node->nid));
+          $link['query']['destination'] = urlencode(drupal_get_path_alias('node/'. $node->nid));
         }
       }
     }
@@ -273,6 +284,10 @@ function nodereference_url_widget(&$form
   elseif (arg(0) == 'node' && arg(1) == 'add') {
     $referenced_nid = is_numeric(arg(3)) ? arg(3) : NULL;
   }
+  //special case for OG nodes 
+  elseif (arg(0) == 'node' && arg(1) == 'ognodeadd') {
+  	   $referenced_nid = is_numeric(arg(2)) ? arg(2) : NULL;
+  }
 
   // Check that the NID is a valid reference.
   if (isset($referenced_nid)) {
