IsMSIE  = navigator.appVersion.indexOf('MSIE') != -1;
IsMSIE7 = navigator.appVersion.indexOf('MSIE 7') != -1;
IsMSIE8 = navigator.appVersion.indexOf('MSIE 8') != -1;

// Generates email address "safe" from harvesters
// <SCRIPT language=javascript>generateAntiSpiderEmail('user', 'domain', 'tld', 'display_text');</SCRIPT>
function generateAntiSpiderEmail(Username, DomainName, TLD, Text, ExtraTagStr) {
	Address = Username + "&#64;" + DomainName + "." + TLD;

	if (!(Text)) {DisplayText = Address}
	else {DisplayText = Text};

	document.write("<a href=\"ma" + "il" + "to:" + Address + "\"" + ExtraTagStr + ">" + DisplayText + "</a>");
}


// Function to create image overlay
// Supports embedding a youtube video with VIDEOSRC:http://www.youtube.com/...
function overlayImgOpen(ImgSrc, ImgLabel, ImgText) {
	
	IsYoutubeVideo = ImgSrc.substr(0,9) == 'VIDEOSRC:';

	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 = 'images/x.gif';
		
		style.position	= 'absolute';
		style.margin	= '-35px 0px 0px ' + ((IsMSIE7 && IsYoutubeVideo)?'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', 'overlayImgClose()');
	setEvent(NewXImg, 'onClick', 'overlayImgClose()');
	
	if (NewImg.width == 0 && !IsYoutubeVideo) {
		setTimeout('overlayImgOpen("' + ImgSrc + '", "' + ImgLabel + '", "' + ImgText + '")', 500);
		return;
	}
	else if (IsYoutubeVideo)
		NewImg.width = 425;
	
	NewTextContainerDiv.style.width = NewImg.width + 'px';

	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'; //String(document.documentElement.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=50)';
		}
		else {
			setProperty('-moz-opacity', '.50', ''); 
			setProperty('opacity', '.50', '');			
		}			
	}
	
	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 {
		NewContainerDiv.appendChild(NewXImg);
		NewContainerDiv.appendChild(NewImg);
	}
	
	NewContainerDiv.appendChild(NewTextContainerDiv);
	NewTextContainerDiv.innerHTML = ImgText;
}

// Function to close overlay
function overlayImgClose() {	
	with (document.body) {
		removeChild(document.getElementById('DisableDiv'));
		removeChild(document.getElementById('MainImgContainer'));
	}
}


// ASSIGNS A JAVASCRIPT EVENT TO A SPECIFIED OBJECT ACCORDING TO THE BROWSER
function setEvent(Obj, Event, Action) {
	
	// For IE, use attachEvent
	if (IsMSIE) {
		eval("Obj.attachEvent('" + Event.toLowerCase() + "', function() { " + Action + " });");
	}
	
	// For proper browsers, simply use setAttribute
	else
		Obj.setAttribute(Event, Action);
}

