     // Overall version of this body of code
     //       = 4;           // 1st Published version:  http://4dnetwrok.org/Notes/.....
     //       = 5;  	     //	Revised 2009.07.27 added notion of ID to go with value in DDn List
     //       = 6;  	     //	Revised 2009.08.11 added support for Who field (and associated drop down)
     //       = 7;  	     //	Revised 2009.08.17 fixed nasty "submit on enter" bug
     var $v4D = 8.1;  	     //	Revised 2009.08.18 re-write AJAX to use hidden fields and include IDs

	var $ActiveDDn    = '';    // Name of active auto-complete DDL
     	var $highlightedRow = -1;
     	var $allowSubmit = true;
	var $mouseOverDDn = false;
	var $enterKeyed = false;
	var $tabKeyed = false;

	function disableSubmit()
	{
		$allowSubmit = false;
		//printlog('submit disabled');
	}

	function holdDDn()
	{
		$mouseOverDDn = true;
	}

	function releaseDDn()
	{
		$mouseOverDDn = false;
	}
	
	function doSubmit()
	{
		return $allowSubmit;
	}

	/*
		Function documentation: doBlurAction
		
		Function handles blur actions that would, by default, remove focus from text input field. 
		There are three blur actions handled by this method:
			1. Click (either on or off the dropdown selection div generated for the text input field)
			2. Enter key (blur action for IE)
			3. Tab key (blur action for IE, FF)
			
	*/
	function doBlurAction($e, $divS, $FnS, $FnSh, $DDn_divS, $EB, $FnN, $uid)
	{
		if($highlightedRow != -1) // a row in the ddn selection div is highlighted (either by mouse hover or by key through)
		{
			if($enterKeyed == false && $tabKeyed == false) // blur action: CLICK
			{
				if($mouseOverDDn) // CLICK: on ddn selection div
				{
					var rowElem = document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].getElementsByTagName('td')[0];
	                        	var $Fval = rowElem.id;
					var result = validate_entry($Fval, $FnN, $EB, $FnSh, $uid);
					if(result != false)
                			{
                        			if (isBlank($Fval))
                        			{
                        			        DDnClear($DDn_divS);
                        			}
                        			else
                        			{
                        			        var $valID = result;
							DDnListDo($divS, $FnS, $FnSh, $DDn_divS, $Fval, $valID, $uid);
                        			        $enterKeyed = false;
                                                	// why mess with allowsubmit here?
							//$allowSubmit = true;
                                                	field =  document.getElementById($FnS);
                                                	setTimeout("field.focus();", 1);
                        			}
                			}
				}
				else $allowSubmit = true; // CLICK: off ddn selection div
			}
			else // blur action: ENTER or TAB
			{
				// selection guaranteed (since highlighted row): entry handled in doKeyDown 
				field =  document.getElementById($FnS);
                        	setTimeout("field.focus();", 1);
			}
			$enterKeyed = false;
			$tabKeyed = false;
			DDnClear($DDn_divS);
		}
		else // no row is highlighted (ddn selection div may or may not be present, input field may or may not have value)
		{
			// cases:
			// 1. click "between" selections (mouse over ddn selection div)
			// 2. click attempt to see more results (mouse over ddn selection div)
			// 3. click off field/ddn selection div
			// 4. enter or tab without text in field (no highlighted row)
			// 5. enter or tab with text in field (no highlighted row)
			// note: action for cases 4 and 5 handled in doKeyDown, no need to handle here

			if($enterKeyed == false && $tabKeyed == false) // blur action: CLICK
                        {
				if($mouseOverDDn) // cases 1, 2
	                        {
					$mouseOverDDn = true;
               	                 	field =  document.getElementById($FnS);
                       			setTimeout("field.focus();", 1);
                        	}
				else // case 3
				{
					DDnClear($DDn_divS);
        	                        $allowSubmit = true;
				}
			}
			else // blur action: ENTER or TAB 
			{
				if(isBlank(document.getElementById($FnS).value)) // case 4 or 5 (case 5 only need be caught for IE below)
				{
					// case 5 (enter keyed recently in IE, so entry actually already made and text cleared)
					if (navigator.appName == "Microsoft Internet Explorer" && $enterKeyed == true) 
                                        {
                                                DDnClear($DDn_divS);
                                                $enterKeyed = false;
                                        }
					field =  document.getElementById($FnS);
                                        setTimeout("field.focus();", 1);
				}
			}
			// reset $enterKeyed and $tabKeyed here if needed . . .
		}
		//printlog();
	}

	function doAdd($divS, $FnS, $DDn_divS, $FnN, $EB, $FnSh, $uid)
	{
		var $Fval = document.getElementById($FnS).value;
		if(isBlank($Fval))
		{
			field =  document.getElementById($FnS);
                      	setTimeout("field.focus();", 1);
			return;
		}

                var result = validate_entry($Fval, $FnN, $EB, $FnSh, $uid);
                if(result != false)
                {
                	if (isBlank($Fval))
                        {
                        	DDnClear($DDn_divS);
                      	}
                       	else
                        {
                         	var $valID = result;
                                Add2List($divS, $FnSh, $FnS, $DDn_divS, $Fval, $valID, $uid);
				DDnClear($DDn_divS);
				// why mess with allowsubmit here?
				//$allowSubmit = true;
                                $enterKeyed = false;                
				field =  document.getElementById($FnS);
                                setTimeout("field.focus();", 1); 
   			}
                                //return true;                  // ecm 09.08.11 so we don't advance to next field
                                //return false;
            	}
             	else // invalid entry entered
                {
                      	DDnClear($DDn_divS);
              	}
	}

     	function doKeyDown($e, $divS, $FnSh, $FnS, $DDn_divS, $FnN, $EB, $uid) 
	{
		document.getElementById($EB).style.display="none"; // hides error bar if it was visible

        	var $keynum;
        	var $keychar;

        	if(window.event) // IE
       		{
        		$keynum = $e.keyCode;
       		}
       		else if($e.which) // Netscape/Firefox/Opera
      		{
        	  	$keynum = $e.which;
       		}
	
		if($keynum == 9)
		{
			if (navigator.appName != "Microsoft Internet Explorer") $e.preventDefault();
			$tabKeyed = true;
		}

		if ($keynum == 38)
       		{
		 	if ($ActiveDDn.length != 0)
                	{
                	        if($highlightedRow != -1) document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].style.background = "";
                	        if($highlightedRow > 0)
                	        {
                	                $highlightedRow--;
                	        }
                	        else
                	        {
                	                $highlightedRow = document.getElementById($ActiveDDn).rows.length - 1;
                	        }
				document.getElementById($FnS).value = document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].getElementsByTagName('td')[0].id;
                	        document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].style.background = "#c8c8c8";
         //     	        document.getElementById($ActiveDDn).focus();

				// start cursor position script

				var obj = document.getElementById($FnS);
				var len = obj.value.length;
				if(obj.createTextRange) 
				{
					var range = obj.createTextRange();
					range.move('character', len);
					range.select();
				}
				else 
				{
					if(obj.selectionStart != null )
					{
						$e.preventDefault();
						obj.focus();
						obj.setSelectionRange(len, len);
					}
					else
					{
						obj.focus();
					}
				}

				// end cursor position script
                	}
                	// return true;         // ecm 09.08.11 so we don't advance to next field
                	//return false;
		}

        	// DownArrow(40)
        	if ($keynum == 40) 
		{
        	    	if ($ActiveDDn.length != 0) 
			{	
				if($highlightedRow != -1) document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].style.background ="";
				if($highlightedRow < document.getElementById($ActiveDDn).rows.length - 1) 
				{
					$highlightedRow++;
				}
				else
				{
					$highlightedRow = 0;
				}
				document.getElementById($FnS).value = document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].getElementsByTagName('td')[0].id;
				document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].style.background ="#c8c8c8";

				// start cursor position script
	
        	                var obj = document.getElementById($FnS);
        	                var len = obj.value.length;
        	                if(obj.createTextRange)
        	                {
        	                        var range = obj.createTextRange();
        	                        range.move('character', len);
        	                        range.select();
        	                }
        	                else
        	                {
        	                        if(obj.selectionStart != null )
        	                        {
        	                                $e.preventDefault();
        	                                obj.focus();
        	                                obj.setSelectionRange(len, len);
        	                        }
        	                        else
        	                        {
        	                                obj.focus();
        	                        }
        	                }

                        	// end cursor position script

			}
                        // return true;         // ecm 09.08.11 so we don't advance to next field
                        //return false;
                }


		// Comma(188), Semicolon(59, 186), Tab(9)
   		if ($keynum==188 || $keynum==59 || $keynum==186 || $keynum==9) 
		{		
        	    	var $Fval = document.getElementById($FnS).value;
	    
			var result = validate_entry($Fval, $FnN, $EB, $FnSh, $uid);
			if(result != false)
			{
			   	if (isBlank($Fval)) 
				{
	        	       		DDnClear($DDn_divS);
	        	    	} 
				else 
				{
					var $valID = result;
					Add2List($divS, $FnSh, $FnS, $DDn_divS, $Fval, $valID, $uid);
					// why mess with allowsubmit here?
					//$allowSubmit = true;
					DDnClear($DDn_divS);
					$enterKeyed = false;
					$tabKeyed = false;
					//if($keynum == 9 && navigator.appName == "Microsoft Internet Explorer") // work around for IE
					if($keynum == 9)
					{
						field =  document.getElementById($FnS);
	              			     	setTimeout("field.focus();", 1);
					}
				}
			}
			else
			{
				DDnClear($DDn_divS); // invalid entry
				if($keynum == 9) $tabKeyed = false;
			}
		}

		// Enter(13)
        	if ($keynum==13)
        	{
        	        $enterKeyed = true; // for IE enter blur action bug

	                var $Fval = document.getElementById($FnS).value;
			if($Fval == '')
			{
				$allowSubmit = true;
				return;
			}

			var result = validate_entry($Fval, $FnN, $EB, $FnSh, $uid);
                        if(result != false) // valid entry
                        {
		                if (isBlank($Fval))
		                {
		                        DDnClear($DDn_divS);
		                }
		                else
		                {
					var $valID = result;
		                        Add2List($divS, $FnSh, $FnS, $DDn_divS, $Fval, $valID, $uid);
		                        if (navigator.appName != "Microsoft Internet Explorer")
		                        {
	        	                        DDnClear($DDn_divS);
	        	                        $enterKeyed = false;
	        	                }
	        	        }
			}
			else // invalid entry
			{
				DDnClear($DDn_divS);
				$enterKeyed = false;
			}
        	 }
  	}

     function isBlank($ss) {
        // A utility function that returns true if a string only contains white space
        for(var $nn=0; $nn < $ss.length; $nn++) {
           var $cc = $ss.charAt($nn);
           if (($cc != ' ') && ($cc != '\n') && ($cc != '')) return false;
        }
        return true;
     }

     function doKeyUp($e, $divS, $FnS, $FnN, $uid, $FnSh, $DDnSel, $DDn_divS) {
        var $keynum;
        var $keychar;
        if(window.event) // IE
          {
          $keynum = $e.keyCode;
          }
          else if($e.which) // Netscape/Firefox/Opera
          {
          $keynum = $e.which;
          }

        if ($keynum >= 13 && $keynum <= 20) return false;    // Enter, Shift, Control, etc.
        if ($keynum >= 112 && $keynum <= 123) return false;  // F1 - F12

        // Esc(27)
        if ($keynum == 27) {
          DDnClear($DDn_divS);
          return false;
        }

	if ($keynum >= 36 && $keynum <= 40) return false; // don't send ajax request when keying through results

        var $Fval = document.getElementById($FnS).value;

        if (isBlank($Fval)) {
           DDnClear($DDn_divS);
           return false;
        }

        if ($Fval == ',' || $Fval==';') {
           document.getElementById($FnS).value = '';
           return false;
        }
	$highlightedRow = -1;
	$NumResults = 10;
        if($keynum != 9) ajaxRequest($FnN, $FnS, $divS, $FnSh, $uid, $DDnSel, $DDn_divS, $NumResults);             
        //return false;

	//printlog();
     }

     function ajaxRequest($FnN, $FnS, $divS, $FnSh, $uid, $DDnSel, $DDn_divS, $NumResults) {
        var $Fval = document.getElementById($FnS).value;

	if (isBlank($Fval)) {
           DDnClear($DDn_divS);
        }

	// Init AJAX OBJ 
        var $AJAX = null;

        if (window.XMLHttpRequest) {
           $AJAX=new XMLHttpRequest();
        } else {
           $AJAX=new ActiveXObject("Microsoft.XMLHTTP");
        }
        if ($AJAX==null) {
           alert("Your browser doesn't support AJAX.");
           //return false;
        }

        $AJAX.onreadystatechange = function() {
           if ($AJAX.readyState==4 || $AJAX.readyState=="complete") {
		callback($AJAX.responseText, $AJAX.status, $DDn_divS, $DDnSel);
           }
        }

        var $url='http://4dnetwork.org/resources/NotesDDn_AJAX.php?FnN=' +$FnN+ '&FnS=' +$FnS;
	$url += '&divS=' +$divS+ '&FnSh=' +$FnSh+ '&DDnSel=' +$DDnSel+ '&DDn_divS=' +$DDn_divS;
	$url += '&uid=' +$uid+ '&Fval=' + url_encode($Fval) + '&NumResults=' + $NumResults + '&short=1';
        //var $url='http://192.168.1.10/4d.html';  // For debugging -ecm

        $AJAX.open("GET", $url, true);       // Open the url this object was set-up with.
        $AJAX.send(null);                    // Send the request.
	document.getElementById($FnS).focus();
     }                           

     function callback($dataS, $statusS, $DDn_divS, $DDnSel) {
	var $d = document.getElementById($DDn_divS);
     	if ($dataS.length !=0) 
	{
           	$ActiveDDn = $DDnSel;
           	$d.innerHTML = $dataS;
           	$d.style.visibility = 'visible';
		
		if($highlightedRow != -1) document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].style.background ="#c8c8c8";
//           	document.getElementById($ActiveDDn).focus();
        }
	else // no results, probablyy an invalid string
	{
	//	$ActiveDDn = '';
		$d.innerHTML = $dataS;
		$d.style.visibility = 'hidden';
	}

     }

	function validate_entry($Fval, $FnN, $EB, $FnSh, $uid)
	{
		// Init AJAX OBJ
	        var $AJAX = null;

	        if (window.XMLHttpRequest) 
		{
           		$AJAX=new XMLHttpRequest();
        	} 
		else 
		{
           		$AJAX=new ActiveXObject("Microsoft.XMLHTTP");
        	}
        	if ($AJAX==null) 
		{
           		alert("Your browser doesn't support AJAX.");
        	}

		var $url='http://4dnetwork.org/resources/DDN_Entry_Validation.php?Fval=' +url_encode($Fval)+ '&FnN=' +$FnN+ '&uid=' +$uid; 	
		$AJAX.open("GET", $url, false);       // Open the url this object was set-up with.
	        $AJAX.send(null);                    // Send the request.

		// $AJAX.responseText takes this form: type:max(:id)
		// type: none/unique/multiple	max: max number of repeat entries	id: id for unique match		
		var resp = $AJAX.responseText;

		var colon = resp.indexOf(':');
		var type = resp.substring(0, colon);
		var max = resp.substring(colon+1, colon+2);

		// perform repeat entry validation
		var repeat_entry = validate_repeat_entry($Fval, $FnSh, max);
		if(repeat_entry)
		{
			var eb = document.getElementById($EB);
                       	eb.innerHTML = '<center>Repeat selection. Please try again.</center>';
                       	eb.style.display="block";
			return false;
		}

		if(type == 'none')
		{
			var eb = document.getElementById($EB);
                       	eb.innerHTML = '<center>Invalid entry. Please try again.</center>';
                       	eb.style.display="block";
			return false;
		//	if($Fval.indexOf('@') != -1 && $Fval.indexOf('.') != -1) // email
		//	{
		//		if($Fval.length < 6) return false;
		//		else return 'E';
		//	}
		//	else return 'N';
		}

		else if(type == 'unique')
		{
			colon = resp.indexOf(':', colon+1);
			var comma = resp.indexOf(',', colon);
			return resp.substring(colon+1, comma);
		} 

		else
		{
			var eb = document.getElementById($EB);
                       	eb.innerHTML = '<center>Invalid entry. Please try again.</center>';
                       	eb.style.display="block";
			return false;
//			return 'A';
		}
	}

	function validate_repeat_entry($Fval, $FnSh, $max)
	{
		$Fval = $Fval.replace(/,/gi,"&#44;");

		var $list = document.getElementById('related_goals_list').value;
              	var $last_i = -1;
		var $count = 0;

		while (true)
		{
			$i = $list.indexOf(',', $last_i+1);
			if ($i==-1) break;

                       	$val = $list.substring($last_i+1,$i);

                        if($Fval == $val) 
			{
				if($count == $max) return true;
				else $count++;
			}

                  	$last_i = $i;
             	}
		return false;
	}

	function generate_clarification_selections($Fval, $FnN, $cc_id, $divS, $FnSh, $index, $suggestion, $uid)
	{
		var $AJAX = null;

                if (window.XMLHttpRequest)
                {
                        $AJAX=new XMLHttpRequest();
                }
                else
                {
                        $AJAX=new ActiveXObject("Microsoft.XMLHTTP");
                }
                if ($AJAX==null)
                {
                        alert("Your browser doesn't support AJAX.");
                }

                var $url = 'http://4dnetwork.org/resources/DDN_Clarification_Selections.php?Fval=' +url_encode($Fval)+ '&FnN=' +$FnN;
		$url += '&divS=' +$divS+ '&FnSh=' +$FnSh+ '&FnSh_Val=' +url_encode(document.getElementById($FnSh).value);
		$url += '&index=' + $index + '&suggestion=' + $suggestion + '&uid=' + $uid;
                
		$AJAX.open("GET", $url, true);       // Open the url this object was set-up with.
                $AJAX.send(null);                    // Send the request.
		$AJAX.onreadystatechange = function() 
		{
           		if ($AJAX.readyState==4 || $AJAX.readyState=="complete") 
			{
				$clarification_content = document.getElementById($cc_id);
				$clarification_content.innerHTML = $AJAX.responseText;
			}
        	}
	}

	function bolden(id)
	{
		document.getElementById(id).style.fontWeight = 'bold';
	}

	function unbolden(id)
	{
		document.getElementById(id).style.fontWeight = '';
	}

	function highlight(row)
	{
		if($highlightedRow != -1)
		{
			document.getElementById($ActiveDDn).getElementsByTagName('tbody')[0].getElementsByTagName('tr')[$highlightedRow].style.background = "";
			$highlightedRow = -1;
		}
		$highlightedRow = row.rowIndex;
		row.style.background = "#c8c8c8";
	}

	function unhighlight(row)
	{
		if($highlightedRow == row.rowIndex) $highlightedRow = -1;
		row.style.background = "";
	}

     	function url_encode($s) 
	{
		// URL restricted characters

        	$s = $s.replace(/\$/gi, "%24");
		$s = $s.replace(/&/gi, "%26");
		$s = $s.replace(/\+/gi, "%2B");
		$s = $s.replace(/,/gi, "%2C");
		$s = $s.replace(/\//gi, "%2F");
		$s = $s.replace(/:/gi, "%3A");		
		$s = $s.replace(/;/gi, "%3B");		
		$s = $s.replace(/=/gi, "%3D");		
		$s = $s.replace(/\?/gi, "%3F");		
		$s = $s.replace(/@/gi, "%40");
	
		// URL unsafe characters

		$s = $s.replace(/ /gi, "%20");	
		$s = $s.replace(/"/gi, "%22");	
		$s = $s.replace(/</gi, "%3C");	
		$s = $s.replace(/>/gi, "%3E");	
		$s = $s.replace(/#/gi, "%23");	
		$s = $s.replace(/%/gi, "%25");	
		$s = $s.replace(/{/gi, "%7B");	
		$s = $s.replace(/}/gi, "%7D");	
		$s = $s.replace(/\|/gi, "%7C");	
		$s = $s.replace(/\\/gi, "%5C");	
		$s = $s.replace(/\^/gi, "%5E");	
		$s = $s.replace(/~/gi, "%7E");	
		$s = $s.replace(/\[/gi, "%5B");	
		$s = $s.replace(/\]/gi, "%5D");	
		$s = $s.replace(/\'/gi, "%60");	
			
		return $s;
     	}

    function DDnListDo($divS, $FnS, $FnSh, $DDn_divS, $selectionVal, $selectionID, $uid)
    {
        document.getElementById($FnS).value = $selectionVal;
	Add2List($divS, $FnSh, $FnS, $DDn_divS, $selectionVal, $selectionID, $uid);
     }

     	function DDnClear($DDn_divS) 
	{
		var $d = document.getElementById($DDn_divS);
        	$d.innerHTML = '';
        	$d.style.visibility = 'hidden';
		$ActiveDDn = '';
		$highlightedRow = -1;
		$mouseOverDDn = false;
	}

        function Add2List($divS, $FnSh, $FnS, $DDn_divS, $Fval, $valID, uid) {
                // Add to list of input strings for field $FnS,
                // keeping track of them in hidden var $FnSh
                // display output in divS


                var title = $Fval;
                if(title.length > 50)
                {
                        title = title.substring(0,50);
                        var last_space = title.lastIndexOf(' ');
                        title = title.substring(0, last_space);
                        title += '...';
                }
                var id = $valID.substring(1);

                $Fval = $Fval.replace(/,/gi,"&#44;");
                document.getElementById('related_goals_list').value += $Fval + ",";

                generate_related_goal_summary($Fval, title, id, uid);

                pack_Div($divS, $FnSh, 2, uid);
        }

        function pack_Div($divS, $FnSh, $FnN, $uid)
        {
                document.getElementById('small').value = '';
        }

        // need tab handler here

function generate_related_goal_summary(goal_title_full, goal_title, goal_id, uid)
{
        var primaryGoalID = document.getElementById('primary_goal_id').value;
        var commaTitle = goal_title_full.replace(/,/gi,"&#44;");

        var html = '';
        html += '<div id="list_row_'+goal_id+'" class="list_row" style="z-index: 1;" onmousemove="handleDrag(event);" ';
        html += '                                       onmouseup="handleRelease('+uid+','+primaryGoalID+','+goal_id+');">';
        html += '<div class="input_super_wrapper"><div class="input_wrapper">';
        html += '       <div class="title left">This Goal</div>'
        html += '       <div class="slider_input" id="weight_prompt_' + goal_id + '">';
        html += '       <div class="caption_wrapper"><div id="caption1_' + goal_id + '" class="caption top">'
        html += '               1 (Slight effect)';
        html += '       </div></div>';
        html += '       <div id="track1_' + goal_id + '" class="track rightTrack"';
        html += '       onmousedown="handleClick(event, this, 1, ' + uid + ', ' + primaryGoalID + ', ' + goal_id + ');">';
        html += '               <div id="resizer1_' + goal_id + '" class="resizer rightResizer" style="width: 16px;';
        html += '                       left: 0px;"></div>';
        html += '               <div id="handle1_'+goal_id+'" class="handle rightHandle" style="left:15px;"';
        html += '                       onmousedown="handleGrab(event,1,'+goal_id+');"'
        html += '                       onmouseover="showCaption(\'caption1_'+goal_id+'\', this);"'
        html += '                       onmouseout="hideCaption(\'caption1_'+goal_id+'\');"></div>';
        html += '       </div>';
        html += '       <div id="track2_' + goal_id + '" class="track leftTrack"';
        html += '       onmousedown="handleClick(event,this, 2, ' + uid + ', ' + primaryGoalID + ', ' + goal_id + ');">';
        html += '               <div id="effected_tail" class="staticEffectedTail"></div>';
        html += '               <div id="resizer2_' + goal_id + '" class="resizer leftResizer" style="width: 44px;background:white;"></div>';
        html += '               <div id="handle2_'+goal_id+'" class="handle leftHandle" style="left:35px;"';
        html += '                       onmousedown="handleGrab(event,2,'+goal_id+');"';
        html += '                       onmouseover="showCaption(\'caption2_'+goal_id+'\', this);"';
        html += '                       onmouseout="hideCaption(\'caption2_'+goal_id+'\');"></div>';
        html += '       </div>';
        html += '       <div class="caption_wrapper"><div id="caption2_' + goal_id + '" class="caption bottom">';
        html += '               1 (Slight effect)';
        html += '       </div></div>';
        html += '       </div>';
        html += '       <div class="title right">';
        html += '               <a href="/goals/view/?goal_id=' + goal_id + '" title="' + goal_title_full + '" style="z-index:1;">';
        html += '                       ' + goal_title + '</a>';
        html += '               <img class="delete-icon" src="/goals/view/delete-icon.png" ';
        html += '                       onclick="removeLink('+primaryGoalID+','+goal_id+',\''+commaTitle+'\','+uid+')" alt="Delete">';
        html += '       </div>';
        html += '       </div></div>';
        html += '</div>';

	updateWeighting(2, uid, primaryGoalID, goal_id);
	updateWeighting(2, uid, goal_id, primaryGoalID);

        document.getElementById('related_goals_wrapper').innerHTML += html;
}


