var currentFontSize;
var step				= 10;
var tableWidthStep 		= 20;
var minimumSize 		= 100;

function onLoad(checklist)
{			
	loadCurrentFontSize();
	setFontSize(checklist);		
}

function loadCurrentFontSize()
{
	current = getCookie("ELP_BI_FONT_SIZE");
	if (current != null)
	{
		currentFontSize = parseInt(current);
	}
	else
	{
		currentFontSize = 100;
	}	
}

function saveCurrentFontSize()
{
	setCookie("ELP_BI_FONT_SIZE", currentFontSize, 20);
}

function increaseFontSize(checklist) 
{		
	if (currentFontSize < minimumSize)
	{
		currentFontSize = 100;
	}
	currentFontSize += step;
	setFontSize(checklist);
	saveCurrentFontSize();
}

function decreaseFontSize(checklist) 
{	
	//DecreaseTableWidth();
	if (currentFontSize  > minimumSize)
	{
		currentFontSize -= step;	
		setFontSize(checklist);
		saveCurrentFontSize();
	}
}

function setFontSize(checklist)
{			
	changeElementFontSize('p', 		currentFontSize);
	changeElementFontSize('h1', 	currentFontSize);
	changeElementFontSize('h2', 	currentFontSize);
	changeElementFontSize('h3', 	currentFontSize);
	changeElementFontSize('input', 	currentFontSize);	
	changeElementFontSize('select',	currentFontSize);
	
	changeElementFontSize('table', 	currentFontSize);
	if (!checklist)
	{
		changeElementFontSize('div', 	currentFontSize);
	}
	else
	{
		changeElementFontSize('span', 	currentFontSize);
	}
	
}

function changeElementFontSize(element, newFontSize)
{
	var elementCollection = document.getElementsByTagName(element);	
	for( i = 0; i < elementCollection.length; i++) 
	{		
		elementCollection[i].style.fontSize = newFontSize + '%';				
    }
}
function IncreaseTableWidth()
{
	var elementCollection = document.getElementsByTagName('table');	
	for( i = 0; i < elementCollection.length; i++) 
	{						
		var oldSize = elementCollection[i].width;
		oldSize = oldSize.replace(/%/, "");
		var newSize = oldSize*1 + tableWidthStep*1;				
		elementCollection[i].width = newSize + '%';		
		alert(newSize);
    }
}

function DecreaseTableWidth()
{
	var elementCollection = document.getElementsByTagName('table');	
	for( i = 0; i < elementCollection.length; i++) 
	{						
		var oldSize = elementCollection[i].width;
		oldSize = oldSize.replace(/%/, "W3Schools");
		var newSize = oldSize*1 - tableWidthStep*1;				
		if (newSize > 0)
		{		
			elementCollection[i].width = newSize + '%';
			alert(newSize);
		}
    }
}

function setCookie(c_name, value, expiredays)
{	
	var exdate 		= new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	eraseCookie(c_name);
	document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +  ';path=/;';
	
}

function eraseCookie(name)
{
	document.cookie = name+"=0; expires= -1;";
}

function getCookie( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) 
	{
		return null;
	}
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function OnChangeLanguage(dropdown)
{		
	var dropdown		= document.getElementById("slcLanguages");		
	var selectedIndex 	= dropdown.selectedIndex;
	var selectedValue 	= dropdown.options[selectedIndex].value;				
	top.location.href 	= "?lang=" + selectedValue;
    
    return true;
}

function OpenLinkInNewWindow(link)
{
	window.open(link,'','scrollbars=no,menubar=no,height=300,width=300,resizable=yes,toolbar=no,location=no,status=no');	
}
