IsMSIE = navigator.appVersion.indexOf('MSIE') != '-1';

// Open popup window
function openWindow(url, iwidth, iheight) {
  var params = 'resizable,width='+iwidth+',height='+iheight
  popupWin = window.open(url, 'popup', params)
}


// Create spider proof email addresses
// Use this code in the body: <SCRIPT language=javascript>generateAntiSpiderEmail('user', 'domain', 'tld', 'display text');</SCRIPT>
function generateAntiSpiderEmail(Username, DomainName, TLD, Text) {
	EmailAddress = Username + "&#64;" + DomainName + "." + TLD;

	if (!(Text)) {DisplayText = EmailAddress}
	else {DisplayText = Text}; 

	document.write("<a href=\"ma" + "il" + "to:" + EmailAddress + "\">" + DisplayText + "</a>");
}


// Populate the Mini Tartan Finder
function buildArray() {
  var a = buildArray.arguments;
  for (i=0; i<a.length; i++) {
    this[i] = a[i];
  }
  this.length = a.length;
}

// Open the Mini Tartan Finder Window
function OpenFinder(form) {
  n = form.tartan.selectedIndex;
  if (n != 0) {
    popupWin = window.open('http://www.kilts.biz/tartan_finder/' + urls[n], 'viewer', 'resizable,width=320,height=250');
  }
}

// Close the Mini Tartan Finder Window
function KillFinder() {
  if (self.popupWin) {
    self.popupWin.close()
  }
}



// Is this MSIE?
IsCrappyMicroshaftBrowser = navigator.appVersion.indexOf('MSIE') != -1;

// ASSIGNS A JAVASCRIPT EVENT TO A SPECIFIED OBJECT ACCORDING TO THE BROWSER
function setEvent(Obj, Event, Action) {

	// For IE, use attachEvent
	if (IsCrappyMicroshaftBrowser) {
		eval("Obj.attachEvent('" + Event.toLowerCase() + "', function() { " + Action + " });");
	}

	// For proper browsers, simply use setAttribute
	else
		Obj.setAttribute(Event, Action);
}


// Function to create image overlay
function enlargeImg(ImgSrc, ImgLabel, ImgText) {
	
	IsYoutubeVideo    = ImgSrc.substr(0,9) == 'YOUTUBE:';
	IsBrightCoveVideo = ImgSrc.substr(0,11) == 'BRIGHTCOVE:';

	with (document) {
		NewContainerDiv	= createElement('div');
		NewDisableDiv	= createElement('div');
		NewImg		= createElement('img');
		NewXImg		= createElement('img');
		ImgTextElmnt	= createTextNode(ImgText);
		NewTextContainerDiv = createElement('div');
	}
	
	with (NewImg) {
		src		= ImgSrc;
		style.margin	= '0px 0px 20px 0px';
		style.cursor	= 'pointer';
		style.display	= 'block';
	
		TmpLabel = ImgLabel + ' [click to close]';		
		setAttribute('alt', TmpLabel);
		setAttribute('title', TmpLabel);
		setAttribute('id', 'MainImg');
	}
	
	with (NewXImg) {
		src = 'x.gif';
		
		style.position	= 'absolute';
		style.margin	= '-35px 0px 0px ' + ((IsMSIE && (IsYoutubeVideo || IsBrightCoveVideo))?'5':NewImg.width+5) + 'px';
		style.cursor	= 'pointer';
		
		setAttribute('width', '30');
		setAttribute('height', '35');
		setAttribute('alt', 'close');
		setAttribute('title', 'close');
		setAttribute('id', 'XImg');
	}
	
	setEvent(NewImg, 'onClick', 'closeImg()');
	setEvent(NewXImg, 'onClick', 'closeImg()');
	
	if (NewImg.width == 0 && !IsYoutubeVideo && !IsBrightCoveVideo) {
		setTimeout('enlargeImg("' + ImgSrc + '", "' + ImgLabel + '", "' + ImgText + '")', 500);
		return;
	}
	else if (IsYoutubeVideo || IsBrightCoveVideo)
		NewImg.width = 425;
	
	NewTextContainerDiv.style.width = NewImg.width;

	setLeft = (Math.round(document.body.clientWidth / 2)*1)/1 - ((NewImg.width + 10) / 2);
	setLeft = ((String(setLeft).indexOf('.') == -1)?String(setLeft):String(setLeft).substr(0, String(setLeft).lastIndexOf('.'))) + 'px';
	
	setTop = String(document.body.scrollTop + 35) + 'px';
	
	with (NewContainerDiv) {
		setAttribute('id', 'MainImgContainer');
		
		style.position	= 'absolute';
		style.top	= setTop;
		style.left	= setLeft;
		style.zIndex	= '2';
		style.background= '#FFFFFF';
		style.fontFamily= 'Arial';
		style.fontSize	= '12px';
		style.padding   = '20px'; 
	}
	
	with (NewDisableDiv.style) {
		top        = '0px';
		left       = '0px';
		width      = '100%';
		position   = 'absolute';
		height     = String(document.body.scrollHeight) + 'px';
		background = '#000000';
		zIndex     = '1';
		
		if (IsMSIE) {
			//toggleSelectMenuVisibility(true, 'hidden');
			filter = 'alpha(opacity=75)';
		}
		else {
			setProperty('-moz-opacity', '.75', ''); 
			setProperty('opacity', '.75', '');			
		}			
	}
	
	NewDisableDiv.setAttribute('id', 'DisableDiv');
	
	with (document.body) {
		appendChild(NewDisableDiv);
		appendChild(NewContainerDiv);
	}
	
	if (IsYoutubeVideo) {
		NewContainerDiv.innerHTML
		= '<object width="425" height="344" style="margin-bottom: 20px"><param name="movie" value="' + ImgSrc.substr(9) + '"></param>'
		+ '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>'
		+ '<embed src="' + ImgSrc.substr(9) + '" type="application/x-shockwave-flash" width="425" height="344" allowscriptaccess="always" '
		+ 'allowfullscreen="true" style="margin-bottom: 20px"></embed></object>';
		
		NewContainerDiv.appendChild(NewXImg);
	}
	
	else if (IsBrightCoveVideo) {
	
		VideoVars = ImgSrc.substr(11).split('|');
				
		NewContainerDiv.innerHTML
		= '<object id="flashObj" width="486" height="412" style="margin-bottom: 20px" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0">'
  		+ '<param name="movie" value="' + VideoVars[0] + '" />'
  		+ '<param name="bgcolor" value="#FFFFFF" />'
  		+ '<param name="flashVars" value="' + VideoVars[1] + '" />'
  		+ '<param name="base" value="http://admin.brightcove.com" />'
  		+ '<param name="seamlesstabbing" value="false" />'
  		+ '<param name="allowFullScreen" value="true" />'
  		+ '<param name="swLiveConnect" value="true" />'
  		+ '<param name="allowScriptAccess" value="always" /><embed style="margin-bottom: 15px" src="' + VideoVars[0] + '" bgcolor="#FFFFFF" flashvars="' + VideoVars[1] + '" base="http://admin.brightcove.com" '
		+ 'name="flashObj" width="486" height="412" seamlesstabbing="false" type="application/x-shockwave-flash" allowfullscreen="true" swliveconnect="true" allowscriptaccess="always" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
		+ '</object>';
		
		NewContainerDiv.appendChild(NewXImg);
	}
	
	else {
		NewContainerDiv.appendChild(NewXImg);
		NewContainerDiv.appendChild(NewImg);
	}
	
	NewContainerDiv.appendChild(NewTextContainerDiv);
	NewTextContainerDiv.appendChild(ImgTextElmnt);
}

/*
// Function to create image overlay
function enlargeImg(ImgSrc, ImgLabel) {

	with (document) {
		NewContainerDiv	= createElement('div');
		NewDisableDiv	= createElement('div');
		NewImg		= createElement('img');
		NewXImg		= createElement('img');
	}

	with (NewImg) {
		src		= ImgSrc;
		style.margin	= '15px';
		style.cursor	= 'pointer';
		style.display	= 'block';

		TmpLabel = ImgLabel + ' [click to close]';
		setAttribute('alt', TmpLabel);
		setAttribute('title', TmpLabel);
		setAttribute('id', 'MainImg');
	}

	with (NewXImg) {
		src = 'http://www.blueskyop.com/images/x.gif';

		style.position	= 'absolute';
		style.cursor	= 'pointer';

		if (IsCrappyMicroshaftBrowser)
			style.margin = '-30px 10px 0px ' + (NewImg.width-0) + 'px';
		else
			style.margin	= '-15px 10px 0px ' + (NewImg.width+15) + 'px';

		setAttribute('width', '30');
		setAttribute('height', '35');
		setAttribute('alt', 'close');
		setAttribute('title', 'close');
		setAttribute('id', 'XImg');
	}

	setEvent(NewImg, 'onClick', 'closeImg()');
	setEvent(NewXImg, 'onClick', 'closeImg()');

	if (NewImg.width == 0) {
		setTimeout('enlargeImg("' + ImgSrc + '", "' + ImgLabel + '")', 500);
		return;
	}

	setLeft = (Math.round(document.body.clientWidth / 2)*1)/1 - ((NewImg.width + 10) / 2);
	setLeft = (String(setLeft).lastIndexOf('.') != '-1')
		  ?String(setLeft).substr(0, String(setLeft).lastIndexOf('.')):String(setLeft) + 'px';

	setTop = String(document.body.scrollTop + 35) + 'px';

	with (NewContainerDiv) {
		setAttribute('id', 'MainImgContainer');

		style.position	= 'absolute';
		style.top	= setTop;
		style.left	= setLeft;
		style.zIndex	= '2';
		style.background= '#FFFFFF';

		if (IsCrappyMicroshaftBrowser)
			style.paddingTop= '15px';
	}

	with (NewDisableDiv.style) {
		top        = '0px';
		left       = '0px';
		width      = '100%';
		position   = 'absolute';
		height     = String(document.body.scrollHeight) + 'px';
		background = '#204052';
		zIndex     = '1';

		if (IsCrappyMicroshaftBrowser) {
			//toggleSelectMenuVisibility(true, 'hidden');
			filter = 'alpha(opacity=75)';
		}
		else {
			setProperty('-moz-opacity', '.75', '');
			setProperty('opacity', '.75', '');
		}
	}

	NewDisableDiv.setAttribute('id', 'DisableDiv');

	with (document.body) {
		appendChild(NewDisableDiv);
		appendChild(NewContainerDiv);
	}

	NewContainerDiv.appendChild(NewXImg);
	NewContainerDiv.appendChild(NewImg);
}
*/

// Function to close overlay
function closeImg() {
	with (NewContainerDiv) {
		try { removeChild(document.getElementById('MainImg')); } catch (e) { }
		removeChild(document.getElementById('XImg'));
	}

	with (document.body) {
		removeChild(document.getElementById('DisableDiv'));
		removeChild(document.getElementById('MainImgContainer'));
	}
}