﻿/**
 * The Startup object is a collection of initialization functions for each page. Initialization
 * functions are registered to the Startup object using Startup.register( function ). These 
 * functions are then called at window.onload in the order that they were registered. Initialization
 * functions must take no parameters. A workaround for this would be to have the functions be attached
 * to objects containing all necessary parameters preset.
 */
var Startup = new Object();
Startup.registered = new Array();

Startup.init = function()
{
	for( i = 0; i < this.registered.length; i++ )
		this.registered[i]();
}

Startup.register = function( callback )
{
	this.registered.push( callback );
}

window.onload = function() { Startup.init() };

// Find all external links, and set them to open in a new window
Startup.register(
	function()
	{
		// Base URL info, change to suit URL
		var URL_BASE = "http://www.invconcepts.com/";
		var SSL_BASE = "https://www.invconcepts.com/";

		if( !document.getElementsByTagName )
			return;

		var links = document.getElementsByTagName( "a" );
		for( var i = 0; i < links.length; i++ )
		{
			var href = links[i].getAttribute( "href" );
			// Check for an empty link, if so, skip
			if( href == null || href == "" )
				continue;

			// Check for a local link, except PDFs, if so, skip
			if( ( href.match( /^(\.\.?)?\//gi ) || href.match( URL_BASE ) || href.match( SSL_BASE ) ) && !href.match( /\.pdf/gi ) )
				continue;

			// Set onclick to open new window, and prevent following the link
			links[i].onclick = function()
			{
				window.open( this.getAttribute( "href" ) );
				return false;
			};
		}
	}
);
