diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php
index 1f81f38594482..01a40150a05d8 100644
--- a/htdocs/core/class/html.formcompany.class.php
+++ b/htdocs/core/class/html.formcompany.class.php
@@ -502,14 +502,15 @@ function select_juridicalstatus($selected='', $country_codeid=0, $filter='')
/**
* Return list of third parties
*
- * @param Object $object Object we try to find contacts
- * @param string $var_id Name of id field
- * @param string $selected Pre-selected third party
- * @param string $htmlname Name of HTML form
- * @param string $limitto Disable answers that are not id in this array list
+ * @param Object $object Object we try to find contacts
+ * @param string $var_id Name of id field
+ * @param string $selected Pre-selected third party
+ * @param string $htmlname Name of HTML form
+ * @param string $limitto Disable answers that are not id in this array list
+ * @param int $forceid This is to force antoher object id than object->id
* @return void
*/
- function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='')
+ function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0)
{
global $conf, $langs;
@@ -544,7 +545,7 @@ function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname=
}
// We call a page after a small delay when a new input has been selected
- $javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;";
+ $javaScript = "window.location=\'./contact.php?".$var_id."=".($forceid>0?$forceid:$object->id)."&".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;";
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\');"'; // When we select with mouse
$htmloption.= 'onKeyUp="if (event.keyCode== 13) { ac_delay(\''.$javaScript.'\',\'500\'); }"'; // When we select with keyboard
@@ -570,7 +571,7 @@ function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname=
}
else
{
- $javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
+ $javaScript = "window.location='./contact.php?".$var_id."=".($forceid>0?$forceid:$object->id)."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '