var MN = {
	
	init:function() 
	{
		if(!document.getElementById || !document.getElementsByTagName)
		{
			return;
    	}
    	
    	MN.printFriendlyPage();	

	},
	
	loadPopup:function(link, elemId, addOverlay)
	{
		var popup = document.createElement("div");
		popup.id  = elemId;
	
		var iFrame    = document.createElement("iframe");
		iFrame.id     = "MN_iframe";
		iFrame.name   = "MN_iframe";
		iFrame.width  = '100%';
		iFrame.height = '100%';
		iFrame.src    = link;
		
		document.body.insertBefore(popup, document.body.firstChild);
		
		popup.appendChild(iFrame);
		
		//if(window.frames['MN_iframe'].document.getElementById('popcloses'))
		//{
		//	alert('s');
		//}
	
		//center the window
		var popupWidth  = -(popup.offsetWidth / 2);
		var popupHeight = -(popup.offsetHeight / 2);
		popup.style.marginLeft = popupWidth  + 'px';
		popup.style.marginTop  = popupHeight + 'px';
		
		if(addOverlay == true)
		{
			MN.overlay();
		}
	},

	unloadPopup:function(elemId)
	{
		while(document.getElementById(elemId))
		{
			document.body.removeChild(document.body.firstChild);
		}
	},
	
	overlay:function()
	{
		var body = document.body;
		var div  = document.createElement("div");
		div.id   = "MN_overlay";
		
		body.insertBefore(div, body.firstChild);
	
		div.style.position        = 'absolute';
		div.style.backgroundColor = '#000000';
		div.style.opacity         = '0.50';
		div.style.top             = '0px';
		div.style.left            = '0px';
		div.style.height          = '100%';
		div.style.width           = '100%';
		div.style.zIndex          = 999;
		
		if(body.scrollTop)
		{
			div.style.height = body.offsetHeight + body.scrollTop  + 'px';
		}
		
		/*window.onscroll = function()
		{
			if(body.scrollTop)
			{
				overlayDiv.style.height= body.offsetHeight + body.scrollTop + 'px';
			}
			else {
				overlayDiv.style.height= '100%';
			}
		}*/
	},
	
	fade:function(eID, startOpacity, stopOpacity, duration) 
	{
    	var speed = Math.round(duration / 100);
    	var timer = 0;
    	if (startOpacity < stopOpacity)
    	{ // fade in
        	for (var i=startOpacity; i<=stopOpacity; i++) 
        	{
            	setTimeout("MN.setOpacity('"+eID+"',"+i+")", timer * speed);
            	timer++;
        	} return;
    	}
    		for (var i=startOpacity; i>=stopOpacity; i--) 
    		{ // fade out
        		setTimeout("MN.setOpacity('"+eID+"',"+i+")", timer * speed);
        		timer++;
    		}
	},
	
	setOpacity:function(eID, opacityLevel) 
	{
    	var eStyle = document.getElementById(eID).style;
    	eStyle.opacity = opacityLevel / 100;
    	eStyle.filter = 'alpha(opacity='+opacityLevel+')';
	},
	
	printFriendlyPage:function()
	{
		if(document.getElementById('print_page'))
		{
			var dimensions = document.getElementById('print_page').className.split('_');
			var scroll 	   = (dimensions[2] == 'scroll') ? ',scrollbars=YES' : '';
			
			document.getElementById('print_page').onclick = function()
			{
				window.open(document.getElementById("print_page").href,'','width=800,height=600' + scroll +',resizable=1');
				
				return false;
			}
		}
	}
}

addHandler('load', window, MN.init);

function addHandler(whichEvent, whichObject, attachThis){

	if(document.addEventListener){

		whichObject.addEventListener(whichEvent, attachThis, 0);
	}
	else if(document.attachEvent){

		whichObject.attachEvent("on"+whichEvent, attachThis);
	}
}

function addToFavorites() {
  	if (window.external) {
   		window.external.AddFavorite('http://www.regalfish.co.uk','Regal Fish Supplies');
 	}
  	else { 
   		alert("Sorry! Your browser doesn't support this function.");
  	}
 }
 
function productSearch() 
{
	var search;
	
	if(document.getElementById('search_text'))
	{
		search = document.getElementById('search_text');
		
		search.onfocus = function() 
		{
			if(search.value == 'Search:')
			{
				search.value = '';
			}
		}
	}	
	
	if(document.getElementById('searchButton'))
	{
		document.getElementById('searchButton').onclick = function() 
		{
			if(search.value == 'Search:' || search.value == '')
			{
				alert('Please enter a search query');
				return false;
			}
			
			document.getElementById('searchform').submit();
		}
	}
}

 
function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
