/*
 * Adds images besides links that goes to other domains or protocols.
 **/
function fix_links()
{
	/* Get all links. */
	var links = document.getElementsByTagName("A");

	/* Loop through all links. */
	for(link_index in links)
	{
		/* Check that current link is an object. */
		if(typeof links[link_index] == "object")
		{
			/* Store the link in a new variable. */
			var current_link = links[link_index];

			/* Define a regexp to check if the protocol is http(s). */
			regexp_protocol = /^(http(s)?)/;

			/* Check so that the link's protocol is http(s). */
			if(regexp_protocol.test(current_link.href))
			{
				/* Define a regexp to check if the domain is other then foretagsgruppen.net. */
				var regexp_domain = /^(http:\/\/(www.)?foretagsgruppen.net)/;

				/* Check if the links domain is other then foretagsgruppen.net. */
				if(!regexp_domain.test(current_link.href))
				{
					/* Add the external class. */
					current_link.className += " external";

					/* Add an onclick to open external links in new window. */
					current_link.setAttribute("onclick", "if(window.open(this.href, 'external')) return false");
				}
			}
			/* Else if the link was not an http(s). */
			else
			{
				/* Define a regexp to check if the link is a sip-link. */
				var regexp_sip = /^sip:/;

				/* Check if the link is a sip-link. */
				if(regexp_sip.test(current_link.href))
				{
					/* Add the sip class. */
					current_link.className += " sip";
				}

				/* Define a regexp to check if the link is a mailto-link. */
				var regexp_mail = /^mailto:/;

				/* Check if the link is a mailto-link. */
				if(regexp_mail.test(current_link.href))
				{
					/* Add the mail class. */
					current_link.className += " mail";
				}
			}
		}
	}
}

/* Run fix_links() on page load. */
window.onload = fix_links;
