// ===================================================================
// Functions used by the showArticles portlet for the various icons
// it has.
// ===================================================================

function emailArticle(url) 
{
    window.open(url, '_blank');
}

function emailCurrentPage(url) 
{
    window.open(url, '_blank');
}

function printArticle(url) 
{
    window.open(url, '_blank');
}

function printCurrentPage(url) 
{
    window.print();
}

function saveArticle(url)
{
    window.open(url, '_blank');
}

function saveCurrentPage(url)
{
	document.execCommand("SaveAs");
}

function zoomInOnArticle(url)
{
	if (resizeFont("Articles-Headline", 2)) {
		resizeFont("Articles-Author", 2);
		resizeFont("Articles-Text", 2);
	}
}

function zoomOutOnArticle(url) 
{
	if (resizeFont("Articles-Headline", -2)) {
		resizeFont("Articles-Author", -2);
		resizeFont("Articles-Text", -2);
	}
}

// -------------------------------------------------------------------
// Increases, or reduces the font-size of an object with the given ID
// tag value.
// -------------------------------------------------------------------
 function resizeFont(id, change) 
 {
  	var elem = document.getElementById(id);
 	var size = getStyle(elem, 'font-size');  

   	if (size) 
   	{
 		var str = '' + size;
	 	var pos = str.indexOf('pt');

	 	if (pos < 0)
	 		pos = str.indexOf('px');
	 	
	 	if (pos >= 0)
	 	{	
 			var num  = 1 * str.substring(0, pos);
 			var type = str.substring(pos, str.length);
 			
 			num += change;
   			elem.style.fontSize = num + type;
   			return true;
   		}
   		else
   		{
   			if (change > 0)
   			{
			 	if (str == 'xx-small')		elem.style.fontSize = 'x-small';
			 	else if (str == 'x-small')	elem.style.fontSize = 'small';
			 	else if (str == 'small')	elem.style.fontSize = 'medium';
			 	else if (str == 'medium')	elem.style.fontSize = 'large';
			 	else if (str == 'large')	elem.style.fontSize = 'x-large';
			 	else if (str == 'x-large')	return false;
   			}
   			else
   			{
			 	if (str == 'x-small')		return false;
			 	else if (str == 'small')	elem.style.fontSize = 'x-small';
			 	else if (str == 'medium')	elem.style.fontSize = 'small';
			 	else if (str == 'large')	elem.style.fontSize = 'medium';
			 	else if (str == 'x-large')	elem.style.fontSize = 'large';
			 	else if (str == 'xx-large')	elem.style.fontSize = 'x-large';
   			}
   		}
   		return true;
   	}
}

// -------------------------------------------------------------------
// Retrieves the current style of a given object.  The style can be
// inline or from a CSS.
// This function is from: http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
// -------------------------------------------------------------------
function getStyle(oElm, strCssRule)
{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle)
	{
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle)
	{
		try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
				return p1.toUpperCase();
			});
			strValue = oElm.currentStyle[strCssRule];
		}
		catch(e){
			// Used to prevent an error in IE 5.0
		}
	}
	return strValue;
}

