var my_link_cookie = "ht_my_links";
var img_path = "/on/img/"; //image path set here

var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);

function SetCookie( strName, strValue )	{
  var strCookie = strName + "=" + escape( strValue );

  // 50 years before expiry should be enough!
  var dtExpire = new Date();
  dtExpire.setTime( dtExpire.getTime() + (365 * 24 * 60 * 60 * 1000 * 50 ) );
  strCookie += "; expires=" + dtExpire.toGMTString();

  document.cookie = strCookie;
}

function SetPerSessionCookie( strName, strValue )	{
  var strCookie = strName + "=" + escape( strValue );
  strCookie += "; path=/";
  document.cookie = strCookie;
}

function GetCookie( strName )	{
  var dc = document.cookie;
  var prefix = strName + "=";
  var begin = dc.indexOf( "; " + prefix );

  if( begin == -1 )  {
    begin = dc.indexOf( prefix );
    if( begin != 0 )	{
      return null;
    }
  }
  else
    begin += 2;

  var end = document.cookie.indexOf( ";", begin );

  if( end == -1 )
    end = dc.length;
  return unescape( dc.substring( begin + prefix.length, end ) );
}


function resetPerSessionCookie()	{
	SetPerSessionCookie( my_link_cookie, "" )
}

function AddToMyLinks(obj,lnk, txt)	{
	if(browserName == "Netscape" && browserVer < 5)	{
		return false;
	}
	obj.style.visibility="hidden";
	var temp = GetCookie( my_link_cookie );	
	if(temp == null)	
		temp = lnk + ">" + txt;
	else
		temp += "|" + lnk + ">" + txt;
	SetPerSessionCookie( my_link_cookie, temp )
	return false;
}

function GetMyLinks()	{
	return GetCookie( my_link_cookie );	
}

function AddMyLinkImage(lnk, txt)	{
	if(browserName == "Netscape" && browserVer < 5)	{
			return false;
	}
	var mytxt = GetCookie( my_link_cookie );	
	var found = false;

	if(txt != null && lnk != null)	{
		txt=txt.replace(/\\/ig,"\\\\");
		txt=txt.replace(/"/ig,"\'\'");
		txt=txt.replace(/'/ig,"\\'");
		if(mytxt != null)	{
			var arr = mytxt.split("|");
			for(i=0;i<arr.length;i++)	{
				var narr = arr[i].split(">");
				//if(narr[0] == lnk && narr[1] == txt)	{
				if(narr[0] == lnk)	{
					found = true;
					break;
				}
			}
		}
		if(!found)	{
			str = "<a href=\"#\" onClick=\"return AddToMyLinks(this,'"+lnk+"','"+ txt+"');\"><img src=\""+img_path+"mc.gif\"  border=0 alt=\"Click to add to 'My Links'\"></a>";
			//alert(str);
			document.write(str);
		}
	}
	return;
}
